Commit Graph

83 Commits

Author SHA1 Message Date
Sybren A. Stüvel f4e0b9185b Shortcodes for YouTube and iframes
Added shortcodes 2.5.0 as dependency; Earlier versions corrupted
non-ASCII characters, see
https://github.com/dmulholland/shortcodes/issues/6

The rendered elements have a `shortcode` CSS class.

The YouTube shortcode supports various ways to refer to a video:

    - `{youtube VideoID}`
    - `{youtube youtube.com or youtu.be URL}`

URLs containing an '=' should be quoted, or otherwise the shortcodes
library will parse it as "key=value" pair.

The IFrame shortcode supports the `cap` and `nocap` attributes. `cap`
indicates the required capability the user should have in order to
render the tag. If `nocap` is given, its contents are shown as a message
to users who do not have this tag; without it, the iframe is silently
hidden.

`{iframe src='https://source' cap='subscriber' nocap='Subscribe to view'}`

Merged test code + added HTML class for shortcode iframes
2018-04-03 10:49:00 +02:00
Sybren A. Stüvel f22dc4d92a Fixed PATCHing comments 2018-03-27 17:42:29 +02:00
Sybren A. Stüvel dfaac59e20 Cache Markdown'ed HTML in database
This is done via coercion rules. To cache the field 'content' in the
database, include this in your Eve schema:

    {'content': {'type': 'string', 'coerce': 'markdown'},
     '_content_html': {'type': 'string'}}

The `_content_html` field will be filled automatically when saving the
document via Eve.

To display the cached HTML, and fall back to display-time rendering if it
is not there, use `{{ document | markdowned('content') }}` in your template.

Still needs unit testing, a CLI command for regenerating the caches, and
a CLI command for migrating the node type definitions in existing projects.
2018-03-27 16:34:32 +02:00
Sybren A. Stüvel d24715a224 Smarter upgrades of node type definitions
- No changes are applied unless the new --go CLI arg is used.
- Differences to node types are actually shown.
- Dynamic form definitions are kept.
2018-03-27 12:03:18 +02:00
Sybren A. Stüvel dee0b18429 utils.doc_diff() now also supports list values 2018-03-27 11:50:23 +02:00
Sybren A. Stüvel e4f229cc70 Fix T51678: 16bit greyscale PNG images thumbnailing fails
generate_local_thumbnails() now uses pathlib and f-string formatting too,
making the code a lot simpler. Furthermore, I removed unused bits of
resize_and_crop() and simplified the rest.
2018-03-22 17:53:14 +01:00
Sybren A. Stüvel b10369a867 Removed unused imports 2018-02-13 16:51:42 +01:00
Sybren A. Stüvel de801e41e3 CLI command for moving all nodes+files to another project
`manage.py operations merge_project src_url dst_url` moves all nodes and
files from the project with `src_url` to the project with `dst_url`.
This also moves soft-deleted files/nodes, as it ignores the _deleted
field. The actual files on the storage backend are copied rather than
moved.

Note that this may invalidate the nodes, as their node type definition
may differ between projects. Since we use direct MongoDB queries the
nodes are moved to the new project anyway. This allows for a
move-first-then-fix approach).
2018-02-13 15:52:21 +01:00
Sybren A. Stüvel cd42ce6cba Moving blobs between nodes now uses storage API
Instead of only being GCS-specific, it now works for all storage
backends.
2018-02-13 15:36:11 +01:00
Sybren A. Stüvel 08a814525b Implement project undelete as PATCH
This is done via a custom PATCH due to the lack of transactions of MongoDB;
we cannot undelete both project-referenced files and file-referenced
projects in one atomic operation.
2018-01-31 14:15:23 +01:00
Sybren A. Stüvel f8ff30fb4d (un)delete on project also (un)delete file documents.
Note that undeleting files cannot be done via Eve, as it doesn't support
PATCHing collections. Instead, direct MongoDB modification is used to set
_deleted=False and provide new _etag and _updated values.
2018-01-31 10:08:17 +01:00
Sybren A. Stüvel 4b5a961e14 Speed up authentication by trusting g.current_user if set. 2018-01-31 10:08:17 +01:00
Sybren A. Stüvel 230b2c669c Implement rename-after-Zencoder-is-done using our Storage API.
This means it's no longer GCS-specific, and can be tested using the local
storage implementation.

