Merge branch 'master' into 2767-doc-updates
[arvados.git] / services / api / app / models / api_client_authorization.rb
index 3b73f408c3f03bf35f48a0711357a0487fdeee8e..82dd0ec2b6177847f72460b87b492950b66a605a 100644 (file)
@@ -62,6 +62,18 @@ 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')