use token in ability checks
This commit is contained in:
parent
b16aa11f65
commit
6da3ece683
3 changed files with 18 additions and 1 deletions
|
@ -473,6 +473,10 @@ class ApplicationController < ActionController::Base
|
||||||
# ...
|
# ...
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def current_ability
|
||||||
|
@current_ability ||= Ability.new(current_user, current_token)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# extract authorisation credentials from headers, returns user = nil if none
|
# extract authorisation credentials from headers, returns user = nil if none
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Ability
|
class Ability
|
||||||
include CanCan::Ability
|
include CanCan::Ability
|
||||||
|
|
||||||
def initialize(user)
|
def initialize(user, token)
|
||||||
can :index, :site
|
can :index, :site
|
||||||
can [:permalink, :edit, :help, :fixthemap, :offline, :export, :about, :preview, :copyright, :key, :id, :welcome], :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:
|
# See the wiki for details:
|
||||||
# https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
|
# https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_capability?(token, cap)
|
||||||
|
token && token.read_attribute(cap)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
7
test/models/abilities_test.rb
Normal file
7
test/models/abilities_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class AbilityTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue