OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
check for ifc file conformity
ulfertsd9cef43d822b
diff --git a/modules/ifc_models/app/contracts/ifc_models/base_contract.rb b/modules/ifc_models/app/contracts/ifc_models/base_contract.rbindex c15176edbba..9be2f216f4c 100644--- a/modules/ifc_models/app/contracts/ifc_models/base_contract.rb+++ b/modules/ifc_models/app/contracts/ifc_models/base_contract.rb@@ -44,6 +44,7 @@ module IFCModelsuser_allowed_to_manageuser_is_uploaderifc_attachment_existent+ ifc_attachment_is_ifcuploader_is_ifc_attachment_authorsuper@@ -65,6 +66,20 @@ module IFCModelserrors.add :base, :ifc_attachment_missing unless model.ifc_attachmentend+ def ifc_attachment_is_ifc+ return unless model.ifc_attachment&.new_record?++ firstline = File.open(model.ifc_attachment.file.file.path, &:readline)++ begin+ unless firstline.match?(/^ISO-10303-21;/)+ errors.add :base, :invalid_ifc_file+ end+ rescue ArgumentError+ errors.add :base, :invalid_ifc_file+ end+ end+def uploader_is_ifc_attachment_authorerrors.add :uploader_id, :invalid if model.ifc_attachment && model.uploader != model.ifc_attachment.authorenddiff --git a/modules/ifc_models/config/locales/en.yml b/modules/ifc_models/config/locales/en.ymlindex 76c1271f5b5..4a5add60683 100644--- a/modules/ifc_models/config/locales/en.yml+++ b/modules/ifc_models/config/locales/en.yml@@ -41,4 +41,5 @@ en:ifc_models/ifc_model:attributes:base:- ifc_attachment_missing: "No ifc file attached"+ ifc_attachment_missing: "No ifc file attached."+ invalid_ifc_file: "The provided file is not a valid IFC file."diff --git a/modules/ifc_models/spec/contracts/ifc_models/shared_contract_examples.rb b/modules/ifc_models/spec/contracts/ifc_models/shared_contract_examples.rbindex cbcc33c4678..6eb3632e5d2 100644--- a/modules/ifc_models/spec/contracts/ifc_models/shared_contract_examples.rb+++ b/modules/ifc_models/spec/contracts/ifc_models/shared_contract_examples.rb@@ -106,6 +106,34 @@ shared_examples_for 'ifc model contract' doendend+ context 'if the new ifc file is no valid ifc file' do+ let(:ifc_file) { FileHelpers.mock_uploaded_file name: "model.ifc", content_type: 'application/binary', binary: true }+ let(:ifc_attachment) do+ User.execute_as current_user do+ ifc_model.attach_files('first' => { 'file' => ifc_file, 'description' => 'ifc' })+ ifc_model.attachments.last+ end+ end++ it 'is invalid' do+ expect_valid(false, base: %i(invalid_ifc_file))+ end+ end++ context 'if the new ifc file is a valid ifc file' do+ let(:ifc_file) do+ FileHelpers.mock_uploaded_file name: "model.ifc", content_type: 'application/binary', binary: true, content: "ISO-10303-21;"+ end+ let(:ifc_attachment) do+ User.execute_as current_user do+ ifc_model.attach_files('first' => { 'file' => ifc_file, 'description' => 'ifc' })+ ifc_model.attachments.last+ end+ end++ it_behaves_like 'is valid'+ end+context 'if user is not allowed to manage ifc models' dolet(:permissions) { [] }