Skip to content

Commit

Permalink
Add api_editor role ability to see and update api keys
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandauer committed Sep 10, 2024
1 parent abfcbb6 commit c33b9c9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ApplicationController < Administrate::ApplicationController
sig { void }
def authenticate_admin
authenticate_user!
render plain: "Not authorised", status: :forbidden unless T.must(current_user).has_role?(:admin)
render plain: "Not authorised", status: :forbidden unless T.must(current_user).has_role?(:admin) || T.must(current_user).has_role?(:api_editor)
end

sig { returns(T::Array[Symbol]) }
Expand Down
10 changes: 5 additions & 5 deletions app/policies/admin/api_key_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ class ApiKeyPolicy < ApplicationPolicy

sig { returns(T::Boolean) }
def index?
user.has_role?(:admin)
user.has_role?(:admin) || user.has_role?(:api_editor)
end

sig { returns(T::Boolean) }
def show?
user.has_role?(:admin)
user.has_role?(:admin) || user.has_role?(:api_editor)
end

sig { returns(T::Boolean) }
def update?
user.has_role?(:admin)
user.has_role?(:admin) || user.has_role?(:api_editor)
end

sig { returns(T::Boolean) }
def create?
user.has_role?(:admin)
user.has_role?(:admin) || user.has_role?(:api_editor)
end

class Scope < ApplicationPolicy::Scope
sig { returns(ActiveRecord::Relation) }
def resolve
user.has_role?(:admin) ? scope.all : scope.none
user.has_role?(:admin) || user.has_role?(:api_editor) ? scope.all : scope.none
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/policies/admin/api_usages_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ApiUsagesPolicy < ApplicationPolicy

sig { returns(T::Boolean) }
def index?
user.has_role?(:admin)
user.has_role?(:admin) || user.has_role?(:api_editor)
end
end
end
6 changes: 3 additions & 3 deletions app/policies/admin/user_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class UserPolicy < ApplicationPolicy
# TODO: Extract this into a DefaultAdminPolicy
sig { returns(T::Boolean) }
def index?
user.has_role?(:admin)
user.has_role?(:admin) || user.has_role?(:api_editor)
end

sig { returns(T::Boolean) }
def show?
user.has_role?(:admin)
user.has_role?(:admin) || user.has_role?(:api_editor)
end

sig { returns(T::Boolean) }
Expand All @@ -29,7 +29,7 @@ def destroy?
class Scope < ApplicationPolicy::Scope
sig { returns(ActiveRecord::Relation) }
def resolve
user.has_role?(:admin) ? scope.all : scope.none
user.has_role?(:admin) || user.has_role?(:api_editor) ? scope.all : scope.none
end
end
end
Expand Down

0 comments on commit c33b9c9

Please sign in to comment.