diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /app/models/personal_access_token.rb | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'app/models/personal_access_token.rb')
-rw-r--r-- | app/models/personal_access_token.rb | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/app/models/personal_access_token.rb b/app/models/personal_access_token.rb index af079f7ebc4..7afee2a35cb 100644 --- a/app/models/personal_access_token.rb +++ b/app/models/personal_access_token.rb @@ -4,6 +4,7 @@ class PersonalAccessToken < ApplicationRecord include Expirable include TokenAuthenticatable include Sortable + extend ::Gitlab::Utils::Override add_authentication_token_field :token, digest: true @@ -23,6 +24,8 @@ class PersonalAccessToken < ApplicationRecord scope :without_impersonation, -> { where(impersonation: false) } scope :for_user, -> (user) { where(user: user) } scope :preload_users, -> { preload(:user) } + scope :order_expires_at_asc, -> { reorder(expires_at: :asc) } + scope :order_expires_at_desc, -> { reorder(expires_at: :desc) } validates :scopes, presence: true validate :validate_scopes @@ -39,12 +42,14 @@ class PersonalAccessToken < ApplicationRecord def self.redis_getdel(user_id) Gitlab::Redis::SharedState.with do |redis| - encrypted_token = redis.get(redis_shared_state_key(user_id)) - redis.del(redis_shared_state_key(user_id)) + redis_key = redis_shared_state_key(user_id) + encrypted_token = redis.get(redis_key) + redis.del(redis_key) + begin Gitlab::CryptoHelper.aes256_gcm_decrypt(encrypted_token) rescue => ex - logger.warn "Failed to decrypt PersonalAccessToken value stored in Redis for User ##{user_id}: #{ex.class}" + logger.warn "Failed to decrypt #{self.name} value stored in Redis for key ##{redis_key}: #{ex.class}" encrypted_token end end @@ -58,6 +63,16 @@ class PersonalAccessToken < ApplicationRecord end end + override :simple_sorts + def self.simple_sorts + super.merge( + { + 'expires_at_asc' => -> { order_expires_at_asc }, + 'expires_at_desc' => -> { order_expires_at_desc } + } + ) + end + protected def validate_scopes |