Skip to content

Commit

Permalink
PEOPLE: QR Code Mitgliederausweis auf Profil
Browse files Browse the repository at this point in the history
  • Loading branch information
Largo committed May 23, 2024
1 parent 0e98e4a commit 5f3f492
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 15 deletions.
7 changes: 7 additions & 0 deletions app/assets/stylesheets/hitobito/customizable/_wagon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 0 additions & 1 deletion app/domain/export/pdf/passes/membership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,3 @@ def t(key)

end
end

17 changes: 12 additions & 5 deletions app/helpers/sac_cas/people_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 0 additions & 5 deletions config/locales/wagon.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
52 changes: 52 additions & 0 deletions spec/views/people/_show_right_z_sac_cas.html.haml_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5f3f492

Please sign in to comment.