-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2370 from alphagov/allow-publishing-managers-to-m…
…anage-their-apps Allow Publishing Managers to manage their apps
- Loading branch information
Showing
13 changed files
with
258 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Account::ApplicationPolicy < BasePolicy | ||
def index? | ||
current_user.govuk_admin? || current_user.publishing_manager? | ||
end | ||
|
||
alias_method :show?, :index? | ||
alias_method :view_permissions?, :index? | ||
|
||
def grant_signin_permission? | ||
current_user.govuk_admin? | ||
end | ||
|
||
def remove_signin_permission? | ||
current_user.has_access_to?(record) && | ||
( | ||
current_user.govuk_admin? || | ||
current_user.publishing_manager? && record.signin_permission.delegatable? | ||
) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
require "test_helper" | ||
require "support/policy_helpers" | ||
|
||
class Account::ApplicationPolicyTest < ActiveSupport::TestCase | ||
include PolicyHelpers | ||
|
||
context "accessing index?" do | ||
%i[superadmin admin super_organisation_admin organisation_admin].each do |user_role| | ||
context "for #{user_role} users" do | ||
setup do | ||
@current_user = FactoryBot.build(:"#{user_role}_user") | ||
end | ||
|
||
should "be permitted" do | ||
assert permit?(@current_user, nil, :index) | ||
end | ||
end | ||
end | ||
|
||
%i[normal].each do |user_role| | ||
context "for #{user_role} users" do | ||
setup do | ||
@current_user = FactoryBot.build(:"#{user_role}_user") | ||
end | ||
|
||
should "be forbidden" do | ||
assert forbid?(@current_user, nil, :index) | ||
end | ||
end | ||
end | ||
end | ||
|
||
context "show?" do | ||
%i[superadmin admin super_organisation_admin organisation_admin].each do |user_role| | ||
context "for #{user_role} users" do | ||
setup do | ||
@current_user = build(:"#{user_role}_user") | ||
end | ||
|
||
should "be permitted" do | ||
assert permit?(@current_user, nil, :show) | ||
end | ||
end | ||
end | ||
|
||
%i[normal].each do |user_role| | ||
context "for #{user_role} users" do | ||
setup do | ||
@current_user = build(:"#{user_role}_user") | ||
end | ||
|
||
should "be forbidden" do | ||
assert forbid?(@current_user, nil, :show) | ||
end | ||
end | ||
end | ||
end | ||
|
||
context "#grant_signin_permission?" do | ||
%i[superadmin admin].each do |user_role| | ||
context "for #{user_role} users" do | ||
setup do | ||
@current_user = build(:"#{user_role}_user") | ||
end | ||
|
||
should "be permitted" do | ||
assert permit?(@current_user, nil, :grant_signin_permission) | ||
end | ||
end | ||
end | ||
|
||
%i[super_organisation_admin organisation_admin normal].each do |user_role| | ||
context "for #{user_role} users" do | ||
setup do | ||
@current_user = build(:"#{user_role}_user") | ||
end | ||
|
||
should "be forbidden" do | ||
assert forbid?(@current_user, nil, :grant_signin_permission) | ||
end | ||
end | ||
end | ||
end | ||
|
||
context "#remove_signin_permission?" do | ||
%i[superadmin admin].each do |user_role| | ||
context "for #{user_role} users" do | ||
setup do | ||
@current_user = create(:"#{user_role}_user") | ||
@application = create(:application) | ||
end | ||
|
||
context "when the user has signin permission for the app" do | ||
setup do | ||
@current_user.grant_application_signin_permission(@application) | ||
end | ||
|
||
should "be permitted" do | ||
assert permit?(@current_user, @application, :remove_signin_permission) | ||
end | ||
end | ||
|
||
context "when the user does not have the signin permission for the app" do | ||
should "be forbidden" do | ||
assert forbid?(@current_user, @application, :remove_signin_permission) | ||
end | ||
end | ||
end | ||
end | ||
|
||
%i[super_organisation_admin organisation_admin].each do |user_role| | ||
context "for #{user_role} users" do | ||
setup do | ||
@current_user = create(:"#{user_role}_user") | ||
@application = create(:application) | ||
end | ||
|
||
context "when the user has signin permission for the app" do | ||
setup do | ||
@current_user.grant_application_signin_permission(@application) | ||
end | ||
|
||
context "and the application has delegatable permissions" do | ||
setup do | ||
@application.signin_permission.update!(delegatable: true) | ||
end | ||
|
||
should "be permitted" do | ||
assert permit?(@current_user, @application, :remove_signin_permission) | ||
end | ||
end | ||
|
||
context "and the application does not have delegatable permissions" do | ||
setup do | ||
@application.signin_permission.update!(delegatable: false) | ||
end | ||
|
||
should "not be permitted" do | ||
assert forbid?(@current_user, @application, :remove_signin_permission) | ||
end | ||
end | ||
end | ||
|
||
context "when the user does not have the signin permission for the app" do | ||
should "be forbidden" do | ||
assert forbid?(@current_user, @application, :remove_signin_permission) | ||
end | ||
end | ||
end | ||
end | ||
|
||
%i[normal].each do |user_role| | ||
context "for #{user_role} users" do | ||
setup do | ||
@current_user = build(:"#{user_role}_user") | ||
end | ||
|
||
should "be forbidden" do | ||
assert forbid?(@current_user, nil, :remove_signin_permission) | ||
end | ||
end | ||
end | ||
end | ||
|
||
context "#view_permissions?" do | ||
%i[superadmin admin super_organisation_admin organisation_admin].each do |user_role| | ||
context "for #{user_role} users" do | ||
setup do | ||
@current_user = build(:"#{user_role}_user") | ||
end | ||
|
||
should "be permitted" do | ||
assert permit?(@current_user, nil, :view_permissions) | ||
end | ||
end | ||
end | ||
|
||
%i[normal].each do |user_role| | ||
context "for #{user_role} users" do | ||
setup do | ||
@current_user = build(:"#{user_role}_user") | ||
end | ||
|
||
should "be forbidden" do | ||
assert forbid?(@current_user, nil, :view_permissions) | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.