mirror of
https://github.com/Cian-H/invenio-config-iform.git
synced 2025-12-23 13:31:58 +00:00
seperate file for access control configuration
permissionsPolicy file will handle the access control configurations.
This commit is contained in:
@@ -9,11 +9,6 @@
|
|||||||
"""invenio module that adds tugraz configs."""
|
"""invenio module that adds tugraz configs."""
|
||||||
|
|
||||||
from flask_babelex import gettext as _
|
from flask_babelex import gettext as _
|
||||||
from invenio_records_permissions.generators import Admin, AnyUser, \
|
|
||||||
AnyUserIfPublic, Disable, RecordOwners
|
|
||||||
from invenio_records_permissions.policies.base import BasePermissionPolicy
|
|
||||||
|
|
||||||
from .permissions import RecordIp
|
|
||||||
|
|
||||||
INVENIO_CONFIG_TUGRAZ_SHIBBOLETH = True
|
INVENIO_CONFIG_TUGRAZ_SHIBBOLETH = True
|
||||||
"""Set True if SAML is configured"""
|
"""Set True if SAML is configured"""
|
||||||
@@ -191,68 +186,8 @@ RECAPTCHA_PRIVATE_KEY = None
|
|||||||
# See:
|
# See:
|
||||||
# https://invenio-records-permissions.readthedocs.io/en/latest/configuration.html
|
# https://invenio-records-permissions.readthedocs.io/en/latest/configuration.html
|
||||||
#
|
#
|
||||||
""""
|
|
||||||
Default policies for records:
|
|
||||||
|
|
||||||
.. code-block:: python
|
RECORDS_PERMISSIONS_RECORD_POLICY = (
|
||||||
|
'invenio_config_tugraz.permissionsPolicy.TUGRAZPermissionPolicy'
|
||||||
# Read access given to everyone.
|
)
|
||||||
can_search = [AnyUser()]
|
|
||||||
# Create action given to no one (Not even superusers) bc Deposits should
|
|
||||||
# be used.
|
|
||||||
can_create = [Disable()]
|
|
||||||
# Read access given to everyone if public record/files and owners always.
|
|
||||||
can_read = [AnyUserIfPublic(), RecordOwners()]
|
|
||||||
# Update access given to record owners.
|
|
||||||
can_update = [RecordOwners()]
|
|
||||||
# Delete access given to admins only.
|
|
||||||
can_delete = [Admin()]
|
|
||||||
# Associated files permissions (which are really bucket permissions)
|
|
||||||
can_read_files = [AnyUserIfPublic(), RecordOwners()]
|
|
||||||
can_update_files = [RecordOwners()]
|
|
||||||
"""
|
|
||||||
|
|
||||||
""""
|
|
||||||
How to override default policies for records.
|
|
||||||
|
|
||||||
Using Custom Generator for a policy:
|
|
||||||
|
|
||||||
.. code-block:: python
|
|
||||||
|
|
||||||
from invenio_rdm_records.permissions import RDMRecordPermissionPolicy
|
|
||||||
from invenio_config_tugraz.permissions import RecordIp
|
|
||||||
|
|
||||||
class TUGRAZPermissionPolicy(RDMRecordPermissionPolicy):
|
|
||||||
|
|
||||||
# Delete access given to RecordIp only.
|
|
||||||
can_delete = [RecordIp()]
|
|
||||||
|
|
||||||
RECORDS_PERMISSIONS_RECORD_POLICY = TUGRAZPermissionPolicy
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class TUGRAZPermissionPolicy(BasePermissionPolicy):
|
|
||||||
"""Access control configuration for records."""
|
|
||||||
|
|
||||||
# Read access to API given to everyone.
|
|
||||||
can_search = [AnyUser()]
|
|
||||||
|
|
||||||
# Read access given to everyone if public record/files and owners always.
|
|
||||||
can_read = [AnyUserIfPublic(), RecordOwners()]
|
|
||||||
|
|
||||||
# Create action given to no one (Not even superusers) bc Deposits should
|
|
||||||
# be used.
|
|
||||||
can_create = [Disable()]
|
|
||||||
|
|
||||||
# Update access given to record owners.
|
|
||||||
can_update = [RecordOwners()]
|
|
||||||
|
|
||||||
# Delete access given to admins only.
|
|
||||||
can_delete = [Admin()]
|
|
||||||
|
|
||||||
# Associated files permissions (which are really bucket permissions)
|
|
||||||
can_read_files = [AnyUserIfPublic(), RecordOwners()]
|
|
||||||
can_update_files = [RecordOwners()]
|
|
||||||
|
|
||||||
RECORDS_PERMISSIONS_RECORD_POLICY = TUGRAZPermissionPolicy
|
|
||||||
"""Access control configuration for records."""
|
"""Access control configuration for records."""
|
||||||
|
|||||||
84
invenio_config_tugraz/permissionsPolicy.py
Normal file
84
invenio_config_tugraz/permissionsPolicy.py
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2020 Mojib Wali.
|
||||||
|
#
|
||||||
|
# invenio-config-tugraz is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the MIT License; see LICENSE file for more
|
||||||
|
# details.
|
||||||
|
|
||||||
|
"""
|
||||||
|
Records permission policies.
|
||||||
|
|
||||||
|
Default policies for records:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
# Read access given to everyone.
|
||||||
|
can_search = [AnyUser()]
|
||||||
|
# Create action given to no one (Not even superusers) bc Deposits should
|
||||||
|
# be used.
|
||||||
|
can_create = [Disable()]
|
||||||
|
# Read access given to everyone if public record/files and owners always.
|
||||||
|
can_read = [AnyUserIfPublic(), RecordOwners()]
|
||||||
|
# Update access given to record owners.
|
||||||
|
can_update = [RecordOwners()]
|
||||||
|
# Delete access given to admins only.
|
||||||
|
can_delete = [Admin()]
|
||||||
|
# Associated files permissions (which are really bucket permissions)
|
||||||
|
can_read_files = [AnyUserIfPublic(), RecordOwners()]
|
||||||
|
can_update_files = [RecordOwners()]
|
||||||
|
|
||||||
|
How to override default policies for records.
|
||||||
|
|
||||||
|
Using Custom Generator for a policy:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
from invenio_rdm_records.permissions import RDMRecordPermissionPolicy
|
||||||
|
from invenio_config_tugraz.permissions import RecordIp
|
||||||
|
|
||||||
|
class TUGRAZPermissionPolicy(RDMRecordPermissionPolicy):
|
||||||
|
|
||||||
|
# Delete access given to RecordIp only.
|
||||||
|
|
||||||
|
can_delete = [RecordIp()]
|
||||||
|
|
||||||
|
RECORDS_PERMISSIONS_RECORD_POLICY = TUGRAZPermissionPolicy
|
||||||
|
|
||||||
|
|
||||||
|
Permissions for Invenio (RDM) Records.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from invenio_records_permissions.generators import Admin, AnyUser, \
|
||||||
|
AnyUserIfPublic, Disable, RecordOwners
|
||||||
|
from invenio_records_permissions.policies.base import BasePermissionPolicy
|
||||||
|
|
||||||
|
from .permissions import RecordIp
|
||||||
|
|
||||||
|
|
||||||
|
class TUGRAZPermissionPolicy(BasePermissionPolicy):
|
||||||
|
"""Access control configuration for records.
|
||||||
|
|
||||||
|
This overrides the /api/records endpoint.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Read access to API given to everyone.
|
||||||
|
can_search = [AnyUser(), RecordIp()]
|
||||||
|
|
||||||
|
# Read access given to everyone if public record/files and owners always.
|
||||||
|
can_read = [AnyUserIfPublic(), RecordOwners(), RecordIp()]
|
||||||
|
|
||||||
|
# Create action given to no one (Not even superusers) bc Deposits should
|
||||||
|
# be used.
|
||||||
|
can_create = [AnyUser()]
|
||||||
|
|
||||||
|
# Update access given to record owners.
|
||||||
|
can_update = [RecordOwners()]
|
||||||
|
|
||||||
|
# Delete access given to admins only.
|
||||||
|
can_delete = [Admin()]
|
||||||
|
|
||||||
|
# Associated files permissions (which are really bucket permissions)
|
||||||
|
can_read_files = [AnyUserIfPublic(), RecordOwners()]
|
||||||
|
can_update_files = [RecordOwners()]
|
||||||
Reference in New Issue
Block a user