Skip to content

Commit

Permalink
documents: removes permssions from the search list
Browse files Browse the repository at this point in the history
* Removes the useless files permissions from the search list to speed up the server responses.

Co-Authored-by: Johnny Mariéthoz <[email protected]>
  • Loading branch information
jma committed Jan 31, 2024
1 parent 221d31d commit d249ac9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ invenio-theme = ">=2.5.7,<3.0.0"

# Invenio auth bundle
invenio-access = ">=2.0.0,<3.0.0"
invenio-accounts = ">=3.0.0,<4.0.0"
invenio-accounts = ">=3.5.2,<4.0.0"
invenio-oauth2server = ">=2.0.0,<3.0.0"
invenio-oauthclient = ">=3.0.0,<4.0.0"
invenio-userprofiles = "^2.3.1"
Expand Down
19 changes: 11 additions & 8 deletions sonar/modules/documents/marshmallow/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,19 @@ class ThumbnailSchemaV1(StrictKeysMixin):

class Meta:
"""Meta for file schema."""

unknown = EXCLUDE

key = SanitizedUnicode()
label = SanitizedUnicode()
type = SanitizedUnicode()
order = fields.Integer()
restriction = fields.Dict(dump_only=True)
links = fields.Dict(dump_only=True)
thumbnail = SanitizedUnicode(dump_only=True)



class FileSchemaV1(ThumbnailSchemaV1):
"""File schema."""

Expand All @@ -64,20 +74,13 @@ class Meta:
bucket = SanitizedUnicode()
file_id = SanitizedUnicode()
version_id = SanitizedUnicode()
key = SanitizedUnicode()
mimetype = SanitizedUnicode()
checksum = SanitizedUnicode()
size = fields.Integer()
label = SanitizedUnicode()
type = SanitizedUnicode()
order = fields.Integer()
external_url = SanitizedUnicode()
access = SanitizedUnicode()
restricted_outside_organisation = fields.Boolean()
embargo_date = SanitizedUnicode()
restriction = fields.Dict(dump_only=True)
links = fields.Dict(dump_only=True)
thumbnail = SanitizedUnicode(dump_only=True)
permissions = fields.Dict(dump_only=True)

@pre_dump
Expand Down Expand Up @@ -149,7 +152,7 @@ class DocumentListMetadataSchemaV1(StrictKeysMixin):
customField3 = fields.List(fields.String(validate=validate.Length(min=1)))
masked = SanitizedUnicode()
_bucket = SanitizedUnicode()
_files = Nested(FileSchemaV1, many=True)
_files = Nested(ThumbnailSchemaV1, many=True)
_oai = fields.Dict()
# When loading, if $schema is not provided, it's retrieved by
# Record.schema property.
Expand Down
19 changes: 19 additions & 0 deletions tests/api/documents/test_documents_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@
from invenio_accounts.testutils import login_user_via_session


def test_get(client, document_with_file):
"""Get REST methods."""
res = client.get(url_for('invenio_records_rest.doc_list', view='global'))
assert res.status_code == 200
assert res.json['hits']['total']['value'] == 1
# the search results does not contains permissions
fdata = res.json['hits']['hits'][0]['metadata']['_files'][0]
assert list(fdata.keys()) == [
'key', 'label', 'type', 'order', 'restriction', 'links', 'thumbnail'
]
assert not fdata.get("permissions")

# the item result should contains permissions
res = client.get(url_for('invenio_records_rest.doc_item', pid_value=document_with_file['pid']))
assert res.status_code == 200
assert res.json['metadata']['_files'][0]['permissions'] == {
'delete': False, 'read': False,'update': False}


def test_put(app, client, document_with_file):
"""Test putting metadata on existing file."""
# Disable configuration
Expand Down

0 comments on commit d249ac9

Please sign in to comment.