Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Abteilungsleitungen to fetch past members #204

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
9 changes: 9 additions & 0 deletions app/abilities/pbs/group_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ module Pbs::GroupAbility
may(:remind_census, :update_member_counts, :delete_member_counts).
in_same_layer_or_below_if_leader

permission(:layer_and_below_full).
may(:show_past_members).
if_abteilungsleitung_in_layer

permission(:approve_applications).may(:index_pending_approvals).if_layer_and_in_same_group

permission(:any).may(:'index_event/camps').all
Expand All @@ -48,6 +52,11 @@ def if_mitarbeiter_gs
role_type?(Group::Bund::MitarbeiterGs)
end

def if_abteilungsleitung_in_layer
in_same_layer_or_below &&
role_type?(Group::Abteilung::Abteilungsleitung, Group::Abteilung::AbteilungsleitungStv)
end

def if_layer_and_in_same_group
if_layer_group && user.groups_with_permission(permission).map(&:id).include?(group.id)
end
Expand Down
15 changes: 1 addition & 14 deletions app/controllers/group_health_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ class GroupHealthController < ApplicationController
GROUP_HEALTH_JOIN = "INNER JOIN #{Group.quoted_table_name} AS layer " \
"ON #{Group.quoted_table_name}.layer_group_id = layer.id " \
'AND layer.group_health = TRUE'.freeze
# query the group of type "Kantonalverband" which lies above in the hierarchical structure
CANTON_JOIN = "LEFT JOIN #{Group.quoted_table_name} AS canton " \
"ON #{Group.quoted_table_name}.lft >= canton.lft " \
"AND #{Group.quoted_table_name}.lft < canton.rgt " \
'AND canton.type = "Group::Kantonalverband"'.freeze
DEFAULT_PAGE_SIZE = 20.freeze

before_action do
Expand Down Expand Up @@ -65,7 +60,7 @@ def roles
end

def groups
respond(Group.from("((#{bund}) UNION (#{cantons}) UNION (#{abt_and_below})) " \
respond(Group.from("((#{bund}) UNION (#{cantons})) " \
"AS #{Group.quoted_table_name}")
.page(params[:page]).per(params[:size] || DEFAULT_PAGE_SIZE)
.as_json(only: GROUPS_FIELDS))
Expand Down Expand Up @@ -193,14 +188,6 @@ def cantons
.to_sql
end

def abt_and_below
Group.select("#{Group.quoted_table_name}.*", 'canton.id as canton_id',
'canton.name as canton_name')
.joins(CANTON_JOIN)
.joins(GROUP_HEALTH_JOIN).distinct
.to_sql
end

def set_j_s_kind(camp)
j_s_kind = camp['j_s_kind'].presence || 'none'
camp.merge(j_s_kind: "j_s_kind_#{j_s_kind}")
Expand Down
15 changes: 8 additions & 7 deletions app/decorators/pbs/person_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ def roles_grouped

private

def layer_group_ids
@layer_group_ids ||= (current_user || current_service_token.dynamic_user).layer_group_ids
end
def layer_group_ids
@layer_group_ids ||= (current_user || current_service_token.dynamic_user).layer_group_ids
end

def visible_roles
@visible_roles ||= roles.select do |role|
layer_group_ids.include?(role.group.layer_group_id) || role.visible_from_above
end
def visible_roles
@visible_roles ||= roles_with_deleted.select do |role|
(layer_group_ids.include?(role.group.layer_group_id) || role.visible_from_above) &&
(!role.deleted? || can?(:show_past_members, role.group))
end
end

end
3 changes: 2 additions & 1 deletion app/models/pbs/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ module Pbs::Person

included do
Person::PUBLIC_ATTRS << :title << :salutation << :correspondence_language <<
:prefers_digital_correspondence << :kantonalverband_id
:prefers_digital_correspondence << :kantonalverband_id <<
:pbs_number << :entry_date << :leaving_date

alias_method_chain :full_name, :title

Expand Down
21 changes: 21 additions & 0 deletions app/serializers/pbs/people_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# encoding: utf-8

# Copyright (c) 2021, Pfadibewegung Schweiz. This file is part of
# hitobito and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito.

module Pbs::PeopleSerializer
extend ActiveSupport::Concern

included do
extension(:public) do |_|
details = h.can?(:show_details, item)
if details
map_properties :gender, :birthday, :pbs_number, :entry_date, :leaving_date,
:primary_group_id
end
end
end

end
1 change: 1 addition & 0 deletions lib/hitobito_pbs/wagon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class Wagon < Rails::Engine

### serializers
PersonSerializer.include Pbs::PersonSerializer
PeopleSerializer.include Pbs::PeopleSerializer
GroupSerializer.include Pbs::GroupSerializer
EventSerializer.include Pbs::EventSerializer
EventParticipationSerializer.include Pbs::EventParticipationSerializer
Expand Down
7 changes: 0 additions & 7 deletions spec/controllers/group_health_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,6 @@
groups(:schekka).update(group_health: true)
end

it 'does export the group having opted in' do
get :groups, format: :json
json = JSON.parse(response.body)
groups = json['groups'].select {|g| g['name'] == groups(:schekka).name}
expect(groups.size).to eq(1)
end

it 'does only export people with roles in a group having opted in' do
get :people, format: :json
json = JSON.parse(response.body)
Expand Down