From 5f3f4923b036a584443b606f24411fa647d542ab Mon Sep 17 00:00:00 2001 From: Andi Date: Thu, 23 May 2024 17:03:01 +0900 Subject: [PATCH] PEOPLE: QR Code Mitgliederausweis auf Profil --- .../hitobito/customizable/_wagon.scss | 7 +++ app/domain/export/pdf/passes/membership.rb | 1 - app/helpers/sac_cas/people_helper.rb | 17 ++++-- ...l.haml => _show_right_z_sac_cas.html.haml} | 9 ++-- config/locales/wagon.de.yml | 5 -- .../_show_right_z_sac_cas.html.haml_spec.rb | 52 +++++++++++++++++++ 6 files changed, 76 insertions(+), 15 deletions(-) rename app/views/people/{_show_event_sac_cas.html.haml => _show_right_z_sac_cas.html.haml} (62%) create mode 100644 spec/views/people/_show_right_z_sac_cas.html.haml_spec.rb diff --git a/app/assets/stylesheets/hitobito/customizable/_wagon.scss b/app/assets/stylesheets/hitobito/customizable/_wagon.scss index 5e573b6b7..ef00af56f 100644 --- a/app/assets/stylesheets/hitobito/customizable/_wagon.scss +++ b/app/assets/stylesheets/hitobito/customizable/_wagon.scss @@ -24,4 +24,11 @@ .turbo-progress-bar { background-color: $link-color !important; +} + +.qr-code-wrapper { + padding: 5px; + border: 1px solid #333; + border-radius: 10px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); } \ No newline at end of file diff --git a/app/domain/export/pdf/passes/membership.rb b/app/domain/export/pdf/passes/membership.rb index 56abb9db5..efb1ed896 100644 --- a/app/domain/export/pdf/passes/membership.rb +++ b/app/domain/export/pdf/passes/membership.rb @@ -56,4 +56,3 @@ def t(key) end end - diff --git a/app/helpers/sac_cas/people_helper.rb b/app/helpers/sac_cas/people_helper.rb index cd88a6ccb..24f2c2c7d 100644 --- a/app/helpers/sac_cas/people_helper.rb +++ b/app/helpers/sac_cas/people_helper.rb @@ -13,12 +13,19 @@ def format_person_sac_family_main_person(person) f(true) elsif main_person.nil? ti('.unknown') + elsif can?(:read, main_person) + link_to(main_person.to_s, main_person) else - if can?(:read, main_person) - link_to(main_person.to_s, main_person) - else - main_person.to_s - end + main_person.to_s end end + + def qr_code_image_tag(person, html_options = {}) + qr_code = People::Membership::VerificationQrCode.new(person).generate + qr_code_png = qr_code.as_png(size: 220) + qr_code_data = Base64.encode64(qr_code_png.to_blob) + default_options = { alt: 'QR Code', size: '220x220' } + options = default_options.merge(html_options) + image_tag("data:image/png;base64,#{qr_code_data}", options) + end end diff --git a/app/views/people/_show_event_sac_cas.html.haml b/app/views/people/_show_right_z_sac_cas.html.haml similarity index 62% rename from app/views/people/_show_event_sac_cas.html.haml rename to app/views/people/_show_right_z_sac_cas.html.haml index 14aa74ed5..6be292848 100644 --- a/app/views/people/_show_event_sac_cas.html.haml +++ b/app/views/people/_show_right_z_sac_cas.html.haml @@ -1,13 +1,14 @@ -# frozen_string_literal: true +- # Named with z so it will show up at the end. -# Copyright (c) 2023, Schweizer Alpen-Club. This file is part of -# hitobito_sac_cas 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_sac_cas. -- if can?(:update, entry) && entry.sac_membership_active? - %h2= t('.documents') +- if can?(:update, entry) && entry.sac_membership_anytime? %div %dl.dl-horizontal - = labeled t('.membership') do - = link_to t('.download'), membership_path(format: :pdf), target: :new + .d-flex.justify-content-center + .qr-code-wrapper + = qr_code_image_tag(entry) \ No newline at end of file diff --git a/config/locales/wagon.de.yml b/config/locales/wagon.de.yml index a0d9e0926..66f3272fe 100644 --- a/config/locales/wagon.de.yml +++ b/config/locales/wagon.de.yml @@ -630,11 +630,6 @@ de: stammsektion: Stammsektion set_stammsektion: Stammsektion setzen - show_event_sac_cas: - documents: Dokumente - membership: Mitgliederausweis - download: Anzeigen - tabs: history: Mitgliedschaften / Verlauf diff --git a/spec/views/people/_show_right_z_sac_cas.html.haml_spec.rb b/spec/views/people/_show_right_z_sac_cas.html.haml_spec.rb new file mode 100644 index 000000000..cd475d1c9 --- /dev/null +++ b/spec/views/people/_show_right_z_sac_cas.html.haml_spec.rb @@ -0,0 +1,52 @@ +# Copyright (c) 2012-2024, Schweizer Alpen-Club. This file is part of +# hitobito_sac_cas 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_sac_cas. + +require 'spec_helper' + +describe 'people/_show_right_z_sac_cas.html.haml' do + include FormatHelper + + let(:dom) { render; Capybara::Node::Simple.new(@rendered) } + + before do + allow(view).to receive_messages(current_user: person) + allow(view).to receive_messages(entry: PersonDecorator.decorate(person)) + allow(controller).to receive_messages(current_user: Person.new) + allow(view).to receive(:can?).with(:update, person).and_return true + end + + context 'member' do + let(:person) { Person.with_membership_years.find(people(:mitglied).id) } + + it 'renders membership info for active membership' do + expect(dom).to have_css '.qr-code-wrapper' + end + + it 'renders membership info for past membership' do + person.roles.destroy_all + expect(dom).to have_css '.qr-code-wrapper' + end + + it 'renders membership info for future membership' do + person.roles.destroy_all + person.roles.create!( + type: FutureRole.sti_name, + group: groups(:bluemlisalp_mitglieder), + convert_on: 1.month.from_now, + convert_to: Group::SektionsMitglieder::Mitglied.sti_name + ) + expect(dom).to have_css '.qr-code-wrapper' + end + end + + context 'other' do + let(:person) { people(:admin) } + + it 'hides membership info' do + expect(dom).not_to have_css '.qr-code-wrapper' + end + + end +end