Skip to content

Commit

Permalink
Link to edit the permissions for a batch when they're not present
Browse files Browse the repository at this point in the history
This allows a user to complete an unfinished batch (i.e. one where the
user has uploaded a CSV file but not selected any permissions).
  • Loading branch information
chrislo committed Sep 11, 2023
1 parent ee13536 commit c7ea253
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/helpers/batch_invitations_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
module BatchInvitationsHelper
def batch_invite_status_link(batch_invitation, &block)
if !batch_invitation.has_permissions?
link_to(new_batch_invitation_permissions_path(batch_invitation), alt: "Edit this batch's permissions", &block)
else
link_to(batch_invitation_path(batch_invitation), alt: "View this batch", &block)
end
end

def batch_invite_status_message(batch_invitation)
if batch_invitation.in_progress?
"In progress. " \
Expand Down
2 changes: 1 addition & 1 deletion app/views/batch_invitations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<% recent_batch_invitations.each do |batch_invitation| %>
<tr>
<td>
<%= link_to(batch_invitation_path(batch_invitation), alt: "View this batch") do %>
<%= batch_invite_status_link(batch_invitation) do %>
<%= batch_invitation.batch_invitation_users.count %> users by <%= batch_invitation.user.name %> at <%= batch_invitation.created_at.to_fs(:govuk_date) %>
<% end %>
</td>
Expand Down
14 changes: 14 additions & 0 deletions test/helpers/batch_invitations_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,18 @@ class BatchInvitationsHelperTest < ActionView::TestCase
end
end
end

context "#batch_invite_status_link" do
should "link to show the batch when it has permissions" do
batch_invitation = create(:batch_invitation, :has_permissions, outcome: "success")

assert_includes batch_invite_status_link(batch_invitation) {}, batch_invitation_path(batch_invitation)
end

should "link to show edit the permissions when it has no permissions" do
batch_invitation = create(:batch_invitation)

assert_includes batch_invite_status_link(batch_invitation) {}, new_batch_invitation_permissions_path(batch_invitation)
end
end
end

0 comments on commit c7ea253

Please sign in to comment.