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

Return oidc membership_verifier_url only for former or active members (#1316) #1317

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
2 changes: 1 addition & 1 deletion app/domain/sac_cas/oidc_claim_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def picture_url(owner)
end

def membership_verify_url(owner)
People::Membership::VerificationQrCode.new(owner).verify_url
People::Membership::VerificationQrCode.new(owner).verify_url if owner.sac_membership_anytime?
end

def phone(owner)
Expand Down
4 changes: 2 additions & 2 deletions app/views/people/_show_right_z_sac_cas.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
- if can?(:update, entry) && entry.sac_membership_anytime?
%section.sac-membership.row
%h2.col-md-8
= t('.section_sac_membership')
= t('.section_sac_membership')
.col-sm-4.d-flex.justify-content-end
= action_button(t('.download_pdf'), membership_path(entry, format: :pdf),
= action_button(t('.download_pdf'), membership_path(entry, format: :pdf),
:download, class: 'membership-download', target: '_blank')

.d-flex.justify-content-center.w-100
Expand Down
22 changes: 20 additions & 2 deletions spec/controllers/oauth/userinfo_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,27 @@
country: user.country,
phone: nil,
picture_url: /\/packs(-test)?\/media\/images\/profile-.*\.svg/,
membership_verify_url: "http://localhost:3000/verify_membership/aSuperSweetToken42"
membership_verify_url: nil
}.deep_stringify_keys)
end

context "with membership" do
let(:user) { mitglied.person }
let(:mitglied) { roles(:mitglied) }

it "includes membership_verify_url" do
get :show, params: {access_token: token.token}
expect(response.status).to eq 200
expect(data["membership_verify_url"]).to eq "http://localhost:3000/verify_membership/aSuperSweetToken42"
end

it "includes membership_verify_url even if expired" do
mitglied.update!(end_on: 1.year.ago)
get :show, params: {access_token: token.token}
expect(response.status).to eq 200
expect(data["membership_verify_url"]).to eq "http://localhost:3000/verify_membership/aSuperSweetToken42"
end
end
end

context "with with_roles scope" do
Expand Down Expand Up @@ -80,7 +98,7 @@
phone: nil,
membership_years: "0.0",
picture_url: %r{packs(-test)?/media/images/profile-.*\.svg},
membership_verify_url: "http://localhost:3000/verify_membership/aSuperSweetToken42",
membership_verify_url: nil,
roles: [
{
group_id: user.roles.first.group_id,
Expand Down
16 changes: 12 additions & 4 deletions spec/domain/oidc_claim_setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
before do
allow(ENV).to receive(:fetch).and_call_original
allow(ENV).to receive(:fetch).with("RAILS_HOST_NAME", "localhost:3000").and_return("hitobito.example.com")
allow(ENV).to receive(:fetch).with("RAILS_HOST_NAME").and_return("hitobito.example.com")
allow_any_instance_of(People::Membership::VerificationQrCode).to receive(:membership_verify_token).and_return("aSuperSweetToken42")
end

shared_examples "shared claims" do
Expand Down Expand Up @@ -49,8 +47,18 @@
expect(claims[:picture_url]).to start_with "http://test.host/rails/active_storage/blobs/redirect"
end

it "membership_verify_url is present" do
expect(claims[:membership_verify_url]).to eq "http://hitobito.example.com/verify_membership/aSuperSweetToken42"
it "membership_verify_url is nil" do
expect(claims[:membership_verify_url]).to be_nil
end

context "mitglied" do
let(:owner) { people(:mitglied) }

before { allow_any_instance_of(People::Membership::VerificationQrCode).to receive(:membership_verify_token).and_return("aSuperSweetToken42") }

it "membership_verify_url is present" do
expect(claims[:membership_verify_url]).to eq "http://hitobito.example.com/verify_membership/aSuperSweetToken42"
end
end

it_behaves_like "shared claims"
Expand Down
Loading