Skip to content

Commit

Permalink
Merge pull request #530 from slovensko-digital/GO-168/make_posp_param…
Browse files Browse the repository at this point in the history
…s_optional

GO-168 Make MessageDraft metadata POSP params optional
  • Loading branch information
luciajanikova authored Dec 19, 2024
2 parents 7ffc634 + 1c898d8 commit f12e452
Show file tree
Hide file tree
Showing 9 changed files with 4,351 additions and 85 deletions.
1 change: 1 addition & 0 deletions app/models/concerns/pdf_visualization_operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def form
return unless xml?

xml_document = xml_unsigned_content
# TODO forms without posp_id, posp_versions
posp_id, posp_version = xml_document&.root&.namespace&.href&.match(UPVS_FORM_IDENTIFIER_PATTERN)&.captures

::Upvs::Form.find_by(
Expand Down
18 changes: 13 additions & 5 deletions app/models/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,20 @@ def any_objects_with_requested_signature?

# TODO remove UPVS, FS stuff from core domain
def form
return ::Fs::Form.find(metadata['fs_form_id']) if metadata['fs_form_id'].present?
if metadata['fs_form_id'].present?
::Fs::Form.find(metadata['fs_form_id'])
elsif all_metadata['posp_id'].present? && all_metadata['posp_version'].present?
::Upvs::Form.find_by(
identifier: all_metadata['posp_id'],
version: all_metadata['posp_version']
)
else
# TODO forms without posp_id, posp_versions
::Upvs::Form.find_by(
identifier: all_metadata['message_type']
)
end

::Upvs::Form.find_by(
identifier: all_metadata['posp_id'],
version: all_metadata['posp_version']
)
end

def update_html_visualization
Expand Down
2 changes: 0 additions & 2 deletions app/models/upvs/message_draft.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ def validate_data

def validate_metadata
errors.add(:metadata, "No recipient URI") unless all_metadata&.dig("recipient_uri")
errors.add(:metadata, "No posp ID") unless all_metadata&.dig("posp_id")
errors.add(:metadata, "No posp version") unless all_metadata&.dig("posp_version")
errors.add(:metadata, "No message type") unless all_metadata&.dig("message_type")

errors.add(:metadata, "Reference ID must be UUID") if all_metadata&.dig("reference_id") && !all_metadata&.dig("reference_id")&.match?(Utils::UUID_PATTERN)
Expand Down
8 changes: 7 additions & 1 deletion app/models/upvs/service_with_form_allow_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
#

class Upvs::ServiceWithFormAllowRule < ApplicationRecord
scope :matching_metadata, ->(metadata) { where("schema_url LIKE ?", "%#{metadata['posp_id']}/#{metadata['posp_version']}").or(where("schema_url LIKE ?", "%#{metadata['posp_id']}/*")) }
scope :matching_metadata, -> (metadata) do
if metadata['posp_id'].present? && metadata['posp_version'].present?
where("schema_url LIKE ?", "%#{metadata['posp_id']}/#{metadata['posp_version']}").or(where("schema_url LIKE ?", "%#{metadata['posp_id']}/*"))
else
where("schema_url LIKE ?", "%#{metadata['message_type']}%")
end
end

def self.all_institutions_with_template_support(template)
::Upvs::ServiceWithFormAllowRule.matching_metadata(template.metadata)
Expand Down
Loading

0 comments on commit f12e452

Please sign in to comment.