Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't allow to delete message while being sent #539

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/controllers/message_drafts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ def destroy
# redirect_path = @message.original_message.present? ? message_thread_path(@message.original_message.thread) : message_drafts_path
redirect_path = @message.original_message.present? ? message_thread_path(@message.original_message.thread) : message_threads_path

@message.destroy

redirect_to redirect_path, notice: "Správa bola zahodená"
if @message.not_yet_submitted?
jsuchal marked this conversation as resolved.
Show resolved Hide resolved
@message.destroy
redirect_to redirect_path, notice: "Správa bola zmazaná"
else
redirect_to redirect_path, alert: "Správu nie je možné zmazať po zaradení na odoslanie"
end
end

def unlock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def destroy
message_drafts_to_destroy_ids = message_threads.map(&:message_drafts).flatten.map(&:id)

message_threads.transaction do
MessageDraft.where(id: message_drafts_to_destroy_ids).destroy_all
MessageDraft.not_in_submission_process.where(id: message_drafts_to_destroy_ids).destroy_all
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luciajanikova nie je toto nejako zavadzajuce, ze oznacis nieco na odoslanie a ono sa to neodosle vlastne (lebo to uz je zaradene na odoslanie). Ci to je by design takto?

end

if message_drafts_to_destroy_ids.present?
Expand Down
25 changes: 25 additions & 0 deletions test/controllers/message_drafts_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'test_helper'

class MessageDraftsControllerTest < ActionController::TestCase
setup do
session[:login_expires_at] = Time.now + 1.day
Current.user = users(:basic)
session[:user_id] = Current.user.id
end
test "should destroy draft with status created" do
# draft should be destroyed if not yet submitted
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tento koment mal byt vlastne nazov testu.

message_draft = messages(:ssd_main_draft)
delete :destroy, params: { id: message_draft.id }
assert_raises(ActiveRecord::RecordNotFound) do
MessageDraft.find(message_draft.id)
end
end
test "should not destroy draft that is being submitted" do
jsuchal marked this conversation as resolved.
Show resolved Hide resolved
message_draft = messages(:ssd_main_draft)
message_draft.metadata[:status] = "being_submitted"
message_draft.save!
delete :destroy, params: { id: message_draft.id }
assert_equal "Správu nie je možné zmazať po zaradení na odoslanie", flash[:alert]
assert MessageDraft.exists?(message_draft.id)
end
end