Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
global: cleanup and integration with new resources approach [more]
- remove factories - remove deposit references - adapt policies to use permission (identity) for filtering
- Loading branch information
Pablo Panero
committed
Sep 16, 2020
1 parent
0e9c718
commit 828250d
Showing
15 changed files
with
48 additions
and
390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,23 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2019 CERN. | ||
# Copyright (C) 2019 Northwestern University. | ||
# Copyright (C) 2019-2020 CERN. | ||
# Copyright (C) 2019-2020 Northwestern University. | ||
# | ||
# Invenio App RDM is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
# Invenio-Records-Permissions is free software; you can redistribute it | ||
# and/or modify it under the terms of the MIT License; see LICENSE file for | ||
# more details. | ||
|
||
"""Invenio Records Permissions API.""" | ||
|
||
from elasticsearch_dsl.query import Q | ||
from flask import current_app | ||
from invenio_search.api import DefaultFilter, RecordsSearch | ||
|
||
from .factories import record_read_permission_factory | ||
|
||
|
||
def rdm_records_filter(): | ||
"""Records filter.""" | ||
# TODO: Implement with new permissions metadata | ||
try: | ||
perm_factory = current_app.config["RECORDS_REST_ENDPOINTS"]["recid"][ | ||
"read_permission_factory_imp" | ||
]() # noqa | ||
except KeyError: | ||
perm_factory = record_read_permission_factory | ||
# FIXME: this might fail if factory returns None, meaning no "query_filter" | ||
# was implemente in the generators. However, IfPublic should always be | ||
# there. | ||
|
||
filters = perm_factory.query_filters | ||
if filters: | ||
def records_permission_filter(permission): | ||
"""Records permission filter.""" | ||
if permission: | ||
qf = None | ||
for f in filters: | ||
for f in permission.query_filters: | ||
qf = qf | f if qf else f | ||
return qf | ||
else: | ||
return Q() | ||
|
||
|
||
# TODO: Move this to invenio-rdm-records and | ||
# * have it provide the permissions OR | ||
# * rely on app's current_search for tests | ||
class RecordsSearch(RecordsSearch): | ||
"""Search class for RDM records.""" | ||
|
||
class Meta: | ||
"""Default index and filter for frontpage search.""" | ||
|
||
index = "records" | ||
doc_types = None | ||
default_filter = DefaultFilter(rdm_records_filter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.