Skip to content

Commit

Permalink
documents: add masked property
Browse files Browse the repository at this point in the history
* Adds `marked` property to documents and hides masked documents on the public interface.
* Closes #570.

Co-Authored-by: Sébastien Délèze <sebastien.deleze@rero.ch>
  • Loading branch information
Sébastien Délèze committed Jul 21, 2021
1 parent 2f96691 commit 4fbfcf4
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,17 @@
"form": {
"hide": true
}
},
"masked": {
"title": "Masked",
"type": "boolean",
"description": "A masked document is visible in the professional interface, but not in the public interface.",
"default": false,
"form": {
"expressionProperties": {
"templateOptions.required": "true"
}
}
}
},
"propertiesOrder": [
Expand Down Expand Up @@ -1866,7 +1877,8 @@
"oa_status",
"customField1",
"customField2",
"customField3"
"customField3",
"masked"
],
"required": [
"$schema",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,9 @@
}
}
},
"masked": {
"type": "boolean"
},
"_created": {
"type": "date"
},
Expand Down
1 change: 1 addition & 0 deletions sonar/modules/documents/marshmallow/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class DocumentMetadataSchemaV1(StrictKeysMixin):
customField1 = fields.List(fields.String(validate=validate.Length(min=1)))
customField2 = fields.List(fields.String(validate=validate.Length(min=1)))
customField3 = fields.List(fields.String(validate=validate.Length(min=1)))
masked = fields.Boolean()
_bucket = SanitizedUnicode()
_files = Nested(FileSchemaV1, many=True)
_oai = fields.Dict()
Expand Down
3 changes: 3 additions & 0 deletions sonar/modules/documents/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def search_factory(self, search, query_parser=None):

# Public search
if view:
# Don't display masked records
search = search.filter('bool', must_not={'term': {'masked': True}})

# Filter record by organisation view.
if view != current_app.config.get('SONAR_APP_DEFAULT_ORGANISATION'):
search = search.filter('term', organisation__pid=view)
Expand Down
28 changes: 27 additions & 1 deletion tests/api/documents/test_documents_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from flask import url_for


def test_collection_query(db, client, document, collection):
def test_collection_query(db, client, document, collection, es_clear):
document['collections'] = [{
'$ref':
'https://sonar.ch/api/collections/{pid}'.format(pid=collection['pid'])
Expand All @@ -36,3 +36,29 @@ def test_collection_query(db, client, document, collection):
assert res.status_code == 200
assert res.json['hits']['total']['value'] == 1
assert not res.json['aggregations'].get('collection')


def test_masked_document(db, client, document, es_clear):
"""Test masked document."""
# Not masked (property not exists)
res = client.get(url_for('invenio_records_rest.doc_list', view='global'))
assert res.status_code == 200
assert res.json['hits']['total']['value'] == 1

# Not masked
document['masked'] = False
document.commit()
document.reindex()
db.session.commit()
res = client.get(url_for('invenio_records_rest.doc_list', view='global'))
assert res.status_code == 200
assert res.json['hits']['total']['value'] == 1

# Masked
document['masked'] = True
document.commit()
document.reindex()
db.session.commit()
res = client.get(url_for('invenio_records_rest.doc_list', view='global'))
assert res.status_code == 200
assert res.json['hits']['total']['value'] == 0

0 comments on commit 4fbfcf4

Please sign in to comment.