Skip to content

Commit

Permalink
Refactor signature removal transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
stage-rl committed Dec 5, 2023
1 parent 1a53af3 commit 19072ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 6 additions & 4 deletions app/controllers/message_drafts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ def destroy

def enable_edit
authorize @message
if @message.remove_form_signature
redirect_to message_thread_path(@message.thread), notice: "Podpisy boli úspešne odstránené, správu je možné upravovať"
else
redirect_to message_thread_path(@message.thread), alert: "Nastala neočakávaná chyba, nepodarilo sa odstrániť podpisy"
@message.transaction do
if @message.remove_form_signature
redirect_to message_thread_path(@message.thread), notice: "Podpisy boli úspešne odstránené, správu je možné upravovať"
else
redirect_to message_thread_path(@message.thread), alert: "Nastala neočakávaná chyba, nepodarilo sa odstrániť podpisy"
end
end
end

Expand Down
8 changes: 3 additions & 5 deletions app/models/message_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@ def remove_signature
unsigned_object = nested_message_objects&.first
return false unless unsigned_object

transaction do
update(name: unsigned_object.name, mimetype: unsigned_object.mimetype, is_signed: false)
message_object_datum.update(blob: unsigned_object.content)
unsigned_object.destroy
end
update(name: unsigned_object.name, mimetype: unsigned_object.mimetype, is_signed: false)
message_object_datum.update(blob: unsigned_object.content)
unsigned_object.destroy
end

private
Expand Down

0 comments on commit 19072ea

Please sign in to comment.