Remove everything
Gutenberg is just unsuitable to be used outside WordPress without using private API and a huge effort that we just can not bear.
This commit is contained in:
parent
dd6f6f80d4
commit
57b0011c96
661
COPYING
661
COPYING
|
@ -1,661 +0,0 @@
|
||||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
|
||||||
Version 3, 19 November 2007
|
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://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.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
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 <https://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
|
|
||||||
<https://www.gnu.org/licenses/>.
|
|
18
Makefile
18
Makefile
|
@ -1,18 +0,0 @@
|
||||||
DEFAULT_DOMAIN = editor
|
|
||||||
POT_FILE = po/$(DEFAULT_DOMAIN).pot
|
|
||||||
LINGUAS = es
|
|
||||||
JSON_FILES = $(patsubst %,web/static/%.json,$(LINGUAS))
|
|
||||||
|
|
||||||
locales: $(JSON_FILES)
|
|
||||||
|
|
||||||
po/%.po: $(POT_FILE)
|
|
||||||
msgmerge --no-wrap --update --backup=off $@ $<
|
|
||||||
|
|
||||||
web/static/%.json: po/%.po
|
|
||||||
npx po2json --format jed1.x $< $@
|
|
||||||
|
|
||||||
$(POT_FILE):
|
|
||||||
wp i18n make-pot . $@ --ignore-domain --include=editor,po/src
|
|
||||||
|
|
||||||
|
|
||||||
.PHONY: locales
|
|
|
@ -1,50 +0,0 @@
|
||||||
/**
|
|
||||||
* SPDX-FileCopyrightText: 2023 jordi fita mas <jordi@tandem.blog>
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-only
|
|
||||||
*/
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"os/signal"
|
|
||||||
"syscall"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
tipus "dev.tandem.ws/tandem/tipus/pkg"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
db, err := tipus.NewDatabase(context.Background(), os.Getenv("TIPUS_DATABASE_URL"))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer db.Close()
|
|
||||||
|
|
||||||
srv := &http.Server{
|
|
||||||
Addr: ":8080",
|
|
||||||
Handler: tipus.NewApplication(db),
|
|
||||||
ReadTimeout: 5 * time.Second,
|
|
||||||
WriteTimeout: 10 * time.Second,
|
|
||||||
IdleTimeout: 2 * time.Minute,
|
|
||||||
}
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
log.Printf("INFO — listening on %s\n", srv.Addr)
|
|
||||||
if err := srv.ListenAndServe(); err != http.ErrServerClosed {
|
|
||||||
log.Fatalf("ERROR — http server: %s\n", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
sigCh := make(chan os.Signal, 1)
|
|
||||||
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
|
|
||||||
<-sigCh
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
||||||
defer cancel()
|
|
||||||
log.Print("INFO - stopping server")
|
|
||||||
if err := srv.Shutdown(ctx); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
-- Deploy tipus:available_languages to pg
|
|
||||||
-- requires: schema_public
|
|
||||||
-- requires: language
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
insert into public.language (lang_tag, name, endonym, selectable, currency_pattern)
|
|
||||||
values ('und', 'Undefined', 'Undefined', false, '%[3]s%.[1]*[2]f')
|
|
||||||
, ('ca', 'Catalan', 'català', true, '%.[1]*[2]f %[3]s')
|
|
||||||
, ('es', 'Spanish', 'español', true, '%.[1]*[2]f %[3]s')
|
|
||||||
;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,25 +0,0 @@
|
||||||
-- Deploy tipus:build_cookie to pg
|
|
||||||
-- requires: roles
|
|
||||||
-- requires: schema_tipus
|
|
||||||
-- requires: current_user_email
|
|
||||||
-- requires: current_user_cookie
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
set search_path to tipus, public;
|
|
||||||
|
|
||||||
create or replace function build_cookie(user_email email default null, user_cookie text default null) returns text as
|
|
||||||
$$
|
|
||||||
select coalesce(user_cookie, current_user_cookie()) || '/' || coalesce(user_email, current_user_email());
|
|
||||||
$$
|
|
||||||
language sql
|
|
||||||
stable;
|
|
||||||
|
|
||||||
revoke execute on function build_cookie(email, text) from public;
|
|
||||||
grant execute on function build_cookie(email, text) to publisher;
|
|
||||||
grant execute on function build_cookie(email, text) to admin;
|
|
||||||
|
|
||||||
comment on function build_cookie(email, text) is
|
|
||||||
'Build the cookie to send to the user’s browser, either for the given values or for the current user.';
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,30 +0,0 @@
|
||||||
-- Deploy tipus:change_password to pg
|
|
||||||
-- requires: roles
|
|
||||||
-- requires: schema_tipus
|
|
||||||
-- requires: schema_auth
|
|
||||||
-- requires: user
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
set search_path to tipus, auth, public;
|
|
||||||
|
|
||||||
create or replace function change_password(new_password text) returns void as
|
|
||||||
$$
|
|
||||||
update "user"
|
|
||||||
set password = new_password
|
|
||||||
where email = current_user_email()
|
|
||||||
and cookie = current_user_cookie()
|
|
||||||
and cookie_expires_at > current_timestamp
|
|
||||||
and length(cookie) > 30
|
|
||||||
$$ language sql
|
|
||||||
security definer
|
|
||||||
set search_path to auth, tipus, pg_temp;
|
|
||||||
|
|
||||||
revoke execute on function change_password(text) from public;
|
|
||||||
grant execute on function change_password(text) to publisher;
|
|
||||||
grant execute on function change_password(text) to admin;
|
|
||||||
|
|
||||||
comment on function change_password(text) is
|
|
||||||
'Changes the password for the current app user';
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,48 +0,0 @@
|
||||||
-- Deploy tipus:check_cookie to pg
|
|
||||||
-- requires: roles
|
|
||||||
-- requires: schema_public
|
|
||||||
-- requires: schema_auth
|
|
||||||
-- requires: user
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
set search_path to public, auth;
|
|
||||||
|
|
||||||
create or replace function check_cookie(input_cookie text) returns name as
|
|
||||||
$$
|
|
||||||
declare
|
|
||||||
uid text;
|
|
||||||
user_email text;
|
|
||||||
user_role name;
|
|
||||||
user_cookie text;
|
|
||||||
begin
|
|
||||||
select user_id::text, email::text, role, cookie
|
|
||||||
into uid, user_email, user_role, user_cookie
|
|
||||||
from "user"
|
|
||||||
where email = split_part(input_cookie, '/', 2)
|
|
||||||
and cookie_expires_at > current_timestamp
|
|
||||||
and length(password) > 0
|
|
||||||
and cookie = split_part(input_cookie, '/', 1);
|
|
||||||
if user_role is null then
|
|
||||||
uid := '0';
|
|
||||||
user_email := '';
|
|
||||||
user_cookie := '';
|
|
||||||
user_role := 'guest'::name;
|
|
||||||
end if;
|
|
||||||
perform set_config('request.user.email', user_email, false);
|
|
||||||
perform set_config('request.user.cookie', user_cookie, false);
|
|
||||||
return user_role;
|
|
||||||
end;
|
|
||||||
$$
|
|
||||||
language plpgsql
|
|
||||||
security definer
|
|
||||||
stable
|
|
||||||
set search_path = auth, pg_temp;
|
|
||||||
|
|
||||||
comment on function check_cookie(text) is
|
|
||||||
'Checks whether a given cookie is for a valid users, returning their role, and setting current_user_email and current_user_cookie';
|
|
||||||
|
|
||||||
revoke execute on function check_cookie(text) from public;
|
|
||||||
grant execute on function check_cookie(text) to authenticator;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,24 +0,0 @@
|
||||||
-- Deploy tipus:current_user_cookie to pg
|
|
||||||
-- requires: roles
|
|
||||||
-- requires: schema_tipus
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
set search_path to tipus;
|
|
||||||
|
|
||||||
create or replace function current_user_cookie() returns text as
|
|
||||||
$$
|
|
||||||
select current_setting('request.user.cookie', true);
|
|
||||||
$$
|
|
||||||
language sql
|
|
||||||
stable;
|
|
||||||
|
|
||||||
comment on function current_user_cookie() is
|
|
||||||
'Returns the cookie of the current Numerus user';
|
|
||||||
|
|
||||||
revoke execute on function current_user_cookie() from public;
|
|
||||||
grant execute on function current_user_cookie() to guest;
|
|
||||||
grant execute on function current_user_cookie() to publisher;
|
|
||||||
grant execute on function current_user_cookie() to admin;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,24 +0,0 @@
|
||||||
-- Deploy tipus:current_user_email to pg
|
|
||||||
-- requires: roles
|
|
||||||
-- requires: schema_tipus
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
set search_path to tipus;
|
|
||||||
|
|
||||||
create or replace function current_user_email() returns text as
|
|
||||||
$$
|
|
||||||
select current_setting('request.user.email', true);
|
|
||||||
$$
|
|
||||||
language sql
|
|
||||||
stable;
|
|
||||||
|
|
||||||
comment on function current_user_email() is
|
|
||||||
'Returns the email of the current Numerus user';
|
|
||||||
|
|
||||||
revoke execute on function current_user_email() from public;
|
|
||||||
grant execute on function current_user_email() to guest;
|
|
||||||
grant execute on function current_user_email() to publisher;
|
|
||||||
grant execute on function current_user_email() to admin;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,16 +0,0 @@
|
||||||
-- Deploy tipus:email to pg
|
|
||||||
-- requires: schema_tipus
|
|
||||||
-- requires: extension_citext
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
set search_path to tipus, public;
|
|
||||||
|
|
||||||
-- regular expression from https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
|
|
||||||
create domain email as citext
|
|
||||||
check ( value ~
|
|
||||||
'^[a-zA-Z0-9.!#$%&''*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$' );
|
|
||||||
|
|
||||||
comment on domain email is 'A valid email address according to HTML5 spec.';
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,33 +0,0 @@
|
||||||
-- Deploy tipus:encrypt_password to pg
|
|
||||||
-- requires: schema_auth
|
|
||||||
-- requires: user
|
|
||||||
-- requires: extension_pgcrypto
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
set search_path to auth, public;
|
|
||||||
|
|
||||||
create or replace function encrypt_password() returns trigger as
|
|
||||||
$$
|
|
||||||
begin
|
|
||||||
if tg_op = 'INSERT' or new.password <> old.password then
|
|
||||||
new.password = crypt(new.password, gen_salt('bf'));
|
|
||||||
end if;
|
|
||||||
return new;
|
|
||||||
end;
|
|
||||||
$$
|
|
||||||
language plpgsql
|
|
||||||
set search_path = auth, pg_temp;
|
|
||||||
|
|
||||||
comment on function encrypt_password() is
|
|
||||||
'Encrypts and salts the input password with the blowfish encryption algorithm';
|
|
||||||
|
|
||||||
revoke execute on function encrypt_password() from public;
|
|
||||||
|
|
||||||
create trigger encrypt_password
|
|
||||||
before insert or update
|
|
||||||
on "user"
|
|
||||||
for each row
|
|
||||||
execute procedure encrypt_password();
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,31 +0,0 @@
|
||||||
-- Deploy tipus:ensure_role_exists to pg
|
|
||||||
-- requires: schema_auth
|
|
||||||
-- requires: user
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
set search_path to auth, public;
|
|
||||||
|
|
||||||
create or replace function ensure_role_exists() returns trigger as
|
|
||||||
$$
|
|
||||||
begin
|
|
||||||
if not exists (select 1 from pg_roles where rolname = new.role) then
|
|
||||||
raise foreign_key_violation using message = 'role not found: ' || new.role;
|
|
||||||
end if;
|
|
||||||
return new;
|
|
||||||
end;
|
|
||||||
$$
|
|
||||||
language plpgsql;
|
|
||||||
|
|
||||||
comment on function ensure_role_exists() is
|
|
||||||
'Makes sure that a role given to a user is a valid, existing role in the cluster.';
|
|
||||||
|
|
||||||
revoke execute on function ensure_role_exists() from public;
|
|
||||||
|
|
||||||
create trigger ensure_role_exists
|
|
||||||
after insert or update
|
|
||||||
on "user"
|
|
||||||
for each row
|
|
||||||
execute procedure ensure_role_exists();
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,8 +0,0 @@
|
||||||
-- Deploy tipus:extension_citext to pg
|
|
||||||
-- requires: schema_public
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
create extension if not exists citext;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,8 +0,0 @@
|
||||||
-- Deploy tipus:extension_pgcrypto to pg
|
|
||||||
-- requires: schema_auth
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
create extension if not exists pgcrypto with schema auth;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,32 +0,0 @@
|
||||||
-- Deploy tipus:language to pg
|
|
||||||
-- requires: roles
|
|
||||||
-- requires: schema_public
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
set search_path to public;
|
|
||||||
|
|
||||||
create table language
|
|
||||||
(
|
|
||||||
lang_tag text primary key check (length(lang_tag) < 36), -- RFC5646 recommends 35 at least
|
|
||||||
name text not null,
|
|
||||||
endonym text not null,
|
|
||||||
selectable boolean not null,
|
|
||||||
currency_pattern text not null
|
|
||||||
);
|
|
||||||
|
|
||||||
grant select on table language to guest;
|
|
||||||
grant select on table language to publisher;
|
|
||||||
grant select on table language to admin;
|
|
||||||
grant select on table language to authenticator;
|
|
||||||
|
|
||||||
comment on table language is
|
|
||||||
'Languages/locales available in Tipus';
|
|
||||||
|
|
||||||
comment on column language.lang_tag is
|
|
||||||
'BCP-47 language tag';
|
|
||||||
|
|
||||||
comment on column language.selectable is
|
|
||||||
'Whether the language should be a option in a user-facing select control.';
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,63 +0,0 @@
|
||||||
-- Deploy tipus:login to pg
|
|
||||||
-- requires: roles
|
|
||||||
-- requires: schema_auth
|
|
||||||
-- requires: schema_tipus
|
|
||||||
-- requires: extension_pgcrypto
|
|
||||||
-- requires: email
|
|
||||||
-- requires: user
|
|
||||||
-- requires: login_attempt
|
|
||||||
-- requires: build_cookie
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
set search_path to tipus, auth;
|
|
||||||
|
|
||||||
create or replace function login(email email, password text, ip_address inet default null) returns text as
|
|
||||||
$$
|
|
||||||
declare
|
|
||||||
user_cookie text;
|
|
||||||
begin
|
|
||||||
if not exists (select *
|
|
||||||
from "user"
|
|
||||||
where "user".email = login.email
|
|
||||||
and "user".password = crypt(login.password, "user".password)) then
|
|
||||||
insert into login_attempt
|
|
||||||
(user_name, ip_address, success)
|
|
||||||
values (login.email, login.ip_address, false);
|
|
||||||
return '';
|
|
||||||
end if;
|
|
||||||
|
|
||||||
select cookie
|
|
||||||
into user_cookie
|
|
||||||
from "user"
|
|
||||||
where "user".email = login.email
|
|
||||||
and cookie_expires_at > current_timestamp
|
|
||||||
and length(cookie) > 30;
|
|
||||||
|
|
||||||
if user_cookie is null then
|
|
||||||
select encode(gen_random_bytes(25), 'hex') into user_cookie;
|
|
||||||
end if;
|
|
||||||
|
|
||||||
update "user"
|
|
||||||
set cookie = user_cookie
|
|
||||||
, cookie_expires_at = current_timestamp + interval '1 year'
|
|
||||||
where "user".email = login.email;
|
|
||||||
|
|
||||||
insert into login_attempt
|
|
||||||
(user_name, ip_address, success)
|
|
||||||
values (login.email, login.ip_address, true);
|
|
||||||
|
|
||||||
return build_cookie(email, user_cookie);
|
|
||||||
end;
|
|
||||||
$$
|
|
||||||
language plpgsql
|
|
||||||
security definer
|
|
||||||
set search_path = auth, tipus, pg_temp;
|
|
||||||
|
|
||||||
comment on function login(email, text, inet) is
|
|
||||||
'Tries to logs a user in, recording the attempt, and returns the cookie to send back to the user if the authentication was successfull.';
|
|
||||||
|
|
||||||
revoke execute on function login(email, text, inet) from public;
|
|
||||||
grant execute on function login(email, text, inet) to guest;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,18 +0,0 @@
|
||||||
-- Deploy tipus:login_attempt to pg
|
|
||||||
-- requires: schema_auth
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
set search_path to auth;
|
|
||||||
|
|
||||||
create table login_attempt
|
|
||||||
(
|
|
||||||
attempt_id bigserial primary key,
|
|
||||||
user_name text not null,
|
|
||||||
ip_address inet -- just in case we logged from a non web application, somehow
|
|
||||||
,
|
|
||||||
success boolean not null,
|
|
||||||
attempted_at timestamptz not null default current_timestamp
|
|
||||||
);
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,34 +0,0 @@
|
||||||
-- Deploy tipus:logout to pg
|
|
||||||
-- requires: roles
|
|
||||||
-- requires: schema_tipus
|
|
||||||
-- requires: schema_auth
|
|
||||||
-- requires: user
|
|
||||||
-- requires: current_user_cookie
|
|
||||||
-- requires: current_user_email
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
set search_path to tipus, auth, public;
|
|
||||||
|
|
||||||
create or replace function logout() returns void as
|
|
||||||
$$
|
|
||||||
update "user"
|
|
||||||
set cookie = default
|
|
||||||
, cookie_expires_at = default
|
|
||||||
where email = current_user_email()
|
|
||||||
and cookie = current_user_cookie()
|
|
||||||
and cookie_expires_at > current_timestamp
|
|
||||||
and length(cookie) > 30
|
|
||||||
$$
|
|
||||||
language sql
|
|
||||||
security definer
|
|
||||||
set search_path to auth, tipus, pg_temp;
|
|
||||||
|
|
||||||
comment on function logout() is
|
|
||||||
'Removes the cookie and its expiry data from the current user, as returned by current_user_email and current_user_cookie';
|
|
||||||
|
|
||||||
revoke execute on function logout() from public;
|
|
||||||
grant execute on function logout() to publisher;
|
|
||||||
grant execute on function logout() to admin;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,27 +0,0 @@
|
||||||
-- Deploy tipus:roles to pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
do
|
|
||||||
$$
|
|
||||||
declare
|
|
||||||
role name;
|
|
||||||
roles name[] := array ['guest', 'publisher', 'admin', 'authenticator'];
|
|
||||||
begin
|
|
||||||
foreach role in array roles
|
|
||||||
loop
|
|
||||||
begin
|
|
||||||
execute 'create role ' || role || ' noinherit nologin';
|
|
||||||
exception
|
|
||||||
when duplicate_object then
|
|
||||||
raise notice '%, skipping', sqlerrm using errcode = sqlstate;
|
|
||||||
end;
|
|
||||||
end loop;
|
|
||||||
end
|
|
||||||
$$;
|
|
||||||
|
|
||||||
grant guest to authenticator;
|
|
||||||
grant publisher to authenticator;
|
|
||||||
grant admin to authenticator;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,10 +0,0 @@
|
||||||
-- Deploy tipus:schema_auth to pg
|
|
||||||
-- requires: roles
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
create schema auth;
|
|
||||||
|
|
||||||
comment on schema auth is 'To keep user’s passwords safe.';
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,14 +0,0 @@
|
||||||
-- Deploy tipus:schema_public to pg
|
|
||||||
-- requires: roles
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
revoke create on schema public from public;
|
|
||||||
revoke usage on schema public from public;
|
|
||||||
|
|
||||||
grant usage on schema public to authenticator;
|
|
||||||
grant usage on schema public to guest;
|
|
||||||
grant usage on schema public to publisher;
|
|
||||||
grant usage on schema public to admin;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,14 +0,0 @@
|
||||||
-- Deploy tipus:schema_tipus to pg
|
|
||||||
-- requires: roles
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
create schema tipus;
|
|
||||||
|
|
||||||
comment on schema tipus is 'The main application schema';
|
|
||||||
|
|
||||||
grant usage on schema tipus to guest;
|
|
||||||
grant usage on schema tipus to publisher;
|
|
||||||
grant usage on schema tipus to admin;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,23 +0,0 @@
|
||||||
-- Deploy tipus:set_cookie to pg
|
|
||||||
-- requires: roles
|
|
||||||
-- requires: schema_public
|
|
||||||
-- requires: check_cookie
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
set search_path to public;
|
|
||||||
|
|
||||||
create or replace function set_cookie(input_cookie text) returns void as
|
|
||||||
$$
|
|
||||||
select set_config('role', check_cookie(input_cookie), false);
|
|
||||||
$$
|
|
||||||
language sql
|
|
||||||
stable;
|
|
||||||
|
|
||||||
comment on function set_cookie(text) is
|
|
||||||
'Sets the user information for the cookie and switches to its role';
|
|
||||||
|
|
||||||
revoke execute on function set_cookie(text) from public;
|
|
||||||
grant execute on function set_cookie(text) to authenticator;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,23 +0,0 @@
|
||||||
-- Deploy tipus:user to pg
|
|
||||||
-- requires: schema_auth
|
|
||||||
-- requires: email
|
|
||||||
-- requires: language
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
set search_path to auth, tipus, public;
|
|
||||||
|
|
||||||
create table "user"
|
|
||||||
(
|
|
||||||
user_id serial primary key,
|
|
||||||
email email not null unique,
|
|
||||||
name text not null,
|
|
||||||
password text not null check (length(password) < 512),
|
|
||||||
role name not null check (length(role) < 512),
|
|
||||||
lang_tag text not null default 'und' references language,
|
|
||||||
cookie text not null default '',
|
|
||||||
cookie_expires_at timestamptz not null default '-infinity'::timestamp,
|
|
||||||
created_at timestamptz not null default current_timestamp
|
|
||||||
);
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,71 +0,0 @@
|
||||||
-- Deploy tipus:user_profile to pg
|
|
||||||
-- requires: roles
|
|
||||||
-- requires: schema_tipus
|
|
||||||
-- requires: user
|
|
||||||
-- requires: current_user_email
|
|
||||||
-- requires: current_user_cookie
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
set search_path to tipus, public;
|
|
||||||
|
|
||||||
create or replace view user_profile
|
|
||||||
with (security_barrier)
|
|
||||||
as
|
|
||||||
select user_id
|
|
||||||
, email
|
|
||||||
, name
|
|
||||||
, role
|
|
||||||
, lang_tag
|
|
||||||
, left(cookie, 10) as csrf_token
|
|
||||||
from auth."user"
|
|
||||||
where email = current_user_email()
|
|
||||||
and cookie = current_user_cookie()
|
|
||||||
and cookie_expires_at > current_timestamp
|
|
||||||
and length(cookie) > 30
|
|
||||||
union all
|
|
||||||
select 0
|
|
||||||
, null::email
|
|
||||||
, ''
|
|
||||||
, 'guest'::name
|
|
||||||
, 'und'
|
|
||||||
, ''
|
|
||||||
where not exists (select 1
|
|
||||||
from auth."user"
|
|
||||||
where email = current_user_email()
|
|
||||||
and cookie = current_user_cookie()
|
|
||||||
and cookie_expires_at > current_timestamp
|
|
||||||
and length(cookie) > 30);
|
|
||||||
|
|
||||||
grant select on table user_profile to guest;
|
|
||||||
grant select, update (email, name, lang_tag) on table user_profile to publisher;
|
|
||||||
grant select, update (email, name, lang_tag) on table user_profile to admin;
|
|
||||||
|
|
||||||
create or replace function update_user_profile() returns trigger as
|
|
||||||
$$
|
|
||||||
begin
|
|
||||||
update auth."user"
|
|
||||||
set email = new.email
|
|
||||||
, name = new.name
|
|
||||||
, lang_tag = new.lang_tag
|
|
||||||
where email = current_user_email()
|
|
||||||
and cookie = current_user_cookie()
|
|
||||||
and cookie_expires_at > current_timestamp
|
|
||||||
and length(cookie) > 30;
|
|
||||||
|
|
||||||
perform set_config('request.user.email', new.email, false);
|
|
||||||
|
|
||||||
return new;
|
|
||||||
end;
|
|
||||||
$$
|
|
||||||
language plpgsql
|
|
||||||
security definer
|
|
||||||
set search_path to auth, tipus, pg_temp;
|
|
||||||
|
|
||||||
create trigger update_user_profile
|
|
||||||
instead of update
|
|
||||||
on user_profile
|
|
||||||
for each row
|
|
||||||
execute procedure update_user_profile();
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,36 +0,0 @@
|
||||||
import { InterfaceSkeleton, FullscreenMode, ComplementaryArea } from '@wordpress/interface';
|
|
||||||
import { BlockBreadcrumb, BlockCanvas, __experimentalLibrary as BlockLibrary } from '@wordpress/block-editor';
|
|
||||||
|
|
||||||
import Header from './Header';
|
|
||||||
import Sidebar from './Sidebar';
|
|
||||||
import { scope } from './constants';
|
|
||||||
|
|
||||||
import blockLibraryCommon from '@wordpress/block-library/build-style/common.css?inline';
|
|
||||||
import blockLibraryEditor from '@wordpress/block-library/build-style/editor.css?inline';
|
|
||||||
import blockLibraryStyle from '@wordpress/block-library/build-style/style.css?inline';
|
|
||||||
import componentsStyle from '@wordpress/components/build-style/style.css?inline';
|
|
||||||
import formatLibraryStyle from '@wordpress/format-library/build-style/style.css?inline';
|
|
||||||
|
|
||||||
export default function BlockEditor({ hasUndo, undo, hasRedo, redo }) {
|
|
||||||
const styles = [
|
|
||||||
{ css: componentsStyle },
|
|
||||||
{ css: blockLibraryCommon },
|
|
||||||
{ css: blockLibraryStyle },
|
|
||||||
{ css: blockLibraryEditor },
|
|
||||||
{ css: formatLibraryStyle },
|
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<FullscreenMode isActive={ true } />
|
|
||||||
<Sidebar />
|
|
||||||
<InterfaceSkeleton
|
|
||||||
header={ <Header hasUndo={hasUndo} undo={undo} hasRedo={hasRedo} redo={redo} /> }
|
|
||||||
content={ <BlockCanvas height="100%" styles={styles} /> }
|
|
||||||
sidebar={ <ComplementaryArea.Slot scope={ scope } /> }
|
|
||||||
secondarySidebar={ <BlockLibrary /> }
|
|
||||||
footer={ <BlockBreadcrumb /> }
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
import { useState } from '@wordpress/element';
|
|
||||||
import { useStateWithHistory } from '@wordpress/compose';
|
|
||||||
import { BlockEditorProvider } from '@wordpress/block-editor';
|
|
||||||
|
|
||||||
import BlockEditor from './BlockEditor';
|
|
||||||
|
|
||||||
import './editor.scss';
|
|
||||||
|
|
||||||
export default function Editor() {
|
|
||||||
const { value, setValue, hasUndo, hasRedo, undo, redo } = useStateWithHistory( { blocks: [] } );
|
|
||||||
const [ blocks, updateBlocks ] = useState([]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<BlockEditorProvider
|
|
||||||
value={ value.blocks }
|
|
||||||
onInput={ ( blocks, { selection }) => setValue( { blocks, selection }, true ) }
|
|
||||||
onChange={ ( blocks, {selection}) => setValue( { blocks, selection }, false ) }
|
|
||||||
>
|
|
||||||
<BlockEditor
|
|
||||||
hasUndo={ hasUndo }
|
|
||||||
undo={ undo }
|
|
||||||
hasRedo={ hasRedo }
|
|
||||||
redo={ redo }
|
|
||||||
/>
|
|
||||||
</BlockEditorProvider>
|
|
||||||
);
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
import { PinnedItems } from '@wordpress/interface';
|
|
||||||
import { Button } from '@wordpress/components';
|
|
||||||
|
|
||||||
import { scope } from './constants';
|
|
||||||
|
|
||||||
export default function Header( { hasUndo, undo, hasRedo, redo } ) {
|
|
||||||
return (
|
|
||||||
<div className="tipus-header">
|
|
||||||
<div>
|
|
||||||
<Button variant="secondary" disabled={ !hasUndo } onClick={ undo }>Undo</Button>
|
|
||||||
<Button variant="secondary" disabled={ !hasRedo } onClick={ redo }>Redo</Button>
|
|
||||||
</div>
|
|
||||||
<div className="tipus-header__settings">
|
|
||||||
<PinnedItems.Slot scope={ scope } />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
import { ComplementaryArea } from '@wordpress/interface';
|
|
||||||
import { Panel } from '@wordpress/components';
|
|
||||||
import { BlockInspector } from '@wordpress/block-editor';
|
|
||||||
import { drawerRight } from '@wordpress/icons';
|
|
||||||
|
|
||||||
import { scope } from './constants';
|
|
||||||
|
|
||||||
export default function Sidebar() {
|
|
||||||
return (
|
|
||||||
<ComplementaryArea
|
|
||||||
scope={ scope }
|
|
||||||
identifier="tipus/block"
|
|
||||||
isActiveByDefault={ true }
|
|
||||||
icon={ drawerRight }
|
|
||||||
>
|
|
||||||
<Panel>
|
|
||||||
<BlockInspector />
|
|
||||||
</Panel>
|
|
||||||
</ComplementaryArea>
|
|
||||||
);
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
export const scope = 'tipus/editor';
|
|
|
@ -1,33 +0,0 @@
|
||||||
@import '@wordpress/components/build-style/style.css';
|
|
||||||
@import '@wordpress/interface/build-style/style.css';
|
|
||||||
@import '@wordpress/block-editor/build-style/style.css';
|
|
||||||
@import '@wordpress/block-editor/build-style/content.css';
|
|
||||||
|
|
||||||
body, html {
|
|
||||||
height: 100%;
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
main {
|
|
||||||
position: fixed;
|
|
||||||
inset: 0;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tipus-header {
|
|
||||||
height: 3.75rem;
|
|
||||||
background: white;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
max-width: 100vw;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tipus-header__settings {
|
|
||||||
display: inline-flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: .5rem;
|
|
||||||
padding-right: .5rem;
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Tipus</title>
|
|
||||||
<link rel="icon" href="data:,">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<main></main>
|
|
||||||
<script type="module" src="main.jsx"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1,14 +0,0 @@
|
||||||
import { createRoot, StrictMode } from '@wordpress/element';
|
|
||||||
import { registerCoreBlocks } from '@wordpress/block-library';
|
|
||||||
import '@wordpress/format-library';
|
|
||||||
|
|
||||||
import Editor from './Editor';
|
|
||||||
|
|
||||||
registerCoreBlocks();
|
|
||||||
|
|
||||||
const root = createRoot(document.querySelector('main'));
|
|
||||||
root.render(
|
|
||||||
<StrictMode>
|
|
||||||
<Editor />
|
|
||||||
</StrictMode>
|
|
||||||
);
|
|
9
go.mod
9
go.mod
|
@ -1,9 +0,0 @@
|
||||||
module dev.tandem.ws/tandem/tipus
|
|
||||||
|
|
||||||
go 1.16
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/jackc/pgx/v4 v4.18.1
|
|
||||||
github.com/leonelquinteros/gotext v1.5.2
|
|
||||||
golang.org/x/text v0.7.0
|
|
||||||
)
|
|
204
go.sum
204
go.sum
|
@ -1,204 +0,0 @@
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
|
||||||
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
|
|
||||||
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
|
|
||||||
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
|
|
||||||
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
|
||||||
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
|
||||||
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
|
|
||||||
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
|
|
||||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
|
||||||
github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw=
|
|
||||||
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
|
||||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
|
||||||
github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0=
|
|
||||||
github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
|
|
||||||
github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
|
|
||||||
github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8=
|
|
||||||
github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
|
|
||||||
github.com/jackc/pgconn v0.0.0-20190420214824-7e0022ef6ba3/go.mod h1:jkELnwuX+w9qN5YIfX0fl88Ehu4XC3keFuOJJk9pcnA=
|
|
||||||
github.com/jackc/pgconn v0.0.0-20190824142844-760dd75542eb/go.mod h1:lLjNuW/+OfW9/pnVKPazfWOgNfH2aPem8YQ7ilXGvJE=
|
|
||||||
github.com/jackc/pgconn v0.0.0-20190831204454-2fabfa3c18b7/go.mod h1:ZJKsE/KZfsUgOEh9hBm+xYTstcNHg7UPMVJqRfQxq4s=
|
|
||||||
github.com/jackc/pgconn v1.8.0/go.mod h1:1C2Pb36bGIP9QHGBYCjnyhqu7Rv3sGshaQUvmfGIB/o=
|
|
||||||
github.com/jackc/pgconn v1.9.0/go.mod h1:YctiPyvzfU11JFxoXokUOOKQXQmDMoJL9vJzHH8/2JY=
|
|
||||||
github.com/jackc/pgconn v1.9.1-0.20210724152538-d89c8390a530/go.mod h1:4z2w8XhRbP1hYxkpTuBjTS3ne3J48K83+u0zoyvg2pI=
|
|
||||||
github.com/jackc/pgconn v1.14.0 h1:vrbA9Ud87g6JdFWkHTJXppVce58qPIdP7N8y0Ml/A7Q=
|
|
||||||
github.com/jackc/pgconn v1.14.0/go.mod h1:9mBNlny0UvkgJdCDvdVHYSjI+8tD2rnKK69Wz8ti++E=
|
|
||||||
github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE=
|
|
||||||
github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8=
|
|
||||||
github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE=
|
|
||||||
github.com/jackc/pgmock v0.0.0-20201204152224-4fe30f7445fd/go.mod h1:hrBW0Enj2AZTNpt/7Y5rr2xe/9Mn757Wtb2xeBzPv2c=
|
|
||||||
github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65 h1:DadwsjnMwFjfWc9y5Wi/+Zz7xoE5ALHsRQlOctkOiHc=
|
|
||||||
github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65/go.mod h1:5R2h2EEX+qri8jOWMbJCtaPWkrrNc7OHwsp2TCqp7ak=
|
|
||||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
|
||||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
|
||||||
github.com/jackc/pgproto3 v1.1.0 h1:FYYE4yRw+AgI8wXIinMlNjBbp/UitDJwfj5LqqewP1A=
|
|
||||||
github.com/jackc/pgproto3 v1.1.0/go.mod h1:eR5FA3leWg7p9aeAqi37XOTgTIbkABlvcPB3E5rlc78=
|
|
||||||
github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190420180111-c116219b62db/go.mod h1:bhq50y+xrl9n5mRYyCBFKkpRVTLYJVWeCc+mEAI3yXA=
|
|
||||||
github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190609003834-432c2951c711/go.mod h1:uH0AWtUmuShn0bcesswc4aBTWGvw0cAxIJp+6OB//Wg=
|
|
||||||
github.com/jackc/pgproto3/v2 v2.0.0-rc3/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM=
|
|
||||||
github.com/jackc/pgproto3/v2 v2.0.0-rc3.0.20190831210041-4c03ce451f29/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM=
|
|
||||||
github.com/jackc/pgproto3/v2 v2.0.6/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
|
||||||
github.com/jackc/pgproto3/v2 v2.1.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
|
||||||
github.com/jackc/pgproto3/v2 v2.3.2 h1:7eY55bdBeCz1F2fTzSz69QC+pG46jYq9/jtSPiJ5nn0=
|
|
||||||
github.com/jackc/pgproto3/v2 v2.3.2/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
|
||||||
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E=
|
|
||||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
|
|
||||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
|
||||||
github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01CGwFsrv11mJRHWJ6aifDLfdV3aVjFF0zg=
|
|
||||||
github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc=
|
|
||||||
github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59/go.mod h1:MWlu30kVJrUS8lot6TQqcg7mtthZ9T0EoIBFiJcmcyw=
|
|
||||||
github.com/jackc/pgtype v1.8.1-0.20210724151600-32e20a603178/go.mod h1:C516IlIV9NKqfsMCXTdChteoXmwgUceqaLfjg2e3NlM=
|
|
||||||
github.com/jackc/pgtype v1.14.0 h1:y+xUdabmyMkJLyApYuPj38mW+aAIqCe5uuBB51rH3Vw=
|
|
||||||
github.com/jackc/pgtype v1.14.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4=
|
|
||||||
github.com/jackc/pgx/v4 v4.0.0-20190420224344-cc3461e65d96/go.mod h1:mdxmSJJuR08CZQyj1PVQBHy9XOp5p8/SHH6a0psbY9Y=
|
|
||||||
github.com/jackc/pgx/v4 v4.0.0-20190421002000-1b8f0016e912/go.mod h1:no/Y67Jkk/9WuGR0JG/JseM9irFbnEPbuWV2EELPNuM=
|
|
||||||
github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQnOEnf1dqHGpw7JmHqHc1NxDoalibchSk9/RWuDc=
|
|
||||||
github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgSXP7iUjYm9C1NxKhny7lq6ee99u/z+IHFcgs=
|
|
||||||
github.com/jackc/pgx/v4 v4.18.1 h1:YP7G1KABtKpB5IHrO9vYwSrCOhs7p3uqhvhhQBptya0=
|
|
||||||
github.com/jackc/pgx/v4 v4.18.1/go.mod h1:FydWkUyadDmdNH/mHnGob881GawxeEm7TcMCzkb+qQE=
|
|
||||||
github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
|
||||||
github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
|
||||||
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
|
||||||
github.com/jackc/puddle v1.3.0 h1:eHK/5clGOatcjX3oWGBO/MpxpbHzSwud5EWTSCI+MX0=
|
|
||||||
github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
|
||||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
|
||||||
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
|
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
|
||||||
github.com/leonelquinteros/gotext v1.5.2 h1:T2y6ebHli+rMBCjcJlHTXyUrgXqsKBhl/ormgvt7lPo=
|
|
||||||
github.com/leonelquinteros/gotext v1.5.2/go.mod h1:AT4NpQrOmyj1L/+hLja6aR0lk81yYYL4ePnj2kp7d6M=
|
|
||||||
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
|
||||||
github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
|
||||||
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
|
||||||
github.com/lib/pq v1.10.2 h1:AqzbZs4ZoCBp+GtejcpCpcxM3zlSMx29dXbUSeVtJb8=
|
|
||||||
github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
|
||||||
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
|
|
||||||
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
|
||||||
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
|
||||||
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
|
||||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
|
||||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
|
||||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
|
||||||
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
|
|
||||||
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
|
|
||||||
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
|
|
||||||
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
|
||||||
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
|
|
||||||
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
|
|
||||||
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
|
||||||
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
|
|
||||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
|
||||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
|
||||||
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
|
||||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
|
||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
|
||||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
||||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
|
||||||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
|
||||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
|
||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
|
||||||
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
|
|
||||||
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
|
||||||
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
|
||||||
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
|
||||||
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
|
||||||
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
|
||||||
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
|
|
||||||
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
|
|
||||||
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
|
|
||||||
go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
|
||||||
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
|
||||||
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
|
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
|
||||||
golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
|
|
||||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
|
||||||
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
|
||||||
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
|
||||||
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
|
||||||
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
|
||||||
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
|
|
||||||
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
|
|
||||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
|
||||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
|
||||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
|
||||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
|
||||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
|
||||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
|
||||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
|
||||||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
|
||||||
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
|
|
||||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
|
||||||
golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
|
||||||
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
|
||||||
golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
|
||||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
|
||||||
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
|
||||||
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
|
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
|
File diff suppressed because it is too large
Load Diff
29
package.json
29
package.json
|
@ -1,29 +0,0 @@
|
||||||
{
|
|
||||||
"name": "tipus",
|
|
||||||
"version": "0.0.0",
|
|
||||||
"type": "module",
|
|
||||||
"description": "Single page editor",
|
|
||||||
"author": "Tàndem",
|
|
||||||
"license": "AGPL-3.0-or-later",
|
|
||||||
"scripts": {
|
|
||||||
"dev": "vite",
|
|
||||||
"build": "vite build",
|
|
||||||
"preview": "vite preview"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@wordpress/block-editor": "^13.0.0",
|
|
||||||
"@wordpress/block-library": "^9.0.0",
|
|
||||||
"@wordpress/components": "^28.0.0",
|
|
||||||
"@wordpress/compose": "^7.0.0",
|
|
||||||
"@wordpress/data": "^10.0.0",
|
|
||||||
"@wordpress/element": "^6.0.0",
|
|
||||||
"@wordpress/format-library": "^5.0.0",
|
|
||||||
"@wordpress/icons": "^10.0.0",
|
|
||||||
"@wordpress/interface": "^6.0.0"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@vitejs/plugin-react": "^4.3.1",
|
|
||||||
"sass": "^1.77.0",
|
|
||||||
"vite": "^5.2.0"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,71 +0,0 @@
|
||||||
package pkg
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"path"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ApplicationHandler struct {
|
|
||||||
db *Db
|
|
||||||
fileHandler http.Handler
|
|
||||||
loginHandler *LoginHandler
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewApplication(db *Db) http.Handler {
|
|
||||||
var handler http.Handler = &ApplicationHandler{
|
|
||||||
db: db,
|
|
||||||
fileHandler: http.FileServer(http.Dir("web/static")),
|
|
||||||
loginHandler: &LoginHandler{},
|
|
||||||
}
|
|
||||||
handler = LocaleSetter(db, handler)
|
|
||||||
handler = LoginChecker(db, handler)
|
|
||||||
handler = Recoverer(handler)
|
|
||||||
handler = Logger(handler)
|
|
||||||
return handler
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *ApplicationHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
||||||
var head string
|
|
||||||
head, r.URL.Path = shiftPath(r.URL.Path)
|
|
||||||
switch head {
|
|
||||||
case "static":
|
|
||||||
h.fileHandler.ServeHTTP(w, r)
|
|
||||||
case "login":
|
|
||||||
h.loginHandler.ServeHTTP(w, r)
|
|
||||||
case "edit":
|
|
||||||
switch r.Method {
|
|
||||||
case http.MethodGet:
|
|
||||||
mustRenderTemplate(w, r, "editor.gohtml", "web.gohtml", nil)
|
|
||||||
default:
|
|
||||||
methodNotAllowed(w, r, http.MethodGet)
|
|
||||||
}
|
|
||||||
case "":
|
|
||||||
switch r.Method {
|
|
||||||
case http.MethodGet:
|
|
||||||
h.serveHomePage(w, r)
|
|
||||||
default:
|
|
||||||
methodNotAllowed(w, r, http.MethodGet)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
http.NotFound(w, r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *ApplicationHandler) serveHomePage(w http.ResponseWriter, r *http.Request) {
|
|
||||||
mustRenderWebTemplate(w, r, "home.gohtml", nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func shiftPath(p string) (head, tail string) {
|
|
||||||
p = path.Clean("/" + p)
|
|
||||||
if i := strings.IndexByte(p[1:], '/') + 1; i <= 0 {
|
|
||||||
return p[1:], "/"
|
|
||||||
} else {
|
|
||||||
return p[1:i], p[i:]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func methodNotAllowed(w http.ResponseWriter, _ *http.Request, allowed ...string) {
|
|
||||||
w.Header().Set("Allow", strings.Join(allowed, ", "))
|
|
||||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
|
||||||
}
|
|
162
pkg/db.go
162
pkg/db.go
|
@ -1,162 +0,0 @@
|
||||||
package pkg
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/jackc/pgx/v4"
|
|
||||||
"github.com/jackc/pgx/v4/pgxpool"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Db struct {
|
|
||||||
*pgxpool.Pool
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewDatabase(ctx context.Context, connString string) (*Db, error) {
|
|
||||||
config, err := pgxpool.ParseConfig(connString)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
config.AfterConnect = func(ctx context.Context, conn *pgx.Conn) error {
|
|
||||||
if _, err := conn.Exec(ctx, "SET search_path TO tipus, public"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
config.BeforeAcquire = func(ctx context.Context, conn *pgx.Conn) bool {
|
|
||||||
cookie := ""
|
|
||||||
if value, ok := ctx.Value(ContextCookieKey).(string); ok {
|
|
||||||
cookie = value
|
|
||||||
}
|
|
||||||
if _, err := conn.Exec(ctx, "select set_cookie($1)", cookie); err != nil {
|
|
||||||
log.Printf("ERROR - Failed to set role: %v", err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
config.AfterRelease = func(conn *pgx.Conn) bool {
|
|
||||||
if _, err := conn.Exec(context.Background(), "RESET ROLE"); err != nil {
|
|
||||||
log.Printf("ERROR - Failed to reset role: %v", err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
pool, err := pgxpool.ConnectConfig(ctx, config)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &Db{pool}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func notFoundErrorOrPanic(err error) bool {
|
|
||||||
if err == pgx.ErrNoRows {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (db *Db) Acquire(ctx context.Context) (*Conn, error) {
|
|
||||||
conn, err := db.Pool.Acquire(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &Conn{conn}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (db *Db) MustAcquire(ctx context.Context) *Conn {
|
|
||||||
conn, err := db.Acquire(ctx)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return conn
|
|
||||||
}
|
|
||||||
|
|
||||||
type Conn struct {
|
|
||||||
*pgxpool.Conn
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Conn) MustBegin(ctx context.Context) *Tx {
|
|
||||||
tx, err := c.Begin(ctx)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return &Tx{tx}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Conn) MustGetText(ctx context.Context, def string, sql string, args ...interface{}) string {
|
|
||||||
var result string
|
|
||||||
if notFoundErrorOrPanic(c.Conn.QueryRow(ctx, sql, args...).Scan(&result)) {
|
|
||||||
return def
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Conn) MustGetBool(ctx context.Context, sql string, args ...interface{}) bool {
|
|
||||||
var result bool
|
|
||||||
if err := c.Conn.QueryRow(ctx, sql, args...).Scan(&result); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Conn) MustExec(ctx context.Context, sql string, args ...interface{}) {
|
|
||||||
if _, err := c.Conn.Exec(ctx, sql, args...); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Conn) MustQuery(ctx context.Context, sql string, args ...interface{}) pgx.Rows {
|
|
||||||
rows, err := c.Conn.Query(ctx, sql, args...)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return rows
|
|
||||||
}
|
|
||||||
|
|
||||||
type Tx struct {
|
|
||||||
pgx.Tx
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tx *Tx) MustCommit(ctx context.Context) {
|
|
||||||
if err := tx.Commit(ctx); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tx *Tx) MustRollback(ctx context.Context) {
|
|
||||||
if err := tx.Rollback(ctx); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tx *Tx) MustGetInteger(ctx context.Context, sql string, args ...interface{}) int {
|
|
||||||
var result int
|
|
||||||
if err := tx.QueryRow(ctx, sql, args...).Scan(&result); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tx *Tx) MustGetIntegerOrDefault(ctx context.Context, def int, sql string, args ...interface{}) int {
|
|
||||||
var result int
|
|
||||||
if notFoundErrorOrPanic(tx.QueryRow(ctx, sql, args...).Scan(&result)) {
|
|
||||||
return def
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tx *Tx) MustCopyFrom(ctx context.Context, tableName string, columns []string, rows [][]interface{}) int64 {
|
|
||||||
copied, err := tx.CopyFrom(ctx, pgx.Identifier{tableName}, columns, pgx.CopyFromRows(rows))
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return copied
|
|
||||||
}
|
|
|
@ -1,83 +0,0 @@
|
||||||
package form
|
|
||||||
|
|
||||||
import (
|
|
||||||
"database/sql/driver"
|
|
||||||
"fmt"
|
|
||||||
"html/template"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Attribute struct {
|
|
||||||
Key, Val string
|
|
||||||
}
|
|
||||||
|
|
||||||
type InputField struct {
|
|
||||||
Name string
|
|
||||||
Label string
|
|
||||||
Type string
|
|
||||||
Val string
|
|
||||||
Is string
|
|
||||||
Required bool
|
|
||||||
Attributes []template.HTMLAttr
|
|
||||||
Errors []error
|
|
||||||
}
|
|
||||||
|
|
||||||
func (field *InputField) Scan(value interface{}) error {
|
|
||||||
if value == nil {
|
|
||||||
field.Val = ""
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
switch v := value.(type) {
|
|
||||||
case time.Time:
|
|
||||||
if field.Type == "date" {
|
|
||||||
field.Val = v.Format("2006-01-02")
|
|
||||||
} else if field.Type == "time" {
|
|
||||||
field.Val = v.Format("15:04")
|
|
||||||
} else {
|
|
||||||
field.Val = v.Format(time.RFC3339)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
field.Val = fmt.Sprintf("%v", v)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (field *InputField) Value() (driver.Value, error) {
|
|
||||||
return field.Val, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (field *InputField) FillValue(r *http.Request) {
|
|
||||||
field.Val = strings.TrimSpace(r.FormValue(field.Name))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (field *InputField) Integer() int {
|
|
||||||
value, err := strconv.Atoi(field.Val)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
func (field *InputField) IntegerOrNil() interface{} {
|
|
||||||
if field.Val != "" {
|
|
||||||
if i := field.Integer(); i > 0 {
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (field *InputField) Float64() float64 {
|
|
||||||
value, err := strconv.ParseFloat(field.Val, 64)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
func (field *InputField) String() string {
|
|
||||||
return field.Val
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
package form
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"net/mail"
|
|
||||||
"net/url"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Validator struct {
|
|
||||||
Valid bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewValidator() *Validator {
|
|
||||||
return &Validator{true}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Validator) AllOK() bool {
|
|
||||||
return v.Valid
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Validator) CheckRequiredInput(field *InputField, message string) bool {
|
|
||||||
return v.checkInput(field, field.Val != "", message)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Validator) CheckInputMinLength(field *InputField, min int, message string) bool {
|
|
||||||
return v.checkInput(field, len(field.Val) >= min, message)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Validator) CheckValidEmailInput(field *InputField, message string) bool {
|
|
||||||
_, err := mail.ParseAddress(field.Val)
|
|
||||||
return v.checkInput(field, err == nil, message)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Validator) CheckPasswordConfirmation(password *InputField, confirm *InputField, message string) bool {
|
|
||||||
return v.checkInput(confirm, password.Val == confirm.Val, message)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Validator) CheckValidURL(field *InputField, message string) bool {
|
|
||||||
_, err := url.ParseRequestURI(field.Val)
|
|
||||||
return v.checkInput(field, err == nil, message)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Validator) CheckValidDate(field *InputField, message string) bool {
|
|
||||||
_, err := time.Parse("2006-01-02", field.Val)
|
|
||||||
return v.checkInput(field, err == nil, message)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Validator) CheckValidInteger(field *InputField, min int, max int, message string) bool {
|
|
||||||
value, err := strconv.Atoi(field.Val)
|
|
||||||
return v.checkInput(field, err == nil && value >= min && value <= max, message)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Validator) CheckValidDecimal(field *InputField, min float64, max float64, message string) bool {
|
|
||||||
value, err := strconv.ParseFloat(field.Val, 64)
|
|
||||||
return v.checkInput(field, err == nil && value >= min && value <= max, message)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Validator) checkInput(field *InputField, ok bool, message string) bool {
|
|
||||||
if !ok {
|
|
||||||
field.Errors = append(field.Errors, errors.New(message))
|
|
||||||
v.Valid = false
|
|
||||||
}
|
|
||||||
return ok
|
|
||||||
}
|
|
104
pkg/locale.go
104
pkg/locale.go
|
@ -1,104 +0,0 @@
|
||||||
package pkg
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/leonelquinteros/gotext"
|
|
||||||
"golang.org/x/text/language"
|
|
||||||
)
|
|
||||||
|
|
||||||
const contextLocaleKey = "tipus-locale"
|
|
||||||
|
|
||||||
type Locale struct {
|
|
||||||
*gotext.Locale
|
|
||||||
CurrencyPattern string
|
|
||||||
Language language.Tag
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewLocale(lang availableLanguage) *Locale {
|
|
||||||
return &Locale{
|
|
||||||
gotext.NewLocale("locales", lang.tag.String()),
|
|
||||||
lang.currencyPattern,
|
|
||||||
lang.tag,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func LocaleSetter(db *Db, next http.Handler) http.Handler {
|
|
||||||
availableLanguages := mustGetAvailableLanguages(db)
|
|
||||||
|
|
||||||
locales := map[language.Tag]*Locale{}
|
|
||||||
var tags []language.Tag
|
|
||||||
for _, lang := range availableLanguages {
|
|
||||||
locale := NewLocale(lang)
|
|
||||||
locale.AddDomain("tipus")
|
|
||||||
locales[lang.tag] = locale
|
|
||||||
tags = append(tags, lang.tag)
|
|
||||||
}
|
|
||||||
defaultLocale := locales[language.Catalan]
|
|
||||||
var matcher = language.NewMatcher(tags)
|
|
||||||
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
var locale *Locale
|
|
||||||
user := getUser(r)
|
|
||||||
locale = locales[user.Language]
|
|
||||||
if locale == nil {
|
|
||||||
t, _, err := language.ParseAcceptLanguage(r.Header.Get("Accept-Language"))
|
|
||||||
if err == nil {
|
|
||||||
tag, _, _ := matcher.Match(t...)
|
|
||||||
var ok bool
|
|
||||||
locale, ok = locales[tag]
|
|
||||||
for !ok && !tag.IsRoot() {
|
|
||||||
tag = tag.Parent()
|
|
||||||
locale, ok = locales[tag]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if locale == nil {
|
|
||||||
locale = defaultLocale
|
|
||||||
}
|
|
||||||
ctx := context.WithValue(r.Context(), contextLocaleKey, locale)
|
|
||||||
next.ServeHTTP(w, r.WithContext(ctx))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func getLocale(r *http.Request) *Locale {
|
|
||||||
return r.Context().Value(contextLocaleKey).(*Locale)
|
|
||||||
}
|
|
||||||
|
|
||||||
func pgettext(context string, str string, locale *Locale) string {
|
|
||||||
return locale.GetC(str, context)
|
|
||||||
}
|
|
||||||
|
|
||||||
func gettext(str string, locale *Locale) string {
|
|
||||||
return locale.Get(str)
|
|
||||||
}
|
|
||||||
|
|
||||||
type availableLanguage struct {
|
|
||||||
tag language.Tag
|
|
||||||
currencyPattern string
|
|
||||||
}
|
|
||||||
|
|
||||||
func mustGetAvailableLanguages(db *Db) []availableLanguage {
|
|
||||||
rows, err := db.Query(context.Background(), "select lang_tag, currency_pattern from language where selectable")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
|
||||||
|
|
||||||
var langs []availableLanguage
|
|
||||||
for rows.Next() {
|
|
||||||
var langTag string
|
|
||||||
var currencyPattern string
|
|
||||||
err = rows.Scan(&langTag, ¤cyPattern)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
langs = append(langs, availableLanguage{language.MustParse(langTag), currencyPattern})
|
|
||||||
}
|
|
||||||
if rows.Err() != nil {
|
|
||||||
panic(rows.Err())
|
|
||||||
}
|
|
||||||
|
|
||||||
return langs
|
|
||||||
}
|
|
|
@ -1,60 +0,0 @@
|
||||||
package pkg
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type loggerResponseWriter struct {
|
|
||||||
http.ResponseWriter
|
|
||||||
statusCode int
|
|
||||||
responseSize int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *loggerResponseWriter) WriteHeader(statusCode int) {
|
|
||||||
w.statusCode = statusCode
|
|
||||||
w.ResponseWriter.WriteHeader(statusCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *loggerResponseWriter) Write(b []byte) (int, error) {
|
|
||||||
w.responseSize += len(b)
|
|
||||||
return w.ResponseWriter.Write(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *loggerResponseWriter) Flush() {
|
|
||||||
if f, ok := w.ResponseWriter.(http.Flusher); ok {
|
|
||||||
f.Flush()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func Logger(handler http.Handler) http.Handler {
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
t := time.Now()
|
|
||||||
logger := loggerResponseWriter{w, 0, 0}
|
|
||||||
|
|
||||||
handler.ServeHTTP(&logger, r)
|
|
||||||
|
|
||||||
statusCode := logger.statusCode
|
|
||||||
if statusCode == 0 {
|
|
||||||
statusCode = http.StatusOK
|
|
||||||
}
|
|
||||||
referer := r.Referer()
|
|
||||||
if referer == "" {
|
|
||||||
referer = "-"
|
|
||||||
}
|
|
||||||
log.Printf("HTTP - %s - - [%s] \"%s %s %s\" %d %d \"%s\" \"%s\" %s\n",
|
|
||||||
r.RemoteAddr,
|
|
||||||
t.Format("02/Jan/2006:15:04:05 -0700"),
|
|
||||||
r.Method,
|
|
||||||
r.URL.Path,
|
|
||||||
r.Proto,
|
|
||||||
statusCode,
|
|
||||||
logger.responseSize,
|
|
||||||
referer,
|
|
||||||
r.UserAgent(),
|
|
||||||
time.Since(t),
|
|
||||||
)
|
|
||||||
|
|
||||||
})
|
|
||||||
}
|
|
207
pkg/login.go
207
pkg/login.go
|
@ -1,207 +0,0 @@
|
||||||
package pkg
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"html/template"
|
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"dev.tandem.ws/tandem/tipus/pkg/form"
|
|
||||||
"golang.org/x/text/language"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
ContextUserKey = "tipus-user"
|
|
||||||
ContextCookieKey = "tipus-cookie"
|
|
||||||
ContextConnKey = "tipus-database"
|
|
||||||
sessionCookie = "tipus-session"
|
|
||||||
defaultRole = "guest"
|
|
||||||
csrfTokenField = "csfrToken"
|
|
||||||
)
|
|
||||||
|
|
||||||
type loginForm struct {
|
|
||||||
locale *Locale
|
|
||||||
Errors []error
|
|
||||||
Email *form.InputField
|
|
||||||
Password *form.InputField
|
|
||||||
}
|
|
||||||
|
|
||||||
func newLoginForm(locale *Locale) *loginForm {
|
|
||||||
return &loginForm{
|
|
||||||
locale: locale,
|
|
||||||
Email: &form.InputField{
|
|
||||||
Name: "email",
|
|
||||||
Label: pgettext("input", "Email", locale),
|
|
||||||
Type: "email",
|
|
||||||
Required: true,
|
|
||||||
Attributes: []template.HTMLAttr{
|
|
||||||
`autofocus="autofocus"`,
|
|
||||||
`autocomplete="username"`,
|
|
||||||
`autocapitalize="none"`,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Password: &form.InputField{
|
|
||||||
Name: "password",
|
|
||||||
Label: pgettext("input", "Password", locale),
|
|
||||||
Type: "password",
|
|
||||||
Required: true,
|
|
||||||
Attributes: []template.HTMLAttr{
|
|
||||||
`autocomplete="current-password"`,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *loginForm) Parse(r *http.Request) error {
|
|
||||||
err := r.ParseForm()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
f.Email.FillValue(r)
|
|
||||||
f.Password.FillValue(r)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *loginForm) Validate() bool {
|
|
||||||
validator := form.NewValidator()
|
|
||||||
if validator.CheckRequiredInput(f.Email, gettext("Email can not be empty.", f.locale)) {
|
|
||||||
validator.CheckValidEmailInput(f.Email, gettext("This value is not a valid email. It should be like name@domain.com.", f.locale))
|
|
||||||
}
|
|
||||||
validator.CheckRequiredInput(f.Password, gettext("Password can not be empty.", f.locale))
|
|
||||||
return validator.AllOK()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *loginForm) mustRender(w http.ResponseWriter, r *http.Request) {
|
|
||||||
mustRenderWebTemplate(w, r, "login.gohtml", f)
|
|
||||||
}
|
|
||||||
|
|
||||||
type LoginHandler struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *LoginHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
||||||
var head string
|
|
||||||
head, r.URL.Path = shiftPath(r.URL.Path)
|
|
||||||
switch head {
|
|
||||||
case "":
|
|
||||||
switch r.Method {
|
|
||||||
case http.MethodGet:
|
|
||||||
h.serveLoginForm(w, r)
|
|
||||||
case http.MethodPost:
|
|
||||||
h.handleLogin(w, r)
|
|
||||||
default:
|
|
||||||
methodNotAllowed(w, r, http.MethodGet, http.MethodPost)
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
http.NotFound(w, r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *LoginHandler) serveLoginForm(w http.ResponseWriter, r *http.Request) {
|
|
||||||
user := getUser(r)
|
|
||||||
if user.LoggedIn {
|
|
||||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
locale := getLocale(r)
|
|
||||||
login := newLoginForm(locale)
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
login.mustRender(w, r)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *LoginHandler) handleLogin(w http.ResponseWriter, r *http.Request) {
|
|
||||||
user := getUser(r)
|
|
||||||
if user.LoggedIn {
|
|
||||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
locale := getLocale(r)
|
|
||||||
login := newLoginForm(locale)
|
|
||||||
if err := login.Parse(r); err != nil {
|
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if login.Validate() {
|
|
||||||
conn := getConn(r)
|
|
||||||
cookie := conn.MustGetText(r.Context(), "", "select login($1, $2, $3)", login.Email, login.Password, remoteAddr(r))
|
|
||||||
if cookie != "" {
|
|
||||||
setSessionCookie(w, cookie)
|
|
||||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
login.Errors = append(login.Errors, errors.New(gettext("Invalid user or password.", locale)))
|
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
|
||||||
} else {
|
|
||||||
w.WriteHeader(http.StatusUnprocessableEntity)
|
|
||||||
}
|
|
||||||
login.mustRender(w, r)
|
|
||||||
}
|
|
||||||
|
|
||||||
func remoteAddr(r *http.Request) string {
|
|
||||||
address := r.Header.Get("X-Forwarded-For")
|
|
||||||
if address == "" {
|
|
||||||
address, _, _ = net.SplitHostPort(r.RemoteAddr)
|
|
||||||
}
|
|
||||||
return address
|
|
||||||
}
|
|
||||||
|
|
||||||
func setSessionCookie(w http.ResponseWriter, cookie string) {
|
|
||||||
http.SetCookie(w, createSessionCookie(cookie, 8766*24*time.Hour))
|
|
||||||
}
|
|
||||||
|
|
||||||
func createSessionCookie(value string, duration time.Duration) *http.Cookie {
|
|
||||||
return &http.Cookie{
|
|
||||||
Name: sessionCookie,
|
|
||||||
Value: value,
|
|
||||||
Path: "/",
|
|
||||||
Expires: time.Now().Add(duration),
|
|
||||||
HttpOnly: true,
|
|
||||||
SameSite: http.SameSiteLaxMode,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type AppUser struct {
|
|
||||||
Email string
|
|
||||||
LoggedIn bool
|
|
||||||
Role string
|
|
||||||
Language language.Tag
|
|
||||||
CsrfToken string
|
|
||||||
}
|
|
||||||
|
|
||||||
func LoginChecker(db *Db, next http.Handler) http.Handler {
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
var ctx = r.Context()
|
|
||||||
if cookie, err := r.Cookie(sessionCookie); err == nil {
|
|
||||||
ctx = context.WithValue(ctx, ContextCookieKey, cookie.Value)
|
|
||||||
}
|
|
||||||
|
|
||||||
conn := db.MustAcquire(ctx)
|
|
||||||
defer conn.Release()
|
|
||||||
ctx = context.WithValue(ctx, ContextConnKey, conn)
|
|
||||||
|
|
||||||
user := &AppUser{
|
|
||||||
Email: "",
|
|
||||||
LoggedIn: false,
|
|
||||||
Role: defaultRole,
|
|
||||||
}
|
|
||||||
row := conn.QueryRow(ctx, "select coalesce(email, ''), role, lang_tag, csrf_token from user_profile")
|
|
||||||
var langTag string
|
|
||||||
if err := row.Scan(&user.Email, &user.Role, &langTag, &user.CsrfToken); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
user.LoggedIn = user.Email != ""
|
|
||||||
user.Language, _ = language.Parse(langTag)
|
|
||||||
ctx = context.WithValue(ctx, ContextUserKey, user)
|
|
||||||
|
|
||||||
next.ServeHTTP(w, r.WithContext(ctx))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func getUser(r *http.Request) *AppUser {
|
|
||||||
return r.Context().Value(ContextUserKey).(*AppUser)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getConn(r *http.Request) *Conn {
|
|
||||||
return r.Context().Value(ContextConnKey).(*Conn)
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
package pkg
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"runtime"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Recoverer(next http.Handler) http.Handler {
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
if r == http.ErrAbortHandler {
|
|
||||||
panic(r)
|
|
||||||
}
|
|
||||||
err, ok := r.(error)
|
|
||||||
if !ok {
|
|
||||||
err = fmt.Errorf("%v", r)
|
|
||||||
}
|
|
||||||
stack := make([]byte, 4<<10)
|
|
||||||
length := runtime.Stack(stack, true)
|
|
||||||
log.Printf("PANIC - %v %s", err, stack[:length])
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
next.ServeHTTP(w, r)
|
|
||||||
})
|
|
||||||
}
|
|
|
@ -1,41 +0,0 @@
|
||||||
package pkg
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"html/template"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
func templateFile(name string) string {
|
|
||||||
return "web/template/" + name
|
|
||||||
}
|
|
||||||
|
|
||||||
func mustRenderTemplate(wr io.Writer, r *http.Request, layout string, filename string, data interface{}) {
|
|
||||||
locale := getLocale(r)
|
|
||||||
user := getUser(r)
|
|
||||||
t := template.New(filename)
|
|
||||||
t.Funcs(template.FuncMap{
|
|
||||||
"gettext": locale.Get,
|
|
||||||
"pgettext": locale.GetC,
|
|
||||||
"currentLocale": func() string {
|
|
||||||
return locale.Language.String()
|
|
||||||
},
|
|
||||||
"csrfToken": func() template.HTML {
|
|
||||||
return template.HTML(fmt.Sprintf(`<input type="hidden" name="%s" value="%s">`, csrfTokenField, user.CsrfToken))
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if _, err := t.ParseFiles(templateFile(filename), templateFile(layout), templateFile("form.gohtml")); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
if w, ok := wr.(http.ResponseWriter); ok {
|
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
||||||
}
|
|
||||||
if err := t.ExecuteTemplate(wr, layout, data); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func mustRenderWebTemplate(w io.Writer, r *http.Request, filename string, data interface{}) {
|
|
||||||
mustRenderTemplate(w, r, "web.gohtml", filename, data)
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
../../node_modules/@wordpress/a11y/src
|
|
|
@ -1 +0,0 @@
|
||||||
../../node_modules/@wordpress/annotations/src
|
|
|
@ -1 +0,0 @@
|
||||||
../../node_modules/@wordpress/api-fetch/src
|
|
|
@ -1 +0,0 @@
|
||||||
../../node_modules/@wordpress/block-editor/src
|
|
|
@ -1 +0,0 @@
|
||||||
../../node_modules/@wordpress/block-library/src
|
|
|
@ -1 +0,0 @@
|
||||||
../../node_modules/@wordpress/blocks/src
|
|
|
@ -1 +0,0 @@
|
||||||
../../node_modules/@wordpress/components/src
|
|
|
@ -1 +0,0 @@
|
||||||
../../node_modules/@wordpress/core-data/src
|
|
|
@ -1 +0,0 @@
|
||||||
../../node_modules/@wordpress/edit-post/src
|
|
|
@ -1 +0,0 @@
|
||||||
../../node_modules/@wordpress/editor/src
|
|
|
@ -1 +0,0 @@
|
||||||
../../node_modules/@wordpress/format-library/src
|
|
|
@ -1 +0,0 @@
|
||||||
../../node_modules/@wordpress/interface/src
|
|
|
@ -1 +0,0 @@
|
||||||
../../node_modules/@automattic/isolated-block-editor/src/
|
|
|
@ -1 +0,0 @@
|
||||||
../../node_modules/@wordpress/keycodes/src
|
|
|
@ -1 +0,0 @@
|
||||||
../../node_modules/@wordpress/list-reusable-blocks/src
|
|
|
@ -1 +0,0 @@
|
||||||
../../node_modules/@wordpress/media-utils/src
|
|
|
@ -1 +0,0 @@
|
||||||
../../node_modules/@wordpress/preferences/src
|
|
|
@ -1 +0,0 @@
|
||||||
../../node_modules/@wordpress/reusable-blocks/src
|
|
|
@ -1 +0,0 @@
|
||||||
../../node_modules/@wordpress/rich-text/src
|
|
|
@ -1 +0,0 @@
|
||||||
../../node_modules/@wordpress/server-side-render/src
|
|
|
@ -1 +0,0 @@
|
||||||
../../node_modules/@wordpress/widgets/src
|
|
|
@ -1,8 +0,0 @@
|
||||||
-- Revert tipus:available_languages from pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
delete
|
|
||||||
from public.language;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,7 +0,0 @@
|
||||||
-- Revert tipus:build_cookie from pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
drop function if exists tipus.build_cookie(tipus.email, text);
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,7 +0,0 @@
|
||||||
-- Revert tipus:change_password from pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
drop function if exists tipus.change_password(text);
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,7 +0,0 @@
|
||||||
-- Revert tipus:check_cookie from pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
drop function if exists public.check_cookie(text);
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,7 +0,0 @@
|
||||||
-- Revert tipus:current_user_cookie from pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
drop function if exists tipus.current_user_cookie();
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,7 +0,0 @@
|
||||||
-- Revert tipus:current_user_email from pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
drop function if exists tipus.current_user_email();
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,7 +0,0 @@
|
||||||
-- Revert tipus:email from pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
drop domain if exists tipus.email;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,8 +0,0 @@
|
||||||
-- Revert tipus:encrypt_password from pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
drop trigger if exists encrypt_password on auth."user";
|
|
||||||
drop function if exists auth.encrypt_password();
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,8 +0,0 @@
|
||||||
-- Revert tipus:ensure_role_exists from pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
drop trigger if exists ensure_role_exists on auth."user";
|
|
||||||
drop function if exists auth.ensure_role_exists();
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,7 +0,0 @@
|
||||||
-- Revert tipus:extension_citext from pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
drop extension if exists citext;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,7 +0,0 @@
|
||||||
-- Revert tipus:extension_pgcrypto from pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
drop extension if exists pgcrypto;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,7 +0,0 @@
|
||||||
-- Revert tipus:language from pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
drop table if exists public.language;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,7 +0,0 @@
|
||||||
-- Revert tipus:login from pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
drop function if exists tipus.login(tipus.email, text, inet);
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,7 +0,0 @@
|
||||||
-- Revert tipus:login_attempt from pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
drop table if exists auth.login_attempt;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,7 +0,0 @@
|
||||||
-- Revert tipus:logout from pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
drop function if exists tipus.logout();
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,10 +0,0 @@
|
||||||
-- Revert tipus:roles from pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
drop role authenticator;
|
|
||||||
drop role admin;
|
|
||||||
drop role publisher;
|
|
||||||
drop role guest;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,7 +0,0 @@
|
||||||
-- Revert tipus:schema_auth from pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
drop schema if exists auth;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,12 +0,0 @@
|
||||||
-- Revert tipus:schema_public from pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
alter default privileges grant execute on functions to public;
|
|
||||||
|
|
||||||
revoke usage on schema public from authenticator;
|
|
||||||
revoke usage on schema public from admin;
|
|
||||||
revoke usage on schema public from publisher;
|
|
||||||
revoke usage on schema public from guest;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,7 +0,0 @@
|
||||||
-- Revert tipus:schema_tipus from pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
drop schema if exists tipus;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,7 +0,0 @@
|
||||||
-- Revert tipus:set_cookie from pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
drop function if exists public.set_cookie(text);
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,7 +0,0 @@
|
||||||
-- Revert tipus:user from pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
drop table if exists auth."user";
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,9 +0,0 @@
|
||||||
-- Revert tipus:user_profile from pg
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
drop trigger if exists update_user_profile on tipus.user_profile;
|
|
||||||
drop function if exists tipus.update_user_profile();
|
|
||||||
drop view if exists tipus.user_profile;
|
|
||||||
|
|
||||||
commit;
|
|
|
@ -1,8 +0,0 @@
|
||||||
[core]
|
|
||||||
engine = pg
|
|
||||||
[engine "pg"]
|
|
||||||
target = db:pg:tipus
|
|
||||||
[deploy]
|
|
||||||
verify = true
|
|
||||||
[rebase]
|
|
||||||
verify = true
|
|
26
sqitch.plan
26
sqitch.plan
|
@ -1,26 +0,0 @@
|
||||||
%syntax-version=1.0.0
|
|
||||||
%project=tipus
|
|
||||||
%uri=https://dev.tandem.ws/tandem/tipus
|
|
||||||
|
|
||||||
roles 2023-06-04T19:01:41Z jordi fita mas <jordi@tandem.blog> # Add database roles
|
|
||||||
schema_auth [roles] 2023-06-04T19:08:37Z jordi fita mas <jordi@tandem.blog> # Add authentication schema
|
|
||||||
schema_public [roles] 2023-06-04T19:11:16Z jordi fita mas <jordi@tandem.blog> # Set privileges to public schema
|
|
||||||
schema_tipus [roles] 2023-06-04T19:13:28Z jordi fita mas <jordi@tandem.blog> # Add application schema
|
|
||||||
extension_citext [schema_public] 2023-06-04T19:15:31Z jordi fita mas <jordi@tandem.blog> # Add citext extension
|
|
||||||
email [schema_tipus extension_citext] 2023-06-04T19:18:12Z jordi fita mas <jordi@tandem.blog> # Add citext extension
|
|
||||||
language [roles schema_public] 2023-06-04T19:20:29Z jordi fita mas <jordi@tandem.blog> # Add relation of available languages
|
|
||||||
available_languages [schema_public language] 2023-06-04T19:23:35Z jordi fita mas <jordi@tandem.blog> # Add the initial available languages
|
|
||||||
user [schema_auth email language] 2023-06-04T19:26:15Z jordi fita mas <jordi@tandem.blog> # Add user relation
|
|
||||||
ensure_role_exists [schema_auth user] 2023-06-04T19:28:20Z jordi fita mas <jordi@tandem.blog> # Add trigger to ensure the user’s role exists
|
|
||||||
extension_pgcrypto [schema_auth] 2023-06-04T19:30:11Z jordi fita mas <jordi@tandem.blog> # Add pgcrypto extension
|
|
||||||
encrypt_password [schema_auth user extension_pgcrypto] 2023-06-04T19:32:12Z jordi fita mas <jordi@tandem.blog> # Add trigger to encrypt user’s password
|
|
||||||
login_attempt [schema_auth] 2023-06-04T19:35:24Z jordi fita mas <jordi@tandem.blog> # Add relation to log login attempts
|
|
||||||
check_cookie [roles schema_public schema_auth user] 2023-06-04T19:47:48Z jordi fita mas <jordi@tandem.blog> # Add function to check if a user cookie is valid
|
|
||||||
current_user_cookie [roles schema_tipus] 2023-06-04T19:40:43Z jordi fita mas <jordi@tandem.blog> # Add function to get the cookie of the current Tipus’ user
|
|
||||||
current_user_email [roles schema_tipus] 2023-06-04T19:42:44Z jordi fita mas <jordi@tandem.blog> # Add function to get the email of the current Tipus’ user
|
|
||||||
build_cookie [roles schema_tipus current_user_email current_user_cookie] 2023-06-04T19:44:45Z jordi fita mas <jordi@tandem.blog> # Add function to build the cookie for the current user
|
|
||||||
set_cookie [roles schema_public check_cookie] 2023-06-04T19:50:49Z jordi fita mas <jordi@tandem.blog> # Add function to set the role based on the cookie
|
|
||||||
login [roles schema_auth schema_tipus extension_pgcrypto email user login_attempt build_cookie] 2023-06-04T19:53:03Z jordi fita mas <jordi@tandem.blog> # Add function to login
|
|
||||||
logout [roles schema_auth schema_tipus current_user_email current_user_cookie user] 2023-06-04T19:56:18Z jordi fita mas <jordi@tandem.blog> # Add function to logout
|
|
||||||
user_profile [roles schema_tipus user current_user_email current_user_cookie] 2023-06-04T19:58:34Z jordi fita mas <jordi@tandem.blog> # Add view for user profile
|
|
||||||
change_password [roles schema_auth schema_tipus user] 2023-06-04T20:00:49Z jordi fita mas <jordi@tandem.blog> # Add function to change the current user’s password
|
|
|
@ -1,72 +0,0 @@
|
||||||
-- Test build_cookie
|
|
||||||
set client_min_messages to warning;
|
|
||||||
create extension if not exists pgtap;
|
|
||||||
reset client_min_messages;
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
select plan(13);
|
|
||||||
|
|
||||||
set search_path to tipus, auth, public;
|
|
||||||
|
|
||||||
select has_function('tipus', 'build_cookie', array ['email', 'text']);
|
|
||||||
select function_lang_is('tipus', 'build_cookie', array ['email', 'text'], 'sql');
|
|
||||||
select function_returns('tipus', 'build_cookie', array ['email', 'text'], 'text');
|
|
||||||
select isnt_definer('tipus', 'build_cookie', array ['email', 'text']);
|
|
||||||
select volatility_is('tipus', 'build_cookie', array ['email', 'text'], 'stable');
|
|
||||||
select function_privs_are('tipus', 'build_cookie', array ['email', 'text'], 'guest', array []::text[]);
|
|
||||||
select function_privs_are('tipus', 'build_cookie', array ['email', 'text'], 'publisher', array ['EXECUTE']);
|
|
||||||
select function_privs_are('tipus', 'build_cookie', array ['email', 'text'], 'admin', array ['EXECUTE']);
|
|
||||||
select function_privs_are('tipus', 'build_cookie', array ['email', 'text'], 'authenticator', array []::text[]);
|
|
||||||
|
|
||||||
set client_min_messages to warning;
|
|
||||||
truncate auth."user" cascade;
|
|
||||||
reset client_min_messages;
|
|
||||||
|
|
||||||
insert into auth."user" (user_id, email, name, password, role, cookie, cookie_expires_at)
|
|
||||||
values (1, 'demo@tandem.blog', 'Demo', 'test', 'publisher', '44facbb30d8a419dfd4bfbc44a4b5539d4970148dfc84bed0e',
|
|
||||||
current_timestamp + interval '1 month')
|
|
||||||
, (9, 'admin@tandem.blog', 'Demo', 'test', 'admin', '12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524',
|
|
||||||
current_timestamp + interval '1 month')
|
|
||||||
;
|
|
||||||
|
|
||||||
select is(
|
|
||||||
build_cookie('test@example.com'::email, '123abc'),
|
|
||||||
'123abc/test@example.com',
|
|
||||||
'Should build the cookie with the given user and cookie value'
|
|
||||||
);
|
|
||||||
|
|
||||||
select set_cookie('44facbb30d8a419dfd4bfbc44a4b5539d4970148dfc84bed0e/demo@tandem.blog');
|
|
||||||
reset role;
|
|
||||||
|
|
||||||
select is(
|
|
||||||
build_cookie(),
|
|
||||||
'44facbb30d8a419dfd4bfbc44a4b5539d4970148dfc84bed0e/demo@tandem.blog',
|
|
||||||
'Should build the cookie for the logged in user'
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
select set_cookie('12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524/admin@tandem.blog');
|
|
||||||
reset role;
|
|
||||||
|
|
||||||
select is(
|
|
||||||
build_cookie(),
|
|
||||||
'12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524/admin@tandem.blog',
|
|
||||||
'Should build the cookie for the other logged in user'
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
select set_cookie('ashtasth');
|
|
||||||
reset role;
|
|
||||||
|
|
||||||
select is(
|
|
||||||
build_cookie(),
|
|
||||||
'/',
|
|
||||||
'Should build the cookie for the guest user'
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
select *
|
|
||||||
from finish();
|
|
||||||
|
|
||||||
rollback;
|
|
|
@ -1,59 +0,0 @@
|
||||||
-- Test change_password
|
|
||||||
set client_min_messages to warning;
|
|
||||||
create extension if not exists pgtap;
|
|
||||||
reset client_min_messages;
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
select plan(14);
|
|
||||||
|
|
||||||
set search_path to tipus, auth, public;
|
|
||||||
|
|
||||||
select has_function('tipus', 'change_password', array ['text']);
|
|
||||||
select function_lang_is('tipus', 'change_password', array ['text'], 'sql');
|
|
||||||
select function_returns('tipus', 'change_password', array ['text'], 'void');
|
|
||||||
select is_definer('tipus', 'change_password', array ['text']);
|
|
||||||
select volatility_is('tipus', 'change_password', array ['text'], 'volatile');
|
|
||||||
select function_privs_are('tipus', 'change_password', array ['text'], 'guest', array []::text[]);
|
|
||||||
select function_privs_are('tipus', 'change_password', array ['text'], 'publisher', array ['EXECUTE']);
|
|
||||||
select function_privs_are('tipus', 'change_password', array ['text'], 'admin', array ['EXECUTE']);
|
|
||||||
select function_privs_are('tipus', 'change_password', array ['text'], 'authenticator', array []::text[]);
|
|
||||||
|
|
||||||
set client_min_messages to warning;
|
|
||||||
truncate auth."user" cascade;
|
|
||||||
reset client_min_messages;
|
|
||||||
|
|
||||||
insert into auth."user" (user_id, email, name, password, role, cookie, cookie_expires_at)
|
|
||||||
values (1, 'demo@tandem.blog', 'Demo', 'test', 'publisher', '44facbb30d8a419dfd4bfbc44a4b5539d4970148dfc84bed0e',
|
|
||||||
current_timestamp + interval '1 month')
|
|
||||||
, (9, 'admin@tandem.blog', 'Demo', 'test', 'admin', '12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524',
|
|
||||||
current_timestamp + interval '1 month')
|
|
||||||
;
|
|
||||||
|
|
||||||
select lives_ok($$ select change_password('another') $$, 'Should run even without current user');
|
|
||||||
|
|
||||||
select isnt_empty(
|
|
||||||
$$ select * from auth."user" where password = crypt('test', password) $$,
|
|
||||||
'Should not have changed any password'
|
|
||||||
);
|
|
||||||
|
|
||||||
select set_cookie('44facbb30d8a419dfd4bfbc44a4b5539d4970148dfc84bed0e/demo@tandem.blog');
|
|
||||||
|
|
||||||
select lives_ok($$ select change_password('another') $$, 'Should run with the correct user');
|
|
||||||
|
|
||||||
reset role;
|
|
||||||
|
|
||||||
select isnt_empty(
|
|
||||||
$$ select * from auth."user" where email = 'demo@tandem.blog' and password = crypt('another', password) $$,
|
|
||||||
'Should have changed the password of the current user'
|
|
||||||
);
|
|
||||||
|
|
||||||
select isnt_empty(
|
|
||||||
$$ select * from auth."user" where email = 'admin@tandem.blog' and password = crypt('test', password) $$,
|
|
||||||
'Should not have changed any other password'
|
|
||||||
);
|
|
||||||
|
|
||||||
select *
|
|
||||||
from finish();
|
|
||||||
|
|
||||||
rollback;
|
|
|
@ -1,115 +0,0 @@
|
||||||
-- Test check_cookie
|
|
||||||
set client_min_messages to warning;
|
|
||||||
create extension if not exists pgtap;
|
|
||||||
reset client_min_messages;
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
select plan(21);
|
|
||||||
|
|
||||||
set search_path to auth, tipus, public;
|
|
||||||
|
|
||||||
select has_function('public', 'check_cookie', array ['text']);
|
|
||||||
select function_lang_is('public', 'check_cookie', array ['text'], 'plpgsql');
|
|
||||||
select function_returns('public', 'check_cookie', array ['text'], 'name');
|
|
||||||
select is_definer('public', 'check_cookie', array ['text']);
|
|
||||||
select volatility_is('public', 'check_cookie', array ['text'], 'stable');
|
|
||||||
select function_privs_are('public', 'check_cookie', array ['text'], 'guest', array []::text[]);
|
|
||||||
select function_privs_are('public', 'check_cookie', array ['text'], 'publisher', array []::text[]);
|
|
||||||
select function_privs_are('public', 'check_cookie', array ['text'], 'admin', array []::text[]);
|
|
||||||
select function_privs_are('public', 'check_cookie', array ['text'], 'authenticator', array ['EXECUTE']);
|
|
||||||
|
|
||||||
set client_min_messages to warning;
|
|
||||||
truncate auth."user" cascade;
|
|
||||||
reset client_min_messages;
|
|
||||||
|
|
||||||
insert into auth."user" (user_id, email, name, password, role, cookie, cookie_expires_at)
|
|
||||||
values (1, 'demo@tandem.blog', 'Demo', 'test', 'publisher', '44facbb30d8a419dfd4bfbc44a4b5539d4970148dfc84bed0e',
|
|
||||||
current_timestamp + interval '1 month')
|
|
||||||
, (9, 'admin@tandem.blog', 'Demo', 'test', 'admin', '12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524',
|
|
||||||
current_timestamp + interval '1 month')
|
|
||||||
;
|
|
||||||
|
|
||||||
prepare user_info as
|
|
||||||
select current_user_email(), current_user_cookie();
|
|
||||||
|
|
||||||
select is(
|
|
||||||
check_cookie('44facbb30d8a419dfd4bfbc44a4b5539d4970148dfc84bed0e/demo@tandem.blog'),
|
|
||||||
'publisher'::name,
|
|
||||||
'Should validate the cookie for the first user'
|
|
||||||
);
|
|
||||||
|
|
||||||
select results_eq(
|
|
||||||
'user_info',
|
|
||||||
$$ values ('demo@tandem.blog', '44facbb30d8a419dfd4bfbc44a4b5539d4970148dfc84bed0e') $$,
|
|
||||||
'Should have updated the settings with the user info'
|
|
||||||
);
|
|
||||||
|
|
||||||
select is(
|
|
||||||
check_cookie('12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524/admin@tandem.blog'),
|
|
||||||
'admin'::name,
|
|
||||||
'Should validate the cookie for the second user'
|
|
||||||
);
|
|
||||||
|
|
||||||
select results_eq(
|
|
||||||
'user_info',
|
|
||||||
$$ values ('admin@tandem.blog', '12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524') $$,
|
|
||||||
'Should have updated the settings with the other user info'
|
|
||||||
);
|
|
||||||
|
|
||||||
select is(
|
|
||||||
check_cookie('44facbb30d8a419dfd4bfbc44a4b5539d4970148dfc84bed0e/admin@tandem.blog'),
|
|
||||||
'guest'::name,
|
|
||||||
'Should only match with the correct email'
|
|
||||||
);
|
|
||||||
|
|
||||||
select results_eq(
|
|
||||||
'user_info',
|
|
||||||
$$ values ('', '') $$,
|
|
||||||
'Should have updated the settings with a guest user'
|
|
||||||
);
|
|
||||||
|
|
||||||
select is(
|
|
||||||
check_cookie('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/admin@tandem.blog'),
|
|
||||||
'guest'::name,
|
|
||||||
'Should only match with the correct cookie value'
|
|
||||||
);
|
|
||||||
|
|
||||||
select results_eq(
|
|
||||||
'user_info',
|
|
||||||
$$ values ('', '') $$,
|
|
||||||
'Should have left the settings with a guest user'
|
|
||||||
);
|
|
||||||
|
|
||||||
update "user"
|
|
||||||
set cookie_expires_at = current_timestamp - interval '1 minute';
|
|
||||||
|
|
||||||
select is(
|
|
||||||
check_cookie('44facbb30d8a419dfd4bfbc44a4b5539d4970148dfc84bed0e/demo@tandem.blog'),
|
|
||||||
'guest'::name,
|
|
||||||
'Should not allow expired cookies'
|
|
||||||
);
|
|
||||||
|
|
||||||
select results_eq(
|
|
||||||
'user_info',
|
|
||||||
$$ values ('', '') $$,
|
|
||||||
'Should have left the settings with a guest user'
|
|
||||||
);
|
|
||||||
|
|
||||||
select is(
|
|
||||||
check_cookie('12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524/admin@tandem.blog'),
|
|
||||||
'guest'::name,
|
|
||||||
'Should not allow expired cookied for the other user as well'
|
|
||||||
);
|
|
||||||
|
|
||||||
select results_eq(
|
|
||||||
'user_info',
|
|
||||||
$$ values ('', '') $$,
|
|
||||||
'Should have left the settings with a guest user'
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
select *
|
|
||||||
from finish();
|
|
||||||
|
|
||||||
rollback;
|
|
|
@ -1,66 +0,0 @@
|
||||||
-- Test current_user_cookie
|
|
||||||
set client_min_messages to warning;
|
|
||||||
create extension if not exists pgtap;
|
|
||||||
reset client_min_messages;
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
set search_path to tipus, auth, public;
|
|
||||||
|
|
||||||
select plan(15);
|
|
||||||
|
|
||||||
select has_function('tipus', 'current_user_cookie', array []::name[]);
|
|
||||||
select function_lang_is('tipus', 'current_user_cookie', array []::name[], 'sql');
|
|
||||||
select function_returns('tipus', 'current_user_cookie', array []::name[], 'text');
|
|
||||||
select isnt_definer('tipus', 'current_user_cookie', array []::name[]);
|
|
||||||
select volatility_is('tipus', 'current_user_cookie', array []::name[], 'stable');
|
|
||||||
select function_privs_are('tipus', 'current_user_cookie', array []::name[], 'guest', array ['EXECUTE']);
|
|
||||||
select function_privs_are('tipus', 'current_user_cookie', array []::name[], 'publisher', array ['EXECUTE']);
|
|
||||||
select function_privs_are('tipus', 'current_user_cookie', array []::name[], 'admin', array ['EXECUTE']);
|
|
||||||
select function_privs_are('tipus', 'current_user_cookie', array []::name[], 'authenticator', array []::text[]);
|
|
||||||
|
|
||||||
set client_min_messages to warning;
|
|
||||||
truncate auth."user" cascade;
|
|
||||||
reset client_min_messages;
|
|
||||||
|
|
||||||
insert into auth."user" (user_id, email, name, password, role, cookie, cookie_expires_at)
|
|
||||||
values (1, 'demo@tandem.blog', 'Demo', 'test', 'publisher', '44facbb30d8a419dfd4bfbc44a4b5539d4970148dfc84bed0e',
|
|
||||||
current_timestamp + interval '1 month')
|
|
||||||
, (5, 'admin@tandem.blog', 'Demo', 'test', 'admin', '12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524',
|
|
||||||
current_timestamp + interval '1 month')
|
|
||||||
;
|
|
||||||
|
|
||||||
select lives_ok(
|
|
||||||
$$ select set_cookie('44facbb30d8a419dfd4bfbc44a4b5539d4970148dfc84bed0e/demo@tandem.blog') $$,
|
|
||||||
'Should change ok for the first user'
|
|
||||||
);
|
|
||||||
|
|
||||||
select is(current_user_cookie(), '44facbb30d8a419dfd4bfbc44a4b5539d4970148dfc84bed0e',
|
|
||||||
'Should return the cookie of the first user');
|
|
||||||
|
|
||||||
reset role;
|
|
||||||
|
|
||||||
|
|
||||||
select lives_ok(
|
|
||||||
$$ select set_cookie('12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524/admin@tandem.blog') $$,
|
|
||||||
'Should change ok for the second user'
|
|
||||||
);
|
|
||||||
|
|
||||||
select is(current_user_cookie(), '12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524',
|
|
||||||
'Should return the cookie of the second user');
|
|
||||||
|
|
||||||
reset role;
|
|
||||||
|
|
||||||
select lives_ok(
|
|
||||||
$$ select set_cookie('') $$,
|
|
||||||
'Should change ok for a guest user'
|
|
||||||
);
|
|
||||||
|
|
||||||
select is(current_user_cookie(), '', 'Should return an empty string');
|
|
||||||
|
|
||||||
reset role;
|
|
||||||
|
|
||||||
select *
|
|
||||||
from finish();
|
|
||||||
|
|
||||||
rollback;
|
|
|
@ -1,65 +0,0 @@
|
||||||
-- Test current_user_email
|
|
||||||
set client_min_messages to warning;
|
|
||||||
create extension if not exists pgtap;
|
|
||||||
reset client_min_messages;
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
set search_path to tipus, auth, public;
|
|
||||||
|
|
||||||
select plan(15);
|
|
||||||
|
|
||||||
select has_function('tipus', 'current_user_email', array []::name[]);
|
|
||||||
select function_lang_is('tipus', 'current_user_email', array []::name[], 'sql');
|
|
||||||
select function_returns('tipus', 'current_user_email', array []::name[], 'text');
|
|
||||||
select isnt_definer('tipus', 'current_user_email', array []::name[]);
|
|
||||||
select volatility_is('tipus', 'current_user_email', array []::name[], 'stable');
|
|
||||||
select function_privs_are('tipus', 'current_user_email', array []::name[], 'guest', array ['EXECUTE']);
|
|
||||||
select function_privs_are('tipus', 'current_user_email', array []::name[], 'publisher', array ['EXECUTE']);
|
|
||||||
select function_privs_are('tipus', 'current_user_email', array []::name[], 'admin', array ['EXECUTE']);
|
|
||||||
select function_privs_are('tipus', 'current_user_email', array []::name[], 'authenticator', array []::text[]);
|
|
||||||
|
|
||||||
set client_min_messages to warning;
|
|
||||||
truncate auth."user" cascade;
|
|
||||||
reset client_min_messages;
|
|
||||||
|
|
||||||
insert into auth."user" (user_id, email, name, password, role, cookie, cookie_expires_at)
|
|
||||||
values (1, 'demo@tandem.blog', 'Demo', 'test', 'publisher', '44facbb30d8a419dfd4bfbc44a4b5539d4970148dfc84bed0e',
|
|
||||||
current_timestamp + interval '1 month')
|
|
||||||
, (5, 'admin@tandem.blog', 'Demo', 'test', 'admin', '12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524',
|
|
||||||
current_timestamp + interval '1 month')
|
|
||||||
;
|
|
||||||
|
|
||||||
select lives_ok(
|
|
||||||
$$ select set_cookie('44facbb30d8a419dfd4bfbc44a4b5539d4970148dfc84bed0e/demo@tandem.blog') $$,
|
|
||||||
'Should change ok for the first user'
|
|
||||||
);
|
|
||||||
|
|
||||||
select is(current_user_email(), 'demo@tandem.blog', 'Should return the email of the first user');
|
|
||||||
|
|
||||||
reset role;
|
|
||||||
|
|
||||||
|
|
||||||
select lives_ok(
|
|
||||||
$$ select set_cookie('12af4c88b528c2ad4222e3740496ecbc58e76e26f087657524/admin@tandem.blog') $$,
|
|
||||||
'Should change ok for the second user'
|
|
||||||
);
|
|
||||||
|
|
||||||
select is(current_user_email(), 'admin@tandem.blog', 'Should return the email of the second user');
|
|
||||||
|
|
||||||
reset role;
|
|
||||||
|
|
||||||
select lives_ok(
|
|
||||||
$$ select set_cookie('') $$,
|
|
||||||
'Should change ok for a guest user'
|
|
||||||
);
|
|
||||||
|
|
||||||
select is(current_user_email(), '', 'Should return an empty string');
|
|
||||||
|
|
||||||
reset role;
|
|
||||||
|
|
||||||
|
|
||||||
select *
|
|
||||||
from finish();
|
|
||||||
|
|
||||||
rollback;
|
|
|
@ -1,33 +0,0 @@
|
||||||
-- Test email
|
|
||||||
set client_min_messages to warning;
|
|
||||||
create extension if not exists pgtap;
|
|
||||||
reset client_min_messages;
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
select plan(5);
|
|
||||||
|
|
||||||
set search_path to tipus, public;
|
|
||||||
|
|
||||||
select has_domain('email');
|
|
||||||
select domain_type_is('email', 'citext');
|
|
||||||
|
|
||||||
select lives_ok($$ select 'test@tandem.com'::email $$, 'Should be able to cast strings to email');
|
|
||||||
|
|
||||||
select throws_ok(
|
|
||||||
$$ SELECT 'test@tandem,,co.uk'::email $$,
|
|
||||||
23514, null,
|
|
||||||
'Should reject email addresses with wrong domain'
|
|
||||||
);
|
|
||||||
|
|
||||||
select throws_ok(
|
|
||||||
$$ SELECT 'test@a@tandem.com'::email $$,
|
|
||||||
23514, null,
|
|
||||||
'Should reject email address with two @ signs'
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
select *
|
|
||||||
from finish();
|
|
||||||
|
|
||||||
rollback;
|
|
|
@ -1,40 +0,0 @@
|
||||||
-- Test encrypt_password
|
|
||||||
set client_min_messages to warning;
|
|
||||||
create extension if not exists pgtap;
|
|
||||||
reset client_min_messages;
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
select plan(11);
|
|
||||||
|
|
||||||
set search_path to auth, tipus, public;
|
|
||||||
|
|
||||||
select has_function('auth', 'encrypt_password', array []::name[]);
|
|
||||||
select function_lang_is('auth', 'encrypt_password', array []::name[], 'plpgsql');
|
|
||||||
select function_returns('auth', 'encrypt_password', array []::name[], 'trigger');
|
|
||||||
select isnt_definer('auth', 'encrypt_password', array []::name[]);
|
|
||||||
select volatility_is('auth', 'encrypt_password', array []::name[], 'volatile');
|
|
||||||
select function_privs_are('auth', 'encrypt_password', array []::name[], 'guest', array []::text[]);
|
|
||||||
select function_privs_are('auth', 'encrypt_password', array []::name[], 'publisher', array []::text[]);
|
|
||||||
select function_privs_are('auth', 'encrypt_password', array []::name[], 'admin', array []::text[]);
|
|
||||||
select function_privs_are('auth', 'encrypt_password', array []::name[], 'authenticator', array []::text[]);
|
|
||||||
|
|
||||||
select trigger_is('user', 'encrypt_password', 'encrypt_password');
|
|
||||||
|
|
||||||
set client_min_messages to warning;
|
|
||||||
truncate "user" cascade;
|
|
||||||
reset client_min_messages;
|
|
||||||
|
|
||||||
insert into "user" (email, name, password, role)
|
|
||||||
values ('info@tandem.blog', 'Perita', 'test', 'guest');
|
|
||||||
|
|
||||||
select row_eq(
|
|
||||||
$$ select email from "user" where password = crypt('test', password) $$,
|
|
||||||
row ('info@tandem.blog'::email),
|
|
||||||
'Should find the new user using its encrypted password'
|
|
||||||
);
|
|
||||||
|
|
||||||
select *
|
|
||||||
from finish();
|
|
||||||
|
|
||||||
rollback;
|
|
|
@ -1,54 +0,0 @@
|
||||||
-- Test ensure_role_exists
|
|
||||||
set client_min_messages to warning;
|
|
||||||
create extension if not exists pgtap;
|
|
||||||
reset client_min_messages;
|
|
||||||
|
|
||||||
begin;
|
|
||||||
|
|
||||||
select plan(14);
|
|
||||||
|
|
||||||
set search_path to auth, public;
|
|
||||||
|
|
||||||
select has_function('auth', 'ensure_role_exists', array []::name[]);
|
|
||||||
select function_lang_is('auth', 'ensure_role_exists', array []::name[], 'plpgsql');
|
|
||||||
select function_returns('auth', 'ensure_role_exists', array []::name[], 'trigger');
|
|
||||||
select isnt_definer('auth', 'ensure_role_exists', array []::name[]);
|
|
||||||
select volatility_is('auth', 'ensure_role_exists', array []::name[], 'volatile');
|
|
||||||
select function_privs_are('auth', 'ensure_role_exists', array []::name[], 'guest', array []::text[]);
|
|
||||||
select function_privs_are('auth', 'ensure_role_exists', array []::name[], 'publisher', array []::text[]);
|
|
||||||
select function_privs_are('auth', 'ensure_role_exists', array []::name[], 'admin', array []::text[]);
|
|
||||||
select function_privs_are('auth', 'ensure_role_exists', array []::name[], 'authenticator', array []::text[]);
|
|
||||||
|
|
||||||
select trigger_is('user', 'ensure_role_exists', 'ensure_role_exists');
|
|
||||||
|
|
||||||
set client_min_messages to warning;
|
|
||||||
truncate "user" cascade;
|
|
||||||
reset client_min_messages;
|
|
||||||
|
|
||||||
select lives_ok(
|
|
||||||
$$ insert into "user" (email, name, password, role) values ('info@tandem.blog', 'Factura', 'test', 'guest') $$,
|
|
||||||
'Should be able to insert a user with a valid role'
|
|
||||||
);
|
|
||||||
|
|
||||||
select throws_ok(
|
|
||||||
$$ insert into "user" (email, name, password, role) values ('nope@tandem.blog', 'Factura', 'test', 'non-existing-role') $$,
|
|
||||||
'23503',
|
|
||||||
'role not found: non-existing-role',
|
|
||||||
'Should not allow insert users with invalid roles'
|
|
||||||
);
|
|
||||||
|
|
||||||
select lives_ok($$ update "user" set role = 'publisher' where email = 'info@tandem.blog' $$,
|
|
||||||
'Should be able to change the role of a user to another valid role'
|
|
||||||
);
|
|
||||||
|
|
||||||
select throws_ok($$ update "user" set role = 'usurer' where email = 'info@tandem.blog' $$,
|
|
||||||
'23503',
|
|
||||||
'role not found: usurer',
|
|
||||||
'Should not allow update users to invalid roles'
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
select *
|
|
||||||
from finish();
|
|
||||||
|
|
||||||
rollback;
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue