Skip to content

Commit 7474d4b

Browse files
committed
permissions: disable write operations when read-only mode is on
1 parent 75e296d commit 7474d4b

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

invenio_requests/services/permissions.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# Copyright (C) 2021 CERN.
4-
# Copyright (C) 2021 Northwestern University.
5-
# Copyright (C) 2021 TU Wien.
3+
# Copyright (C) 2021 CERN.
4+
# Copyright (C) 2021 Northwestern University.
5+
# Copyright (C) 2021-2022 TU Wien.
66
#
77
# Invenio-Requests is free software; you can redistribute it and/or
88
# modify it under the terms of the MIT License; see LICENSE file for more
@@ -15,6 +15,7 @@
1515
AnyUser,
1616
AuthenticatedUser,
1717
Disable,
18+
DisableIfReadOnly,
1819
SystemProcess,
1920
SystemProcessWithoutSuperUser,
2021
)
@@ -26,7 +27,8 @@ class PermissionPolicy(RecordPermissionPolicy):
2627
"""Permission policy."""
2728

2829
# Ability in general to create requests (not which request you can create)
29-
can_create = [AuthenticatedUser(), SystemProcess()]
30+
can_create = [AuthenticatedUser(), SystemProcess(), DisableIfReadOnly()]
31+
3032
# Just about ability to perform a search (not what requests you can access)
3133
can_search = [AuthenticatedUser(), SystemProcess()]
3234

@@ -47,6 +49,7 @@ class PermissionPolicy(RecordPermissionPolicy):
4749
Status(["created"], [Creator()]),
4850
Status(["submitted"], [Creator(), Receiver()]),
4951
SystemProcess(),
52+
DisableIfReadOnly(),
5053
]
5154

5255
can_delete = [
@@ -56,32 +59,35 @@ class PermissionPolicy(RecordPermissionPolicy):
5659
[Disable()],
5760
),
5861
SystemProcess(),
62+
DisableIfReadOnly(),
5963
]
6064

6165
# Submit, cancel, expire, accept and decline actions only deals
6266
# with requests in a **single state** and thus doesn't need to take the
6367
# request status into account.
64-
can_action_submit = [Creator(), SystemProcess()]
65-
can_action_cancel = [Creator(), SystemProcess()]
68+
can_action_submit = [Creator(), SystemProcess(), DisableIfReadOnly()]
69+
can_action_cancel = [Creator(), SystemProcess(), DisableIfReadOnly()]
6670
# `SystemProcessWithoutSuperUser`: expire is an automatic action done only by
6771
# the system, therefore the `superuser-action` must be explicitly excluded
6872
# as it's added by default to any permission.
69-
can_action_expire = [SystemProcessWithoutSuperUser()]
70-
can_action_accept = [Receiver(), SystemProcess()]
71-
can_action_decline = [Receiver(), SystemProcess()]
73+
can_action_expire = [SystemProcessWithoutSuperUser(), DisableIfReadOnly()]
74+
can_action_accept = [Receiver(), SystemProcess(), DisableIfReadOnly()]
75+
can_action_decline = [Receiver(), SystemProcess(), DisableIfReadOnly()]
7276

7377
# Request events/comments
7478
# Events are in most cases protected by the associated request.
7579
can_update_comment = [
7680
Commenter(),
7781
SystemProcess(),
82+
DisableIfReadOnly(),
7883
]
7984
can_delete_comment = [
8085
Commenter(),
8186
SystemProcess(),
87+
DisableIfReadOnly(),
8288
]
8389
# If you can read the request you can create events for the request.
84-
can_create_comment = can_read
90+
can_create_comment = can_read + [DisableIfReadOnly()]
8591

8692
# Needed by the search events permission because a permission_action must
8793
# be provided to create_search(), but the event search is already protected

0 commit comments

Comments
 (0)