Commit Graph

110 Commits

Author SHA1 Message Date
d8c24ae45d Properly return http status 201 when creating subscription 2022-04-08 15:42:13 +02:00
032d223018 Add an endpoint letting a community auth site subscribe to updates
When a user logs into a community auth site, that account is
automatically subscribed to receive updates from the system whenever any
changes are made to the user, such as name/email/ssh keys. However, when
a site imports a user without them being directly logging in, that
subscription is not set up, so any changes made are lost until the user
first logs in.

This commnit adds an endpoint to the auth system so that a site can
expliciltly request updates are sent about a user. This will create a
"fake login" on that site, which will enable the normal system to start
sending data. The access to the endpoint is protected with a hmac
authentication using the existing community auth key.
2022-03-07 21:29:08 +01:00
d41687fe5b Remove accidentally duplicated return statement 2021-12-19 12:10:57 +01:00
e545c0b3c3 Show a proper confirmation page after adding an email to an org
This should (hopefully) help reduce some confusion.
2021-11-18 14:21:42 +01:00
0724c08e40 Require explicit tagging on views taking query parameters
Require each view to declare which query parameters it wants, and filter
out any other parameters.

We have very few views that actually take query parameters, and random
additional query patterns will have no effect on the view. However, they
will break frontend caching (in making them look like different pages).

This will be extended into an implementation in the caching frontends as
well, btu it's needed in the backend to ensure that local testing will
have tbe same effect as the caches.
2021-02-22 10:43:59 +01:00
978ba27bae Add headline separating the submit_header for organisations 2021-01-14 17:24:37 +01:00
d5c005997e Only show sections on submissions dashbaord that has entries
Instead of showing (confusing) empty sections, remove the complete
section from she page.

From Andreas Scherbaum, though not his patch in the end
2021-01-04 14:40:07 +01:00
ea9becd746 Re-do markdown handling for better user experience and security
* Get rid of the django_markwhat dependency, and implement our own
  classes to get more control. In passing also remove django-markdown,
  because we never used that.
* Instead of trying to clean markdown with regexps, use the bleach
  library (NEW DEPENDENCY) with special whitelisting of allowed tags
  based off standard markdown. This means that one can input links or
  formatting in HTML if one prefers, as long as it renders to the same
  subset of tags that markdown allows.
* Replace javascript based client side preview with an actual call to a
  preview URL that renders the exact result using the same function,
  since the use of showdown on the client was increasingly starting to
  differ from the server, and since that cannot be kept secure the same
  way. Rewrite the client side javascript to work better with the now
  longer interval between updates of the preview.

Long in planning, but never got around to it.

Suggestion to use bleach for escaping from David Fetter.
2020-11-12 18:52:04 +01:00
e2fd8a84d5 Prevent creating new accounts with email registered as secondary
If an email is already added as a secondary address to one account,
don't allow creating a new account using that email, unless it's
removed. Otherwise we end up with the same email address attached to
multiple different accounts, which can cause big problems downstream.

This should never have been allowed of course, but was missed when
support for secondary emails was added.
2020-09-26 22:08:44 +02:00
d7d5b105d1 Improve moderation messages somewhat
Change the subject to use the title of the object instead of the id, and
include a link to the moderation page. There's surely more to be done,
but this is a decent start.
2020-09-18 11:13:36 +02:00
7a9e532091 Track multiple email addresses for an organisation
This allows organisation managers to add more than one email address to
an organisation, and use this for sending news from. Sending news is the
only thing that the email field is used for at this point. Adding an
email will trigger a validation email sent to the address with a token
to confirm it, so that we can actually trust the emails.

Remove the previous registered emails on organisations. These addresses
were never validated and thus cannot really be trusted, so it's better
to remove them cleanly than to migrate them into the new system and be
uncertain.

Finally, in passing, remove the phone field on organisations. We've
never used that for anything and there's not really any point in
collecting the data.
2020-09-10 14:52:41 +02:00
5ffe6c389c Re-work moderation of submitted items
This includes a number of new features:

* Move some moderation functionality into shared places, so we don't
  keep re-inventing the wheel.
* Implement three-state moderation, where the submitter can edit their
  item and then explicitly say "i'm done, please moderate this now".
  This is currently only implemented for News, but done in a reusable
  way.
* Move moderation workflow to it's own set of URLs instead of
  overloading it on the general admin interface. Admin interface remains
  for editing things, but these are now separated out into separate
  things.
* Do proper stylesheet clearing for moderation of markdown fields, using
  a dynamic sandboxed iframe, so it's not ruined by the /admin/ css.
* Move moderation email notification into dedicated moderation code,
  thereby simplifying the admin subclassing we did which was in some
  places quite fragile.
* Reset date of news postings to the date of their approval, when
  approved. This avoids some annoying ordering issues.
2020-09-10 14:52:41 +02:00
07ae4d3e51 Prefetch managers when viewing the organistion list
This removes a few thousand SQL queries and speeds up the page "a bit"
2020-09-07 17:20:56 +02:00
fb99733afe Teach pgweb to handle secondary email addresses
This allows each account to have more than one email address, of which
one is primary. Adding more addresses will trigger an email with a
verification link (of course). The field previously known as "email" is
now changed to be "primary email".

Change the profile form to allow freely changing between the added
addresses which one is the primary. Remove the functionality to directly
change the primary email -- instead one has to add a new address first
and then change to that one, which simplifies several things in the
handling.
2020-08-11 11:33:46 +02:00
e9c84c668f Fix query for tracking number of community auth logins
Embarassing thinko would cap the number of logins at 2...
2020-07-07 12:25:39 +02:00
b405302d97 Avoid returning HttpServerError for things not server errors
With the new django, alerts are raised for everything with status 500,
not juse exceptions. This put a light on a number of places where we
were returning 500 server error code for things that are not actually
server errors. Some should be a regular 200 ok with an error message,
and others should be a permissions error.
2020-04-04 14:43:27 +02:00
ccb1282531 Update authentication to be django 2 compatible 2020-04-03 19:05:26 +02:00
9e70a4e0c3 Track when an account last logged into a community auth site
This information can be useful when trying to debug issues with the
community auth and the wonders of distributed data...

No actual django model is created because django still doesn't support
multi-column primary keys. Thus no tool to use the data yet other than
psql.
2020-02-25 10:58:05 +01:00
a91c267ec1 Send password reset emails to stored email address
Even though compared to be case insensitively equal,
there are unicode cases where they can be different.
2020-01-03 22:00:32 +01:00
12306255ad Switch to using pycryptodome instead of pycrypto
pycrypto is not being maintained, and pycryptodome is theoretically
a drop-in replacement (in practice, it seems it was close)
2019-11-01 14:52:35 +01:00
ff11e85e25 Replace \r with \n in ssh key dumps 2019-10-09 15:29:09 +02:00
f6a756387b Clarify when a password is entered in the community auth signup flow
Suggested by Andreas Scherbaum.
2019-04-01 11:10:46 +02:00
499a40baf7 Update for new module/namespace for urllib 2019-01-26 16:19:26 +01:00
edad84b1d0 Fix base64 encodings 2019-01-26 16:19:26 +01:00
a156829375 Generic unicode updates 2019-01-26 16:19:26 +01:00
7547b6f766 Update syntax for relative imports 2019-01-26 16:19:26 +01:00
00ab822ea8 Fix deprecated comparison structs 2019-01-17 21:19:57 +01:00
0883ac6423 Fix whitespace and indentation, per pep8 2019-01-17 20:47:43 +01:00
87237f6536 Tabs, meet your new overlords: spaces
In a quest to reach pep8, use spaces to indent rather than tabs.
2019-01-17 15:35:39 +01:00
b2771a29bb Allow framing google.com on account signup page
This is used for the recaptcha. Also enable this for oauth signups,
previously missed.
2018-12-29 11:49:57 +01:00
d36ea4a985 Enable setting of security http headers
The following security policy headers are set:

X-XSS-Protection: 1; mode=block -- always set

X-Frame-Options: DENY is set for all pages except for the documentation
  pages, primarily because pgadmin4 loads them in an iframe which would
  break.

Content-Security-Policy: <x>-src
  Is set to allow the default of self only, then allowing scripts for
  google analytics and fonts for google fonts. Images are allowed from everywhere.
  frame-ancestors 'none' is set by the same rules as X-Frame-Options

This also adds a decorator for @script_sources to have a single view
allow extra sources, and this is used for recaptcha. A generic decorator
is also made for other types of exclusions, though we don't have any at
this point.

If the setting SECURITY_POLICY_REPORT_ONLY is set to True then the policy
will be report-only and not enforced (for testing), otherwise enforcing
mode is enabled.

The setting SECURITY_POLICY_REPORT_URI sets where to send security
policy reports, if any.
2018-12-21 21:46:28 +01:00
5ba39f457f Break up "Awaiting Moderation" and "Approved" articles/events/etc.
This was becoming illegible and also hard to maintain based on how
we changed up the look/feel of the entire site. That way, we have
two distinct categories for both types of objects, which makes it
easier for the user to understand what is what.

