Skip to content

Commit

Permalink
Ignore legacy api key scope columns in preparation for removal
Browse files Browse the repository at this point in the history
To deploy after #4676 has been deployed & we are confident we will not need to rollback
  • Loading branch information
segiddins committed May 8, 2024
1 parent a2d46d5 commit cb8fe4f
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions app/models/api_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class ApiKey < ApplicationRecord
APPLICABLE_GEM_API_SCOPES = %i[push_rubygem yank_rubygem add_owner remove_owner].freeze
EXCLUSIVE_SCOPES = %i[show_dashboard].freeze

self.ignored_columns += API_SCOPES

belongs_to :owner, polymorphic: true

has_one :api_key_rubygem_scope, dependent: :destroy
Expand All @@ -11,7 +13,6 @@ class ApiKey < ApplicationRecord
has_one :oidc_api_key_role, class_name: "OIDC::ApiKeyRole", 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_legacy_scope_columns
before_validation :set_owner_from_user
after_create :record_create_event
after_update :record_expire_event, if: :saved_change_to_expires_at?
Expand Down Expand Up @@ -46,6 +47,7 @@ def self.expire_all!
return scope_enabled if !scope_enabled || new_record?
touch :last_accessed_at
end
alias_method scope, :"can_#{scope}?"
end

def scopes
Expand Down Expand Up @@ -148,13 +150,6 @@ def set_owner_from_user
self.owner ||= user
end

def set_legacy_scope_columns
scopes = self.scopes
API_SCOPES.each do |scope|
self[scope] = scopes.include?(scope)
end
end

def record_create_event
case owner
when User
Expand Down

0 comments on commit cb8fe4f

Please sign in to comment.