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

Fix api_key_created email when api key belongs to an oidc id token #4233

Merged
merged 1 commit into from
Nov 24, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/api_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ApiKey < ApplicationRecord
has_one :api_key_rubygem_scope, dependent: :destroy
has_one :ownership, through: :api_key_rubygem_scope
has_one :oidc_id_token, class_name: "OIDC::IdToken", dependent: :restrict_with_error
has_one :oidc_api_key_role, through: :oidc_id_token, inverse_of: :api_key
has_one :oidc_api_key_role, through: :oidc_id_token, source: :api_key_role, inverse_of: :api_keys
has_many :pushed_versions, class_name: "Version", inverse_of: :pusher_api_key, foreign_key: :pusher_api_key_id, dependent: :nullify

before_validation :set_owner_from_user
Expand Down
2 changes: 1 addition & 1 deletion app/models/oidc/id_token.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class OIDC::IdToken < ApplicationRecord
belongs_to :api_key_role, class_name: "OIDC::ApiKeyRole", foreign_key: "oidc_api_key_role_id", inverse_of: :id_tokens
belongs_to :api_key_role, class_name: "OIDC::ApiKeyRole", foreign_key: :oidc_api_key_role_id, inverse_of: :id_tokens
belongs_to :api_key, inverse_of: :oidc_id_token
has_one :provider, through: :api_key_role, inverse_of: :id_tokens
has_one :user, through: :api_key_role, inverse_of: :oidc_id_tokens
Expand Down
2 changes: 1 addition & 1 deletion app/views/mailer/api_key_created.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Created at: <strong><%= @api_key.created_at.to_formatted_s(:rfc822) %></strong>
<% if @api_key.oidc_id_token.present? %>
<br>
<%= ApiKey.human_attribute_name(:oidc_api_key_role) %>: <strong><%= link_to(@api_key.oidc_api_key_role.name, profile_oidc_api_key_role_path(@api_key.oidc_api_key_role.token), target: :_blank) %></strong>
<%= ApiKey.human_attribute_name(:oidc_api_key_role) %>: <strong><%= link_to(@api_key.oidc_api_key_role.name, profile_oidc_api_key_role_url(@api_key.oidc_api_key_role.token), target: :_blank) %></strong>
<% end %>
<br>
</p>
Expand Down
5 changes: 5 additions & 0 deletions test/mailers/previews/mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ def api_key_created
Mailer.api_key_created(api_key.id)
end

def api_key_created_oidc_api_key_role
api_key = OIDC::IdToken.last.api_key
Mailer.api_key_created(api_key.id)
end

def api_key_revoked
api_key = ApiKey.last
Mailer.api_key_revoked(api_key.user.id, api_key.name, api_key.enabled_scopes.join(", "), "https://example.com")
Expand Down