X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/fc100474c5d74b20b2576bd3a8f633746c0c6fb2..c3d4b399c57e711f0cd87c2178f873a688323967:/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 fca57dce8f..5817ff6648 100644 --- a/services/api/app/models/api_client_authorization.rb +++ b/services/api/app/models/api_client_authorization.rb @@ -20,6 +20,8 @@ class ApiClientAuthorization < ArvadosModel t.add :scopes end + UNLOGGED_CHANGES = ['last_used_at', 'last_used_by_ip_address', 'updated_at'] + def assign_random_api_token self.api_token ||= rand(2**256).to_s(36) end @@ -28,7 +30,7 @@ class ApiClientAuthorization < ArvadosModel self.user.andand.uuid end def owner_uuid_was - self.user_id_changed? ? User.find(self.user_id_was).andand.uuid : self.user.andand.uuid + self.user_id_changed? ? User.where(id: self.user_id_was).first.andand.uuid : self.user.andand.uuid end def owner_uuid_changed? self.user_id_changed? @@ -60,6 +62,24 @@ class ApiClientAuthorization < ArvadosModel end def modified_at=(x) end + def scopes_allow?(req_s) + scopes.each do |scope| + return true if (scope == 'all') or (scope == req_s) or + ((scope.end_with? '/') and (req_s.start_with? scope)) + end + false + end + + def scopes_allow_request?(request) + scopes_allow? [request.request_method, request.path].join(' ') + end + + def logged_attributes + attrs = attributes.dup + attrs.delete('api_token') + attrs + end + protected def permission_to_create @@ -71,4 +91,8 @@ class ApiClientAuthorization < ArvadosModel not self.user_id_changed? and not self.owner_uuid_changed?) end + + def log_update + super unless (changed - UNLOGGED_CHANGES).empty? + end end