Skip to content

Commit

Permalink
allow to permanently remove submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
omohokcoj committed Jul 20, 2024
1 parent cb38549 commit 4bdb249
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
17 changes: 14 additions & 3 deletions app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,22 @@ def create
end

def destroy
@submission.update!(archived_at: Time.current)
notice =
if params[:permanently].present?
@submission.destroy!

SendSubmissionArchivedWebhookRequestJob.perform_async('submission_id' => @submission.id)
Rollbar.info("Remove submission: #{@submission.id}") if defined?(Rollbar)

redirect_back(fallback_location: template_path(@submission.template), notice: 'Submission has been archived')
'Submission has been removed'
else
@submission.update!(archived_at: Time.current)

SendSubmissionArchivedWebhookRequestJob.perform_async('submission_id' => @submission.id)

'Submission has been archived'
end

redirect_back(fallback_location: template_path(@submission.template), notice:)
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/views/submissions_archived/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</div>
<% if @pagy.count > 0 %>
<div class="space-y-4">
<%= render partial: 'templates/submission', collection: @submissions, locals: { with_template: true } %>
<%= render partial: 'templates/submission', collection: @submissions, locals: { with_template: true, archived: true } %>
</div>
<% elsif params[:q].present? %>
<div class="text-center">
Expand Down
5 changes: 5 additions & 0 deletions app/views/templates/_submission.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
<%= button_to button_title(title: nil, disabled_with: 'Arch', icon: svg_icon('archive', class: 'w-6 h-6')), submission_path(submission), class: 'btn btn-outline btn-sm w-full md:w-fit', form: { class: 'flex' }, title: 'Archive', method: :delete, data: { turbo_confirm: 'Are you sure?' }, onclick: 'event.stopPropagation()' %>
</span>
<% end %>
<% if local_assigns[:archived] && can?(:destroy, submission) %>
<span data-tip="Remove" class="sm:tooltip tooltip-top">
<%= button_to button_title(title: nil, disabled_with: 'Rem', icon: svg_icon('trash', class: 'w-6 h-6')), submission_path(submission, permanently: true), class: 'btn btn-outline btn-sm w-full md:w-fit', form: { class: 'flex' }, title: 'Remove', method: :delete, data: { turbo_confirm: 'Submission deletion is irreversible and will permanently remove all associated signed documents with it. Are you sure?' }, onclick: 'event.stopPropagation()' %>
</span>
<% end %>
</div>
<% else %>
<div class="space-y-1 w-full md:mr-2">
Expand Down
2 changes: 1 addition & 1 deletion app/views/templates_archived_submissions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</div>
<% if @pagy.count > 0 %>
<div class="space-y-4">
<%= render partial: 'templates/submission', collection: @submissions, locals: { template: @template } %>
<%= render partial: 'templates/submission', collection: @submissions, locals: { template: @template, archived: true } %>
</div>
<% elsif params[:q].present? %>
<div class="text-center">
Expand Down

0 comments on commit 4bdb249

Please sign in to comment.