Handles default expires_at date directly into DeployToken model
This commit is contained in:
parent
8c27658043
commit
18a1569319
6 changed files with 17 additions and 7 deletions
|
@ -11,10 +11,10 @@ module DeployTokensHelper
|
|||
end
|
||||
|
||||
def expires_at_value(expires_at)
|
||||
expires_at unless expires_at >= DeployToken::FUTURE_DATE
|
||||
expires_at unless expires_at >= DeployToken::FOREVER
|
||||
end
|
||||
|
||||
def show_expire_at?(token)
|
||||
token.expires? && token.expires_at != DeployToken::FUTURE_DATE
|
||||
token.expires? && token.expires_at != DeployToken::FOREVER
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,9 @@ class DeployToken < ActiveRecord::Base
|
|||
add_authentication_token_field :token
|
||||
|
||||
AVAILABLE_SCOPES = %i(read_repository read_registry).freeze
|
||||
FUTURE_DATE = Date.new(3000 - 01 - 01)
|
||||
FOREVER = DateTime.new(3000, 1, 1)
|
||||
|
||||
default_value_for :expires_at, FOREVER
|
||||
|
||||
has_many :project_deploy_tokens, inverse_of: :deploy_token
|
||||
has_many :projects, through: :project_deploy_tokens
|
||||
|
|
|
@ -16,7 +16,7 @@ module DeployTokens
|
|||
end
|
||||
|
||||
def default_expires_at
|
||||
DeployToken::FUTURE_DATE
|
||||
DeployToken::FOREVER
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ class CreateDeployTokens < ActiveRecord::Migration
|
|||
t.boolean :read_repository, null: false, default: false
|
||||
t.boolean :read_registry, null: false, default: false
|
||||
|
||||
t.datetime_with_timezone :expires_at, null: false, default: '3000-01-01'
|
||||
t.datetime_with_timezone :expires_at, null: false
|
||||
t.datetime_with_timezone :created_at, null: false
|
||||
|
||||
t.string :name, null: false
|
||||
|
|
|
@ -687,7 +687,7 @@ ActiveRecord::Schema.define(version: 20180405142733) do
|
|||
t.boolean "revoked", default: false
|
||||
t.boolean "read_repository", default: false, null: false
|
||||
t.boolean "read_registry", default: false, null: false
|
||||
t.datetime_with_timezone "expires_at", default: '3000-01-01 00:00:00', null: false
|
||||
t.datetime_with_timezone "expires_at", null: false
|
||||
t.datetime_with_timezone "created_at", null: false
|
||||
t.string "name", null: false
|
||||
t.string "token", null: false
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe DeployTokens::CreateService, :clean_gitlab_redis_shared_state do
|
||||
describe DeployTokens::CreateService do
|
||||
let(:project) { create(:project) }
|
||||
let(:user) { create(:user) }
|
||||
let(:deploy_token_params) { attributes_for(:deploy_token) }
|
||||
|
@ -22,6 +22,14 @@ describe DeployTokens::CreateService, :clean_gitlab_redis_shared_state do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when expires at date is not passed' do
|
||||
let(:deploy_token_params) { attributes_for(:deploy_token, expires_at: '') }
|
||||
|
||||
it 'should set FOREVER date' do
|
||||
expect(subject.expires_at).to eq(DeployToken::FOREVER)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the deploy token is invalid' do
|
||||
let(:deploy_token_params) { attributes_for(:deploy_token, read_repository: false, read_registry: false) }
|
||||
|
||||
|
|
Loading…
Reference in a new issue