X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/998f990baafdd07501d801d063c7ed6b21feec6a..e8d73e8066b61f7704dc0f6cf200953cdf9a5e60:/services/api/app/models/api_client_authorization.rb diff --git a/services/api/app/models/api_client_authorization.rb b/services/api/app/models/api_client_authorization.rb index 6b308a231c..4218645d5d 100644 --- a/services/api/app/models/api_client_authorization.rb +++ b/services/api/app/models/api_client_authorization.rb @@ -13,6 +13,8 @@ class ApiClientAuthorization < ArvadosModel after_initialize :assign_random_api_token serialize :scopes, Array + before_validation :clamp_token_expiration + api_accessible :user, extend: :common do |t| t.add :owner_uuid t.add :user_id @@ -384,6 +386,17 @@ class ApiClientAuthorization < ArvadosModel protected + def clamp_token_expiration + if !current_user.andand.is_admin && Rails.configuration.API.MaxTokenLifetime > 0 + max_token_expiration = Time.now + Rails.configuration.API.MaxTokenLifetime + if self.new_record? && (self.expires_at.nil? || self.expires_at > max_token_expiration) + self.expires_at = max_token_expiration + elsif !self.new_record? && self.expires_at_changed? && (self.expires_at.nil? || self.expires_at > max_token_expiration) + self.expires_at = max_token_expiration + end + end + end + def permission_to_create current_user.andand.is_admin or (current_user.andand.id == self.user_id) end @@ -394,7 +407,6 @@ class ApiClientAuthorization < ArvadosModel end def log_update - super unless (saved_changes.keys - UNLOGGED_CHANGES).empty? end end