Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Für jeden Anhang bei Anlässen, Kursen etc. kann neu individuell ausgewählt werden, ob der Anhang global sichtbar ist (wie bisher) oder ob nur Teilnehmende oder nur das Leitungsteam den Anhang sehen darf (hitobito_sac_cas#486)
* Einführung Mitgliedschaftskonzept (People::Membership) sowie Membership Verification Endpoint (Verschieben vom SKV Wagon in den Core) (hitobito#2511)
* Die Rollentypen werden nun alphabetisch sortiert im Auswahlmenü (hitobito_sac_cas#552)

## Version 2.1

Expand Down
8 changes: 6 additions & 2 deletions app/decorators/group_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ def prepend_complete_address(html)
end
end

def role_types
klass.role_types.sort_by(&:label)
end

def possible_roles
klass.role_types.select do |type|
role_types.select do |type|
# users from above cannot create non visible roles
!type.restricted? &&
(type.visible_from_above? || can?(:index_local_people, model))
end
end

def allowed_roles_for_self_registration
klass.role_types.reject do |r|
role_types.reject do |r|
r.restricted? ||
r.permissions.any? { |p| Role::Types::WRITING_PERMISSIONS.include?(p) }
end
Expand Down
64 changes: 51 additions & 13 deletions spec/decorators/group_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,67 @@

describe 'possible roles' do
its(:possible_roles) do
should eq [Group::TopGroup::Leader,
Group::TopGroup::LocalGuide,
Group::TopGroup::Secretary,
Group::TopGroup::LocalSecretary,
Group::TopGroup::GroupManager,
Group::TopGroup::Member,
Group::TopGroup::InvisiblePeopleManager,
Role::External]
should eq [
Role::External,
Group::TopGroup::GroupManager,
Group::TopGroup::InvisiblePeopleManager,
Group::TopGroup::Leader,
Group::TopGroup::LocalGuide,
Group::TopGroup::LocalSecretary,
Group::TopGroup::Member,
Group::TopGroup::Secretary
]
end
end

context 'Top Group Roles' do
let(:group) { groups(:top_group) }

it 'sorts the list alphabetically by label' do
common_arguments = { count: 1, scope: [:activerecord, :models] }

[[:'group/top_group/leader', 'Leader', 'X'],
[:'group/top_group/local_guide', 'Local guide', 'F'],
[:'group/top_group/secretary', 'Secretary', 'D'],
[:'group/top_group/local_secretary', 'Local secretary', 'L'],
[:'group/top_group/group_manager', 'Group manager', 'E'],
[:'group/top_group/member', 'Member', 'M'],
[:'group/top_group/invisible_people_manager', 'Invisible people manager', 'G'],
[:'role/external', 'External', 'H']].each do |class_path, class_name, sort_key|
expect(I18n).to receive(:translate).with(class_path,
{ default: [:role,
class_name] }.merge(common_arguments))
.twice.and_return(sort_key)
end

expected_role_list_label = %w(D E F G H L M X)
expected_role_list_class = %w(Group::TopGroup::Secretary Group::TopGroup::GroupManager
Group::TopGroup::LocalGuide
Group::TopGroup::InvisiblePeopleManager
Role::External
Group::TopGroup::LocalSecretary
Group::TopGroup::Member
Group::TopGroup::Leader)

role_types = subject.role_types
expect(role_types.map(&:label)).to eq(expected_role_list_label)
expect(role_types.map(&:name)).to eq(expected_role_list_class)
end
end

describe 'allowed_roles_for_self_registration' do
its(:allowed_roles_for_self_registration) do
should eq [Group::TopGroup::LocalSecretary,
Group::TopGroup::Member,
Role::External]
should eq [Role::External,
Group::TopGroup::LocalSecretary,
Group::TopGroup::Member]
end

describe 'allowed_roles_for_self_registration in a bottom group' do
let(:model) { groups(:bottom_group_one_one) }

it 'should include roles which are not visible_from_above' do
expect(subject.allowed_roles_for_self_registration).to eq [
Group::BottomGroup::Member, Role::External
Role::External, Group::BottomGroup::Member
]
end
end
Expand Down Expand Up @@ -119,7 +156,8 @@ class DummyGroup < Group # rubocop:disable Lint/ConstantDefinitionInBlock
it 'renders link with icon and text' do
expect(node).to have_link 'Hauptgruppe setzen'
expect(node).to have_css 'a i.fas.fa-star[filled=true]'
expect(node.find('a')['href']).to eq(primary_group_group_person_path(model, person, primary_group_id: model.id))
expect(node.find('a')['href']).to eq(primary_group_group_person_path(model, person,
primary_group_id: model.id))
end
end

Expand Down