Skip to content

Commit

Permalink
Move AccountApplicationsPolicy -> Account::ApplicationPolicy
Browse files Browse the repository at this point in the history
TODO: Fold this into the relevant commits in this branch
  • Loading branch information
chrisroos committed Sep 21, 2023
1 parent 267beca commit dbcaa9a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/controllers/account/applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ class Account::ApplicationsController < ApplicationController
before_action :authenticate_user!

def show
authorize :account_applications
authorize [:account, Doorkeeper::Application]

redirect_to account_applications_path
end

def index
authorize :account_applications
authorize [:account, Doorkeeper::Application]

@applications_with_signin = Doorkeeper::Application.can_signin(current_user)
@applications_without_signin = Doorkeeper::Application.not_retired.without_signin_permission_for(current_user)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/account/permissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class Account::PermissionsController < ApplicationController
def index
@application = Doorkeeper::Application.not_retired.find(params[:application_id])

authorize @application, :view_permissions?, policy_class: AccountApplicationsPolicy
authorize [:account, @application], :view_permissions?
end
end
9 changes: 5 additions & 4 deletions app/controllers/account/signin_permissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@ class Account::SigninPermissionsController < ApplicationController
before_action :authenticate_user!

def create
authorize :account_applications, :grant_signin_permission?

application = Doorkeeper::Application.not_retired.find(params[:application_id])

authorize [:account, application], :grant_signin_permission?

current_user.grant_application_signin_permission(application)
redirect_to account_applications_path
end

def delete
@application = Doorkeeper::Application.not_retired.find(params[:application_id])

authorize @application, :remove_signin_permission?, policy_class: AccountApplicationsPolicy
authorize [:account, @application], :remove_signin_permission?
end

def destroy
application = Doorkeeper::Application.not_retired.find(params[:application_id])

authorize application, :remove_signin_permission?, policy_class: AccountApplicationsPolicy
authorize [:account, application], :remove_signin_permission?

current_user.remove_application_signin_permission(application)
redirect_to account_applications_path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AccountApplicationsPolicy < BasePolicy
class Account::ApplicationPolicy < BasePolicy
def index?
current_user.govuk_admin?
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "test_helper"
require "support/policy_helpers"

class AccountApplicationsPolicyTest < ActiveSupport::TestCase
class Account::ApplicationPolicyTest < ActiveSupport::TestCase
include PolicyHelpers

context "accessing index?" do
Expand Down

0 comments on commit dbcaa9a

Please sign in to comment.