Skip to content

Commit

Permalink
Move permissions_for to PermissionsHelper
Browse files Browse the repository at this point in the history
In preparation for using this helper in the /account pages.

There's nothing specific to batch invitations in this method and moving
it won't break any existing functionality because we currently include
all helpers into every view.
  • Loading branch information
chrisroos committed Sep 26, 2023
1 parent 9b768e7 commit ec76d40
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 32 deletions.
7 changes: 0 additions & 7 deletions app/helpers/batch_invitation_permissions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,4 @@ def formatted_permission_name(application_name, permission_name)
permission_name
end
end

def permissions_for(application)
all_permissions = application.supported_permissions.grantable_from_ui
signin, others = all_permissions.partition(&:signin?)

signin + others.sort_by(&:name)
end
end
8 changes: 8 additions & 0 deletions app/helpers/permissions_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module PermissionsHelper
def permissions_for(application)
all_permissions = application.supported_permissions.grantable_from_ui
signin, others = all_permissions.partition(&:signin?)

signin + others.sort_by(&:name)
end
end
25 changes: 0 additions & 25 deletions test/helpers/batch_invitation_permissions_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,4 @@ class BatchInvitationPermissionsHelperTest < ActionView::TestCase
assert_equal "Has access to Whitehall?", formatted_permission_name("Whitehall", SupportedPermission::SIGNIN_NAME)
end
end

context "#permissions_for" do
should "return all of the supported permissions that are grantable from the ui" do
application = create(:application,
name: "Whitehall",
with_supported_permissions: ["Editor", SupportedPermission::SIGNIN_NAME],
with_supported_permissions_not_grantable_from_ui: ["Not grantable"])

permission_names = permissions_for(application).map(&:name)

assert permission_names.include?("Editor")
assert permission_names.include?(SupportedPermission::SIGNIN_NAME)
assert_not permission_names.include?("Not grantable")
end

should "sort the permissions alphabetically by name, but with the signin permission first" do
application = create(:application,
name: "Whitehall",
with_supported_permissions: ["Writer", "Editor", SupportedPermission::SIGNIN_NAME])

permission_names = permissions_for(application).map(&:name)

assert_equal [SupportedPermission::SIGNIN_NAME, "Editor", "Writer"], permission_names
end
end
end
28 changes: 28 additions & 0 deletions test/helpers/permissions_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require "test_helper"

class PermissionsHelperTest < ActionView::TestCase
context "#permissions_for" do
should "return all of the supported permissions that are grantable from the ui" do
application = create(:application,
name: "Whitehall",
with_supported_permissions: ["Editor", SupportedPermission::SIGNIN_NAME],
with_supported_permissions_not_grantable_from_ui: ["Not grantable"])

permission_names = permissions_for(application).map(&:name)

assert permission_names.include?("Editor")
assert permission_names.include?(SupportedPermission::SIGNIN_NAME)
assert_not permission_names.include?("Not grantable")
end

should "sort the permissions alphabetically by name, but with the signin permission first" do
application = create(:application,
name: "Whitehall",
with_supported_permissions: ["Writer", "Editor", SupportedPermission::SIGNIN_NAME])

permission_names = permissions_for(application).map(&:name)

assert_equal [SupportedPermission::SIGNIN_NAME, "Editor", "Writer"], permission_names
end
end
end

0 comments on commit ec76d40

Please sign in to comment.