Skip to content

Commit

Permalink
Return membership years as integer in json api and oidc
Browse files Browse the repository at this point in the history
  • Loading branch information
amaierhofer committed Dec 31, 2024
1 parent e97a385 commit 6970c49
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
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 @@ -66,7 +66,7 @@ def phone(owner)
end

def membership_years(owner)
Person.with_membership_years.find_by(id: owner.id).membership_years
Person.with_membership_years.find_by(id: owner.id).membership_years.to_i
end

def user_groups(owner)
Expand Down
3 changes: 2 additions & 1 deletion app/resources/sac_cas/person_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ module SacCas::PersonResource
@object.membership_years if @object.sac_membership_anytime?
end
on_extra_attribute :membership_years do |scope|
scope.with_membership_years
# NOTE cannot simply chain with_membership_years as it calculates bad results
Person.with_membership_years.where(id: scope.select("people.id"))
end

with_options writable: false, sortable: false, filterable: false do
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/oauth/userinfo_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
town: user.town,
country: user.country,
phone: nil,
picture_url: /\/packs(-test)?\/media\/images\/profile-.*\.svg/,
picture_url: %r{packs(-test)?/media/images/profile-.*\.svg},
membership_verify_url: nil
}.deep_stringify_keys)
end
Expand Down Expand Up @@ -96,7 +96,7 @@
primary_group_id: user.primary_group_id,
language: user.language,
phone: nil,
membership_years: "0.0",
membership_years: 0,
picture_url: %r{packs(-test)?/media/images/profile-.*\.svg},
membership_verify_url: nil,
roles: [
Expand Down
10 changes: 10 additions & 0 deletions spec/domain/oidc_claim_setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@
it "is blank when no matching number exists" do
expect(claims[:membership_years]).to eq 0
end

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

it "membership_verify_url is present" do
travel_to(Time.zone.local(2024, 12, 1)) do
expect(claims[:membership_years]).to eq 9
end
end
end
end

it_behaves_like "shared claims"
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/oauth_profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def make_request(skip_checks: true)
zip_code: user.zip_code,
town: user.town,
country: user.country,
picture_url: /\/packs(-test)?\/media\/images\/profile-.*\.svg/,
picture_url: %r{packs(-test)?/media/images/profile-.*\.svg},
membership_verify_url: "http://localhost:3000/verify_membership/aSuperSweetToken42",
phone: nil
}.deep_stringify_keys)
Expand Down Expand Up @@ -82,7 +82,7 @@ def make_request(skip_checks: true)
picture_url: "http://www.example.com/packs-test/media/images/profile-c150952c7e2ec2cf298980d55b2bcde3.svg",
membership_verify_url: "http://localhost:3000/verify_membership/aSuperSweetToken42",
phone: nil,
membership_years: (Date.current.year - 2015.to_f).to_s,
membership_years: (Date.current.year - 2015.to_f).to_i,
roles: [{
group_id: user.roles.first.group_id,
group_name: user.roles.first.group.name,
Expand Down
6 changes: 4 additions & 2 deletions spec/resources/person/reads_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@

it "can be requested" do
params[:extra_fields] = {people: "membership_years"}
render
travel_to(Date.new(2024, 12, 3)) do
render
end
expect(attributes.keys).to include :membership_years
expect(attributes[:membership_years]).not_to be_blank
expect(attributes[:membership_years]).to eq 9
end

context "without membership" do
Expand Down

0 comments on commit 6970c49

Please sign in to comment.