diff --git a/lib/additionals/concerns/query.rb b/lib/additionals/concerns/query.rb index 916b912f..3eb7de87 100644 --- a/lib/additionals/concerns/query.rb +++ b/lib/additionals/concerns/query.rb @@ -240,7 +240,7 @@ module Additionals end def roles_values - Role.givable.sorted.pluck(:name, :id).map { |name, id| [name, id.to_s] } + Role.givable.visible.sorted.pluck(:name, :id).map { |name, id| [name, id.to_s] } end def groups_values @@ -269,7 +269,7 @@ module Additionals end def sql_for_assigned_to_group_field(_field, operator, value) - sql_for_field 'assigned_to_id', operator, members_of_groups(group_id: value), queried_table_name, 'author_id' + sql_for_field 'assigned_to_id', operator, members_of_groups(group_id: value, with_group_id: true), queried_table_name, 'author_id' end def sql_for_author_role_field(field, operator, value) diff --git a/lib/additionals/patches/role_patch.rb b/lib/additionals/patches/role_patch.rb index 83db7146..409edb71 100644 --- a/lib/additionals/patches/role_patch.rb +++ b/lib/additionals/patches/role_patch.rb @@ -8,6 +8,18 @@ module Additionals included do safe_attributes 'hide' end + + class_methods do + def visible(user = User.current) + if user.admin? || + user.allowed_to?(:show_hidden_roles_in_memberbox, nil, global: true) || + AdditionalsPlugin.active_hrm? && User.current.hrm_allowed_to?(:view_hrm) + all + else + where hide: false + end + end + end end end end