Also reworded the explanation for what is going on, both based on
the structural change and because it read like a literal interpretation
of the code.
2018-11-04 09:39:30 -05:00
7f3581c62e Allow empty 'next' link when asking for community auth consent
Per crashdump
2018-08-14 13:37:23 +02:00
d25251aca4 Fix comment typo 2018-07-04 19:41:26 +02:00
c597b0288c Force login before giving community auth consent
In the normal workflow this would always happen, but if the user got to
the page without being logged in (probably most likely to happen if the
session timed out while waiting to proceed) we would crash on trying to
create an invalid consent record. Instead, force a re-login in this
case.
2018-06-25 16:43:59 +02:00
c9c4ce728e Don't crash on concurrent consent given
If a user gave consent to sharing community auth data in two parallel
sessions, one of them would crash with a unique violation. To avoid
that, use the django function for get_or_create(), and just throw away
the results if it turned out to be a get.
2018-06-08 12:45:52 +02:00
f7d6709fae Implement consent for third party orgs in commmunity auth
This adds a new model for CommunityAuthOrg representing the organisation
that runs the system that's being authenticated (e.g. PostgreSQL Europe
or PostgreSQL US). For this we just keep a name and a "is consent required" flag.

In the case where consent is required, we keep track on a per-user basis
of if they have given consent to sharing their data with this
organistion. If they haven't, we ask for it before completing the
redirect and actually sharing the data.
2018-05-30 16:25:37 -04:00
73706bdaba Rename NOREPLY_FROM to ACCOUNTS_NOREPLY_FROM
This is today only used for things coming out of the accounts system,
like new accounts and password resets. To make sure we don't
accidentally start using it for something else, change the name of the
parameter.
2018-05-01 17:52:15 +02:00
5a36dbc8ad Append "/" to pgweb hosted URLs that currently lack one.
By default, Django expects URLs to end with a "/" but if it
accepts a request without a trailing slash, it will issue a
permanent redirect with the slash appended. While this is great,
it does mean an extra request to the server.

This patch adds a "/" to anchor tags that did not have one
already appended to it, thus helping to save time for a user
browsing .org as well as for the server.
2018-04-15 15:14:04 -04:00
872d8b8e76 Ensure "News Article" and "Professional Service" are titles.
In the "Your Account" workflow, ensure that "News Article" and
"Professional Service" appear as titles throughout.
2018-04-15 13:05:15 -04:00
d033d5f036 Re-implement password reset token sending natively
The django version of password reset is broken in multiple way. What's
hurting us in particular is it cannot reset the password of a user where
the old password was generated by a deprecated hasher. Which, of course,
is exactly one of the cases where being able to reset the password is
important.

We still use the same infrastructure, and we use the actual django code
for *changing* the password -- this just replaces the token sender with
something that's a lot simpler and less broken.
2018-03-23 13:21:16 +01:00
487d86bee3 Fix that HttpServerError now takes a request as parameter 2018-03-10 10:54:13 -05:00
fd37389a3b Replace NavContext and render_to_response with render_pgweb
render_to_response does not work on newer django, so it needs to be
replaced. And using a speicfic context actually overcomplicates things,
it's easier to just use a wrapper function. For those cases where we
don't need NavContext, just use render() (the new shortcut function from
django), which also removes the need to use RequestContext.
2018-03-10 10:38:11 -05:00
e37ee54d25 Add ability for cauth sites to download ssh public keys
This removes the last need to directly access the upstream database
(from the git server), so remove that view as well.
2017-12-10 17:23:03 +01:00
090f0cc915 Don't try to log data that's not always available 2017-10-30 15:25:37 +01:00
43d7a16b31 More logging on password resets 2017-10-30 15:23:54 +01:00
022dd26283 Enforce lowercase email addresses in more places
We don't want two different accounts to exist with the same email
address only differing in case. This had already happened for a few
which have been manually fixed, since it turns out we only enforced the
rule on new account creation, not when accounts changed email address or
when they were created using oauth. Also add database level constraints to
make sure this cannot happen again if some codepath is missed.
2017-10-13 14:09:22 +02:00
cc8c058857 Split out noreply sender address to separate config parameter
We want to use the noreply@ email address when sending out notifications
to addresses that have yet to be verified, since we can just ignore
bounces to those.
2017-09-27 12:01:45 +02:00
fb0f12a51f Maintain redirection URL across oauth signup
Previously when signing up for a new account in the middle of an
authentication process, the final redirection URL was lost and the user
was sent back to the /account/ page. Instead, we now redirect to the
proper URL (for sending back to the community auth client site) if it's
available in the session, both for successful signup and for
canceled logins.
2017-09-16 13:36:29 +02:00
5defff8eaa Properly pass next value across failed password attempts
In the event of a failed password attempt, we'd loose the "next url"
part in community auth, so once the correct password was entered an
error message about unknown redirect would show up.
2017-09-16 13:36:29 +02:00