X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/91fc65a2e3ad47414344a6d5dc03cb5fb2a08ce1..25256a484914ee40d829d9184fb4107dd0a77d44:/app/models/capability.rb?ds=sidebyside diff --git a/app/models/capability.rb b/app/models/capability.rb index 174687503..db2d71711 100644 --- a/app/models/capability.rb +++ b/app/models/capability.rb @@ -5,15 +5,17 @@ class Capability def initialize(user, token) if user - can [:read, :read_one], UserPreference if has_capability?(token, :allow_read_prefs) - can [:update, :update_one, :delete_one], UserPreference if has_capability?(token, :allow_write_prefs) + can [:read, :read_one], UserPreference if capability?(token, :allow_read_prefs) + can [:update, :update_one, :delete_one], UserPreference if capability?(token, :allow_write_prefs) end end + private + # If a user provides no tokens, they've authenticated via a non-oauth method # and permission to access to all capabilities is assumed. - def has_capability?(token, cap) + def capability?(token, cap) token.nil? || token.read_attribute(cap) end end