]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/ability.rb
use token in ability checks
[rails.git] / app / models / ability.rb
index 864225e8e83a151e737a8246a4d610c2723fae4b..897316691328fc8d673ace7001cbda2f73aa3473 100644 (file)
@@ -1,7 +1,9 @@
+# frozen_string_literal: true
+
 class Ability
   include CanCan::Ability
 
-  def initialize(user)
+  def initialize(user, token)
     can :index, :site
     can [:permalink, :edit, :help, :fixthemap, :offline, :export, :about, :preview, :copyright, :key, :id, :welcome], :site
 
@@ -35,4 +37,8 @@ class Ability
     # See the wiki for details:
     # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
   end
+
+  def has_capability?(token, cap)
+    token && token.read_attribute(cap)
+  end
 end