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
[39451] remove base64 snapshot data from bcf vp
Eric Schubertc8a35f97da23
diff --git a/db/migrate/20211022143726_remove_snapshot_data.rb b/db/migrate/20211022143726_remove_snapshot_data.rbnew file mode 100644index 00000000000..3e7e3935d10--- /dev/null+++ b/db/migrate/20211022143726_remove_snapshot_data.rb@@ -0,0 +1,12 @@+class RemoveSnapshotData < ActiveRecord::Migration[6.1]+ def up+ execute <<~SQL.squish+ UPDATE bcf_viewpoints+ SET json_viewpoint = json_viewpoint #- '{snapshot,snapshot_data}';+ SQL+ end++ def down+ # removed snapshot data cannot be restored+ end+enddiff --git a/modules/bim/app/contracts/bim/bcf/viewpoints/create_contract.rb b/modules/bim/app/contracts/bim/bcf/viewpoints/create_contract.rbindex 504ba111263..c029df26af0 100644--- a/modules/bim/app/contracts/bim/bcf/viewpoints/create_contract.rb+++ b/modules/bim/app/contracts/bim/bcf/viewpoints/create_contract.rb@@ -1,5 +1,3 @@-#-- encoding: UTF-8-#-- copyright# OpenProject is an open source project management software.# Copyright (C) 2012-2021 the OpenProject GmbH@@ -78,7 +76,7 @@ module Bim::Bcfspace_boundaries_visibleopenings_visible).freeze- COLOR_REGEXP = /#([0-9a-f]{2})?[0-9a-f]{6}/+ COLOR_REGEXP = /#([0-9a-f]{2})?[0-9a-f]{6}/.freezeWHITELISTED_DIMENSIONS = %w(x y z).freeze@@ -86,7 +84,7 @@ module Bim::Bcfattribute :issueattribute :snapshotattribute :json_viewpoint do- validate_json_viewpoint_present+ validate_json_viewpoint_blankvalidate_json_viewpoint_hashnext if errors.any?@@ -103,7 +101,7 @@ module Bim::Bcfvalidate_guidend- def validate_json_viewpoint_present+ def validate_json_viewpoint_blankerrors.add(:json_viewpoint, :blank) if viewpoint.blank?end@@ -119,7 +117,7 @@ module Bim::Bcfreturn unless (sjson = viewpoint['snapshot'])errors.add(:json_viewpoint, :snapshot_type_unsupported) unless %w(jpg png).include? sjson['snapshot_type']- errors.add(:json_viewpoint, :snapshot_data_blank) unless sjson['snapshot_data'].present?+ errors.add(:json_viewpoint, :snapshot_data_blank) if sjson['snapshot_data'].blank?enddef validate_index@@ -216,13 +214,13 @@ module Bim::Bcfenddef invalid_components?(components)- return false unless components.present?+ return false if components.blank?!components.is_a?(Array) || components.any? { |component| invalid_component?(component) }enddef invalid_colorings?(colorings)- return false unless colorings.present?+ return false if colorings.blank?!colorings.is_a?(Array) || colorings.any? { |coloring| invalid_coloring?(coloring) }enddiff --git a/modules/bim/app/models/bim/bcf/viewpoint.rb b/modules/bim/app/models/bim/bcf/viewpoint.rbindex bfabeabab5a..513c1017570 100644--- a/modules/bim/app/models/bim/bcf/viewpoint.rb+++ b/modules/bim/app/models/bim/bcf/viewpoint.rb@@ -1,3 +1,31 @@+#-- 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.+#+++module Bim::Bcfclass Viewpoint < ActiveRecord::Baseself.table_name = :bcf_viewpointsdiff --git a/modules/bim/app/services/bim/bcf/viewpoints/create_service.rb b/modules/bim/app/services/bim/bcf/viewpoints/create_service.rbindex ccde2ca34f7..2243ece5207 100644--- a/modules/bim/app/services/bim/bcf/viewpoints/create_service.rb+++ b/modules/bim/app/services/bim/bcf/viewpoints/create_service.rb@@ -1,5 +1,3 @@-#-- encoding: UTF-8-#-- copyright# OpenProject is an open source project management software.# Copyright (C) 2012-2021 the OpenProject GmbH@@ -31,6 +29,14 @@module Bim::Bcfmodule Viewpointsclass CreateService < ::BaseServices::Create+ protected++ def persist(service_result)+ # snapshot base64 data must not get stored+ service_result.result.json_viewpoint['snapshot']&.delete('snapshot_data')++ super(service_result)+ endendendenddiff --git a/modules/bim/app/services/bim/bcf/viewpoints/set_attributes_service.rb b/modules/bim/app/services/bim/bcf/viewpoints/set_attributes_service.rbindex 2b51e02cb14..e9e70f80af1 100644--- a/modules/bim/app/services/bim/bcf/viewpoints/set_attributes_service.rb+++ b/modules/bim/app/services/bim/bcf/viewpoints/set_attributes_service.rb@@ -1,5 +1,3 @@-#-- encoding: UTF-8-#-- copyright# OpenProject is an open source project management software.# Copyright (C) 2012-2021 the OpenProject GmbH@@ -31,6 +29,8 @@module Bim::Bcfmodule Viewpointsclass SetAttributesService < ::BaseServices::SetAttributes+ private+def set_attributes(params)super@@ -38,7 +38,7 @@ module Bim::Bcfenddef set_default_attributes(_params)- model.json_viewpoint['guid'] = model.uuid+ viewpoint['guid'] = model.uuidenddef set_snapshot@@ -46,10 +46,10 @@ module Bim::Bcfname = "snapshot.#{snapshot_extension}"file = OpenProject::Files- .create_uploaded_file(name: name,- content_type: snapshot_content_type,- content: snapshot_binary_contents,- binary: true)+ .create_uploaded_file(name: name,+ content_type: snapshot_content_type,+ content: snapshot_binary_contents,+ binary: true)# This might break once the service is also used# to update existing viewpoints as the snapshot method will@@ -60,9 +60,9 @@ module Bim::Bcfenddef snapshot_data_complete?- model.json_viewpoint['snapshot'] &&+ viewpoint['snapshot'] &&snapshot_extension &&- snapshot_base_64 &&+ snapshot_base64 &&snapshot_url_parts.length > 1end@@ -70,9 +70,9 @@ module Bim::Bcf# Return nil when the extension is not within the specified set# which will lead to the snapshot not being created.# The contract will catch the error.- return unless model.json_viewpoint['snapshot']+ return unless viewpoint['snapshot']- case model.json_viewpoint['snapshot']['snapshot_type']+ case viewpoint['snapshot']['snapshot_type']when 'png''image/png'when 'jpg'@@ -81,11 +81,11 @@ module Bim::Bcfenddef snapshot_extension- model.json_viewpoint['snapshot']['snapshot_type']+ viewpoint['snapshot']['snapshot_type']end- def snapshot_base_64- model.json_viewpoint['snapshot']['snapshot_data']+ def snapshot_base64+ viewpoint['snapshot']['snapshot_data']enddef snapshot_binary_contents@@ -93,7 +93,11 @@ module Bim::Bcfenddef snapshot_url_parts- snapshot_base_64.match(/\Adata:([-\w]+\/[-\w+.]+)?;base64,(.*)/m) || []+ snapshot_base64.match(/\Adata:([-\w]+\/[-\w+.]+)?;base64,(.*)/m) || []+ end++ def viewpoint+ model.json_viewpointendendenddiff --git a/modules/bim/spec/requests/api/bcf/v2_1/viewpoints_api_spec.rb b/modules/bim/spec/requests/api/bcf/v2_1/viewpoints_api_spec.rbindex e4749a62bd8..4cabf77a630 100644--- a/modules/bim/spec/requests/api/bcf/v2_1/viewpoints_api_spec.rb+++ b/modules/bim/spec/requests/api/bcf/v2_1/viewpoints_api_spec.rb@@ -267,6 +267,7 @@ describe 'BCF 2.1 viewpoints resource', type: :request, content_type: :json, witparams.merge(guid: new_viewpoint.uuid)+ .merge("snapshot" => { "snapshot_type" => "png" })endlet(:expected_status) { 201 }@@ -274,10 +275,10 @@ describe 'BCF 2.1 viewpoints resource', type: :request, content_type: :json, witit 'creates the viewpoint with an attachment for the snapshot' doexpect(Bim::Bcf::Viewpoint.count)- .to eql 2+ .to be 2expect(Bim::Bcf::Viewpoint.last.attachments.count)- .to eql 1+ .to be 1endcontext 'lacking permission to see project' do@@ -331,7 +332,7 @@ describe 'BCF 2.1 viewpoints resource', type: :request, content_type: :json, witit 'creates the viewpoint with an attachment for the snapshot' doexpect(Bim::Bcf::Viewpoint.count)- .to eql 2+ .to be 2endend