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
[Fix] Create rake task to fix missing notification settings (#11362)
Dombi Attila1691077d44b8
diff --git a/app/contracts/users/create_contract.rb b/app/contracts/users/create_contract.rbindex e7eeff62087..11e80033860 100644--- a/app/contracts/users/create_contract.rb+++ b/app/contracts/users/create_contract.rb@@ -41,6 +41,7 @@ module Usersvalidate :authentication_definedvalidate :type_is_uservalidate :user_limit_not_exceeded+ validate :notification_settings_presentprivate@@ -50,6 +51,12 @@ module Usersendend+ def notification_settings_present+ if model.notification_settings.empty?+ errors.add :notification_settings, :blank+ end+ end+def authentication_definederrors.add :password, :blank if model.active? && no_auth?enddiff --git a/lib/tasks/fix_missing_notification_settings.rake b/lib/tasks/fix_missing_notification_settings.rakenew file mode 100644index 00000000000..8fdd0366b02--- /dev/null+++ b/lib/tasks/fix_missing_notification_settings.rake@@ -0,0 +1,44 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 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.+#++++namespace :migrations do+ desc "Fix the missing notification settings"+ task fix_missing_notification_settings: :environment do+ ActiveRecord::Base.connection.execute <<~SQL.squish+ INSERT INTO+ notification_settings+ (user_id)+ SELECT+ u.id+ FROM+ users u+ WHERE type = 'User'+ AND NOT EXISTS (SELECT * FROM notification_settings ns WHERE ns.user_id = u.id)+ SQL+ end+enddiff --git a/spec/contracts/users/create_contract_spec.rb b/spec/contracts/users/create_contract_spec.rbindex 63f8a87c4b0..c2d83b7390b 100644--- a/spec/contracts/users/create_contract_spec.rb+++ b/spec/contracts/users/create_contract_spec.rb@@ -43,7 +43,8 @@ describe Users::CreateContract dologin: user_login,mail: user_mail,password: user_password,- password_confirmation: user_password_confirmation+ password_confirmation: user_password_confirmation,+ notification_settings: [NotificationSetting.new]}end