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

GO-49 Do not submit message unless requested signatures present #484

Merged
Merged
Changes from 3 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
1 change: 0 additions & 1 deletion app/controllers/message_drafts_controller.rb
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ def submit
if @message.submit
redirect_to message_thread_path(@message.thread), notice: "Správa bola zaradená na odoslanie"
else
# TODO FIX: Tato hlaska sa zobrazuje aj ked je object oznaceny ako to_be_signed, ale nebol este podpisany
redirect_to message_thread_path(@message.thread), alert: @message.not_submittable_errors.join(', ')
end
end
Original file line number Diff line number Diff line change
@@ -9,10 +9,12 @@ def submit
message_threads = message_thread_policy_scope.where(id: ids).includes(:messages)
message_threads.transaction do
submission_results = SubmitMessageDraftsAction.run(message_threads)
if submission_results
redirect_back fallback_location: message_threads_path, notice: "Správy vo vláknach boli zaradené na odoslanie", status: 303
else
if submission_results.none?(true)
jsuchal marked this conversation as resolved.
Show resolved Hide resolved
redirect_back fallback_location: message_threads_path, alert: "Vo vláknach sa našli správy, ktoré neboli podpísané všetkými podpismi", status: 303 and return if any_missing_signature?(message_threads)
redirect_back fallback_location: message_threads_path, alert: "Vo vláknach sa nenašli žiadne správy na odoslanie", status: 303
else
redirect_back fallback_location: message_threads_path, alert: "Správy, ktoré neboli podpísané všetkými podpismi neboli zaradené na odoslanie", status: 303 and return if any_missing_signature?(message_threads)
redirect_back fallback_location: message_threads_path, notice: "Správy vo vláknach boli zaradené na odoslanie", status: 303
end
end
end
@@ -41,6 +43,10 @@ def destroy
def message_thread_policy_scope
policy_scope(MessageThread)
end

def any_missing_signature?(message_threads)
message_threads.any? { |thread| thread.any_objects_with_requested_signature? }
Copy link
Member

Choose a reason for hiding this comment

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

Resp nevieme sa tu rovno spytat, ze "existuje nejaky requesting tag na objekte v tychto vlaknach"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Upravila som, pozri prosim.

end
end
end
end
4 changes: 4 additions & 0 deletions app/models/message.rb
Original file line number Diff line number Diff line change
@@ -96,6 +96,10 @@ def authorized?
metadata["delivery_notification"] && metadata["authorized"] == true
end

def any_objects_with_requested_signature?
objects.any? { |message_object| message_object.tags.where(type: SignatureRequestedFromTag.to_s).any? }
end
Copy link
Member

Choose a reason for hiding this comment

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

Toto mozno by sa dalo aj jednym exists selectom z opacnej strany nie?

Copy link
Member Author

Choose a reason for hiding this comment

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

Upravila som, pozri prosim.


