Skip to content

Commit

Permalink
Remove to_be_signed attribute from MessageObjects
Browse files Browse the repository at this point in the history
  • Loading branch information
luciajanikova committed Oct 29, 2024
1 parent 6da4232 commit 270661c
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 14 deletions.
7 changes: 6 additions & 1 deletion app/controllers/api/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def message_drafts
@message.save

permitted_message_draft_params.fetch(:objects, []).each do |object_params|
message_object = @message.objects.create(object_params.except(:content, :tags))
message_object = @message.objects.create(object_params.except(:content, :to_be_signed, :tags))

object_params.fetch(:tags, []).each do |tag_name|
tag = @tenant.user_signature_tags.find_by(name: tag_name)
Expand All @@ -33,6 +33,11 @@ def message_drafts
end
@message.thread.box.tenant.signed_externally_tag!.assign_to_message_object(message_object) if message_object.is_signed

if object_params[:to_be_signed]
@message.tenant.signer_group.signature_requested_from_tag&.assign_to_message_object(message_object)
@message.tenant.signer_group.signature_requested_from_tag&.assign_to_thread(@message.thread)
end

MessageObjectDatum.create(
message_object: message_object,
blob: Base64.decode64(object_params[:content])
Expand Down
6 changes: 5 additions & 1 deletion app/jobs/upvs/drafts/load_content_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ def load_message_draft_objects(message_draft, objects_path, signed:, to_be_signe
mimetype: Utils.file_mimetype_by_name(entry_name: file_name, is_form: is_form),
object_type: is_form ? "FORM" : "ATTACHMENT",
is_signed: signed,
to_be_signed: to_be_signed,
message: message_draft,
visualizable: is_form ? false : nil,
tags: tags
)

if to_be_signed
message_draft_object.message.tenant.signer_group.signature_requested_from_tag&.assign_to_message_object(message_draft_object)
message_draft_object.message.tenant.signer_group.signature_requested_from_tag&.assign_to_thread(message_draft_object.message.thread)
end

MessageObjectDatum.create(
message_object: message_draft_object,
blob: File.read(File.join(objects_path, file_name))
Expand Down
5 changes: 2 additions & 3 deletions app/models/fs/message_draft.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,12 @@ def self.create_and_validate_with_fs_form(form_files: [], author:, fs_client: Fs
form_object = message.objects.create(
object_type: 'FORM',
name: form_file.original_filename,
mimetype: form_file.content_type,
to_be_signed: fs_form.signature_required
mimetype: form_file.content_type
)
form_object.update(is_signed: form_object.asice?)
message.thread.box.tenant.signed_externally_tag!.assign_to_message_object(form_object) if form_object.is_signed?

if form_object.to_be_signed && !form_object.is_signed?
if fs_form.signature_required && !form_object.is_signed?
message.thread.box.tenant.signer_group.signature_requested_from_tag&.assign_to_message_object(form_object)
message.thread.box.tenant.signer_group.signature_requested_from_tag&.assign_to_thread(message.thread)
end
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) && !any_objects_with_requested_signature?
form_object&.content&.present? && 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' if (objects.to_be_signed.any? { |o| !o.is_signed? } || any_objects_with_requested_signature?)
errors << 'Pred odoslaním podpíšte všetky dokumenty na podpis' if any_objects_with_requested_signature?
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
3 changes: 0 additions & 3 deletions app/models/message_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# mimetype :string
# name :string
# object_type :string not null
# to_be_signed :boolean default(FALSE), not null
# visualizable :boolean
# created_at :datetime not null
# updated_at :datetime not null
Expand All @@ -24,8 +23,6 @@ class MessageObject < ApplicationRecord
has_one :archived_object, dependent: :destroy

scope :unsigned, -> { where(is_signed: false) }
scope :to_be_signed, -> { where(to_be_signed: true) }
scope :should_be_signed, -> { where(to_be_signed: true, is_signed: false) }

validates :name, presence: { message: "Name can't be blank" }, on: :validate_data
validate :allowed_mimetype?, on: :validate_data
Expand Down
2 changes: 1 addition & 1 deletion app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +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"]) }
scope :signature_requesting, -> { where(type: "SignatureRequestedFromTag") }
scope :archived, -> { where(type: ArchivedTag.to_s) }

after_update_commit ->(tag) { EventBus.publish(:tag_renamed, tag) if previous_changes.key?("name") }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveToBeSignedAttributeFromMessageObjects < ActiveRecord::Migration[7.1]
def change
remove_column :message_objects, :to_be_signed
end
end
3 changes: 1 addition & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ paths:
description: Indikátor či je obsah objektu podpísaný
type: boolean
to_be_signed:
description: Indikátor či obsah objektu má byť podpísaný
description: Indikátor či obsah objektu má byť podpísaný. V prípade hodnoty true je vyžiadaný podpis na danom objekte
type: boolean
mimetype:
description: Typ internetového média v súlade s typom a obsahom objektu
Expand Down
36 changes: 36 additions & 0 deletions test/integration/upvs_message_drafts_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,42 @@ class UpvsMessageDraftsApiTest < ActionDispatch::IntegrationTest
assert_not_equal Message.count, @before_request_messages_count
end

test 'SignatureRestedTag is assigned from SignerGroup if object marked to_be_signed' do
message_params = {
type: 'Upvs::MessageDraft',
title: 'Všeobecná agenda',
uuid: SecureRandom.uuid,
metadata: {
posp_id: 'App.GeneralAgenda',
posp_version: '1.9',
message_type: 'App.GeneralAgenda',
correlation_id: SecureRandom.uuid,
sender_uri: 'SSDMainURI',
recipient_uri: 'ico://sk/12345678',
},
objects: [
{
name: 'Form.xml',
is_signed: false,
to_be_signed: true,
mimetype: 'application/x-eform-xml',
object_type: 'FORM',
content: Base64.encode64('<?xml version="1.0" encoding="utf-8"?>
<GeneralAgenda xmlns="http://schemas.gov.sk/form/App.GeneralAgenda/1.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<subject>Všeobecný predmet</subject>
<text>Všeobecný text</text>
</GeneralAgenda>')
}
]
}

post '/api/messages/message_drafts', params: message_params.merge({ token: generate_api_token(sub: @tenant.id, key_pair: @key_pair)} ), as: :json

assert_response :created
assert @box.messages.last.objects.first.tags.include?(@tenant.signer_group.signature_requested_from_tag)
assert @box.messages.last.thread.tags.include?(@tenant.signature_requested_tag!)
end

test 'can upload valid message with tags if they exist' do
message_params = {
type: 'Upvs::MessageDraft',
Expand Down

0 comments on commit 270661c

Please sign in to comment.