Skip to content

Commit

Permalink
WIP Add Users::PermissionsController#edit
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Roos <[email protected]>
  • Loading branch information
chrislo and chrisroos committed Nov 30, 2023
1 parent 22a17b9 commit 55f91f0
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/controllers/users/permissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def show
.sort_by { |permission| @user.has_permission?(permission) ? 0 : 1 }
end

def edit
# authorize [:account, @application], :edit_permissions?
# @permissions = @application.sorted_supported_permissions_grantable_from_ui(include_signin: false)
end

def update
user = User.find(params[:user_id])
signin_permission = user.application_permissions.find_by!(supported_permission: @application.signin_permission)
Expand Down
43 changes: 43 additions & 0 deletions app/views/users/permissions/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<% content_for :title_caption, "Manage other users" %>
<% content_for :title, "Update #{@user.name}'s permissions for #{@application.name}" %>

<% content_for :breadcrumbs,
render("govuk_publishing_components/components/breadcrumbs", {
collapse_on_mobile: true,
breadcrumbs: [
{
title: "Dashboard",
url: root_path,
},
{
title: "Users",
url: users_path,
},
{
title: @user.name,
url: edit_user_path(@user),
},
{
title: "Update #{@user.name}'s permissions for #{@application.name}",
}
]
})
%>

<%= form_tag user_application_permissions_path(@user, @application), method: :patch do |f| %>
<%= render "govuk_publishing_components/components/checkboxes", {
name: "application[supported_permission_ids][]",
heading: "Permissions",
items: @permissions.map { |permission| { label: permission.name, value: permission.id, checked: @user.has_permission?(permission) } },
} %>

<%= hidden_field_tag "application[supported_permission_ids][]", @application.signin_permission.id, id: "checkboxes-signin" %>

<div class="govuk-button-group">
<%= render "govuk_publishing_components/components/button", {
text: "Update permissions"
} %>

<%= link_to "Cancel", edit_user_path(@user), class: "govuk-link govuk-link--no-visited-state" %>
</div>
<% end %>
25 changes: 25 additions & 0 deletions test/controllers/users/permissions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,31 @@ class Users::PermissionsControllerTest < ActionController::TestCase
end
end

context "#edit" do
should "prevent unauthenticated users" do
application = create(:application)
user = create(:user)

get :edit, params: { user_id: user, application_id: application.id }

assert_redirected_to "/users/sign_in"
end

should "prevent unauthorized users" do
application = create(:application)
user = create(:user)

current_user = create(:admin_user)
sign_in current_user

stub_policy current_user, signin_permission, edit?: false

get :edit, params: { user_id: user, application_id: application.id }

assert_not_authorised
end
end

context "#update" do
should "prevent unauthenticated users" do
application = create(:application)
Expand Down

0 comments on commit 55f91f0

Please sign in to comment.