# TODO remove UPVS stuff from core domain
def form
::Upvs::Form.find_by(
4 changes: 2 additions & 2 deletions app/models/message_draft.rb
Original file line number Diff line number Diff line change
@@ -107,15 +107,15 @@ def created_from_template?
end

def submittable?
form_object.content.present? && objects.to_be_signed.all? { |o| o.is_signed? } && correctly_created? && valid?(:validate_data)
form_object&.content&.present? && objects.to_be_signed.all? { |o| o.is_signed? } && correctly_created? && valid?(:validate_data) && !any_objects_with_requested_signature?
end

def not_submittable_errors
return [] if submittable?

errors = []
errors << 'Vyplňte obsah správy' unless form_object.content.present?
errors << 'Pred odoslaním podpíšte všetky dokumenty na podpis' unless objects.to_be_signed.all? { |o| o.is_signed? }
errors << 'Pred odoslaním podpíšte všetky dokumenty na podpis' if (objects.to_be_signed.any? { |o| !o.is_signed? } || any_objects_with_requested_signature?)
Copy link
Member

Choose a reason for hiding this comment

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

Nie je toto nejaka duplicita? Preco sa pytame ci je podpisany a potom este raz ci tam nie je nejaky objekt co ma byt podpisany?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ano, je to do urcitej miery duplicita, lebo v casti UPVS importov sme zvyknuti na oznacenie cez atribut to_be_signed a inak cez tagy. Mali by sme to zjednotit, tento atribut to_be_signed si myslim, ze nepotrebujeme.
Uz mame na to lepsie riesenie (vtedy este uplne nebolo). Skusim upratat.

errors << 'Obsah správy nie je validný' if invalid? || !valid?(:validate_data)
errors << 'Správu bude možné odoslať až po ukončení validácie' if being_validated?

6 changes: 3 additions & 3 deletions app/models/message_object.rb
Original file line number Diff line number Diff line change
@@ -153,11 +153,11 @@ def thread

def remove_object_related_tags_from_thread
tags.each do |tag|
message.thread.unassign_tag(tag) unless other_thread_objects_include_tag?(tag)
thread.unassign_tag(tag) unless other_thread_objects_include_tag?(tag)
end

message.thread.unassign_tag(message.tenant.signed_tag!) unless message.thread.tags.reload.where(type: SignedByTag.to_s).any?
message.thread.unassign_tag(message.tenant.signature_requested_tag!) unless message.thread.tags.reload.where(type: SignatureRequestedFromTag.to_s).any?
thread.unassign_tag(message.tenant.signed_tag!) unless thread.tags.reload.where(type: SignedByTag.to_s).any?
thread.unassign_tag(message.tenant.signature_requested_tag!) unless thread.tags.reload.where(type: SignatureRequestedFromTag.to_s).any?
end

def other_thread_objects_include_tag?(tag)
4 changes: 4 additions & 0 deletions app/models/message_thread.rb
Original file line number Diff line number Diff line change
@@ -167,6 +167,10 @@ def unassign_tag(tag)
message_threads_tags.find_by(tag: tag)&.destroy
end

def any_objects_with_requested_signature?
tags.signature_requesting.any?
end

private

def has_tag?(tag)
1 change: 1 addition & 0 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@ class Tag < ApplicationRecord
scope :simple, -> { where(type: SimpleTag.to_s) }
scope :visible, -> { where(visible: true) }
scope :signing_tags, -> { where(type: ["SignedTag", "SignedByTag", "SignatureRequestedTag", "SignatureRequestedFromTag"]) }
scope :signature_requesting, -> { where(type: ["SignatureRequestedTag", "SignatureRequestedFromTag"]) }
Copy link
Member

Choose a reason for hiding this comment

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

Nestaci sa pytat na ten prvy?

Copy link
Member Author

Choose a reason for hiding this comment

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

Staci na druhy (prvy byva iba na threade, druhy byva na threade & na message objecte rovnako), upravila som

scope :archived, -> { where(type: ArchivedTag.to_s) }

after_update_commit ->(tag) { EventBus.publish(:tag_renamed, tag) if previous_changes.key?("name") }
4 changes: 4 additions & 0 deletions test/fixtures/message_object_data.yml
Original file line number Diff line number Diff line change
@@ -12,6 +12,10 @@ draft_two:
message_object: ssd_main_general_draft_two_form
blob: <GeneralAgenda xmlns="http://schemas.gov.sk/form/App.GeneralAgenda/1.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><subject>predmet</subject><text>text</text></GeneralAgenda>

draft_three:
message_object: ssd_main_draft_to_be_signed2_draft_form
blob: <GeneralAgenda xmlns="http://schemas.gov.sk/form/App.GeneralAgenda/1.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><subject>predmet</subject><text>text</text></GeneralAgenda>

empty_draft:
message_object: ssd_main_empty_draft_form
blob: <GeneralAgenda xmlns="http://schemas.gov.sk/form/App.GeneralAgenda/1.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><subject></subject><text></text></GeneralAgenda>
2 changes: 1 addition & 1 deletion test/fixtures/message_objects.yml
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ ssd_main_draft_to_be_signed_draft_two_form:
ssd_main_draft_to_be_signed2_draft_form:
message: ssd_main_draft_to_be_signed2_draft
name: MyString
mimetype: MyString
mimetype: application/x-eform-xml
object_type: FORM

ssd_main_draft_to_be_signed3_draft_one_form:
9 changes: 8 additions & 1 deletion test/fixtures/messages.yml
Original file line number Diff line number Diff line change
@@ -216,7 +216,7 @@ ssd_main_draft_to_be_signed_draft_two:
author: basic

ssd_main_draft_to_be_signed2_draft:
type: MessageDraft
type: Upvs::MessageDraft
uuid: <%= SecureRandom.uuid %>
title: MyStringDraft3
html_visualization: MyString
@@ -225,6 +225,13 @@ ssd_main_draft_to_be_signed2_draft:
replyable: false
metadata:
status: created
sktalk_class: EGOV_APPLICATION
posp_id: App.GeneralAgenda
posp_version: 1.9
message_type: App.GeneralAgenda
correlation_id: <%= SecureRandom.uuid %>
recipient_uri:
ico://sk/12345678
author: basic

ssd_main_draft_to_be_signed3_draft:
9 changes: 9 additions & 0 deletions test/models/message_object_test.rb
Original file line number Diff line number Diff line change
@@ -206,6 +206,15 @@ class MessageObjectTest < ActiveSupport::TestCase
assert_not object.message.thread.tags.include?(tenant.signed_tag!)
end

test "before_destroy callback deletes SignatureRequested Tag from message thread (if no more objects with SignatureRequestedFromTag present)" do
message_object = message_objects(:ssd_main_draft_to_be_signed2_draft_form)
message_thread = message_object.message.thread

message_object.destroy

assert_equal false, message_thread.tags.reload.include?(message_thread.tenant.signature_requested_tag!)
end

test "before_destroy callback keeps object related tags for message thread (if another objects with the tag present in the message)" do
tenant = tenants(:ssd)
signer = users(:basic_two)
15 changes: 15 additions & 0 deletions test/system/message_drafts_test.rb
Original file line number Diff line number Diff line change
@@ -56,4 +56,19 @@ class MessageDraftsTest < ApplicationSystemTestCase
refute_selector(thread_in_listing_selector(thread_general))
refute_selector(thread_in_listing_selector(thread_issue))
end

test "message is not submitted and flash message is shown when user tries to send message without requested signatures present" do
message_thread = message_threads(:ssd_main_draft_to_be_signed2)
message_draft = messages(:ssd_main_draft_to_be_signed2_draft)

visit message_thread_path(message_thread)

within("#upvs_message_draft_#{message_draft.id}") do
assert_button "Odoslať"

click_button "Odoslať"
end

assert_text "Pred odoslaním podpíšte všetky dokumenty na podpis"
end
end