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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions app/models/message_draft.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
6 changes: 3 additions & 3 deletions app/models/message_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions app/models/message_thread.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ def unassign_tag(tag)
message_threads_tags.find_by(tag: tag)&.destroy
end

def any_objects_with_requested_signature?
messages.any? { |message| message.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 tak, ze ked tam je requested tag tak potom ked to podpises tak uz tam taky tag nebude? Cize staci zistit, ze tam nejaky takyto tag je 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.

Je, vieme to tak ulahcit

end

private

def has_tag?(tag)
Expand Down
Loading