Required implementation of a rename operation. To mirror Google's API, I've
implemented the renaming of a Blob as a function on the Bucket class.
To me this makes sense, as it requires creating a new Blob instance, which
shouldn't be done by another Blob.
2018-01-26 14:54:34 +01:00
Sybren A. Stüvel 75e2402420 Removed unused import 2018-01-26 12:49:53 +01:00
Sybren A. Stüvel fb121a9601 Test actual Zencoder notification.
This notification was taken from our API history and was actually sent to
us by Zencoder.
2018-01-26 12:49:45 +01:00
Sybren A. Stüvel f8c3408f18 Properly handle errors when saving updated file doc after Zencoder notif.
We never checked the return values from the put_internal() call, so errors
would have passed silently into the night.
2018-01-26 12:49:15 +01:00
Sybren A. Stüvel 89ca0516a9 Better handling of Zencoder error notifications. 2018-01-26 12:29:22 +01:00
Sybren A. Stüvel 5ae98507e3 Added missing unittest for encoding.size_descriptor() 2018-01-26 12:15:56 +01:00
Sybren A. Stüvel 66ac8c6587 Modernised ZencoderNotificationTest 2018-01-26 12:15:42 +01:00
Sybren A. Stüvel fd95135f66 PEP 8 formatting and removal of unused import 2018-01-26 11:42:56 +01:00
Sybren A. Stüvel 987d6d03a6 Fix T49280: Make texture files (in texture node) sortable
Rather than making them sortable, I made them automatically sorted upon
saving the node. The colour map comes first, then the other maps in
alphabetical order.
2018-01-26 11:42:42 +01:00
Sybren A. Stüvel fd3e795824 Store IP-based org-given roles in the user document.
This is a two-stage approach that happens when a new token is verified
with Blender ID and stored in our local MongoDB:

  - Given the remote IP address of the HTTP request, compute and store the
    org roles in the token document.
  - Recompute the user's roles based on their own roles, regular org roles,
    and the roles stored in non-expired token documents.

This happens once per hour, since that's how long we store tokens in our
database.
2018-01-25 14:01:28 +01:00
Sybren A. Stüvel 270bb21646 Support IP range editing in Organization view_embed 2018-01-25 14:01:28 +01:00
Sybren A. Stüvel d3f97358d9 Work around Eve not supporting returning binary data 2018-01-25 14:01:28 +01:00
Sybren A. Stüvel c44f0489bc Backend support for organization IP ranges.
We can now store IP ranges with Organizations. The aim is to have any user
logging in with a remote IP address within such a race will get the
organization roles assigned to the user object stored in the Flask session.

This commit just contains the MongoDB storage and querying, and not yet the
updates to the user.
2018-01-25 14:01:28 +01:00
Sybren A. Stüvel 01f81ce4d5 Send a Blinker signal when someone's subscription status changes
This is very close to the 'roles changed' signal, with the difference that
it is sent only once for multiple role changes.
2017-12-21 12:59:32 +01:00
Francesco Siddi 20ca3f8ee4 Rename blender_id url to blender-id
This fixes a non-compliant to RFC 1178 exception raised by the Django implementation of Blender ID. The issue is debated here https://code.djangoproject.com/ticket/20264.
2017-12-12 18:49:52 +01:00
Sybren A. Stüvel 8a400c5c0f Gracefully handle users with empty full_name 2017-12-08 14:03:30 +01:00
Sybren A. Stüvel 2bcc26860f Removed 'subscriber' cap from 'admin' role
This allows admins to test what happens when users do not have a
subscription. To give the user subscriber capability, just grant demo role
as well.
2017-12-06 12:09:21 +01:00
Sybren A. Stüvel 0b218eb656 Use Blender ID to obtain subscription status.
Instead of performing a call to the Blender Store, call to Blender ID to
get the user's subscription status.

