1 # frozen_string_literal: true
4 include CanCan::Ability
6 def initialize(user, token)
8 can [:read, :read_one], UserPreference if capability?(token, :allow_read_prefs)
9 can [:update, :update_one, :delete_one], UserPreference if capability?(token, :allow_write_prefs)
16 # If a user provides no tokens, they've authenticated via a non-oauth method
17 # and permission to access to all capabilities is assumed.
18 def capability?(token, cap)
19 token.nil? || token.read_attribute(cap)