-
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.
Add top-level UserApplicationPermissionPolicy
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
class UserApplicationPermissionPolicy < BasePolicy | ||
def index? | ||
Pundit.policy(current_user, user).edit? | ||
end | ||
|
||
def remove_signin_permission? | ||
user.has_access_to?(application) && | ||
( | ||
current_user.govuk_admin? || | ||
current_user.publishing_manager? && application.signin_permission.delegatable? | ||
) | ||
end | ||
|
||
def edit_permissions? | ||
remove_signin_permission? | ||
end | ||
|
||
def view_permissions? | ||
Pundit.policy(current_user, user).edit? && | ||
user.has_access_to?(application) | ||
end | ||
|
||
def delete? | ||
edit_permissions? | ||
end | ||
|
||
def destroy? | ||
delete? | ||
end | ||
|
||
def show? | ||
view_permissions? | ||
end | ||
|
||
def edit? | ||
edit_permissions? | ||
end | ||
|
||
def update? | ||
edit_permissions? | ||
end | ||
|
||
private | ||
|
||
def user | ||
record.user | ||
end | ||
|
||
def application | ||
record.application | ||
end | ||
end |