diff --git a/app/controllers/api/messages_controller.rb b/app/controllers/api/messages_controller.rb index dcecd946f..8fd89a1db 100644 --- a/app/controllers/api/messages_controller.rb +++ b/app/controllers/api/messages_controller.rb @@ -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) @@ -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]) diff --git a/app/jobs/upvs/drafts/load_content_job.rb b/app/jobs/upvs/drafts/load_content_job.rb index 9180ffa49..e3a041f65 100644 --- a/app/jobs/upvs/drafts/load_content_job.rb +++ b/app/jobs/upvs/drafts/load_content_job.rb @@ -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)) diff --git a/app/models/fs/message_draft.rb b/app/models/fs/message_draft.rb index 18b9d9abf..c23776006 100644 --- a/app/models/fs/message_draft.rb +++ b/app/models/fs/message_draft.rb @@ -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 diff --git a/app/models/message_draft.rb b/app/models/message_draft.rb index 792d0b8d6..b552e89a8 100644 --- a/app/models/message_draft.rb +++ b/app/models/message_draft.rb @@ -107,7 +107,7 @@ 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 @@ -115,7 +115,7 @@ def not_submittable_errors 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? diff --git a/app/models/message_object.rb b/app/models/message_object.rb index 0b97493a8..6ebece908 100644 --- a/app/models/message_object.rb +++ b/app/models/message_object.rb @@ -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 @@ -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 diff --git a/app/models/tag.rb b/app/models/tag.rb index c8f2d3b2e..2054f4fd0 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -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") } diff --git a/db/migrate/20241029064753_remove_to_be_signed_attribute_from_message_objects.rb b/db/migrate/20241029064753_remove_to_be_signed_attribute_from_message_objects.rb new file mode 100644 index 000000000..50256c12c --- /dev/null +++ b/db/migrate/20241029064753_remove_to_be_signed_attribute_from_message_objects.rb @@ -0,0 +1,5 @@ +class RemoveToBeSignedAttributeFromMessageObjects < ActiveRecord::Migration[7.1] + def change + remove_column :message_objects, :to_be_signed + end +end diff --git a/db/schema.rb b/db/schema.rb index b22c56b6d..452398837 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_08_20_143244) do +ActiveRecord::Schema[7.1].define(version: 2024_10_29_064753) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -387,7 +387,6 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.boolean "is_signed" - t.boolean "to_be_signed", default: false, null: false t.boolean "visualizable" t.index ["message_id"], name: "index_message_objects_on_message_id" end diff --git a/public/openapi.yaml b/public/openapi.yaml index 85eff9eba..da517fe51 100644 --- a/public/openapi.yaml +++ b/public/openapi.yaml @@ -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 diff --git a/test/integration/upvs_message_drafts_api_test.rb b/test/integration/upvs_message_drafts_api_test.rb index 670dd2eb4..94c1b20c5 100644 --- a/test/integration/upvs_message_drafts_api_test.rb +++ b/test/integration/upvs_message_drafts_api_test.rb @@ -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(' + + Všeobecný predmet + Všeobecný text +') + } + ] + } + + 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',