From 9f2e4742e354f5548b4956060f1bfa5ee3bd6657 Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Thu, 23 Feb 2017 17:47:06 +0000 Subject: applies relevant changes to the code and code structure --- app/models/personal_access_token.rb | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'app/models/personal_access_token.rb') diff --git a/app/models/personal_access_token.rb b/app/models/personal_access_token.rb index cf94b01c33e..676e0832d54 100644 --- a/app/models/personal_access_token.rb +++ b/app/models/personal_access_token.rb @@ -7,20 +7,13 @@ class PersonalAccessToken < ActiveRecord::Base belongs_to :user + before_save :ensure_token + default_scope { where(impersonation: false) } scope :active, -> { where(revoked: false).where("expires_at >= NOW() OR expires_at IS NULL") } scope :inactive, -> { where("revoked = true OR expires_at < NOW()") } - scope :impersonation, -> { where(impersonation: true) } - - class << self - alias_method :and_impersonation_tokens, :unscoped - - def generate(params) - personal_access_token = self.new(params) - personal_access_token.ensure_token - personal_access_token - end - end + scope :impersonation, -> { unscoped.where(impersonation: true) } + scope :with_impersonation_tokens, -> { unscoped } def revoke! self.revoked = true -- cgit v1.2.1