diff options
author | Eric Eastwood <contact@ericeastwood.com> | 2017-12-03 22:01:18 -0600 |
---|---|---|
committer | Eric Eastwood <contact@ericeastwood.com> | 2017-12-07 16:22:37 -0600 |
commit | 116d8cfcfbe26f0bb5c6ac49a841f9555b44cf07 (patch) | |
tree | e6483b2318bb2f779813d24a652c0b350d12fd77 /app/models | |
parent | e0f84130567dc34edf1ae75fcf595e24991d2fa9 (diff) | |
download | gitlab-ce-116d8cfcfbe26f0bb5c6ac49a841f9555b44cf07.tar.gz |
Fix new personal access token showing up in a flash message40754-fix-flash-usage-with-personal-access-token
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/personal_access_token.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/app/models/personal_access_token.rb b/app/models/personal_access_token.rb index cfcb03138b7..063dc521324 100644 --- a/app/models/personal_access_token.rb +++ b/app/models/personal_access_token.rb @@ -3,6 +3,8 @@ class PersonalAccessToken < ActiveRecord::Base include TokenAuthenticatable add_authentication_token_field :token + REDIS_EXPIRY_TIME = 3.minutes + serialize :scopes, Array # rubocop:disable Cop/ActiveRecordSerialize belongs_to :user @@ -27,6 +29,21 @@ class PersonalAccessToken < ActiveRecord::Base !revoked? && !expired? end + def self.redis_getdel(user_id) + Gitlab::Redis::SharedState.with do |redis| + token = redis.get(redis_shared_state_key(user_id)) + redis.del(redis_shared_state_key(user_id)) + token + end + end + + def self.redis_store!(user_id, token) + Gitlab::Redis::SharedState.with do |redis| + redis.set(redis_shared_state_key(user_id), token, ex: REDIS_EXPIRY_TIME) + token + end + end + protected def validate_scopes @@ -38,4 +55,8 @@ class PersonalAccessToken < ActiveRecord::Base def set_default_scopes self.scopes = Gitlab::Auth::DEFAULT_SCOPES if self.scopes.empty? end + + def self.redis_shared_state_key(user_id) + "gitlab:personal_access_token:#{user_id}" + end end |