Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions modules/invenio-deposit/invenio_deposit/views/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def dbsession_clean(exception):
options['item_route']: (
options.pop('update_decorators', []), ('PUT', 'PATCH')),
}
action_decorators = options.pop('action_decorators', [])

options.setdefault('search_class', DepositSearch)
search_class = obj_or_import_string(options['search_class'])
Expand Down Expand Up @@ -192,6 +193,9 @@ def dbsession_clean(exception):
pid_type=options['pid_type'],
ctx=ctx,
)
if action_decorators:
deposit_actions = decorate_view(
deposit_actions, action_decorators, ('POST',))

blueprint.add_url_rule(
'{0}/actions/<any({1}):action>'.format(
Expand Down
5 changes: 5 additions & 0 deletions modules/invenio-deposit/tests/test_views_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ def test_create_blueprint_route_decorators():
default_media_type='application/json',
create_decorators=[_abort_factory(418)],
update_decorators=[_abort_factory(409)],
action_decorators=[_abort_factory(403)],
)
)
app = Flask('testapp')
Expand All @@ -688,8 +689,12 @@ def test_create_blueprint_route_decorators():
assert client.post('/deposits/').status_code == 418
assert client.put('/deposits/1').status_code == 409
assert client.patch('/deposits/1').status_code == 409
assert client.post('/deposits/1/actions/edit').status_code == 403
assert client.post('/deposits/1/actions/discard').status_code == 403
assert client.post('/deposits/1/actions/publish').status_code == 403
assert 'create_decorators' in endpoints['depid']
assert 'update_decorators' in endpoints['depid']
assert 'action_decorators' in endpoints['depid']


def _abort_factory(code):
Expand Down
8 changes: 7 additions & 1 deletion modules/weko-deposit/tests/test_weko_deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ def test_ItemResource_put(app, db):
headers = {'content-type': 'application/json'}
with patch('weko_deposit.tasks.RecordsSearch', mock_recordssearch), \
patch("weko_deposit.rest.WekoRecord.get_record_by_pid", return_value=None):
# put には require_item_edit_permission が付いているため、
# 未認証では本体に入る前に 401 になる。
# ログイン後の更新の流れは test_rest.py::test_put で見ている。
res = client.put("/deposits/redirect/1",
data=json.dumps(data), headers=headers)
assert res.status_code == 200
assert res.status_code == 401


def test_deposit_rest_endpoints_route_decorators():
Expand All @@ -97,3 +100,6 @@ def test_deposit_rest_endpoints_route_decorators():
assert DEPOSIT_REST_ENDPOINTS['depid']['update_decorators'] == expected
assert WEKO_DEPOSIT_REST_ENDPOINTS['depid']['update_decorators'] \
== expected
assert DEPOSIT_REST_ENDPOINTS['depid']['action_decorators'] == expected
assert WEKO_DEPOSIT_REST_ENDPOINTS['depid']['action_decorators'] \
== expected
1 change: 1 addition & 0 deletions modules/weko-deposit/weko_deposit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
delete_permission_factory_imp=deny_all,
create_decorators=['weko_accounts.utils:login_required_customize'],
update_decorators=['weko_deposit.rest:require_item_edit_permission'],
action_decorators=['weko_deposit.rest:require_item_edit_permission'],
)
)

Expand Down
4 changes: 2 additions & 2 deletions scripts/instance.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -765,9 +765,9 @@ WEKO_WORKFLOW_ENABLE_AUTO_SET_INDEX_FOR_ITEM_TYPE = True
#--- Enable showing term of use
WEKO_WORKFLOW_ENABLE_SHOWING_TERM_OF_USE = True
#--- Enable issuing tokens for guest activities
WEKO_WORKFLOW_GUEST_TOKEN_ISSUE_ENABLED = True
WEKO_WORKFLOW_GUEST_TOKEN_ISSUE_ENABLED = False
#--- Enable accepting tokens for guest activities
WEKO_WORKFLOW_GUEST_TOKEN_ACCEPT_ENABLED = True
WEKO_WORKFLOW_GUEST_TOKEN_ACCEPT_ENABLED = False

from weko_user_profiles.config import WEKO_USERPROFILES_GENERAL_ROLE, WEKO_USERPROFILES_GRADUATED_STUDENT_ROLE, WEKO_USERPROFILES_STUDENT_ROLE

Expand Down
Loading