Skip to content

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

Inform users about external password change

Oliver Günther1a4bc24480c7
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb
index 8b87e40f9b6..ace77f009c3 100644
--- a/app/controllers/account_controller.rb
+++ b/app/controllers/account_controller.rb
@@ -110,7 +110,8 @@ class AccountController < ApplicationController
unless user.change_password_allowed?
# user uses an external authentication
- Rails.logger.error "Password cannot be changed for user: #{mail}"
+ UserMailer.password_change_not_possible(user).deliver_later
+ Rails.logger.warn "Password cannot be changed for user: #{mail}"
return
end
diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb
index 1cdd485a0be..b414116e05e 100644
--- a/app/mailers/user_mailer.rb
+++ b/app/mailers/user_mailer.rb
@@ -74,10 +74,23 @@ class UserMailer < ApplicationMailer
t(:mail_subject_lost_password, value: Setting.app_title))
end
+ def password_change_not_possible(user)
+ @user = user
+ @provider =
+ if user.ldap_auth_source
+ user.ldap_auth_source.name
+ else
+ user.authentication_provider
+ end
+ open_project_headers 'Type' => 'Account'
+
+ send_mail(user, t('mail_password_change_not_possible.title'))
+ end
+
def news_added(user, news)
@news = news
- open_project_headers 'Type' => 'News'
+ open_project_headers 'Type' => 'News'
open_project_headers 'Project' => @news.project.identifier if @news.project
message_id @news, user
@@ -106,7 +119,7 @@ class UserMailer < ApplicationMailer
def news_comment_added(user, comment)
@comment = comment
- @news = @comment.commented
+ @news = @comment.commented
open_project_headers 'Project' => @news.project.identifier if @news.project
@@ -165,7 +178,7 @@ class UserMailer < ApplicationMailer
end
def account_information(user, password)
- @user = user
+ @user = user
@password = password
open_project_headers 'Type' => 'Account'
@@ -175,7 +188,7 @@ class UserMailer < ApplicationMailer
end
def account_activation_requested(admin, user)
- @user = user
+ @user = user
@activation_url = url_for(controller: '/users',
action: :index,
status: 'registered',
diff --git a/app/views/user_mailer/password_change_not_possible.html.erb b/app/views/user_mailer/password_change_not_possible.html.erb
new file mode 100644
index 00000000000..59f514de5d7
--- /dev/null
+++ b/app/views/user_mailer/password_change_not_possible.html.erb
@@ -0,0 +1,33 @@
+<%#-- copyright
+OpenProject is an open source project management software.
+Copyright (C) 2012-2023 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.
+
+++#%>
+<p><%= t('mail_password_change_not_possible.body',
+ app_title: Setting.app_title,
+ name: @provider) %></p>
+
+<p><%= t('mail_password_change_not_possible.subtext') %></p>
diff --git a/app/views/user_mailer/password_change_not_possible.text.erb b/app/views/user_mailer/password_change_not_possible.text.erb
new file mode 100644
index 00000000000..b8dafb6b9ca
--- /dev/null
+++ b/app/views/user_mailer/password_change_not_possible.text.erb
@@ -0,0 +1,34 @@
+<%#-- copyright
+OpenProject is an open source project management software.
+Copyright (C) 2012-2023 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.
+
+++#%>
+
+<%= t('mail_password_change_not_possible.body',
+ app_title: Setting.app_title,
+ name: @provider) %>
+
+<%= t('mail_password_change_not_possible.subtext') %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 208607b748f..7d9063b5892 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -2264,6 +2264,10 @@ en:
mail_body_incoming_email_error_in_reply_to: "At %{received_at} %{from_email} wrote"
mail_body_incoming_email_error_logs: "Logs"
mail_body_lost_password: "To change your password, click on the following link:"
+ mail_password_change_not_possible:
+ title: "Password change not possible"
+ body: "Your account at %{app_title} is connected to an external authentication provider (%{name})."
+ subtext: "Passwords for external account cannot be changed in the application. Please use the lost password functionality of your authentication provider."
mail_body_register: "Welcome to %{app_title}. Please activate your account by clicking on this link:"
mail_body_register_header_title: "Project member invitation email"
mail_body_register_user: "Dear %{name}, "
diff --git a/spec/features/auth/lost_password_spec.rb b/spec/features/auth/lost_password_spec.rb
index 2166f6657fc..a28d0f3f021 100644
--- a/spec/features/auth/lost_password_spec.rb
+++ b/spec/features/auth/lost_password_spec.rb
@@ -67,4 +67,45 @@ RSpec.describe 'Lost password' do
expect(page)
.to have_current_path(my_page_path)
end
+
+ context 'when user has an auth source' do
+ let!(:ldap_auth_source) { create(:ldap_auth_source, name: 'Foo') }
+ let!(:user) { create(:user, ldap_auth_source:) }
+
+ it 'sends an email with external auth info' do
+ visit account_lost_password_path
+
+ # shows same flash for invalid and existing users
+ fill_in 'mail', with: user.mail
+ click_on 'Submit'
+
+ expect(page).to have_selector('.op-toast.-success', text: I18n.t(:notice_account_lost_email_sent))
+
+ perform_enqueued_jobs
+ expect(ActionMailer::Base.deliveries.size).to be 1
+ mail = ActionMailer::Base.deliveries.first
+ expect(mail.subject).to eq I18n.t('mail_password_change_not_possible.title')
+ expect(mail.body.parts.first.body.to_s).to include 'Foo'
+ end
+ end
+
+ context 'when user has identity_url' do
+ let!(:user) { create(:user, identity_url: 'saml:foobar') }
+
+ it 'sends an email with external auth info' do
+ visit account_lost_password_path
+
+ # shows same flash for invalid and existing users
+ fill_in 'mail', with: user.mail
+ click_on 'Submit'
+
+ expect(page).to have_selector('.op-toast.-success', text: I18n.t(:notice_account_lost_email_sent))
+
+ perform_enqueued_jobs
+ expect(ActionMailer::Base.deliveries.size).to be 1
+ mail = ActionMailer::Base.deliveries.first
+ expect(mail.subject).to eq I18n.t('mail_password_change_not_possible.title')
+ expect(mail.body.parts.first.body.to_s).to include 'Saml'
+ end
+ end
end