diff options
author | Mayra Cabrera <mcabrera@gitlab.com> | 2018-04-06 22:48:17 +0300 |
---|---|---|
committer | Mayra Cabrera <mcabrera@gitlab.com> | 2018-04-07 06:28:44 +0300 |
commit | 5bc58bac2678aed9c8b2318f9f4d4825baa2b110 (patch) | |
tree | f35313fd689afa287f6c93a3d78ce8a0d61cc71c /app/models/deploy_token.rb | |
parent | d6450717abefbe4dbf891cb4d285f6c84e44f168 (diff) |
Handle limit for datetime attributes on MySQL
The TIMESTAMP data type is used for values that contain both date and
time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to
'2038-01-19 03:14:07' UTC.
A Forever lib class was included to handle future dates for PostgreSQL
and MySQL, also changes were made to DeployToken to enforce Forever.date
Also removes extra conditional from JwtController
Diffstat (limited to 'app/models/deploy_token.rb')
-rw-r--r-- | app/models/deploy_token.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/app/models/deploy_token.rb b/app/models/deploy_token.rb index bfdc5457157..fe726b156d4 100644 --- a/app/models/deploy_token.rb +++ b/app/models/deploy_token.rb @@ -4,9 +4,8 @@ class DeployToken < ActiveRecord::Base add_authentication_token_field :token AVAILABLE_SCOPES = %i(read_repository read_registry).freeze - FOREVER = DateTime.new(3000, 1, 1) - default_value_for :expires_at, FOREVER + default_value_for(:expires_at) { Forever.date } has_many :project_deploy_tokens, inverse_of: :deploy_token has_many :projects, through: :project_deploy_tokens @@ -45,6 +44,15 @@ class DeployToken < ActiveRecord::Base projects.first end + def expires_at + expires_at = read_attribute(:expires_at) + expires_at != Forever.date ? expires_at : nil + end + + def expires_at=(value) + write_attribute(:expires_at, value.presence || Forever.date) + end + private def ensure_at_least_one_scope |