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
[#57388] create table: export_settings
Tobias Dillmann0ff47c2656cf
diff --git a/app/models/export_setting.rb b/app/models/export_setting.rbnew file mode 100644index 00000000000..ae18d027c9c--- /dev/null+++ b/app/models/export_setting.rb@@ -0,0 +1,49 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+#++++class ExportSetting < ApplicationRecord+ belongs_to :query++ POSSIBLE_FORMATS = %w[csv xls pdf_table pdf_report pdf_gantt].freeze++ validates :query_id, presence: true+ validates :format, presence: true, inclusion: { in: POSSIBLE_FORMATS }+ validates :settings, presence: true++ validate :unique_format_per_query++ private++ def unique_format_per_query+ if ExportSetting.exists?(query_id: query_id, format: format) && (new_record? || format_changed?)+ errors.add(:format, "there already is an export setting for this query with this format")+ end+ end+enddiff --git a/app/models/query.rb b/app/models/query.rbindex e3572776494..0ede8c5c42b 100644--- a/app/models/query.rb+++ b/app/models/query.rb@@ -43,6 +43,7 @@ class Query < ApplicationRecordhas_many :ical_tokens,through: :ical_token_query_assignments,class_name: "Token::ICal"+ has_many :export_settings, dependent: :destroy# no `dependent: :destroy` as the ical_tokens are destroyed in the following before_destroy callback# dependent: :destroy is not possible as this would only delete the ical_token_query_assignmentsbefore_destroy :destroy_ical_tokensdiff --git a/db/migrate/20250326151553_export_settings.rb b/db/migrate/20250326151553_export_settings.rbnew file mode 100644index 00000000000..36f4b2e037b--- /dev/null+++ b/db/migrate/20250326151553_export_settings.rb@@ -0,0 +1,43 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+#++++class ExportSettings < ActiveRecord::Migration[8.0]+ def change+ create_table :export_settings do |t|+ t.references :query, null: false, foreign_key: true+ t.string :format, null: false+ t.jsonb :settings, default: {}, null: false++ t.timestamps+ end++ add_index :export_settings, %i[query_id format], unique: true+ end+end