Compare commits
55 commits
1b6767b703
...
6e4bb3729f
Author | SHA1 | Date | |
---|---|---|---|
6e4bb3729f | |||
32be1999e9 | |||
Cayo Puigdefabregas | d638b12d39 | ||
Cayo Puigdefabregas | 4e9df475c3 | ||
Cayo Puigdefabregas | dcf2e43d57 | ||
Cayo Puigdefabregas | 4b9875157c | ||
Cayo Puigdefabregas | f1b3941e57 | ||
cayop | 4453095657 | ||
Cayo Puigdefabregas | 0c36e12da6 | ||
Cayo Puigdefabregas | 59d99fa434 | ||
Cayo Puigdefabregas | 3b70a6c7cc | ||
cayop | b620079da7 | ||
Cayo Puigdefabregas | 017dc818da | ||
Cayo Puigdefabregas | e0929c03c7 | ||
Cayo Puigdefabregas | 3e967c5a1a | ||
Cayo Puigdefabregas | 533bee30ec | ||
Cayo Puigdefabregas | a6d077aa2d | ||
Cayo Puigdefabregas | 1ef48b3dd8 | ||
Cayo Puigdefabregas | 36fe3310a3 | ||
cayop | 0a9596d33b | ||
Cayo Puigdefabregas | 3e7b5c1df5 | ||
Cayo Puigdefabregas | e0258cbf02 | ||
Cayo Puigdefabregas | 1abd846922 | ||
cayop | 355355dcfc | ||
Cayo Puigdefabregas | 35bf1a65a2 | ||
Cayo Puigdefabregas | 472d61bdc2 | ||
Cayo Puigdefabregas | 124395a313 | ||
Cayo Puigdefabregas | 693dbc639c | ||
55e85e5a3e | |||
Cayo Puigdefabregas | 898846b1df | ||
Cayo Puigdefabregas | 13ba92a6fc | ||
cayop | 74d6126c0b | ||
Cayo Puigdefabregas | 2f17d01780 | ||
Cayo Puigdefabregas | 2b4b469b0e | ||
Cayo Puigdefabregas | aa31aefb42 | ||
029640347d | |||
Cayo Puigdefabregas | 665fbf852a | ||
Cayo Puigdefabregas | 9dfaf0f60b | ||
Cayo Puigdefabregas | b8ab991a4f | ||
94470cbdd1 | |||
b47b5d3b4b | |||
e96afda483 | |||
f39cdefc75 | |||
dffe663e05 | |||
cayop | 76457893f5 | ||
cayop | fc0bb95017 | ||
fae8882c21 | |||
cayop | ce80d1f3c2 | ||
1a28e071e9 | |||
e2f5358d83 | |||
58c0e9059a | |||
e3b0d70f04 | |||
5b84d81590 | |||
b5b90c50f6 | |||
6399739228 |
235
LICENSE
Normal file
235
LICENSE
Normal file
|
@ -0,0 +1,235 @@
|
|||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
"Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of the GNU Affero General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
workbench-script
|
||||
Copyright (C) 2024 ereuse
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see <http://www.gnu.org/licenses/>.
|
19
README.md
19
README.md
|
@ -1,21 +1,20 @@
|
|||
# INSTALACION:
|
||||
# INSTALACIÓN:
|
||||
|
||||
la instalacion es muy estandar
|
||||
La instalación es muy estándar
|
||||
|
||||
```
|
||||
python -m venv env
|
||||
source env/bin/actevate
|
||||
python install -r requirements.txt
|
||||
python -m venv env
|
||||
source env/bin/actevate
|
||||
python install -r requirements.txt
|
||||
```
|
||||
|
||||
## IMPORTANT EXTERNAL DEPENDETS
|
||||
## IMPORTANT EXTERNAL DEPENDENCIES
|
||||
|
||||
Para arrancarlo es necesario tener el paquete xapian-bindings en tu ordenador. No se instala por pip asi que depende de cada sistema operativo:
|
||||
https://xapian.org/download
|
||||
Para arrancarlo es necesario tener el paquete `xapian-bindings` en tu ordenador. No se instala mediante `pip`, así que depende de cada [sistema operativo](https://xapian.org/download).
|
||||
|
||||
Luego solo necesitas:
|
||||
|
||||
```
|
||||
./manage.py migrate
|
||||
./manage.py runserver
|
||||
./manage.py migrate
|
||||
./manage.py runserver
|
||||
```
|
||||
|
|
0
admin/__init__.py
Normal file
0
admin/__init__.py
Normal file
3
admin/admin.py
Normal file
3
admin/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
6
admin/apps.py
Normal file
6
admin/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AdminConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "admin"
|
0
admin/migrations/__init__.py
Normal file
0
admin/migrations/__init__.py
Normal file
3
admin/models.py
Normal file
3
admin/models.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
19
admin/templates/admin_panel.html
Normal file
19
admin/templates/admin_panel.html
Normal file
|
@ -0,0 +1,19 @@
|
|||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h3>{{ subtitle }}</h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<a href="{% url 'admin:institution' user.institution.pk %}" class="btn btn-green-admin">
|
||||
{% translate "Institution" %}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
39
admin/templates/admin_users.html
Normal file
39
admin/templates/admin_users.html
Normal file
|
@ -0,0 +1,39 @@
|
|||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h3>{{ subtitle }}</h3>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<a href="{% url 'admin:new_user' %}" class="btn btn-green-admin">{% translate "Add new user" %}</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Email</th>
|
||||
<th>is Admin</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
{% for u in users %}
|
||||
<td>{{ u.email }}</td>
|
||||
<td>{{ u.is_admin }}</td>
|
||||
<td><a href="{% url 'admin:edit_user' u.pk %}"><i class="bi bi-eye"></i></td>
|
||||
<td><a href="{% url 'admin:delete_user' u.pk %}" class="text-danger" title="Remove"><i class="bi bi-trash"></i></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
38
admin/templates/delete_user.html
Normal file
38
admin/templates/delete_user.html
Normal file
|
@ -0,0 +1,38 @@
|
|||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h3>{{ subtitle }}</h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% load django_bootstrap5 %}
|
||||
<div class="row mb-3">
|
||||
<div class="col">
|
||||
Are you sure than want remove the lot {{ object.name }} with {{ object.devices.count }} devices.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form role="form" method="post">
|
||||
{% csrf_token %}
|
||||
{% if form.errors %}
|
||||
<div class="alert alert-danger alert-icon alert-icon-border alert-dismissible" role="alert">
|
||||
<div class="icon"><span class="mdi mdi-close-circle-o"></span></div>
|
||||
<div class="message">
|
||||
{% for field, error in form.errors.items %}
|
||||
{{ error }}<br />
|
||||
{% endfor %}
|
||||
<button class="btn-close" type="button" data-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% bootstrap_form form %}
|
||||
<div class="form-actions-no-box">
|
||||
<a class="btn btn-grey" href="{% url 'admin:users' %}">{% translate "Cancel" %}</a>
|
||||
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Delete' %}" />
|
||||
</div>
|
||||
|
||||
</form>
|
||||
{% endblock %}
|
32
admin/templates/institution.html
Normal file
32
admin/templates/institution.html
Normal file
|
@ -0,0 +1,32 @@
|
|||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h3>{{ subtitle }}</h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% load django_bootstrap5 %}
|
||||
<form role="form" method="post">
|
||||
{% csrf_token %}
|
||||
{% if form.errors %}
|
||||
<div class="alert alert-danger alert-icon alert-icon-border alert-dismissible" role="alert">
|
||||
<div class="icon"><span class="mdi mdi-close-circle-o"></span></div>
|
||||
<div class="message">
|
||||
{% for field, error in form.errors.items %}
|
||||
{{ error }}<br />
|
||||
{% endfor %}
|
||||
<button class="btn-close" type="button" data-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% bootstrap_form form %}
|
||||
<div class="form-actions-no-box">
|
||||
<a class="btn btn-grey" href="{% url 'admin:panel' %}">{% translate "Cancel" %}</a>
|
||||
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
|
||||
</div>
|
||||
|
||||
</form>
|
||||
{% endblock %}
|
32
admin/templates/user.html
Normal file
32
admin/templates/user.html
Normal file
|
@ -0,0 +1,32 @@
|
|||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h3>{{ subtitle }}</h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% load django_bootstrap5 %}
|
||||
<form role="form" method="post">
|
||||
{% csrf_token %}
|
||||
{% if form.errors %}
|
||||
<div class="alert alert-danger alert-icon alert-icon-border alert-dismissible" role="alert">
|
||||
<div class="icon"><span class="mdi mdi-close-circle-o"></span></div>
|
||||
<div class="message">
|
||||
{% for field, error in form.errors.items %}
|
||||
{{ error }}<br />
|
||||
{% endfor %}
|
||||
<button class="btn-close" type="button" data-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% bootstrap_form form %}
|
||||
<div class="form-actions-no-box">
|
||||
<a class="btn btn-grey" href="{% url 'admin:users' %}">{% translate "Cancel" %}</a>
|
||||
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
|
||||
</div>
|
||||
|
||||
</form>
|
||||
{% endblock %}
|
3
admin/tests.py
Normal file
3
admin/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
13
admin/urls.py
Normal file
13
admin/urls.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
from django.urls import path
|
||||
from admin import views
|
||||
|
||||
app_name = 'admin'
|
||||
|
||||
urlpatterns = [
|
||||
path("panel/", views.PanelView.as_view(), name="panel"),
|
||||
path("users/", views.UsersView.as_view(), name="users"),
|
||||
path("users/new", views.CreateUserView.as_view(), name="new_user"),
|
||||
path("users/edit/<int:pk>", views.EditUserView.as_view(), name="edit_user"),
|
||||
path("users/delete/<int:pk>", views.DeleteUserView.as_view(), name="delete_user"),
|
||||
path("institution/<int:pk>", views.InstitutionView.as_view(), name="institution"),
|
||||
]
|
118
admin/views.py
Normal file
118
admin/views.py
Normal file
|
@ -0,0 +1,118 @@
|
|||
from django.urls import reverse_lazy
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.views.generic.edit import (
|
||||
CreateView,
|
||||
UpdateView,
|
||||
DeleteView,
|
||||
)
|
||||
from dashboard.mixins import DashboardView, Http403
|
||||
from user.models import User, Institution
|
||||
|
||||
|
||||
class AdminView(DashboardView):
|
||||
def get(self, *args, **kwargs):
|
||||
response = super().get(*args, **kwargs)
|
||||
if not self.request.user.is_admin:
|
||||
raise Http403
|
||||
|
||||
return response
|
||||
|
||||
class PanelView(AdminView, TemplateView):
|
||||
template_name = "admin_panel.html"
|
||||
title = _("Admin")
|
||||
breadcrumb = _("admin") + " /"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
return context
|
||||
|
||||
|
||||
class UsersView(AdminView, TemplateView):
|
||||
template_name = "admin_users.html"
|
||||
title = _("Users")
|
||||
breadcrumb = _("admin / Users") + " /"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context.update({
|
||||
"users": User.objects.filter()
|
||||
})
|
||||
return context
|
||||
|
||||
|
||||
class CreateUserView(AdminView, CreateView):
|
||||
template_name = "user.html"
|
||||
title = _("User")
|
||||
breadcrumb = _("admin / User") + " /"
|
||||
success_url = reverse_lazy('admin:users')
|
||||
model = User
|
||||
fields = (
|
||||
"email",
|
||||
"password",
|
||||
"is_admin",
|
||||
)
|
||||
|
||||
def form_valid(self, form):
|
||||
form.instance.institution = self.request.user.institution
|
||||
form.instance.set_password(form.instance.password)
|
||||
response = super().form_valid(form)
|
||||
return response
|
||||
|
||||
|
||||
class DeleteUserView(AdminView, DeleteView):
|
||||
template_name = "delete_user.html"
|
||||
title = _("Delete user")
|
||||
breadcrumb = "admin / Delete user"
|
||||
success_url = reverse_lazy('admin:users')
|
||||
model = User
|
||||
fields = (
|
||||
"email",
|
||||
"password",
|
||||
"is_admin",
|
||||
)
|
||||
|
||||
def form_valid(self, form):
|
||||
response = super().form_valid(form)
|
||||
return response
|
||||
|
||||
|
||||
class EditUserView(AdminView, UpdateView):
|
||||
template_name = "user.html"
|
||||
title = _("Edit user")
|
||||
breadcrumb = "admin / Edit user"
|
||||
success_url = reverse_lazy('admin:users')
|
||||
model = User
|
||||
fields = (
|
||||
"email",
|
||||
"is_admin",
|
||||
)
|
||||
|
||||
def get_form_kwargs(self):
|
||||
pk = self.kwargs.get('pk')
|
||||
self.object = get_object_or_404(self.model, pk=pk)
|
||||
#self.object.set_password(self.object.password)
|
||||
kwargs = super().get_form_kwargs()
|
||||
return kwargs
|
||||
|
||||
|
||||
class InstitutionView(AdminView, UpdateView):
|
||||
template_name = "institution.html"
|
||||
title = _("Edit institution")
|
||||
section = "admin"
|
||||
subtitle = _('Edit institution')
|
||||
model = Institution
|
||||
success_url = reverse_lazy('admin:panel')
|
||||
fields = (
|
||||
"name",
|
||||
"logo",
|
||||
"location",
|
||||
"responsable_person",
|
||||
"supervisor_person"
|
||||
)
|
||||
|
||||
def get_form_kwargs(self):
|
||||
self.object = self.request.user.institution
|
||||
kwargs = super().get_form_kwargs()
|
||||
return kwargs
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 5.0.6 on 2024-09-19 15:09
|
||||
# Generated by Django 5.0.6 on 2024-10-10 11:34
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
|
@ -26,6 +26,7 @@ class Migration(migrations.Migration):
|
|||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("tag", models.CharField(max_length=50)),
|
||||
("token", models.UUIDField()),
|
||||
(
|
||||
"owner",
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
from django.db import models
|
||||
from user.models import User
|
||||
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class Token(models.Model):
|
||||
tag = models.CharField(max_length=50)
|
||||
token = models.UUIDField()
|
||||
owner = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
|
|
|
@ -33,12 +33,30 @@ class TokensTable(tables.Table):
|
|||
},
|
||||
orderable=False
|
||||
)
|
||||
|
||||
edit_token = ButtonColumn(
|
||||
linkify={
|
||||
"viewname": "api:edit_token",
|
||||
"args": [tables.A("pk")]
|
||||
},
|
||||
attrs = {
|
||||
"a": {
|
||||
"type": "button",
|
||||
"class": "text-primary",
|
||||
"title": "Remove",
|
||||
}
|
||||
},
|
||||
orderable=False,
|
||||
verbose_name="Edit"
|
||||
)
|
||||
token = tables.Column(verbose_name=_("Token"), empty_values=())
|
||||
tag = tables.Column(verbose_name=_("Tag"), empty_values=())
|
||||
|
||||
def render_view_user(self):
|
||||
return format_html('<i class="bi bi-eye"></i>')
|
||||
|
||||
def render_edit_token(self):
|
||||
return format_html('<i class="bi bi-pencil-square"></i>')
|
||||
|
||||
# def render_token(self, record):
|
||||
# return record.get_memberships()
|
||||
|
||||
|
@ -63,5 +81,5 @@ class TokensTable(tables.Table):
|
|||
class Meta:
|
||||
model = Token
|
||||
template_name = "custom_table.html"
|
||||
fields = ("token", "view_user")
|
||||
fields = ("token", "tag", "edit_token")
|
||||
|
||||
|
|
32
api/templates/new_token.html
Normal file
32
api/templates/new_token.html
Normal file
|
@ -0,0 +1,32 @@
|
|||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h3>{{ subtitle }}</h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% load django_bootstrap5 %}
|
||||
<form role="form" method="post">
|
||||
{% csrf_token %}
|
||||
{% if form.errors %}
|
||||
<div class="alert alert-danger alert-icon alert-icon-border alert-dismissible" role="alert">
|
||||
<div class="icon"><span class="mdi mdi-close-circle-o"></span></div>
|
||||
<div class="message">
|
||||
{% for field, error in form.errors.items %}
|
||||
{{ error }}<br />
|
||||
{% endfor %}
|
||||
<button class="btn-close" type="button" data-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% bootstrap_form form %}
|
||||
<div class="form-actions-no-box">
|
||||
<a class="btn btn-grey" href="{% url 'api:tokens' %}">{% translate "Cancel" %}</a>
|
||||
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
|
||||
</div>
|
||||
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -8,6 +8,7 @@
|
|||
{{ subtitle }}
|
||||
</h3>
|
||||
{% render_table table %}
|
||||
|
||||
<div class="form-actions-no-box">
|
||||
<a class="btn btn-green-admin" href="{% url 'api:new_token' %}">{% translate "Generate a new token" %} <i class="bi bi-plus"></i></a>
|
||||
</div>
|
||||
|
|
|
@ -9,5 +9,6 @@ urlpatterns = [
|
|||
path('snapshot/', views.NewSnapshot, name='new_snapshot'),
|
||||
path('tokens/', views.TokenView.as_view(), name='tokens'),
|
||||
path('tokens/new', views.TokenNewView.as_view(), name='new_token'),
|
||||
path("tokens/<int:pk>/edit", views.EditTokenView.as_view(), name="edit_token"),
|
||||
path('tokens/<int:pk>/del', views.TokenDeleteView.as_view(), name='delete_token'),
|
||||
]
|
||||
|
|
73
api/views.py
73
api/views.py
|
@ -1,13 +1,18 @@
|
|||
import json
|
||||
|
||||
from django.urls import reverse_lazy
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.views.generic.edit import DeleteView
|
||||
from django.views.generic.base import View
|
||||
from django.http import JsonResponse
|
||||
from django_tables2 import SingleTableView
|
||||
from django.views.generic.base import View
|
||||
from django.views.generic.edit import (
|
||||
CreateView,
|
||||
DeleteView,
|
||||
UpdateView,
|
||||
)
|
||||
from django.http import JsonResponse
|
||||
from uuid import uuid4
|
||||
|
||||
from dashboard.mixins import DashboardView
|
||||
|
@ -29,14 +34,14 @@ def NewSnapshot(request):
|
|||
return JsonResponse({'error': 'Invalid request method'}, status=400)
|
||||
|
||||
# Authentication
|
||||
# auth_header = request.headers.get('Authorization')
|
||||
# if not auth_header or not auth_header.startswith('Bearer '):
|
||||
# return JsonResponse({'error': 'Invalid or missing token'}, status=401)
|
||||
auth_header = request.headers.get('Authorization')
|
||||
if not auth_header or not auth_header.startswith('Bearer '):
|
||||
return JsonResponse({'error': 'Invalid or missing token'}, status=401)
|
||||
|
||||
# token = auth_header.split(' ')[1]
|
||||
# tk = Token.objects.filter(token=token).first()
|
||||
# if not tk:
|
||||
# return JsonResponse({'error': 'Invalid or missing token'}, status=401)
|
||||
token = auth_header.split(' ')[1]
|
||||
tk = Token.objects.filter(token=token).first()
|
||||
if not tk:
|
||||
return JsonResponse({'error': 'Invalid or missing token'}, status=401)
|
||||
|
||||
# Validation snapshot
|
||||
try:
|
||||
|
@ -60,9 +65,7 @@ def NewSnapshot(request):
|
|||
# save_in_disk(data, tk.user)
|
||||
|
||||
try:
|
||||
# Build(data, tk.user)
|
||||
user = User.objects.get(email="user@example.org")
|
||||
Build(data, user)
|
||||
Build(data, tk.owner)
|
||||
except Exception:
|
||||
return JsonResponse({'status': 'fail'}, status=200)
|
||||
|
||||
|
@ -89,7 +92,7 @@ class TokenView(DashboardView, SingleTableView):
|
|||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context.update({
|
||||
'tokens': Token.objects,
|
||||
'tokens': Token.objects.all(),
|
||||
})
|
||||
return context
|
||||
|
||||
|
@ -105,10 +108,42 @@ class TokenDeleteView(DashboardView, DeleteView):
|
|||
return redirect('api:tokens')
|
||||
|
||||
|
||||
class TokenNewView(DashboardView, View):
|
||||
class TokenNewView(DashboardView, CreateView):
|
||||
template_name = "new_token.html"
|
||||
title = _("Credential management")
|
||||
section = "Credential"
|
||||
subtitle = _('New Tokens')
|
||||
icon = 'bi bi-key'
|
||||
model = Token
|
||||
success_url = reverse_lazy('api:tokens')
|
||||
fields = (
|
||||
"tag",
|
||||
)
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
Token.objects.create(token=uuid4(), owner=self.request.user)
|
||||
def form_valid(self, form):
|
||||
form.instance.owner = self.request.user
|
||||
form.instance.token = uuid4()
|
||||
return super().form_valid(form)
|
||||
|
||||
return redirect('api:tokens')
|
||||
|
||||
|
||||
class EditTokenView(DashboardView, UpdateView):
|
||||
template_name = "new_token.html"
|
||||
title = _("Credential management")
|
||||
section = "Credential"
|
||||
subtitle = _('New Tokens')
|
||||
icon = 'bi bi-key'
|
||||
model = Token
|
||||
success_url = reverse_lazy('api:tokens')
|
||||
fields = (
|
||||
"tag",
|
||||
)
|
||||
|
||||
def get_form_kwargs(self):
|
||||
pk = self.kwargs.get('pk')
|
||||
self.object = get_object_or_404(
|
||||
self.model,
|
||||
owner=self.request.user,
|
||||
pk=pk,
|
||||
)
|
||||
kwargs = super().get_form_kwargs()
|
||||
return kwargs
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from django.urls import resolve
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.shortcuts import get_object_or_404, redirect, Http404
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
|
@ -45,10 +45,11 @@ class DashboardView(LoginRequiredMixin):
|
|||
|
||||
def get_session_devices(self):
|
||||
dev_ids = self.request.session.pop("devices", [])
|
||||
|
||||
|
||||
self._devices = []
|
||||
annotation = Annotation.objects.filter(value__in=dev_ids)
|
||||
for x in annotation.filter(owner=self.request.user.institution).distinct():
|
||||
for x in Annotation.objects.filter(value__in=dev_ids).filter(
|
||||
owner=self.request.user.institution
|
||||
).distinct():
|
||||
self._devices.append(Device(id=x.value))
|
||||
return self._devices
|
||||
|
||||
|
@ -57,7 +58,11 @@ class DetailsMixin(DashboardView, TemplateView):
|
|||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.pk = kwargs['pk']
|
||||
self.object = get_object_or_404(self.model, pk=self.pk, owner=self.request.user.institution)
|
||||
self.object = get_object_or_404(
|
||||
self.model,
|
||||
pk=self.pk,
|
||||
owner=self.request.user.institution
|
||||
)
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
|
@ -71,14 +76,46 @@ class DetailsMixin(DashboardView, TemplateView):
|
|||
class InventaryMixin(DashboardView, TemplateView):
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
dev_ids = dict(self.request.POST).get("devices", [])
|
||||
self.request.session["devices"] = dev_ids
|
||||
url = self.request.POST.get("url")
|
||||
post = dict(self.request.POST)
|
||||
url = post.get("url")
|
||||
|
||||
if url:
|
||||
dev_ids = post.get("devices", [])
|
||||
self.request.session["devices"] = dev_ids
|
||||
|
||||
try:
|
||||
resource = resolve(url)
|
||||
resource = resolve(url[0])
|
||||
if resource and dev_ids:
|
||||
return redirect(url)
|
||||
return redirect(url[0])
|
||||
except Exception:
|
||||
pass
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
limit = self.request.GET.get("limit")
|
||||
page = self.request.GET.get("page")
|
||||
try:
|
||||
limit = int(limit)
|
||||
page = int(page)
|
||||
if page < 1:
|
||||
page = 1
|
||||
if limit < 1:
|
||||
limit = 10
|
||||
except:
|
||||
limit = 10
|
||||
page = 1
|
||||
|
||||
offset = (page - 1) * limit
|
||||
devices, count = self.get_devices(self.request.user, offset, limit)
|
||||
total_pages = (count + limit - 1) // limit
|
||||
|
||||
context.update({
|
||||
'devices': devices,
|
||||
'count': count,
|
||||
"limit": limit,
|
||||
"offset": offset,
|
||||
"page": page,
|
||||
"total_pages": total_pages,
|
||||
})
|
||||
return context
|
||||
|
|
|
@ -61,12 +61,12 @@
|
|||
<header class="navbar navbar-dark sticky-top admin bg-green flex-md-nowrap p-0 shadow">
|
||||
<a class="navbar-brand col-md-3 col-lg-2 me-0 px-3" href="#">DEVICEHUB</a>
|
||||
<div class="navbar-nav navbar-sub-brand">
|
||||
PANGEA
|
||||
{{ user.institution.name|upper }}
|
||||
</div>
|
||||
<div class="navbar-nav">
|
||||
<div class="nav-item text-nowrap">
|
||||
<i id="user-avatar" class="bi bi-person-circle"></i>
|
||||
<a class="navbar-sub-brand px-3" href="#">{{ user.email }}</a>
|
||||
<a class="navbar-sub-brand px-3" href="{% url 'user:panel' %}">{{ user.email }}</a>
|
||||
<a class="logout" href="{% url 'login:logout' %}">
|
||||
<i class="fa-solid fa-arrow-right-from-bracket"></i>
|
||||
</a>
|
||||
|
@ -79,6 +79,26 @@
|
|||
<nav id="sidebarMenu" class="col-md-3 col-lg-2 d-md-block bg-light sidebar collapse">
|
||||
<div class="position-sticky pt-5">
|
||||
<ul class="nav flex-column">
|
||||
{% if user.is_admin %}
|
||||
<li class="nav-item">
|
||||
<a class="admin {% if path in 'panel users' %}active {% endif %}nav-link fw-bold" data-bs-toggle="collapse" data-bs-target="#ul_admin" aria-expanded="false" aria-controls="ul_admin" href="javascript:void()">
|
||||
<i class="bi bi-person-fill-gear icon_sidebar"></i>
|
||||
{% trans 'Admin' %}
|
||||
</a>
|
||||
<ul class="flex-column mb-2 ul_sidebar accordion-collapse {% if path in 'panel users' %}expanded{% else %}collapse{% endif %}" id="ul_admin" data-bs-parent="#sidebarMenu">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link{% if path == 'panel' %} active2{% endif %}" href="{% url 'admin:panel' %}">
|
||||
{% trans 'Panel' %}
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link{% if path == 'users' %} active2{% endif %}" href="{% url 'admin:users' %}">
|
||||
{% trans 'Users' %}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="nav-item">
|
||||
<a class="admin {% if path == 'unassigned_devices' %}active {% endif %}nav-link fw-bold" data-bs-toggle="collapse" data-bs-target="#ul_devices" aria-expanded="false" aria-controls="ul_devices" href="javascript:void()">
|
||||
<i class="bi bi-laptop icon_sidebar"></i>
|
||||
|
@ -143,12 +163,6 @@
|
|||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link fw-bold" href="{% url 'api:tokens' %}">
|
||||
<i class="bi-menu-button-wide icon_sidebar"></i>
|
||||
{% trans 'Tokens' %}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
@ -165,7 +179,19 @@
|
|||
{% endblock messages %}
|
||||
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2">
|
||||
<h1 class="h2">{{ title }}</h1>
|
||||
|
||||
<form method="post" action="{% url 'dashboard:search' %}">
|
||||
{% csrf_token %}
|
||||
<div class="input-group rounded">
|
||||
<input type="search" name="search" class="form-control rounded" placeholder="Search your device..." aria-label="Search" aria-describedby="search-addon" />
|
||||
<span class="input-group-text border-0" id="search-addon">
|
||||
<i class="fas fa-search"></i>
|
||||
</span>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="row border-bottom mb-3">
|
||||
<div class="col">
|
||||
<small style="color:#899bbd"><i>{{ breadcrumb }}</i></small>
|
||||
|
|
|
@ -1,213 +0,0 @@
|
|||
{% load i18n static %}
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
{% block head %}
|
||||
{% block meta %}
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="robots" content="NONE,NOARCHIVE" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="Pangea">
|
||||
{% endblock %}
|
||||
<title>{% block title %}{% if title %}{{ title }} – {% endif %}DeviceHub{% endblock %}</title>
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
{% block style %}
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
|
||||
<link rel="stylesheet" href= "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
|
||||
<link href="{% static "/css/bootstrap.min.css" %}" rel="stylesheet">
|
||||
|
||||
<style>
|
||||
.bd-placeholder-img {
|
||||
font-size: 1.125rem;
|
||||
text-anchor: middle;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.bd-placeholder-img-lg {
|
||||
font-size: 3.5rem;
|
||||
}
|
||||
}
|
||||
html, body {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.main-content {
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
footer {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="{% static "/css/dashboard.css" %}" rel="stylesheet">
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
<header class="navbar navbar-dark sticky-top admin bg-green flex-md-nowrap p-0 shadow">
|
||||
<a class="navbar-brand col-md-3 col-lg-2 me-0 px-3" href="#">DEVICE HUB</a>
|
||||
<div class="navbar-nav navbar-sub-brand">
|
||||
PANGEA
|
||||
</div>
|
||||
<div class="navbar-nav">
|
||||
<div class="nav-item text-nowrap">
|
||||
<i id="user-avatar" class="bi bi-person-circle"></i>
|
||||
<a class="navbar-sub-brand px-3" href="#">{{ user.email }}</a>
|
||||
<a class="logout" href="{% url 'login:logout' %}">
|
||||
<i class="fa-solid fa-arrow-right-from-bracket"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<nav id="sidebarMenu" class="col-md-3 col-lg-2 d-md-block bg-light sidebar collapse">
|
||||
<div class="position-sticky pt-5">
|
||||
<ul class="nav flex-column">
|
||||
<li class="nav-item">
|
||||
<a class="admin nav-link {% if section == 'Home' %}active {% endif %}fw-bold" href="{% url 'dashboard:dashboard' %}">
|
||||
<i class="bi bi-house-door icon_sidebar"></i>
|
||||
{% trans 'Dashboard' %}
|
||||
</a>
|
||||
<hr />
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="admin {% if section == 'People' %}active {% endif %}nav-link fw-bold" data-bs-toggle="collapse" data-bs-target="#people" aria-expanded="false" aria-controls="people" href="javascript:void()">
|
||||
<i class="bi bi-people icon_sidebar"></i>
|
||||
{% trans 'Users' %}
|
||||
</a>
|
||||
<ul class="flex-column mb-2 ul_sidebar accordion-collapse {% if section == 'People' %}expanded{% else %}collapse{% endif %}" id="people" data-bs-parent="#sidebarMenu">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link{% if path == 'admin_people_list' %} active2{% endif %}" href="{# url 'idhub:admin_people_list' #}">
|
||||
{% trans 'View users' %}
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link{% if path == 'admin_people_new' %} active2{% endif %}" href="{# url 'idhub:admin_people_new' #}">
|
||||
{% trans 'Add user' %}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="admin nav-link {% if section == 'AccessControl' %}active {% endif %}fw-bold" data-bs-toggle="collapse" data-bs-target="#control-access" aria-expanded="false" aria-controls="control-access" href="javascript:void()">
|
||||
<i class="fa-solid fa-arrow-right-from-bracket icon_sidebar"></i>
|
||||
{% trans 'Roles' %}
|
||||
</a>
|
||||
<ul class="flex-column mb-2 ul_sidebar accordion-collapse {% if section == 'AccessControl' %}expanded{% else %}collapse{% endif %}" id="control-access" data-bs-parent="#sidebarMenu">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link{% if path == 'admin_roles' %} active2{% endif %}" href="{# url 'idhub:admin_roles' #}">
|
||||
{% trans 'Manage roles' %}
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link{% if path == 'admin_services' %} active2{% endif %}" href="{# url 'idhub:admin_services' #}">
|
||||
{% trans 'Manage services' %}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="admin nav-link {% if section == 'Credential' %}active {% endif %}fw-bold" data-bs-toggle="collapse" data-bs-target="#credential" aria-expanded="false" aria-controls="credential" href="javascript:void()">
|
||||
<i class="bi bi-patch-check icon_sidebar"></i>
|
||||
{% trans 'Credentials' %}
|
||||
</a>
|
||||
<ul class="flex-column mb-2 ul_sidebar accordion-collapse {% if section == 'Credential' %}expanded{% else %}collapse{% endif %}" id="credential" data-bs-parent="#sidebarMenu">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link{% if path == 'admin_credentials' %} active2{% endif %}" href="{# url 'idhub:admin_credentials' #}">
|
||||
{% trans 'View credentials' %}
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a id="wallet" class="nav-link" data-bs-toggle="collapse" data-bs-target="#lwallet" aria-expanded="false" aria-controls="lwallet" href="javascript:void()">
|
||||
{% trans "Organization's wallet" %}
|
||||
</a>
|
||||
<ul class="flex-column mb-2 accordion-collapse {% if wallet %}expanded{% else %}collapse{% endif %}" id="lwallet" data-bs-parent="#wallet">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link{% if path == 'admin_dids' %} active2{% endif %}" href="{# url 'idhub:admin_dids' #}">
|
||||
{% trans 'Manage Identities (DIDs)' %}
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link{% if path == 'admin_wallet_credentials' %} active2{% endif %}" href="{# url 'idhub:admin_wallet_credentials' #}">
|
||||
{% trans 'View org. credentials' %}
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link{% if path == 'admin_wallet_config_issue' %} active2{% endif %}" href="{# url 'idhub:admin_wallet_config_issue' #}">
|
||||
{% trans 'Configure credential issuance' %}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="admin nav-link {% if section == 'Templates' %}active {% endif %}fw-bold" href="{# url 'idhub:admin_schemas' #}">
|
||||
<i class="bi bi-file-earmark-text icon_sidebar"></i>
|
||||
{% trans 'Templates' %}
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="admin nav-link {% if section == 'ImportExport' %}active {% endif %}fw-bold" href="{# url 'idhub:admin_import' #}">
|
||||
<i class="bi bi-arrow-down-square icon_sidebar"></i>
|
||||
{% trans 'Data' %}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
|
||||
{% block messages %}
|
||||
{% for message in messages %}
|
||||
<div class="alert {{ message.tags|default:'info' }} alert-dismissible fade show mt-3" role="alert">
|
||||
{{ message }}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close">
|
||||
</button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endblock messages %}
|
||||
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||
<h1 class="h2">{{ title }}</h1>
|
||||
<div class="btn-toolbar mb-2 mb-md-0">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% block content %}
|
||||
{% endblock content %}
|
||||
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Footer -->
|
||||
<footer class="footer text-center mt-auto py-3">
|
||||
<div class="container">
|
||||
<span class="text-muted">{{ commit_id }}</span>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
{% block script %}
|
||||
<script src="{% static "js/jquery-3.3.1.slim.min.js" %}"></script>
|
||||
<script src="{% static "js/popper.min.js" %}"></script>
|
||||
<script src="{% static "js/bootstrap.min.js" %}"></script>
|
||||
{% block extrascript %}{% endblock %}
|
||||
{% endblock %}
|
||||
</body>
|
||||
</html>
|
47
dashboard/templates/pagination.html
Normal file
47
dashboard/templates/pagination.html
Normal file
|
@ -0,0 +1,47 @@
|
|||
{% load i18n %}
|
||||
{% load range %}
|
||||
|
||||
<ul class="pagination">
|
||||
{% if page_number > 1 %}
|
||||
<li class="previous">
|
||||
<a type="button" class="btn btn-grey border border-dark" href="?page=1&limit={{ limit }}">
|
||||
«
|
||||
</a>
|
||||
</li>
|
||||
<li class="previous">
|
||||
<a type="button" class="btn btn-grey border border-dark" href="?page={{ page_number|add:-1 }}&limit={{ limit }}">
|
||||
{% trans 'Previous' %}
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% if total_pages > 1 %}
|
||||
|
||||
{% for p in total_pages|range_filter:page_number %}
|
||||
<li {% if p == page_number %}class="active"{% endif %}>
|
||||
<a type="button" class="btn btn-grey{% if p == page_number %}-selected{% endif %}
|
||||
border border-dark"
|
||||
{% if p == page_number or p == "..." %}
|
||||
href="#">
|
||||
{% else %}
|
||||
href="?page={{ p }}&limit={{ limit }}">
|
||||
{% endif %}
|
||||
{{ p }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% if page_number < total_pages %}
|
||||
<li class="previous">
|
||||
<a type="button" class="btn btn-grey border border-dark" href="?page={{ page_number|add:+1 }}&limit={{ limit }}">
|
||||
{% trans 'Next' %}
|
||||
</a>
|
||||
</li>
|
||||
<li class="previous">
|
||||
<a type="button" class="btn btn-grey border border-dark" href="?page={{ total_pages }}&limit={{ limit }}">
|
||||
»
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
|
@ -1,5 +1,7 @@
|
|||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
{% load paginacion %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
|
@ -33,7 +35,19 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<th scope="col" data-sortable="">
|
||||
<a class="dataTable-sorter" href="#">Title</a>
|
||||
select
|
||||
</th>
|
||||
<th scope="col" data-sortable="">
|
||||
shortid
|
||||
</th>
|
||||
<th scope="col" data-sortable="">
|
||||
type
|
||||
</th>
|
||||
<th scope="col" data-sortable="">
|
||||
manufacturer
|
||||
</th>
|
||||
<th scope="col" data-sortable="">
|
||||
model
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -45,14 +59,28 @@
|
|||
</td>
|
||||
<td>
|
||||
<a href="{% url 'device:details' dev.id %}">
|
||||
{{ dev.type }} {{ dev.manufacturer }} {{ dev.model }}
|
||||
{{ dev.shortid }}
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
{{ dev.type }}
|
||||
</td>
|
||||
<td>
|
||||
{{ dev.manufacturer }}
|
||||
</td>
|
||||
<td>
|
||||
{{ dev.model }}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
{% endfor %}
|
||||
</table>
|
||||
<button type="submit" value="{% url 'lot:del_devices' %}" name="url">Remove</button> <button type="submit" name="url" value="{% url 'lot:add_devices' %}">add</button>
|
||||
<button class="btn btn-green-admin" type="submit" value="{% url 'lot:del_devices' %}" name="url">Remove</button> <button class="btn btn-green-admin" type="submit" name="url" value="{% url 'lot:add_devices' %}">add</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="row mt-3">
|
||||
<div class="col">
|
||||
{% render_pagination page total_pages limit %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
0
dashboard/templatetags/__init__.py
Normal file
0
dashboard/templatetags/__init__.py
Normal file
20
dashboard/templatetags/paginacion.py
Normal file
20
dashboard/templatetags/paginacion.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from django import template
|
||||
|
||||
register = template.Library()
|
||||
|
||||
@register.inclusion_tag('pagination.html')
|
||||
def render_pagination(page_number, total_pages, limit=10):
|
||||
"""
|
||||
Template tag for render pagination
|
||||
|
||||
Args:
|
||||
- page_number: number of actual page
|
||||
- total_pages: total pages.
|
||||
|
||||
Use it template: {% render_pagination page_number total_pages %}
|
||||
"""
|
||||
return {
|
||||
'page_number': page_number,
|
||||
'total_pages': total_pages,
|
||||
'limit': limit
|
||||
}
|
23
dashboard/templatetags/range.py
Normal file
23
dashboard/templatetags/range.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
from django import template
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@register.filter
|
||||
def range_filter(value, page):
|
||||
m = 11
|
||||
mind = page -1 - m // 2
|
||||
maxd = page + 1 + m // 2
|
||||
if mind < 0:
|
||||
maxd += abs(mind)
|
||||
if maxd > value:
|
||||
mind -= abs(maxd-value-1)
|
||||
total_pages = [x for x in range(1, value + 1) if maxd > x > mind]
|
||||
|
||||
if value > m:
|
||||
if total_pages[0] > 1:
|
||||
total_pages = ["..."] + total_pages
|
||||
if total_pages[-1] < value:
|
||||
total_pages = total_pages + ["..."]
|
||||
|
||||
return total_pages
|
|
@ -6,4 +6,5 @@ app_name = 'dashboard'
|
|||
urlpatterns = [
|
||||
path("", views.UnassignedDevicesView.as_view(), name="unassigned_devices"),
|
||||
path("<int:pk>/", views.LotDashboardView.as_view(), name="lot"),
|
||||
path("search", views.SearchView.as_view(), name="search"),
|
||||
]
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
import json
|
||||
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic.edit import FormView
|
||||
from django.shortcuts import Http404
|
||||
from django.db.models import Q
|
||||
|
||||
from dashboard.mixins import InventaryMixin, DetailsMixin
|
||||
from evidence.models import Annotation
|
||||
from evidence.xapian import search
|
||||
from device.models import Device
|
||||
from lot.models import Lot
|
||||
|
||||
|
@ -10,15 +18,8 @@ class UnassignedDevicesView(InventaryMixin):
|
|||
title = _("Unassigned Devices")
|
||||
breadcrumb = "Devices / Unassigned Devices"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
devices = Device.get_unassigned(self.request.user.institution)
|
||||
|
||||
context.update({
|
||||
'devices': devices,
|
||||
})
|
||||
|
||||
return context
|
||||
def get_devices(self, user, offset, limit):
|
||||
return Device.get_unassigned(self.request.user.institution, offset, limit)
|
||||
|
||||
|
||||
class LotDashboardView(InventaryMixin, DetailsMixin):
|
||||
|
@ -30,14 +31,75 @@ class LotDashboardView(InventaryMixin, DetailsMixin):
|
|||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
devices = self.get_devices()
|
||||
lot = context.get('object')
|
||||
context.update({
|
||||
'devices': devices,
|
||||
'lot': lot,
|
||||
})
|
||||
return context
|
||||
|
||||
def get_devices(self):
|
||||
chids = self.object.devicelot_set.all().values_list("device_id", flat=True).distinct()
|
||||
return [Device(id=x) for x in chids]
|
||||
def get_devices(self, user, offset, limit):
|
||||
chids = self.object.devicelot_set.all().values_list(
|
||||
"device_id", flat=True
|
||||
).distinct()
|
||||
|
||||
chids_page = chids[offset:offset+limit]
|
||||
return [Device(id=x) for x in chids_page], chids.count()
|
||||
|
||||
|
||||
class SearchView(InventaryMixin):
|
||||
template_name = "unassigned_devices.html"
|
||||
section = "Search"
|
||||
title = _("Search Devices")
|
||||
breadcrumb = "Devices / Search Devices"
|
||||
|
||||
def get_devices(self, user, offset, limit):
|
||||
post = dict(self.request.POST)
|
||||
query = post.get("search")
|
||||
|
||||
if not query:
|
||||
return [], 0
|
||||
|
||||
matches = search(
|
||||
self.request.user.institution,
|
||||
query[0],
|
||||
offset,
|
||||
limit
|
||||
)
|
||||
|
||||
if not matches.size():
|
||||
return self.search_hids(query, offset, limit)
|
||||
|
||||
annotations = []
|
||||
for x in matches:
|
||||
annotations.extend(self.get_annotations(x))
|
||||
|
||||
devices = [Device(id=x) for x in set(annotations)]
|
||||
count = matches.size()
|
||||
return devices, count
|
||||
|
||||
def get_annotations(self, xp):
|
||||
snap = xp.document.get_data()
|
||||
uuid = json.loads(snap).get('uuid')
|
||||
|
||||
return Annotation.objects.filter(
|
||||
type=Annotation.Type.SYSTEM,
|
||||
owner=self.request.user.institution,
|
||||
uuid=uuid
|
||||
).values_list("value", flat=True).distinct()
|
||||
|
||||
def search_hids(self, query, offset, limit):
|
||||
qry = Q()
|
||||
|
||||
for i in query[0].split(" "):
|
||||
if i:
|
||||
qry |= Q(value__startswith=i)
|
||||
|
||||
chids = Annotation.objects.filter(
|
||||
type=Annotation.Type.SYSTEM,
|
||||
owner=self.request.user.institution
|
||||
).filter(
|
||||
qry
|
||||
).values_list("value", flat=True).distinct()
|
||||
chids_page = chids[offset:offset+limit]
|
||||
|
||||
return [Device(id=x) for x in chids_page], chids.count()
|
||||
|
|
|
@ -23,7 +23,7 @@ DEVICE_TYPES = [
|
|||
class DeviceForm(forms.Form):
|
||||
type = forms.ChoiceField(choices = DEVICE_TYPES, required=False)
|
||||
amount = forms.IntegerField(required=False, initial=1)
|
||||
customer_id = forms.CharField(required=False)
|
||||
custom_id = forms.CharField(required=False)
|
||||
name = forms.CharField(required=False)
|
||||
value = forms.CharField(required=False)
|
||||
|
||||
|
@ -49,14 +49,14 @@ class BaseDeviceFormSet(forms.BaseFormSet):
|
|||
row["amount"] = d["amount"]
|
||||
if d.get("name"):
|
||||
row[d["name"]] = d.get("value", '')
|
||||
if d.get("customer_id"):
|
||||
row['CUSTOMER_ID']= d["customer_id"]
|
||||
if d.get("custom_id"):
|
||||
row['CUSTOM_ID']= d["custom_id"]
|
||||
|
||||
doc = create_doc(row)
|
||||
if not commit:
|
||||
return doc
|
||||
|
||||
create_index(doc)
|
||||
create_index(doc, self.user)
|
||||
create_annotation(doc, user, commit=commit)
|
||||
return doc
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from django.db import models
|
||||
from django.db import models, connection
|
||||
|
||||
from utils.constants import STR_SM_SIZE, STR_SIZE, STR_EXTEND_SIZE, ALGOS
|
||||
from evidence.models import Annotation, Evidence
|
||||
|
@ -27,6 +27,7 @@ class Device:
|
|||
# the id is the chid of the device
|
||||
self.id = kwargs["id"]
|
||||
self.pk = self.id
|
||||
self.shortid = self.pk[:6]
|
||||
self.algorithm = None
|
||||
self.owner = None
|
||||
self.annotations = []
|
||||
|
@ -89,10 +90,10 @@ class Device:
|
|||
def get_hids(self):
|
||||
annotations = self.get_annotations()
|
||||
|
||||
self.hids = annotations.filter(
|
||||
self.hids = list(set(annotations.filter(
|
||||
type=Annotation.Type.SYSTEM,
|
||||
key__in=ALGOS.keys(),
|
||||
).values_list("value", flat=True)
|
||||
).values_list("value", flat=True)))
|
||||
|
||||
def get_evidences(self):
|
||||
if not self.uuids:
|
||||
|
@ -114,30 +115,59 @@ class Device:
|
|||
self.lots = [x.lot for x in DeviceLot.objects.filter(device_id=self.id)]
|
||||
|
||||
@classmethod
|
||||
def get_unassigned(cls, institution):
|
||||
chids = DeviceLot.objects.filter(lot__owner=institution).values_list("device_id", flat=True).distinct()
|
||||
annotations = Annotation.objects.filter(
|
||||
owner=institution,
|
||||
type=Annotation.Type.SYSTEM,
|
||||
).exclude(value__in=chids).values_list("value", flat=True).distinct()
|
||||
return [cls(id=x) for x in annotations]
|
||||
def get_unassigned(cls, institution, offset=0, limit=None):
|
||||
|
||||
# return cls.objects.filter(
|
||||
# owner=user
|
||||
# ).annotate(num_lots=models.Count('lot')).filter(num_lots=0)
|
||||
sql = """
|
||||
SELECT DISTINCT t1.value from evidence_annotation as t1
|
||||
left join lot_devicelot as t2 on t1.value = t2.device_id
|
||||
where t2.device_id is null and owner_id=={institution} and type=={type}
|
||||
""".format(
|
||||
institution=institution.id,
|
||||
type=Annotation.Type.SYSTEM,
|
||||
)
|
||||
if limit:
|
||||
sql += " limit {} offset {}".format(int(limit), int(offset))
|
||||
|
||||
sql += ";"
|
||||
|
||||
annotations = []
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute(sql)
|
||||
annotations = cursor.fetchall()
|
||||
|
||||
devices = [cls(id=x[0]) for x in annotations]
|
||||
count = cls.get_unassigned_count(institution)
|
||||
return devices, count
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_unassigned_count(cls, institution):
|
||||
|
||||
sql = """
|
||||
SELECT count(DISTINCT t1.value) from evidence_annotation as t1
|
||||
left join lot_devicelot as t2 on t1.value = t2.device_id
|
||||
where t2.device_id is null and owner_id=={institution} and type=={type};
|
||||
""".format(
|
||||
institution=institution.id,
|
||||
type=Annotation.Type.SYSTEM,
|
||||
)
|
||||
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute(sql)
|
||||
return cursor.fetchall()[0][0]
|
||||
|
||||
@property
|
||||
def is_websnapshot(self):
|
||||
if not self.last_evidence:
|
||||
self.get_last_evidence()
|
||||
return self.last_evidence.doc['type'] == "WebSnapshot"
|
||||
|
||||
return self.last_evidence.doc['type'] == "WebSnapshot"
|
||||
|
||||
@property
|
||||
def last_user_evidence(self):
|
||||
if not self.last_evidence:
|
||||
self.get_last_evidence()
|
||||
return self.last_evidence.doc['kv'].items()
|
||||
|
||||
|
||||
@property
|
||||
def manufacturer(self):
|
||||
if not self.last_evidence:
|
||||
|
@ -146,6 +176,9 @@ class Device:
|
|||
|
||||
@property
|
||||
def type(self):
|
||||
if self.last_evidence.doc['type'] == "WebSnapshot":
|
||||
return self.last_evidence.doc.get("device", {}).get("type", "")
|
||||
|
||||
if not self.last_evidence:
|
||||
self.get_last_evidence()
|
||||
return self.last_evidence.get_chassis()
|
||||
|
@ -161,5 +194,3 @@ class Device:
|
|||
if not self.last_evidence:
|
||||
self.get_last_evidence()
|
||||
return self.last_evidence.get_components()
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h3>{{ object.id }}</h3>
|
||||
<h3>{{ object.shortid }}</h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -40,15 +40,6 @@
|
|||
{% endif %}
|
||||
{{ form.management_form }}
|
||||
<div class="container" id="formset-container">
|
||||
<div class="row mb-2">
|
||||
<div class="col"></div>
|
||||
<div class="col-2 text-center">
|
||||
<a href="javascript:void()" onclick="addForm(this);" type="button" class="btn btn-green-admin">
|
||||
<i class="bi bi-plus"></i>
|
||||
{% trans 'Add' %}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-2">
|
||||
<div class="col">
|
||||
{% bootstrap_field form.0.type %}
|
||||
|
@ -61,7 +52,18 @@
|
|||
</div>
|
||||
<div class="row mb-2">
|
||||
<div class="col">
|
||||
{% bootstrap_field form.0.customer_id %}
|
||||
{% bootstrap_field form.0.custom_id %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-2">
|
||||
<div class="col-10">
|
||||
<span class="fw-bold">{% trans 'Component details' %}</span>
|
||||
</div>
|
||||
<div class="col-2 text-center">
|
||||
<a href="javascript:void()" onclick="addForm(this);" type="button" class="btn btn-green-admin text-nowrap">
|
||||
<i class="bi bi-plus"></i>
|
||||
{% trans 'Add component' %}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{% for f in form %}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import json
|
||||
|
||||
from django.http import Http404
|
||||
from django.urls import reverse_lazy
|
||||
from django.shortcuts import get_object_or_404, Http404
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
@ -9,9 +10,8 @@ from django.views.generic.edit import (
|
|||
FormView,
|
||||
)
|
||||
from django.views.generic.base import TemplateView
|
||||
from dashboard.mixins import DashboardView
|
||||
from dashboard.mixins import DashboardView, Http403
|
||||
from evidence.models import Annotation
|
||||
from evidence.xapian import search
|
||||
from lot.models import LotTag
|
||||
from device.models import Device
|
||||
from device.forms import DeviceFormSet
|
||||
|
@ -21,7 +21,7 @@ class NewDeviceView(DashboardView, FormView):
|
|||
template_name = "new_device.html"
|
||||
title = _("New Device")
|
||||
breadcrumb = "Device / New Device"
|
||||
success_url = reverse_lazy('device:add')
|
||||
success_url = reverse_lazy('dashboard:unassigned_devices')
|
||||
form_class = DeviceFormSet
|
||||
|
||||
def form_valid(self, form):
|
||||
|
@ -72,7 +72,11 @@ class EditDeviceView(DashboardView, UpdateView):
|
|||
|
||||
def get_form_kwargs(self):
|
||||
pk = self.kwargs.get('pk')
|
||||
self.object = get_object_or_404(self.model, pk=pk)
|
||||
self.object = get_object_or_404(
|
||||
self.model,
|
||||
pk=pk,
|
||||
owner=self.request.user.institution
|
||||
)
|
||||
self.success_url = reverse_lazy('device:details', args=[pk])
|
||||
kwargs = super().get_form_kwargs()
|
||||
return kwargs
|
||||
|
@ -89,6 +93,8 @@ class DetailsView(DashboardView, TemplateView):
|
|||
self.object = Device(id=self.pk)
|
||||
if not self.object.last_evidence:
|
||||
raise Http404
|
||||
if self.object.owner != self.request.user.institution:
|
||||
raise Http403
|
||||
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
|
@ -114,6 +120,7 @@ class AddAnnotationView(DashboardView, CreateView):
|
|||
|
||||
def form_valid(self, form):
|
||||
form.instance.owner = self.request.user.institution
|
||||
form.instance.user = self.request.user
|
||||
form.instance.uuid = self.annotation.uuid
|
||||
form.instance.type = Annotation.Type.USER
|
||||
response = super().form_valid(form)
|
||||
|
@ -123,10 +130,14 @@ class AddAnnotationView(DashboardView, CreateView):
|
|||
pk = self.kwargs.get('pk')
|
||||
institution = self.request.user.institution
|
||||
self.annotation = Annotation.objects.filter(
|
||||
owner=institution, value=pk, type=Annotation.Type.SYSTEM
|
||||
owner=institution,
|
||||
value=pk,
|
||||
type=Annotation.Type.SYSTEM
|
||||
).first()
|
||||
|
||||
if not self.annotation:
|
||||
get_object_or_404(Annotation, pk=0, owner=institution)
|
||||
raise Http404
|
||||
|
||||
self.success_url = reverse_lazy('device:details', args=[pk])
|
||||
kwargs = super().get_form_kwargs()
|
||||
return kwargs
|
||||
|
@ -142,6 +153,7 @@ class AddDocumentView(DashboardView, CreateView):
|
|||
|
||||
def form_valid(self, form):
|
||||
form.instance.owner = self.request.user.institution
|
||||
form.instance.user = self.request.user
|
||||
form.instance.uuid = self.annotation.uuid
|
||||
form.instance.type = Annotation.Type.DOCUMENT
|
||||
response = super().form_valid(form)
|
||||
|
@ -151,10 +163,14 @@ class AddDocumentView(DashboardView, CreateView):
|
|||
pk = self.kwargs.get('pk')
|
||||
institution = self.request.user.institution
|
||||
self.annotation = Annotation.objects.filter(
|
||||
owner=institution, value=pk, type=Annotation.Type.SYSTEM
|
||||
owner=institution,
|
||||
value=pk,
|
||||
type=Annotation.Type.SYSTEM
|
||||
).first()
|
||||
|
||||
if not self.annotation:
|
||||
get_object_or_404(Annotation, pk=0, owner=institution)
|
||||
raise Http404
|
||||
|
||||
self.success_url = reverse_lazy('device:details', args=[pk])
|
||||
kwargs = super().get_form_kwargs()
|
||||
return kwargs
|
||||
|
|
|
@ -42,7 +42,7 @@ CSRF_TRUSTED_ORIGINS = config('CSRF_TRUSTED_ORIGINS', default=f'https://{DOMAIN}
|
|||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
"django.contrib.admin",
|
||||
# "django.contrib.admin",
|
||||
"django.contrib.auth",
|
||||
"django.contrib.contenttypes",
|
||||
"django.contrib.sessions",
|
||||
|
@ -61,6 +61,7 @@ INSTALLED_APPS = [
|
|||
"lot",
|
||||
"documents",
|
||||
"dashboard",
|
||||
"admin",
|
||||
"api",
|
||||
]
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@ urlpatterns = [
|
|||
path("dashboard/", include("dashboard.urls")),
|
||||
path("evidence/", include("evidence.urls")),
|
||||
path("device/", include("device.urls")),
|
||||
path("admin/", include("admin.urls")),
|
||||
path("user/", include("user.urls")),
|
||||
path("lot/", include("lot.urls")),
|
||||
path('api/', include('api.urls')),
|
||||
]
|
||||
|
|
|
@ -9,11 +9,14 @@ set -u
|
|||
set -x
|
||||
|
||||
main() {
|
||||
if [ "${DETACH:-}" ]; then
|
||||
detach_arg='-d'
|
||||
fi
|
||||
# remove old database
|
||||
sudo rm -vf db/*
|
||||
docker compose down
|
||||
docker compose down -v
|
||||
docker compose build
|
||||
docker compose up
|
||||
docker compose up ${detach_arg:-}
|
||||
}
|
||||
|
||||
main "${@}"
|
||||
|
|
18
docs/es/manual.md
Normal file
18
docs/es/manual.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Evidencias
|
||||
|
||||
## Placeholder
|
||||
Introducción de evidencias a través de formulario web.
|
||||
|
||||
La *clave* representa el tipo de detalle que se quiere registrar y el *valor* representa lo que se quiere registrar. Véase la siguiente tabla con ejemplos.
|
||||
|
||||
| Clave | Valor |
|
||||
|-------------------------------|---------------------|
|
||||
| marca | Lenovo |
|
||||
| Tarjeta de red | RealTech 1000 |
|
||||
| Pantalla | Samsung |
|
||||
| Dimensiones de pantalla | 15' |
|
||||
| Detalles visuales de pantalla | Rota por un lateral |
|
||||
|
||||
## Snapshots
|
||||
|
||||
Introducción de evidencias a través de programa [workbench-script](https://farga.pangea.org/ereuse/workbench-script)
|
80
docs/es/modelo-datos.md
Normal file
80
docs/es/modelo-datos.md
Normal file
|
@ -0,0 +1,80 @@
|
|||
Modelo de datos *abstracto* de devicehub que ayuda a tener una idea de cómo funciona
|
||||
|
||||
Recordad que por ser este un proyecto de django, se puede obtener de forma automatizada un diagrama de datos con el comando `graph_models` (más adelante vemos de documentar mejor cómo generarlo)
|
||||
|
||||
```mermaid
|
||||
erDiagram
|
||||
|
||||
%% los snapshots/placeholders son ficheros de FS inmutables, se insertan en xapian
|
||||
%% y via su uuid se anotan
|
||||
%% placeholders también se pueden firmar (como un spnashot, otra fuente)
|
||||
EVIDENCE {
|
||||
json obj "its uuid is the PK"
|
||||
}
|
||||
|
||||
USER {
|
||||
int id PK
|
||||
string personal-data-etc
|
||||
}
|
||||
|
||||
%% includes the relevant CHID with algorithm for the device build
|
||||
EVIDENCE_ANNOTATION {
|
||||
int id PK
|
||||
uuid uuid "ref evidence (snapshot,placeholder)"
|
||||
string key
|
||||
string value
|
||||
int type "0: sys_deviceid, 1: usr_deviceid, 2: user"
|
||||
ts created
|
||||
int owner FK
|
||||
}
|
||||
|
||||
ALGORITHM {
|
||||
string algorithm
|
||||
}
|
||||
|
||||
%% todas las anotaciones que tienen CHID
|
||||
%% y su key es un algoritmo de los que tenemos
|
||||
|
||||
%% un device es una evaluación
|
||||
|
||||
DEVICE {
|
||||
string CHID
|
||||
}
|
||||
|
||||
DEVICE_ANNOTATION {
|
||||
string CHID FK
|
||||
string key
|
||||
string value
|
||||
uuid uuid "from last snapshot"
|
||||
}
|
||||
|
||||
LOT {
|
||||
int id PK
|
||||
string name
|
||||
string code "id alt legacy"
|
||||
string description
|
||||
bool closed
|
||||
int owner FK
|
||||
ts created
|
||||
ts updated
|
||||
|
||||
}
|
||||
|
||||
LOT_ANNOTATION {
|
||||
string id FK
|
||||
string key
|
||||
string value
|
||||
}
|
||||
|
||||
SNAPSHOT ||--|| EVIDENCE: "via workbench"
|
||||
PLACEHOLDER ||--|| EVIDENCE: "via webform"
|
||||
|
||||
EVIDENCE ||--|{ EVIDENCE_ANNOTATION: "are interpreted"
|
||||
USER ||--|{ EVIDENCE_ANNOTATION: "manually entered"
|
||||
ALGORITHM ||--|{ EVIDENCE_ANNOTATION: "automatically entered"
|
||||
EVIDENCE_ANNOTATION }|--|{ DEVICE: "aggregates"
|
||||
DEVICE }|--|{ LOT: "aggregates"
|
||||
|
||||
DEVICE ||--|| DEVICE_ANNOTATION: "enriches data"
|
||||
LOT ||--|| LOT_ANNOTATION: "enriches data"
|
||||
```
|
|
@ -1,25 +0,0 @@
|
|||
from pathlib import Path
|
||||
|
||||
from pint import UnitRegistry
|
||||
|
||||
# Sets up the unit handling
|
||||
unit_registry = Path(__file__).parent / 'unit_registry'
|
||||
|
||||
unit = UnitRegistry()
|
||||
unit.load_definitions(str(unit_registry / 'quantities.txt'))
|
||||
TB = unit.TB
|
||||
GB = unit.GB
|
||||
MB = unit.MB
|
||||
Mbs = unit.Mbit / unit.s
|
||||
MBs = unit.MB / unit.s
|
||||
Hz = unit.Hz
|
||||
GHz = unit.GHz
|
||||
MHz = unit.MHz
|
||||
Inch = unit.inch
|
||||
mAh = unit.hour * unit.mA
|
||||
mV = unit.mV
|
||||
|
||||
base2 = UnitRegistry()
|
||||
base2.load_definitions(str(unit_registry / 'base2.quantities.txt'))
|
||||
|
||||
GiB = base2.GiB
|
|
@ -55,16 +55,20 @@ class UserTagForm(forms.Form):
|
|||
tag = forms.CharField(label=_("Tag"))
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.pk = None
|
||||
self.uuid = kwargs.pop('uuid', None)
|
||||
annotation = Annotation.objects.filter(
|
||||
self.user = kwargs.pop('user')
|
||||
instance = Annotation.objects.filter(
|
||||
uuid=self.uuid,
|
||||
type=Annotation.Type.SYSTEM,
|
||||
key='CUSTOM_ID',
|
||||
owner=self.user.institution
|
||||
).first()
|
||||
|
||||
if annotation:
|
||||
kwargs['initial'].update({'tag': annotation.value})
|
||||
|
||||
|
||||
if instance:
|
||||
kwargs["initial"]["tag"] = instance.value
|
||||
self.pk = instance.pk
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def clean(self):
|
||||
|
@ -72,18 +76,33 @@ class UserTagForm(forms.Form):
|
|||
if not data:
|
||||
return False
|
||||
self.tag = data
|
||||
self.instance = Annotation.objects.filter(
|
||||
uuid=self.uuid,
|
||||
type=Annotation.Type.SYSTEM,
|
||||
key='CUSTOM_ID',
|
||||
owner=self.user.institution
|
||||
).first()
|
||||
|
||||
return True
|
||||
|
||||
def save(self, user, commit=True):
|
||||
if not commit:
|
||||
return
|
||||
|
||||
if self.instance:
|
||||
if not self.tag:
|
||||
self.instance.delete()
|
||||
self.instance.value = self.tag
|
||||
self.instance.save()
|
||||
return
|
||||
|
||||
Annotation.objects.create(
|
||||
uuid=self.uuid,
|
||||
owner=user.institution,
|
||||
type=Annotation.Type.SYSTEM,
|
||||
key='CUSTOM_ID',
|
||||
value=self.tag
|
||||
value=self.tag,
|
||||
owner=self.user.institution,
|
||||
user=self.user
|
||||
)
|
||||
|
||||
|
||||
|
@ -112,12 +131,12 @@ class ImportForm(forms.Form):
|
|||
for n in data_pd.keys():
|
||||
if 'type' not in [x.lower() for x in data_pd[n]]:
|
||||
raise ValidationError("You need a column with name 'type'")
|
||||
|
||||
|
||||
for k, v in data_pd[n].items():
|
||||
if k.lower() == "type":
|
||||
if v not in Device.Types.values:
|
||||
raise ValidationError("{} is not a valid device".format(v))
|
||||
|
||||
|
||||
self.rows.append(data_pd[n])
|
||||
|
||||
return data
|
||||
|
@ -133,7 +152,7 @@ class ImportForm(forms.Form):
|
|||
if commit:
|
||||
for doc, cred in table:
|
||||
cred.save()
|
||||
create_index(doc)
|
||||
create_index(doc, self.user)
|
||||
return table
|
||||
|
||||
return
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 5.0.6 on 2024-07-27 16:23
|
||||
# Generated by Django 5.0.6 on 2024-10-10 09:46
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
|
@ -10,6 +10,7 @@ class Migration(migrations.Migration):
|
|||
initial = True
|
||||
|
||||
dependencies = [
|
||||
("user", "0001_initial"),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
|
@ -30,7 +31,9 @@ class Migration(migrations.Migration):
|
|||
("uuid", models.UUIDField()),
|
||||
(
|
||||
"type",
|
||||
models.SmallIntegerField(choices=[(0, "System"), (1, "User")]),
|
||||
models.SmallIntegerField(
|
||||
choices=[(0, "System"), (1, "User"), (2, "Document")]
|
||||
),
|
||||
),
|
||||
("key", models.CharField(max_length=256)),
|
||||
("value", models.CharField(max_length=256)),
|
||||
|
@ -38,6 +41,15 @@ class Migration(migrations.Migration):
|
|||
"owner",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to="user.institution",
|
||||
),
|
||||
),
|
||||
(
|
||||
"user",
|
||||
models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
# Generated by Django 5.0.6 on 2024-07-29 14:58
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("evidence", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="annotation",
|
||||
name="type",
|
||||
field=models.SmallIntegerField(
|
||||
choices=[(0, "System"), (1, "User"), (2, "Document"), (3, "Action")]
|
||||
),
|
||||
),
|
||||
]
|
|
@ -1,20 +0,0 @@
|
|||
# Generated by Django 5.0.6 on 2024-07-29 15:37
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("evidence", "0002_alter_annotation_type"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="annotation",
|
||||
name="type",
|
||||
field=models.SmallIntegerField(
|
||||
choices=[(0, "System"), (1, "User"), (2, "Document")]
|
||||
),
|
||||
),
|
||||
]
|
|
@ -1,22 +0,0 @@
|
|||
# Generated by Django 5.0.6 on 2024-09-18 10:55
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("evidence", "0003_alter_annotation_type"),
|
||||
("user", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="annotation",
|
||||
name="owner",
|
||||
field=models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE, to="user.institution"
|
||||
),
|
||||
),
|
||||
]
|
|
@ -6,7 +6,7 @@ from django.db import models
|
|||
from utils.constants import STR_SM_SIZE, STR_EXTEND_SIZE, CHASSIS_DH
|
||||
from evidence.xapian import search
|
||||
from evidence.parse_details import ParseSnapshot
|
||||
from user.models import Institution
|
||||
from user.models import User, Institution
|
||||
|
||||
|
||||
class Annotation(models.Model):
|
||||
|
@ -18,6 +18,7 @@ class Annotation(models.Model):
|
|||
created = models.DateTimeField(auto_now_add=True)
|
||||
uuid = models.UUIDField()
|
||||
owner = models.ForeignKey(Institution, on_delete=models.CASCADE)
|
||||
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
|
||||
type = models.SmallIntegerField(choices=Type)
|
||||
key = models.CharField(max_length=STR_EXTEND_SIZE)
|
||||
value = models.CharField(max_length=STR_EXTEND_SIZE)
|
||||
|
@ -56,8 +57,10 @@ class Evidence:
|
|||
|
||||
def get_doc(self):
|
||||
self.doc = {}
|
||||
if not self.owner:
|
||||
self.get_owner()
|
||||
qry = 'uuid:"{}"'.format(self.uuid)
|
||||
matches = search(qry, limit=1)
|
||||
matches = search(self.owner, qry, limit=1)
|
||||
if matches.size() < 0:
|
||||
return
|
||||
|
||||
|
@ -83,12 +86,24 @@ class Evidence:
|
|||
return self.components
|
||||
|
||||
def get_manufacturer(self):
|
||||
if self.doc.get("type") == "WebSnapshot":
|
||||
kv = self.doc.get('kv', {})
|
||||
if len(kv) < 1:
|
||||
return ""
|
||||
return list(self.doc.get('kv').values())[0]
|
||||
|
||||
if self.doc.get("software") != "EreuseWorkbench":
|
||||
return self.doc['device']['manufacturer']
|
||||
|
||||
return self.dmi.manufacturer().strip()
|
||||
|
||||
def get_model(self):
|
||||
if self.doc.get("type") == "WebSnapshot":
|
||||
kv = self.doc.get('kv', {})
|
||||
if len(kv) < 2:
|
||||
return ""
|
||||
return list(self.doc.get('kv').values())[1]
|
||||
|
||||
if self.doc.get("software") != "EreuseWorkbench":
|
||||
return self.doc['device']['model']
|
||||
|
||||
|
|
|
@ -5,13 +5,13 @@ import hashlib
|
|||
|
||||
from datetime import datetime
|
||||
from dmidecode import DMIParse
|
||||
from evidence.xapian import search, index
|
||||
from evidence.models import Annotation
|
||||
from evidence.xapian import index
|
||||
from utils.constants import ALGOS, CHASSIS_DH
|
||||
|
||||
|
||||
def get_network_cards(child, nets):
|
||||
if child['id'] == 'network':
|
||||
if child['id'] == 'network' and "PCI:" in child.get("businfo"):
|
||||
nets.append(child)
|
||||
if child.get('children'):
|
||||
[get_network_cards(x, nets) for x in child['children']]
|
||||
|
@ -49,7 +49,7 @@ class Build:
|
|||
|
||||
def index(self):
|
||||
snap = json.dumps(self.json)
|
||||
index(self.uuid, snap)
|
||||
index(self.user.institution, self.uuid, snap)
|
||||
|
||||
def generate_chids(self):
|
||||
self.algorithms = {
|
||||
|
@ -76,6 +76,7 @@ class Build:
|
|||
Annotation.objects.create(
|
||||
uuid=self.uuid,
|
||||
owner=self.user.institution,
|
||||
user=self.user,
|
||||
type=Annotation.Type.SYSTEM,
|
||||
key=k,
|
||||
value=v
|
||||
|
|
|
@ -66,8 +66,17 @@
|
|||
{% endif %}
|
||||
{% bootstrap_form form %}
|
||||
<div class="container">
|
||||
<a class="btn btn-grey" href="{% url 'dashboard:unassigned_devices' %}">{% translate "Cancel" %}</a>
|
||||
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<a class="btn btn-grey" href="">{% translate "Cancel" %}</a>
|
||||
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
|
||||
</div>
|
||||
{% if form.tag.value %}
|
||||
<div class="col-1">
|
||||
<a class="btn btn-yellow" href="{% url 'evidence:delete_annotation' form.pk %}">{% translate "Delete" %}</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
K = KiB = k = kb = KB
|
||||
M = MiB = m = mb = MB
|
||||
G = GiB = g = gb = GB
|
||||
T = TiB = t = tb = TB
|
|
@ -1,9 +0,0 @@
|
|||
HZ = hertz = hz
|
||||
KHZ = kilohertz = khz
|
||||
MHZ = megahertz = mhz
|
||||
GHZ = gigahertz = ghz
|
||||
B = byte = b = UNIT = unit
|
||||
KB = kilobyte = kb = K = k
|
||||
MB = megabyte = mb = M = m
|
||||
GB = gigabyte = gb = G = g
|
||||
T = terabyte = tb = T = t
|
|
@ -19,4 +19,5 @@ urlpatterns = [
|
|||
path("import", views.ImportView.as_view(), name="import"),
|
||||
path("<uuid:pk>", views.EvidenceView.as_view(), name="details"),
|
||||
path("<uuid:pk>/download", views.DownloadEvidenceView.as_view(), name="download"),
|
||||
path('annotation/<int:pk>/del', views.AnnotationDeleteView.as_view(), name='delete_annotation'),
|
||||
]
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
import json
|
||||
|
||||
from urllib.parse import urlparse
|
||||
from django.http import HttpResponse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.shortcuts import get_object_or_404, redirect, Http404
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.urls import reverse_lazy
|
||||
from django.urls import reverse_lazy, resolve
|
||||
from django.views.generic.edit import (
|
||||
DeleteView,
|
||||
FormView,
|
||||
)
|
||||
|
||||
|
||||
from dashboard.mixins import DashboardView, Http403
|
||||
from evidence.models import Evidence
|
||||
from evidence.models import Evidence, Annotation
|
||||
from evidence.forms import UploadForm, UserTagForm, ImportForm
|
||||
# from django.shortcuts import render
|
||||
# from rest_framework import viewsets
|
||||
|
@ -106,6 +110,7 @@ class EvidenceView(DashboardView, FormView):
|
|||
self.pk = self.kwargs.get('pk')
|
||||
kwargs = super().get_form_kwargs()
|
||||
kwargs['uuid'] = self.pk
|
||||
kwargs['user'] = self.request.user
|
||||
return kwargs
|
||||
|
||||
def form_valid(self, form):
|
||||
|
@ -135,3 +140,30 @@ class DownloadEvidenceView(DashboardView, TemplateView):
|
|||
response = HttpResponse(data, content_type="application/json")
|
||||
response['Content-Disposition'] = 'attachment; filename={}'.format("credential.json")
|
||||
return response
|
||||
|
||||
|
||||
class AnnotationDeleteView(DashboardView, DeleteView):
|
||||
model = Annotation
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.pk = kwargs['pk']
|
||||
|
||||
try:
|
||||
referer = self.request.META["HTTP_REFERER"]
|
||||
path_referer = urlparse(referer).path
|
||||
resolver_match = resolve(path_referer)
|
||||
url_name = resolver_match.view_name
|
||||
kwargs_view = resolver_match.kwargs
|
||||
except:
|
||||
# if is not possible resolve the reference path return 404
|
||||
raise Http404
|
||||
|
||||
self.object = get_object_or_404(
|
||||
self.model,
|
||||
pk=self.pk,
|
||||
owner=self.request.user.institution
|
||||
)
|
||||
self.object.delete()
|
||||
|
||||
|
||||
return redirect(url_name, **kwargs_view)
|
||||
|
|
|
@ -10,7 +10,7 @@ import xapian
|
|||
# indexer.set_stemmer(stemmer)
|
||||
|
||||
|
||||
def search(qs, offset=0, limit=10):
|
||||
def search(institution, qs, offset=0, limit=10):
|
||||
database = xapian.Database("db")
|
||||
|
||||
qp = xapian.QueryParser()
|
||||
|
@ -18,18 +18,21 @@ def search(qs, offset=0, limit=10):
|
|||
qp.set_stemmer(xapian.Stem("english"))
|
||||
qp.set_stemming_strategy(xapian.QueryParser.STEM_SOME)
|
||||
qp.add_prefix("uuid", "uuid")
|
||||
# qp.add_prefix("snapshot", "snapshot")
|
||||
query = qp.parse_query(qs)
|
||||
institution_term = "U{}".format(institution.id)
|
||||
final_query = xapian.Query(
|
||||
xapian.Query.OP_AND, query, xapian.Query(institution_term)
|
||||
)
|
||||
enquire = xapian.Enquire(database)
|
||||
enquire.set_query(query)
|
||||
enquire.set_query(final_query)
|
||||
matches = enquire.get_mset(offset, limit)
|
||||
return matches
|
||||
|
||||
|
||||
def index(uuid, snap):
|
||||
def index(institution, uuid, snap):
|
||||
uuid = 'uuid:"{}"'.format(uuid)
|
||||
try:
|
||||
matches = search(uuid, limit=1)
|
||||
matches = search(institution, uuid, limit=1)
|
||||
if matches.size() > 0:
|
||||
return
|
||||
except (xapian.DatabaseNotFoundError, xapian.DatabaseOpeningError):
|
||||
|
@ -47,5 +50,7 @@ def index(uuid, snap):
|
|||
indexer.index_text(snap)
|
||||
indexer.index_text(uuid, 10, "uuid")
|
||||
# indexer.index_text(snap, 1, "snapshot")
|
||||
institution_term = "U{}".format(institution.id)
|
||||
doc.add_term(institution_term)
|
||||
|
||||
database.add_document(doc)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% extends "auth/login_base.html" %}
|
||||
{% extends "login_base.html" %}
|
||||
{% load i18n django_bootstrap5 %}
|
||||
|
||||
{% block login_content %}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% extends "auth/login_base.html" %}
|
||||
{% extends "login_base.html" %}
|
||||
{% load i18n django_bootstrap5 %}
|
||||
|
||||
{% block login_content %}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% extends "auth/login_base.html" %}
|
||||
{% extends "login_base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block login_content %}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 5.0.6 on 2024-07-27 16:23
|
||||
# Generated by Django 5.0.6 on 2024-10-10 10:35
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
|
@ -10,6 +10,7 @@ class Migration(migrations.Migration):
|
|||
initial = True
|
||||
|
||||
dependencies = [
|
||||
("user", "0001_initial"),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
|
@ -36,6 +37,15 @@ class Migration(migrations.Migration):
|
|||
"owner",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to="user.institution",
|
||||
),
|
||||
),
|
||||
(
|
||||
"user",
|
||||
models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
|
@ -62,6 +72,51 @@ class Migration(migrations.Migration):
|
|||
),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="LotAnnotation",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("created", models.DateTimeField(auto_now_add=True)),
|
||||
(
|
||||
"type",
|
||||
models.SmallIntegerField(
|
||||
choices=[(0, "System"), (1, "User"), (2, "Document")]
|
||||
),
|
||||
),
|
||||
("key", models.CharField(max_length=256)),
|
||||
("value", models.CharField(max_length=256)),
|
||||
(
|
||||
"lot",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE, to="lot.lot"
|
||||
),
|
||||
),
|
||||
(
|
||||
"owner",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to="user.institution",
|
||||
),
|
||||
),
|
||||
(
|
||||
"user",
|
||||
models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="LotTag",
|
||||
fields=[
|
||||
|
@ -79,6 +134,15 @@ class Migration(migrations.Migration):
|
|||
"owner",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to="user.institution",
|
||||
),
|
||||
),
|
||||
(
|
||||
"user",
|
||||
models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
# Generated by Django 5.0.6 on 2024-07-29 15:37
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("lot", "0001_initial"),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="LotAnnotation",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("created", models.DateTimeField(auto_now_add=True)),
|
||||
(
|
||||
"type",
|
||||
models.SmallIntegerField(
|
||||
choices=[(0, "System"), (1, "User"), (2, "Document")]
|
||||
),
|
||||
),
|
||||
("key", models.CharField(max_length=256)),
|
||||
("value", models.CharField(max_length=256)),
|
||||
(
|
||||
"lot",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE, to="lot.lot"
|
||||
),
|
||||
),
|
||||
(
|
||||
"owner",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -1,36 +0,0 @@
|
|||
# Generated by Django 5.0.6 on 2024-09-18 10:55
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("lot", "0002_lotannotation"),
|
||||
("user", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="lot",
|
||||
name="owner",
|
||||
field=models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE, to="user.institution"
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="lotannotation",
|
||||
name="owner",
|
||||
field=models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE, to="user.institution"
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="lottag",
|
||||
name="owner",
|
||||
field=models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE, to="user.institution"
|
||||
),
|
||||
),
|
||||
]
|
|
@ -6,7 +6,7 @@ from utils.constants import (
|
|||
STR_EXTEND_SIZE,
|
||||
)
|
||||
|
||||
from user.models import Institution
|
||||
from user.models import User, Institution
|
||||
# from device.models import Device
|
||||
# from evidence.models import Annotation
|
||||
|
||||
|
@ -14,6 +14,7 @@ from user.models import Institution
|
|||
class LotTag(models.Model):
|
||||
name = models.CharField(max_length=STR_SIZE, blank=False, null=False)
|
||||
owner = models.ForeignKey(Institution, on_delete=models.CASCADE)
|
||||
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
@ -30,8 +31,9 @@ class Lot(models.Model):
|
|||
name = models.CharField(max_length=STR_SIZE, blank=True, null=True)
|
||||
code = models.CharField(max_length=STR_SIZE, blank=True, null=True)
|
||||
description = models.CharField(max_length=STR_SIZE, blank=True, null=True)
|
||||
closed = models.BooleanField(default=True)
|
||||
closed = models.BooleanField(default=False)
|
||||
owner = models.ForeignKey(Institution, on_delete=models.CASCADE)
|
||||
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
|
||||
type = models.ForeignKey(LotTag, on_delete=models.CASCADE)
|
||||
|
||||
def add(self, v):
|
||||
|
@ -53,6 +55,7 @@ class LotAnnotation(models.Model):
|
|||
created = models.DateTimeField(auto_now_add=True)
|
||||
lot = models.ForeignKey(Lot, on_delete=models.CASCADE)
|
||||
owner = models.ForeignKey(Institution, on_delete=models.CASCADE)
|
||||
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
|
||||
type = models.SmallIntegerField(choices=Type)
|
||||
key = models.CharField(max_length=STR_EXTEND_SIZE)
|
||||
value = models.CharField(max_length=STR_EXTEND_SIZE)
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
||||
<button type="submit">Save</button>
|
||||
<button class="btn btn-green-admin" type="submit">Save</button>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -7,6 +7,16 @@
|
|||
<h3>{{ subtitle }}</h3>
|
||||
</div>
|
||||
<div class="col text-center">
|
||||
{% if show_closed %}
|
||||
<a href="?show_closed=false" class="btn btn-green-admin">
|
||||
{% trans 'Hide closed lots' %}
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="?show_closed=true" class="btn btn-green-admin">
|
||||
{% trans 'Show closed lots' %}
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
<a href="{% url 'lot:add' %}" type="button" class="btn btn-green-admin">
|
||||
<i class="bi bi-plus"></i>
|
||||
{% trans 'Add new lot' %}
|
||||
|
|
15
lot/views.py
15
lot/views.py
|
@ -29,6 +29,7 @@ class NewLotView(DashboardView, CreateView):
|
|||
|
||||
def form_valid(self, form):
|
||||
form.instance.owner = self.request.user.institution
|
||||
form.instance.user = self.request.user
|
||||
response = super().form_valid(form)
|
||||
return response
|
||||
|
||||
|
@ -68,7 +69,11 @@ class EditLotView(DashboardView, UpdateView):
|
|||
|
||||
def get_form_kwargs(self):
|
||||
pk = self.kwargs.get('pk')
|
||||
self.object = get_object_or_404(self.model, pk=pk)
|
||||
self.object = get_object_or_404(
|
||||
self.model,
|
||||
owner=self.request.user.institution,
|
||||
pk=pk,
|
||||
)
|
||||
# self.success_url = reverse_lazy('dashbiard:lot', args=[pk])
|
||||
kwargs = super().get_form_kwargs()
|
||||
return kwargs
|
||||
|
@ -126,11 +131,13 @@ class LotsTagsView(DashboardView, TemplateView):
|
|||
tag = get_object_or_404(LotTag, owner=self.request.user.institution, id=self.pk)
|
||||
self.title += " {}".format(tag.name)
|
||||
self.breadcrumb += " {}".format(tag.name)
|
||||
lots = Lot.objects.filter(owner=self.request.user.institution).filter(type=tag)
|
||||
show_closed = self.request.GET.get('show_closed', 'false') == 'true'
|
||||
lots = Lot.objects.filter(owner=self.request.user.institution).filter(type=tag, closed=show_closed)
|
||||
context.update({
|
||||
'lots': lots,
|
||||
'title': self.title,
|
||||
'breadcrumb': self.breadcrumb
|
||||
'breadcrumb': self.breadcrumb,
|
||||
'show_closed': show_closed
|
||||
})
|
||||
return context
|
||||
|
||||
|
@ -145,6 +152,7 @@ class LotAddDocumentView(DashboardView, CreateView):
|
|||
|
||||
def form_valid(self, form):
|
||||
form.instance.owner = self.request.user.institution
|
||||
form.instance.user = self.request.user
|
||||
form.instance.lot = self.lot
|
||||
form.instance.type = LotAnnotation.Type.DOCUMENT
|
||||
response = super().form_valid(form)
|
||||
|
@ -214,6 +222,7 @@ class LotAddAnnotationView(DashboardView, CreateView):
|
|||
|
||||
def form_valid(self, form):
|
||||
form.instance.owner = self.request.user.institution
|
||||
form.instance.user = self.request.user
|
||||
form.instance.lot = self.lot
|
||||
form.instance.type = LotAnnotation.Type.USER
|
||||
response = super().form_valid(form)
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
4 login
|
||||
8 device models
|
||||
4 inventory template
|
||||
4 upload snapshots
|
||||
16 parse snapshots
|
||||
16 build devices
|
||||
8 action models
|
||||
8 view actions
|
||||
8 lot models
|
||||
16 view lots
|
||||
8 edit device
|
||||
16 documents
|
||||
8 tag
|
||||
8 print label
|
||||
4 server erase
|
||||
4 profile
|
||||
8 erase views
|
||||
8 erase certificate
|
||||
4 inventory snapshots
|
||||
8 search
|
||||
join split devices
|
||||
|
||||
168 horas => 21 dias
|
|
@ -10,4 +10,4 @@ pandas==2.2.2
|
|||
xlrd==2.0.1
|
||||
odfpy==1.4.1
|
||||
pytz==2024.2
|
||||
Pint==0.24.3
|
||||
|
||||
|
|
2
reset.sh
2
reset.sh
|
@ -1,5 +1,5 @@
|
|||
rm db/*
|
||||
python3 manage.py migrate
|
||||
python3 manage.py add_institution Pangea
|
||||
python3 manage.py add_user Pangea user@example.org 1234
|
||||
python3 manage.py add_user Pangea user@example.org 1234 True
|
||||
python3 manage.py up_snapshots example/snapshots/ user@example.org
|
||||
|
|
20
user/forms.py
Normal file
20
user/forms.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from django import forms
|
||||
|
||||
|
||||
class SettingsForm(forms.Form):
|
||||
token = forms.ChoiceField(
|
||||
choices = []
|
||||
)
|
||||
erasure = forms.ChoiceField(
|
||||
choices = [(0, 'Not erasure'),
|
||||
('basic', 'Erasure Basic'),
|
||||
('baseline', 'Erasure Baseline'),
|
||||
('enhanced', 'Erasure Enhanced'),
|
||||
],
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
tokens = kwargs.pop('tokens')
|
||||
super().__init__(*args, **kwargs)
|
||||
tk = [(str(x.token), x.tag) for x in tokens]
|
||||
self.fields['token'].choices = tk
|
|
@ -1,6 +1,9 @@
|
|||
from uuid import uuid4
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.contrib.auth import get_user_model
|
||||
from user.models import Institution
|
||||
from api.models import Token
|
||||
|
||||
|
||||
User = get_user_model()
|
||||
|
@ -13,18 +16,24 @@ class Command(BaseCommand):
|
|||
parser.add_argument('institution', type=str, help='institution')
|
||||
parser.add_argument('email', type=str, help='email')
|
||||
parser.add_argument('password', type=str, help='password')
|
||||
parser.add_argument('is_admin', nargs='?', default=False, type=str, help='is admin')
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
self.email = kwargs['email']
|
||||
self.password = kwargs['password']
|
||||
self.institution = Institution.objects.get(name=kwargs['institution'])
|
||||
self.create_user()
|
||||
email = kwargs['email']
|
||||
password = kwargs['password']
|
||||
is_admin = kwargs['is_admin']
|
||||
institution = Institution.objects.get(name=kwargs['institution'])
|
||||
self.create_user(institution, email, password, is_admin)
|
||||
|
||||
def create_user(self):
|
||||
def create_user(self, institution, email, password, is_admin):
|
||||
self.u = User.objects.create(
|
||||
institution=self.institution,
|
||||
email=self.email,
|
||||
password=self.password
|
||||
institution=institution,
|
||||
email=email,
|
||||
password=password,
|
||||
is_admin=is_admin,
|
||||
)
|
||||
self.u.set_password(self.password)
|
||||
self.u.set_password(password)
|
||||
self.u.save()
|
||||
token = uuid4()
|
||||
Token.objects.create(token=token, owner=self.u)
|
||||
print(f"TOKEN: {token}")
|
||||
|
|
27
user/templates/panel.html
Normal file
27
user/templates/panel.html
Normal file
|
@ -0,0 +1,27 @@
|
|||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row mb-3">
|
||||
<div class="col">
|
||||
<h3>{{ subtitle }}</h3>
|
||||
</div>
|
||||
<div class="col text-center">
|
||||
{{ user.email }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<a class="nav-link fw-bold" href="{% url 'api:tokens' %}">
|
||||
{% translate 'Admin your Tokens' %}
|
||||
</a>
|
||||
</div>
|
||||
<div class="col">
|
||||
<a class="nav-link fw-bold" href="{% url 'user:settings' %}">
|
||||
{% translate 'Download a settings file' %}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
32
user/templates/settings.html
Normal file
32
user/templates/settings.html
Normal file
|
@ -0,0 +1,32 @@
|
|||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h3>{{ subtitle }}</h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% load django_bootstrap5 %}
|
||||
<form role="form" method="post">
|
||||
{% csrf_token %}
|
||||
{% if form.errors %}
|
||||
<div class="alert alert-danger alert-icon alert-icon-border alert-dismissible" role="alert">
|
||||
<div class="icon"><span class="mdi mdi-close-circle-o"></span></div>
|
||||
<div class="message">
|
||||
{% for field, error in form.errors.items %}
|
||||
{{ error }}<br />
|
||||
{% endfor %}
|
||||
<button class="btn-close" type="button" data-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% bootstrap_form form %}
|
||||
<div class="form-actions-no-box">
|
||||
<a class="btn btn-grey" href="{% url 'user:panel' %}">{% translate "Cancel" %}</a>
|
||||
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
|
||||
</div>
|
||||
|
||||
</form>
|
||||
{% endblock %}
|
6
user/templates/settings.ini
Normal file
6
user/templates/settings.ini
Normal file
|
@ -0,0 +1,6 @@
|
|||
[settings]
|
||||
url = {{ url }}
|
||||
token = {{ token }}
|
||||
erase = {{ erasure }}
|
||||
legacy = false
|
||||
# path = /path/to/save
|
6
user/templates/settings_legacy.ini
Normal file
6
user/templates/settings_legacy.ini
Normal file
|
@ -0,0 +1,6 @@
|
|||
[settings]
|
||||
url = {{ url }}
|
||||
token = {{ token }}
|
||||
legacy = true
|
||||
# erase = {{ erasure }}
|
||||
# path = /path/to/save
|
9
user/urls.py
Normal file
9
user/urls.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from django.urls import path
|
||||
from user import views
|
||||
|
||||
app_name = 'user'
|
||||
|
||||
urlpatterns = [
|
||||
path("panel/", views.PanelView.as_view(), name="panel"),
|
||||
path("settings/", views.SettingsView.as_view(), name="settings"),
|
||||
]
|
|
@ -1,37 +1,50 @@
|
|||
from decouple import config
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import render
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic.base import TemplateView
|
||||
from dashboard.mixins import DashboardView
|
||||
from django.views.generic.edit import (
|
||||
FormView,
|
||||
)
|
||||
|
||||
from user.forms import SettingsForm
|
||||
from api.models import Token
|
||||
|
||||
|
||||
class PanelView(DashboardView, TemplateView):
|
||||
template_name = "panel.html"
|
||||
title = _("User")
|
||||
breadcrumb = "User / Panel"
|
||||
subtitle = "User panel"
|
||||
|
||||
class ProfileView(DashboardView):
|
||||
template_name = "profile.html"
|
||||
subtitle = _('My personal data')
|
||||
icon = 'bi bi-person-gear'
|
||||
fields = ('first_name', 'last_name', 'email')
|
||||
success_url = reverse_lazy('idhub:user_profile')
|
||||
model = User
|
||||
|
||||
def get_queryset(self, **kwargs):
|
||||
queryset = Membership.objects.select_related('user').filter(
|
||||
user=self.request.user)
|
||||
|
||||
return queryset
|
||||
|
||||
def get_object(self):
|
||||
return self.request.user
|
||||
|
||||
def get_form(self):
|
||||
form = super().get_form()
|
||||
return form
|
||||
|
||||
class SettingsView(DashboardView, FormView):
|
||||
template_name = "settings.html"
|
||||
title = _("Download Settings")
|
||||
breadcrumb = "user / workbench / settings"
|
||||
form_class = SettingsForm
|
||||
|
||||
def form_valid(self, form):
|
||||
return super().form_valid(form)
|
||||
cleaned_data = form.cleaned_data.copy()
|
||||
settings_tmpl = "settings.ini"
|
||||
path = reverse("api:new_snapshot")
|
||||
cleaned_data['url'] = self.request.build_absolute_uri(path)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context.update({
|
||||
'lang': self.request.LANGUAGE_CODE,
|
||||
})
|
||||
return context
|
||||
if config("LEGACY", False):
|
||||
cleaned_data['token'] = config.get('TOKEN_LEGACY', '')
|
||||
cleaned_data['url'] = config.get('URL_LEGACY', '')
|
||||
settings_tmpl = "settings_legacy.ini"
|
||||
|
||||
data = render(self.request, settings_tmpl, cleaned_data)
|
||||
response = HttpResponse(data.content, content_type="application/text")
|
||||
response['Content-Disposition'] = 'attachment; filename={}'.format("settings.ini")
|
||||
return response
|
||||
|
||||
def get_form_kwargs(self):
|
||||
tokens = Token.objects.filter(owner=self.request.user)
|
||||
kwargs = super().get_form_kwargs()
|
||||
kwargs['tokens'] = tokens
|
||||
return kwargs
|
||||
|
||||
|
|
|
@ -70,6 +70,7 @@ def create_annotation(doc, user, commit=False):
|
|||
data = {
|
||||
'uuid': doc['uuid'],
|
||||
'owner': user.institution,
|
||||
'user': user,
|
||||
'type': Annotation.Type.SYSTEM,
|
||||
'key': 'CUSTOMER_ID',
|
||||
'value': doc['CUSTOMER_ID'],
|
||||
|
@ -80,10 +81,10 @@ def create_annotation(doc, user, commit=False):
|
|||
return Annotation(**data)
|
||||
|
||||
|
||||
def create_index(doc):
|
||||
def create_index(doc, user):
|
||||
if not doc or not doc.get('uuid'):
|
||||
return []
|
||||
|
||||
_uuid = doc['uuid']
|
||||
ev = json.dumps(doc)
|
||||
index(_uuid, ev)
|
||||
index(user.institution, _uuid, ev)
|
||||
|
|
Loading…
Reference in a new issue