Commit a7ac2286 authored by Kaspar Vollenweider's avatar Kaspar Vollenweider

Merge branch 'feat/only_superadmin_can_create_group_offer_categories' into 'develop'

feat: only superadmins can create, update and destroy group offer categories

See merge request !945
parents 4b8c0ab7 b6b940f5
Pipeline #43395 passed with stage
in 43 minutes and 22 seconds
class GroupOfferCategoryPolicy < ApplicationPolicy
alias_method :index?, :superadmin_or_department_manager?
alias_method :show?, :superadmin_or_department_manager?
alias_method :new?, :superadmin_or_department_manager?
alias_method :edit?, :superadmin_or_department_manager?
alias_method :create?, :superadmin_or_department_manager?
alias_method :update?, :superadmin_or_department_manager?
alias_method :new?, :superadmin?
alias_method :edit?, :superadmin?
alias_method :create?, :superadmin?
alias_method :update?, :superadmin?
end
......@@ -2,7 +2,8 @@ h1= t('.group_offer_categories')
ul.list-inline
li= button_link icon_span(:back), group_offers_path
li= form_navigation_btn :new, with_row: false
- if policy(GroupOfferCategory).new?
li= form_navigation_btn :new, with_row: false
.table-responsive
table.table.table-striped
......@@ -11,7 +12,8 @@ ul.list-inline
th= sort_link @q, :category_name, t_attr(:category_name)
th= sort_link @q, :description, 'Beschreibung'
th= sort_link @q, :category_state, t_attr(:category_state)
th colspan='1'
- if policy(GroupOfferCategory).edit?
th
tbody
- @group_offer_categories.each do |category|
......@@ -19,4 +21,5 @@ ul.list-inline
td= category.category_name
td= category.description
td= t(".category_states.#{category.category_state}")
td= link_to t_action(:edit), edit_group_offer_category_path(category)
- if policy(GroupOfferCategory).edit?
td= link_to t_action(:edit), edit_group_offer_category_path(category)
......@@ -12,7 +12,8 @@ nav.navbar.section-navigation#filters
ul.list-inline
- if policy(GroupOffer).new?
li= button_link t_title(:new), new_group_offer_path, dimension: 'sm'
li= button_link t('.group_offer_categories'), group_offer_categories_path, dimension: 'sm'
- if policy(GroupOfferCategory).index?
li= button_link t('.group_offer_categories'), group_offer_categories_path, dimension: 'sm'
li= button_link icon_span(:xlsx), url_for(format: :xlsx, q: search_parameters), dimension: 'sm'
li= link_to icon_span(:print), url_for(print: :true, q: search_parameters), { class: 'btn btn-default btn-sm', target: '_blank' }
hr
......
......@@ -6,8 +6,15 @@ class GroupOfferCategoryPolicyTest < PolicyAssertions::Test
'update?')
end
test 'department managaer can use all category actions' do
assert_permit(create(:department_manager), GroupOfferCategory, 'new?', 'create?', 'index?',
'show?', 'edit?', 'update?')
test 'department managaer can show and index' do
department_manager = create(:department_manager)
assert_permit(department_manager, GroupOfferCategory, 'index?', 'show?')
refute_permit(department_manager, GroupOfferCategory, 'new?', 'create?', 'edit?', 'update?')
end
test 'social_worker cant use categories' do
social_worker = create(:social_worker)
refute_permit(social_worker, GroupOfferCategory, 'index?', 'show?', 'new?', 'create?', 'edit?',
'update?')
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment