221 Commits

Author SHA1 Message Date
6d6a40b8c0 Empty lists don't seem to be stored in MongoDB any more
It looks like with the new Eve (or one of its dependencies) empty lists
aren't stored any more; rather than storing `{'org_roles': []}`, it skips
the `'org_roles'` key altogether. Not sure what caused this, as it was
mentioned in neither the Eve nor the PyMongo changelog.
2018-08-29 11:26:19 +02:00
a8a7166e78 Use self.assertRaises as context manager 2018-08-28 17:45:58 +02:00
8a0f582a80 Removed dependency on flask_pymongo 2018-07-13 17:08:06 +02:00
0fdcbc3947 Restored MarkDown conversion using 'validator': 'markdown' 2018-07-13 17:02:38 +02:00
8dc3296bd5 Schema change for IP range, use validator instead of type
Custom types became rather useless in Cerberus 1.0 since the type checker
is cripled (doesn't know field name, cannot return useful/detailed error
messages). Instead we use a validator now.
2018-07-13 15:03:35 +02:00
a699138fd6 Merge branch 'master' into wip-flask-one 2018-07-13 13:50:24 +02:00
466adabbb0 Added unit tests for IP range validation 2018-07-13 13:50:01 +02:00
aaf452e18b Fixed Cerberus canary unit test
Apparently it's no longer possible for Cerberus to validate its own schemas.
2018-07-13 12:02:40 +02:00
baa77a7de5 Merge branch 'master' into wip-flask-one 2018-07-13 11:43:57 +02:00
5fb40eb32b Simple unittests for Cerberus validation 2018-07-13 11:42:31 +02:00
549cf0a3e8 WIP on libraries upgrade 2018-07-12 15:23:57 +02:00
9f380751f5 Support for capabilities check in any shortcode
Use the @capcheck decorator on any shortcode that should support
this. Currently used by iframe and youtube.
2018-07-11 12:32:00 +02:00
9ee7b742ab Make more consistent use of BLENDER_ID_ENDPOINT
Now BLENDER_ID_ENDPOINT is used for the Blender ID OAuth config,
and it's directly accessed when building requests for Blender ID token
validation (without using utility functions).
2018-06-22 19:38:27 +02:00
58c33074c3 Fix unittest for jinja.do_markdown
We were passing invalid html to do_markdown, which was returning a valid
version, by closing the <script> tag.
2018-06-22 17:10:38 +02:00
0e14bdd09f Introduce rating functions
These hotness and confidence calculation algorithms come from Reddit
and have been tweaked based on our experience on the Dillo project.
2018-06-03 02:09:20 +02:00
c9789f46db {iframe} shortcode no longer requires cap=xxx 2018-04-04 15:44:52 +02:00
3e7722a567 Expand image for {attachment slug link=self}
Clicking on the image will no longer open it directly, but expand it
instead.
2018-04-03 15:44:24 +02:00
1ba1da49c3 Pass positional arguments to attachment render functions
This allows handling `{attachment slug link}` as a synonym for
`{attachment slug link=self}`.
2018-04-03 15:42:47 +02:00
67e8e7c082 Disallow spaces in attachment slugs
Slugs shouldn't have spaces. It also interferes with using slugs in
shortcodes.
2018-04-03 13:59:31 +02:00
cbb5d546ef Fixed CLI cmd upgrade_attachment_schema
It didn't add the {'coerce': 'markdown'}, which caused the
upgrade_attachment_usage CLI command to skip 'upgraded' nodes.
2018-04-03 12:49:34 +02:00
3b452d14ce Render attachments with shortcodes rather than slugs
The attachments should now be rendered using `{attachment slug}` instead
of `@[slug]`. The `link` attribute can be specified in the shortcode
(for attachments that support it), rather than in the attachment itself.

The attachment subdocument is now reduced to `{oid: File ObjectID}`, and
nodes without attachments should NOT have an `attachment` property at
all (previously it would be an empty dict). This makes querying for
nodes with/out attachments easier.

The CLI command `upgrade_attachment_schema` can do dry-run and remove
empty attachments:

- Added --go to actually perform the database changes.
- Remove empty attachments, so that a node either has one or more
  attachments or no attachments sub-document at all.

The CLI command `upgrade_attachment_usage` converts `@[slug]` to
`{attachment slug}`. It also takes into account 'link' and 'link_custom'
fields on the attachment. After conversion those fields are removed from
the attachment itself.

Simplified maintentance CLI commands that iterate over all projects:
I've moved the common approach (either run on one project or all of
them, skipping deleted ones, giving a message upon dry-run, and showing
duration of the command) to a new _db_projects() function. The new
function is now used by two recently-touched CLI commands; more of them
could be migrated to use this.
2018-04-03 10:59:20 +02:00
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
fe7e078f8b Added unit test
Should have been part of prev commit.
2018-03-28 12:42:36 +02:00
f22dc4d92a Fixed PATCHing comments 2018-03-27 17:42:29 +02:00
218c3f0dca Fixed comment rendering 2018-03-27 17:13:12 +02:00
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
d2a0a5ae26 Added CLI command 'maintenance purge_home_projects'
This command soft-deletes home projects when their owning user is no longer
there.
2018-03-27 15:45:32 +02:00
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
dee0b18429 utils.doc_diff() now also supports list values 2018-03-27 11:50:23 +02:00
12272750c3 T53890: Improving static content serving
Static files are now served with an 8-character hash before the last
extension. For example, `tutti.min.js` is now served as
`tutti.min.abcd1234.js`. When doing a request the hash is removed before
serving the static file.

The hash must be 8 characters long, and is taken from STATIC_FILE_HASH.
It is up to the deployment to change this configuration variable
whenever static files change. This forces browsers that download newly
deployed HTML to also refresh the dependencies (most importantly
JS/CSS).

For this to work, the URL must be built with `url_for('static_xxx',
filename='/path/to/file')`. The 'static' module still returns regular,
hashless URLs.
2018-03-23 17:36:14 +01:00
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
b10369a867 Removed unused imports 2018-02-13 16:51:42 +01:00
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
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
1b57b333df Removed the URLer service
We don't have a need for it any more, so it can go.
2018-01-31 14:33:41 +01:00
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
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
4b5a961e14 Speed up authentication by trusting g.current_user if set. 2018-01-31 10:08:17 +01:00
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
2e2314c16b Replace storage backend 'pillar' with 'local'
The backend 'pillar' is obsolete; 'local' is the modernity and uses our
nice storage API.
2018-01-26 14:13:03 +01:00
75e2402420 Removed unused import 2018-01-26 12:49:53 +01:00
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
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
89ca0516a9 Better handling of Zencoder error notifications. 2018-01-26 12:29:22 +01:00
5ae98507e3 Added missing unittest for encoding.size_descriptor() 2018-01-26 12:15:56 +01:00
66ac8c6587 Modernised ZencoderNotificationTest 2018-01-26 12:15:42 +01:00
fd95135f66 PEP 8 formatting and removal of unused import 2018-01-26 11:42:56 +01:00
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
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
270bb21646 Support IP range editing in Organization view_embed 2018-01-25 14:01:28 +01:00