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
Add templated property to projects
Oliver Günther467b1860ae9d
diff --git a/app/contracts/projects/base_contract.rb b/app/contracts/projects/base_contract.rbindex 086a6159ee9..417629f0d30 100644--- a/app/contracts/projects/base_contract.rb+++ b/app/contracts/projects/base_contract.rb@@ -36,6 +36,7 @@ module Projectsattribute :nameattribute :identifierattribute :description+ attribute :templatedattribute :publicattribute :active dovalidate_active_presentdiff --git a/app/contracts/projects/instantiate_template_contract.rb b/app/contracts/projects/instantiate_template_contract.rbnew file mode 100644index 00000000000..e12fcd355b8--- /dev/null+++ b/app/contracts/projects/instantiate_template_contract.rb@@ -0,0 +1,41 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 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-2017 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 docs/COPYRIGHT.rdoc for more details.+#++++module Projects+ class CreateContract < BaseContract+ private++ def validate_user_allowed_to_manage+ unless user.allowed_to_globally?(:add_project) ||+ model.parent && user.allowed_to?(:add_subprojects, model.parent)++ errors.add :base, :error_unauthorized+ end+ end+ end+enddiff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rbindex ac445179789..3b53d661fae 100644--- a/app/models/permitted_params.rb+++ b/app/models/permitted_params.rb@@ -279,6 +279,7 @@ class PermittedParams:identifier,:project_type_id,:parent_id,+ :templated,status: %i(code explanation),custom_fields: [],work_package_custom_field_ids: [],diff --git a/app/models/queries/projects/filters/templated_filter.rb b/app/models/queries/projects/filters/templated_filter.rbnew file mode 100644index 00000000000..75fc32f5837--- /dev/null+++ b/app/models/queries/projects/filters/templated_filter.rb@@ -0,0 +1,37 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 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-2017 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 docs/COPYRIGHT.rdoc for more details.+#++++class Queries::Projects::Filters::ActiveFilter < Queries::Projects::Filters::ProjectFilter+ include Queries::Filters::Shared::BooleanFilter++ def self.key+ :active+ end+enddiff --git a/app/services/projects/instantiate_template_service.rb b/app/services/projects/instantiate_template_service.rbnew file mode 100644index 00000000000..6042d8bcb74--- /dev/null+++ b/app/services/projects/instantiate_template_service.rb@@ -0,0 +1,43 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 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-2017 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 docs/COPYRIGHT.rdoc for more details.+#++++module Projects+ class CreateFromTemplateService < ::BaseServices::BaseContracted+ attr_reader :template_id++ def initialize(user:, template_id: )+ super user: user, contract_class:+ @template_id = template_id+ end++ def after_validate(params)+ end+ end+enddiff --git a/app/views/projects/form/attributes/_templated.html.erb b/app/views/projects/form/attributes/_templated.html.erbnew file mode 100644index 00000000000..64b1ff5a03a--- /dev/null+++ b/app/views/projects/form/attributes/_templated.html.erb@@ -0,0 +1,32 @@+<%#-- copyright+OpenProject is an open source project management software.+Copyright (C) 2012-2020 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-2017 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 docs/COPYRIGHT.rdoc for more details.++++#%>++<div class="form--field">+ <%= form.check_box :templated %>+</div>diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 15cd90293ba..ed6a5cec4ef 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -464,6 +464,7 @@ en:types: "Types"versions: "Versions"work_packages: "Work Packages"+ templated: 'Template project'projects/status:code: 'Status'explanation: 'Status description'@@ -2004,6 +2005,9 @@ en:warning_one: Members of the project will have to relocate the project's repositories.warning_two: Existing links to the project will no longer work.title: Change the project's identifier+ template:+ use_template: 'Use template'+ make_template: 'Set as template'archive:are_you_sure: "Are you sure you want to archive the project '%{name}'?"archived: "Archived"diff --git a/db/migrate/20200527130633_add_templated_to_project.rb b/db/migrate/20200527130633_add_templated_to_project.rbnew file mode 100644index 00000000000..2d342d157bb--- /dev/null+++ b/db/migrate/20200527130633_add_templated_to_project.rb@@ -0,0 +1,5 @@+class AddTemplatedToProject < ActiveRecord::Migration[6.0]+ def change+ add_column :projects, :templated, :boolean, default: false, null: false+ end+end