Currently this is performed as a second HTTP call after logging in; in the
future we may want to include the roles in the login response from Blender
ID, so that we can do this in one call instead of two.
2017-11-30 15:28:35 +01:00
Sybren A. Stüvel 390d687f61 Added utility to find project ID from URL.
This is mostly useful for the CLI interface, as the majority of our Pillar
code actually needs more project information than just the ID.
2017-11-03 14:33:19 +01:00
Sybren A. Stüvel f17453ba10 Added 'operations hash_auth_tokens' CLI command. 2017-10-05 13:04:44 +02:00
Sybren A. Stüvel c57aefd48b Hash authentication tokens before storing in the database. 2017-10-05 12:57:16 +02:00
Sybren A. Stüvel 230c15d51c Fix snag that happens when PUTting a user document without roles key. 2017-09-14 11:23:35 +02:00
Dalai Felinto 216b9278af A user should not be able to vote on own content
This should be hidden in the UI as well, but the backend should support this too.
We also want to set initial rating of 1 for contents that need it.

This commit includes a new unittest for this case.

Reviewers: sybren

Differential Revision: https://developer.blender.org/D2825
2017-09-06 13:51:32 +02:00
Sybren A. Stüvel a6f56a4811 OAuth test: checking email address too 2017-08-25 12:53:21 +02:00
Francesco Siddi 41a82c44c5 Tests for providers callbacks
Also added SERVER_NAME in config_testing and pre-populated the  keys of OAUTH_CREDENTIALS, since the implementation of providers is part of the application.
2017-08-25 10:55:35 +02:00
Francesco Siddi cecf81a07d Initial tests for OAuthSignIn 2017-08-25 10:55:35 +02:00
Sybren A. Stüvel b9ae4396e5 Orgs: show "My Organizations" in the user's menu
This is shown only when the user is member of or administrator for one or
more organizations, otherwise it's hidden.
2017-08-24 14:28:18 +02:00
Sybren A. Stüvel be12bd7d99 Orgs: allow users to leave an organization 2017-08-24 14:28:18 +02:00
Sybren A. Stüvel 1e1bd83baf Orgs: refresh all members' roles after org changed roles 2017-08-24 14:28:18 +02:00
Sybren A. Stüvel f1edb901d1 Orgs: allow setting org admin via web interface / PATCH request 2017-08-24 14:28:18 +02:00
Sybren A. Stüvel 1bd6e07fe2 Orgs: Allow adding individual known users by user ID.
This is used for the selection by user search.
2017-08-24 14:28:17 +02:00
Sybren A. Stüvel 72404d0fd9 Handle registration of previously unknown organization members.
When a new user is created, two things happen:
  - before inserting into MongoDB, the organizational roles are given
  - after inserting, the organizations are updated to move the user from
    `unknown_members` to `members`.
2017-08-24 14:26:19 +02:00
Sybren A. Stüvel b53d485960 Added access control to organizations Eve endpoints 2017-08-24 14:26:19 +02:00
Sybren A. Stüvel cf51d1a280 Added utility function current_user() that acts like flask_login.current_user
This actually returns an AnonymousUser object, instead of None, when the
user is not logged in.

For compatibility with existing code, this function doesn't set
g.current_user to that AnonymousUser instance. We may decide to do this
later.
2017-08-24 14:26:19 +02:00
Sybren A. Stüvel efc1890871 Added PATCH support for organizations
With a PATCH request you can now:
  - assign users,
  - remove a user,
  - edit the name, description, and website fields.

Only the organization admin user can do this.
2017-08-24 14:26:19 +02:00
Sybren A. Stüvel 93d534fe94 Added Organization Manager.
This is a Flamenco/Attract-style Manager object that's instantiated by
the PillarApplication. It can create Organizations and assign/remove
users.

Also I updated the Organization schema to reflect the currently desired
design.

NOTA BENE: this does not include any security/authorisation checks on Eve's
organizations collection.
2017-08-24 14:25:52 +02:00
Sybren A. Stüvel 575a7ed1a7 Introduced role-based capability system.
It's still rather limited and hard-coded, but it works.
2017-08-18 14:47:42 +02:00
Sybren A. Stüvel 566a23d3b6 Unified user representation for web and API calls
Both approaches now use a pillar.auth.UserClass instance. g.current_user
is now always set to that instance, even for web entry points.

This UserClass instance can still be keyed like the old dict, but this is
for temporary compatibility and shouldn't be relied on in new or touched
code.
2017-08-18 13:19:34 +02:00