diff --git a/app/helpers/batch_invitations_helper.rb b/app/helpers/batch_invitations_helper.rb
index 90cfd7c3b..30778c38a 100644
--- a/app/helpers/batch_invitations_helper.rb
+++ b/app/helpers/batch_invitations_helper.rb
@@ -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. " \
diff --git a/app/views/batch_invitations/new.html.erb b/app/views/batch_invitations/new.html.erb
index 59da3281c..6efdc0db3 100644
--- a/app/views/batch_invitations/new.html.erb
+++ b/app/views/batch_invitations/new.html.erb
@@ -17,7 +17,7 @@
<% recent_batch_invitations.each do |batch_invitation| %>
- <%= 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 %>
|
diff --git a/test/helpers/batch_invitations_helper_test.rb b/test/helpers/batch_invitations_helper_test.rb
index f7190cde5..9c9b5b132 100644
--- a/test/helpers/batch_invitations_helper_test.rb
+++ b/test/helpers/batch_invitations_helper_test.rb
@@ -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