diff options
author | Mayra Cabrera <mcabrera@gitlab.com> | 2018-04-06 17:30:21 +0300 |
---|---|---|
committer | Mayra Cabrera <mcabrera@gitlab.com> | 2018-04-07 05:20:17 +0300 |
commit | 29913816309c6f6387b20c8702bcc8e90ef3a984 (patch) | |
tree | 6dbd8f3367d423a72c0d058d5e1a29296873c1f6 /app/models | |
parent | ca35c65b026e57307a13f25ebc11f11c978ed697 (diff) |
Addresses database comments
- Adds a default on expires_at datetime
- Modifies deploy tokens views to handle default expires at value
- Use datetime_with_timezone where possible
- Remove unused scopes
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/deploy_token.rb | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/app/models/deploy_token.rb b/app/models/deploy_token.rb index 11add42b2c5..688540dd67f 100644 --- a/app/models/deploy_token.rb +++ b/app/models/deploy_token.rb @@ -4,6 +4,7 @@ class DeployToken < ActiveRecord::Base add_authentication_token_field :token AVAILABLE_SCOPES = %i(read_repository read_registry).freeze + FUTURE_DATE = Date.new(3000 - 01 - 01) has_many :project_deploy_tokens, inverse_of: :deploy_token has_many :projects, through: :project_deploy_tokens @@ -13,9 +14,7 @@ class DeployToken < ActiveRecord::Base accepts_nested_attributes_for :project_deploy_tokens - scope :active, -> { where("revoked = false AND (expires_at >= NOW() OR expires_at IS NULL)") } - scope :read_repository, -> { where(read_repository: true) } - scope :read_registry, -> { where(read_registry: true) } + scope :active, -> { where("revoked = false AND expires_at >= NOW()") } def revoke! update!(revoked: true) @@ -26,7 +25,7 @@ class DeployToken < ActiveRecord::Base end def scopes - AVAILABLE_SCOPES.select { |token_scope| send("#{token_scope}") } # rubocop:disable GitlabSecurity/PublicSend + AVAILABLE_SCOPES.select { |token_scope| read_attribute(token_scope) } end def username @@ -37,6 +36,9 @@ class DeployToken < ActiveRecord::Base project == requested_project end + # This is temporal. Currently we limit DeployToken + # to a single project, later we're going to extend + # that to be for multiple projects and namespaces. def project projects.first end |