From ee88bb547dbbdbf9c72ebd9e6a3db34776835c27 Mon Sep 17 00:00:00 2001 From: Diego Steiner Date: Thu, 10 Oct 2024 12:15:50 +0200 Subject: [PATCH] feat: add manager to participation view (hitobito_jubla#78) --- app/domain/youth/export/pdf/participation.rb | 25 -------- .../participations/_people_managers.html.haml | 4 +- app/views/person/managers/_list.html.haml | 2 +- .../participations/_attrs.html.haml_spec.rb | 57 +++++++++++++++++++ 4 files changed, 60 insertions(+), 28 deletions(-) delete mode 100644 app/domain/youth/export/pdf/participation.rb create mode 100644 spec/views/event/participations/_attrs.html.haml_spec.rb diff --git a/app/domain/youth/export/pdf/participation.rb b/app/domain/youth/export/pdf/participation.rb deleted file mode 100644 index 4af8abb..0000000 --- a/app/domain/youth/export/pdf/participation.rb +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (c) 2012-2013, Jungwacht Blauring 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 Youth::Export::Pdf - module Participation - class PersonAndEvent < Export::Pdf::Participation::PersonAndEvent - class Person < Export::Pdf::Participation::PersonAndEvent::Person - def render - super - render_people_managers - end - - def render_people_managers - return unless FeatureGate.enabled?('people.people_managers') - - person.people_managers&.each do |manager| - labeled_attr(manager, :manager) - end - end - end - end - end -end diff --git a/app/views/event/participations/_people_managers.html.haml b/app/views/event/participations/_people_managers.html.haml index 830428d..5c76151 100644 --- a/app/views/event/participations/_people_managers.html.haml +++ b/app/views/event/participations/_people_managers.html.haml @@ -1,5 +1,5 @@ - # frozen_string_literal: true -- + - # Copyright (c) 2024, Schweizer Alpen-Club. 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 @@ -8,5 +8,5 @@ - FeatureGate.if('people.people_managers') do - if entry.person.people_managers.any? - %section + %section = render 'person/managers/list', person: entry.person diff --git a/app/views/person/managers/_list.html.haml b/app/views/person/managers/_list.html.haml index dd7235e..80c5a80 100644 --- a/app/views/person/managers/_list.html.haml +++ b/app/views/person/managers/_list.html.haml @@ -12,7 +12,7 @@ - person.people_managers.each do |item| %tr %td - %strong= link_to(item.manager, item.manager, data: { turbo_frame: :_top }) + %strong= link_to_if(can?(:show, item.manager), item.manager, item.manager, data: { turbo_frame: :_top }) %div.d-flex.gap-2 = mail_to(item.email) = phone_to(item.phone_number.number, item.phone_number) if item.phone_number.present? diff --git a/spec/views/event/participations/_attrs.html.haml_spec.rb b/spec/views/event/participations/_attrs.html.haml_spec.rb new file mode 100644 index 0000000..1077597 --- /dev/null +++ b/spec/views/event/participations/_attrs.html.haml_spec.rb @@ -0,0 +1,57 @@ +# Copyright (c) 2012-2013, Jungwacht Blauring 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. + +require "spec_helper" + +describe "event/participations/_attrs.html.haml" do + let(:event) { EventDecorator.decorate(Fabricate(:course, groups: [groups(:top_layer)])) } + let(:participation) { Fabricate(:event_participation, event: event) } + subject(:dom) do + render + Capybara::Node::Simple.new(@rendered) + end + + let(:params) do + {"action" => "show", + "controller" => "event/participations", + "group_id" => "1", + "event_id" => "36"} + end + + before do + assign(:event, event) + assign(:group, event.groups.first.decorate) + assign(:answers, []) + allow(view).to receive_messages(parent: event) + allow(view).to receive_messages(entry: participation.decorate) + allow(view).to receive_messages(params: params) + # allow(view).to receive_messages(current_person: people(:top_leader)) + # Fabricate(event.participant_types.first.name, participation: participation) + # participation.reload + end + + context "with PeopleManager assigned" do + let!(:manager) do + Fabricate(:person).tap do |manager| + manager.phone_numbers.create(number: "+41 44 123 45 57", label: "Privat") + participation.person.managers << manager + end + end + + it "marks participations where required questions are unanswered" do + login_as(people(:top_leader)) + + expect(dom).to have_text PeopleManager.model_name.human(count: 2) + expect(dom).to have_text manager.to_s + expect(dom).to have_text manager.email + expect(dom).to have_text manager.phone_numbers.first + end + end + + def login_as(user) + allow(controller).to receive_messages(current_user: user) + allow(view).to receive_messages(current_user: user) + end +end