diff options
Diffstat (limited to 'app/controllers/concerns')
| -rw-r--r-- | app/controllers/concerns/role_required.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/app/controllers/concerns/role_required.rb b/app/controllers/concerns/role_required.rb new file mode 100644 index 00000000..b841b8cc --- /dev/null +++ b/app/controllers/concerns/role_required.rb | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | # Controller-level role gates, for surfaces that are not nodes and so cannot | ||
| 2 | # be reached by Node#restricted?. The node gates live in the models, since | ||
| 3 | # those verbs are callable from rake tasks; these are HTTP-only. | ||
| 4 | module RoleRequired | ||
| 5 | extend ActiveSupport::Concern | ||
| 6 | |||
| 7 | private | ||
| 8 | |||
| 9 | def require_redaktion | ||
| 10 | return if current_user&.redaktion? | ||
| 11 | deny_role_access(:redaktion_required) | ||
| 12 | end | ||
| 13 | |||
| 14 | def require_admin | ||
| 15 | return if current_user&.is_admin? | ||
| 16 | deny_role_access(:admin_required) | ||
| 17 | end | ||
| 18 | |||
| 19 | def deny_role_access(key) | ||
| 20 | flash[:error] = t("flash.common.#{key}") | ||
| 21 | redirect_to admin_path | ||
| 22 | end | ||
| 23 | end | ||
