]> git.openstreetmap.org Git - rails.git/blob - app/models/capability.rb
2a5c927748bbdb969b6d37e376a099374085bed4
[rails.git] / app / models / capability.rb
1 # frozen_string_literal: true
2
3 class Capability
4   include CanCan::Ability
5
6   def initialize(token)
7     can [:read, :read_one], UserPreference if capability?(token, :allow_read_prefs)
8     can [:update, :update_one, :delete_one], UserPreference if capability?(token, :allow_write_prefs)
9   end
10
11   private
12
13   def capability?(token, cap)
14     token&.read_attribute(cap)
15   end
16 end