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
Allow downloading IFC files (#9750)
Wieland Lindenthal7273bdfab55e
diff --git a/modules/bim/app/cells/bim/ifc_models/row_cell.rb b/modules/bim/app/cells/bim/ifc_models/row_cell.rbindex 4e03b6970bc..7e682216fdb 100644--- a/modules/bim/app/cells/bim/ifc_models/row_cell.rb+++ b/modules/bim/app/cells/bim/ifc_models/row_cell.rb@@ -44,10 +44,16 @@ module Bim###def button_links+ links = []+ # Seeded IFC models currently actually only have the XKT and NOT(!) the IFC original seeded+ if model.ifc_attachment+ links << download_link+ end+if User.current.allowed_to?(:manage_ifc_models, model.project)- [edit_link, delete_link]+ links.push(edit_link, delete_link)else- []+ linksendend@@ -56,14 +62,24 @@ module Bimbcf_project_ifc_model_path(model.project, model),class: 'icon icon-delete',data: { confirm: I18n.t(:text_are_you_sure) },+ title: I18n.t(:button_delete),method: :deleteend+ def download_link+ link_to '',+ API::V3::Utilities::PathHelper::ApiV3Path.attachment_content(model.ifc_attachment&.id),+ class: 'icon icon-download',+ title: I18n.t(:button_download),+ download: true+ end+def edit_linklink_to '',edit_bcf_project_ifc_model_path(model.project, model),class: 'icon icon-edit',- accesskey: accesskey(:edit)+ accesskey: accesskey(:edit),+ title: I18n.t(:button_edit)endendenddiff --git a/modules/bim/spec/factories/ifc_model_factory.rb b/modules/bim/spec/factories/ifc_model_factory.rbindex 2228dad43ea..81a03741cc1 100644--- a/modules/bim/spec/factories/ifc_model_factory.rb+++ b/modules/bim/spec/factories/ifc_model_factory.rb@@ -68,4 +68,11 @@ FactoryBot.define doendendend++ factory :ifc_model_without_ifc_attachment, class: '::Bim::IfcModels::IfcModel' do+ sequence(:title) { |n| "Model without ifc_attachment #{n}" }+ project factory: :project+ uploader factory: :user+ is_default { true }+ endenddiff --git a/modules/bim/spec/views/bim/ifc_models/ifc_models/index.html.erb_spec.rb b/modules/bim/spec/views/bim/ifc_models/ifc_models/index.html.erb_spec.rbnew file mode 100644index 00000000000..e6366ca6604--- /dev/null+++ b/modules/bim/spec/views/bim/ifc_models/ifc_models/index.html.erb_spec.rb@@ -0,0 +1,95 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require 'spec_helper'++describe 'bim/ifc_models/ifc_models/index', type: :view do+ let(:project) { FactoryBot.create(:project, enabled_module_names: %i[bim]) }+ let(:ifc_model) do+ FactoryBot.create(:ifc_model,+ uploader: uploader_user,+ title: "office.ifc",+ project: project).tap do |model|+ model.uploader = uploader_user+ end+ end+ let(:role) do+ FactoryBot.create(:role,+ permissions: %i[view_ifc_models manage_ifc_models])+ end+ let(:user) do+ FactoryBot.create :user,+ member_in_project: project,+ member_through_role: role+ end+ let(:uploader_user) { user }++ before do+ assign(:project, project)+ ifc_models = [ifc_model]+ allow(ifc_models).to receive(:defaults).and_return(ifc_models)+ assign(:ifc_models, ifc_models)++ controller.request.path_parameters[:project_id] = project.id++ allow(User).to receive(:current).and_return(user)+ render+ end++ context 'with permission manage_ifc_models' do+ context 'with ifc_attachment' do+ it 'lists the IFC model with all three buttons' do+ expect(rendered).to have_text('office.ifc')+ expect(rendered).to have_link('Download')+ expect(rendered).to have_link('Delete')+ expect(rendered).to have_link('Edit')+ end+ end++ context 'without ifc_attachment' do+ let(:ifc_model) do+ FactoryBot.create(:ifc_model_without_ifc_attachment,+ title: "office.ifc",+ project: project)+ end++ it 'lists the IFC model with all but the download button' do+ expect(rendered).to have_text('office.ifc')+ expect(rendered).not_to have_link('Download')+ expect(rendered).to have_link('Delete')+ expect(rendered).to have_link('Edit')+ end+ end+ end++ context 'without permission manage_ifc_models' do+ it 'only shows the download button' do+ expect(rendered).to have_link('Download')+ end+ end+end