Skip to content

Commit b89f2a4

Browse files
authored
Merge pull request #219 from open-data/feature/read-only-mode
Site Read Only Mode
2 parents e32654a + b83f28a commit b89f2a4

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

changes/219.canada.feature

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Added a `ckan.site_read_only` config option which disables actions causing side effects,
2+
such as `*_create`, `*_update`, and `*_delete`, for non-sysadmin users.
3+
4+
This setting does not prevent updates to the database from sysadmin users or updates
5+
that skip the action API, such as collecting page view tracking data.

ckan/authz.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,13 @@ def is_authorized(action: str, context: Context,
225225
if not getattr(auth_function, 'auth_sysadmins_check', False):
226226
return {'success': True}
227227

228+
# (canada fork only): site read only mode
229+
# TODO: upstream contrib!!!
230+
if config.get('ckan.site_read_only', False):
231+
if not getattr(p.toolkit.get_action(action), 'side_effect_free', False):
232+
return {'success': False,
233+
'msg': _('Site is in read only mode')}
234+
228235
# If the auth function is flagged as not allowing anonymous access,
229236
# and an existing user object is not provided in the context, deny
230237
# access straight away

0 commit comments

Comments
 (0)