]> git.openstreetmap.org Git - rails.git/blob - app/abilities/capability.rb
Pluralize old_ controllers
[rails.git] / app / abilities / 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