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
Remove AuthSource base namespace, model
Oliver Günthere32d2d005898
diff --git a/app/contracts/users/base_contract.rb b/app/contracts/users/base_contract.rbindex 262604fc3ed..a96c873e505 100644--- a/app/contracts/users/base_contract.rb+++ b/app/contracts/users/base_contract.rb@@ -42,7 +42,7 @@ module Userswritable: ->(*) { user.admin? && model.id != user.id }attribute :language- attribute :auth_source_id,+ attribute :ldap_auth_source_id,writable: ->(*) { user.allowed_to_globally?(:manage_user) || user.allowed_to_globally?(:create_user) }attribute :status,@@ -91,7 +91,7 @@ module Users# rubocop:disable Rails/DynamicFindBydef existing_auth_source- if auth_source_id && AuthSource.find_by_unique(auth_source_id).nil?+ if ldap_auth_source_id && LdapAuthSource.find_by_unique(ldap_auth_source_id).nil?errors.add :auth_source, :error_not_foundendenddiff --git a/app/contracts/users/create_contract.rb b/app/contracts/users/create_contract.rbindex 179bbb5fef2..09e9b432d08 100644--- a/app/contracts/users/create_contract.rb+++ b/app/contracts/users/create_contract.rb@@ -62,7 +62,7 @@ module Usersenddef no_auth?- model.password.blank? && model.auth_source_id.blank? && model.identity_url.blank?+ model.password.blank? && model.ldap_auth_source_id.blank? && model.identity_url.blank?end##diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rbindex 237cea34400..885c6abef45 100644--- a/app/controllers/account_controller.rb+++ b/app/controllers/account_controller.rb@@ -225,7 +225,7 @@ class AccountController < ApplicationControllersession[:invitation_token] = token.valueuser = token.user- if user.auth_source && user.auth_source.auth_method_name == 'LDAP'+ if user.ldap_auth_source && user.ldap_auth_source.auth_method_name == 'LDAP'activate_through_ldap userelseactivate_user user@@ -247,7 +247,7 @@ class AccountController < ApplicationControllerdef activate_through_ldap(user)session[:auth_source_registration] = {login: user.login,- auth_source_id: user.auth_source_id+ ldap_auth_source_id: user.ldap_auth_source_id}flash[:notice] = I18n.t('account.auth_source_login', login: user.login).html_safe@@ -276,7 +276,7 @@ class AccountController < ApplicationControlleruser = find_or_create_sso_user(login, save: false)if user.try(:new_record?)- return onthefly_creation_failed user, login: user.login, auth_source_id: user.auth_source_id+ return onthefly_creation_failed user, login: user.login, ldap_auth_source_id: user.ldap_auth_source_idendshow_sso_error_for user@@ -360,7 +360,7 @@ class AccountController < ApplicationControlleruser.attributes = permitted_params.useruser.activateuser.login = session[:auth_source_registration][:login]- user.auth_source_id = session[:auth_source_registration][:auth_source_id]+ user.ldap_auth_source_id = session[:auth_source_registration][:ldap_auth_source_id]respond_for_registered_user(user)end@@ -437,7 +437,7 @@ class AccountController < ApplicationControllerflash_and_log_invalid_credentialsendelsif user.new_record?- onthefly_creation_failed(user, login: user.login, auth_source_id: user.auth_source_id)+ onthefly_creation_failed(user, login: user.login, ldap_auth_source_id: user.ldap_auth_source_id)else# Valid usersuccessful_authentication(user)diff --git a/app/controllers/auth_sources_controller.rb b/app/controllers/auth_sources_controller.rbdeleted file mode 100644index 0e53b24245b..00000000000--- a/app/controllers/auth_sources_controller.rb+++ /dev/null@@ -1,122 +0,0 @@-#-- 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.-#++--class AuthSourcesController < ApplicationController- include PaginationHelper- layout 'admin'-- before_action :require_admin- before_action :block_if_password_login_disabled-- def index- @auth_sources = AuthSource- .order(id: :asc)- .page(page_param)- .per_page(per_page_param)-- render 'auth_sources/index'- end-- def new- @auth_source = auth_source_class.new- render 'auth_sources/new'- end-- def edit- @auth_source = AuthSource.find(params[:id])- render 'auth_sources/edit'- end-- def create- @auth_source = auth_source_class.new permitted_params.auth_source- if @auth_source.save- flash[:notice] = I18n.t(:notice_successful_create)- redirect_to action: 'index'- else- render 'auth_sources/new'- end- end-- def update- @auth_source = AuthSource.find(params[:id])- updated = permitted_params.auth_source- updated.delete :account_password if updated[:account_password].blank?-- if @auth_source.update updated- flash[:notice] = I18n.t(:notice_successful_update)- redirect_to action: 'index'- else- render 'auth_sources/edit'- end- end-- def test_connection- @auth_method = AuthSource.find(params[:id])- begin- @auth_method.test_connection- flash[:notice] = I18n.t(:notice_successful_connection)- rescue StandardError => e- flash[:error] = I18n.t(:error_unable_to_connect, value: e.message)- end- redirect_to action: 'index'- end-- def destroy- @auth_source = AuthSource.find(params[:id])- if @auth_source.users.empty?- @auth_source.destroy-- flash[:notice] = t(:notice_successful_delete)- else- flash[:warning] = t(:notice_wont_delete_auth_source)- end- redirect_to action: 'index'- end-- protected-- def auth_source_class- AuthSource- end-- def default_breadcrumb- if action_name == 'index'- t(:label_auth_source_plural)- else- ActionController::Base.helpers.link_to(t(:label_auth_source_plural), ldap_auth_sources_path)- end- end-- def show_local_breadcrumb- true- end-- def block_if_password_login_disabled- render_404 if OpenProject::Configuration.disable_password_login?- end-enddiff --git a/app/controllers/concerns/auth_source_sso.rb b/app/controllers/concerns/auth_source_sso.rbindex 9b6c7f6759c..0eb726e02da 100644--- a/app/controllers/concerns/auth_source_sso.rb+++ b/app/controllers/concerns/auth_source_sso.rb@@ -117,12 +117,12 @@ module AuthSourceSSOdef find_user_from_auth_source(login)User.by_login(login)- .where.not(auth_source_id: nil)+ .where.not(ldap_auth_source_id: nil).firstenddef create_user_from_auth_source(login, save:)- attrs = AuthSource.find_user(login)+ attrs = LdapAuthSource.find_user(login)return unless attrsattrs[:login] = login@@ -143,7 +143,7 @@ module AuthSourceSSOcall.on_success dologger.info("User '#{user.login}' created from external auth source: " +- "#{user.auth_source.type} - #{user.auth_source.name}"+ "#{user.ldap_auth_source.type} - #{user.ldap_auth_source.name}")enddiff --git a/app/controllers/ldap_auth_sources_controller.rb b/app/controllers/ldap_auth_sources_controller.rbindex d64343cf8b5..ccc52f08a1c 100644--- a/app/controllers/ldap_auth_sources_controller.rb+++ b/app/controllers/ldap_auth_sources_controller.rb@@ -26,12 +26,90 @@# See COPYRIGHT and LICENSE files for more details.#++-class LdapAuthSourcesController < AuthSourcesController+class LdapAuthSourcesController < ApplicationControllermenu_item :ldap_authentication+ include PaginationHelper+ layout 'admin'++ before_action :require_admin+ before_action :block_if_password_login_disabled++ def index+ @auth_sources = LdapAuthSource+ .order(id: :asc)+ .page(page_param)+ .per_page(per_page_param)+ end++ def new+ @auth_source = LdapAuthSource.new+ end++ def edit+ @auth_source = LdapAuthSource.find(params[:id])+ end++ def create+ @auth_source = LdapAuthSource.new permitted_params.ldap_auth_source+ if @auth_source.save+ flash[:notice] = I18n.t(:notice_successful_create)+ redirect_to action: 'index'+ else+ render 'new'+ end+ end++ def update+ @auth_source = LdapAuthSource.find(params[:id])+ updated = permitted_params.ldap_auth_source+ updated.delete :account_password if updated[:account_password].blank?++ if @auth_source.update updated+ flash[:notice] = I18n.t(:notice_successful_update)+ redirect_to action: 'index'+ else+ render 'edit'+ end+ end++ def test_connection+ @auth_method = LdapAuthSource.find(params[:id])+ begin+ @auth_method.test_connection+ flash[:notice] = I18n.t(:notice_successful_connection)+ rescue StandardError => e+ flash[:error] = I18n.t(:error_unable_to_connect, value: e.message)+ end+ redirect_to action: 'index'+ end++ def destroy+ @auth_source = LdapAuthSource.find(params[:id])+ if @auth_source.users.empty?+ @auth_source.destroy++ flash[:notice] = t(:notice_successful_delete)+ else+ flash[:warning] = t(:notice_wont_delete_auth_source)+ end+ redirect_to action: 'index'+ endprotected- def auth_source_class- LdapAuthSource+ def default_breadcrumb+ if action_name == 'index'+ t(:label_auth_source_plural)+ else+ ActionController::Base.helpers.link_to(t(:label_auth_source_plural), ldap_auth_sources_path)+ end+ end++ def show_local_breadcrumb+ true+ end++ def block_if_password_login_disabled+ render_404 if OpenProject::Configuration.disable_password_login?endenddiff --git a/app/helpers/accounts_helper.rb b/app/helpers/accounts_helper.rbindex 34f1682fa17..878282cfc41 100644--- a/app/helpers/accounts_helper.rb+++ b/app/helpers/accounts_helper.rb@@ -26,7 +26,7 @@ module AccountsHelper# is active. However, if an auth source is present, do show it independently from# the `email_login` setting as we can't say if the auth source's login is the email address.def registration_show_email?- !Setting.email_login? || @user.auth_source_id.present?+ !Setting.email_login? || @user.ldap_auth_source_id.present? # rubocop:disable Rails/HelperInstanceVariableenddef registration_footerdiff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rbindex 56dcdb06ce8..9afc395ab1c 100644--- a/app/helpers/users_helper.rb+++ b/app/helpers/users_helper.rb@@ -135,6 +135,6 @@ module UsersHelperenddef can_users_have_auth_source?- AuthSource.any? && !OpenProject::Configuration.disable_password_login?+ LdapAuthSource.any? && !OpenProject::Configuration.disable_password_login?endenddiff --git a/app/models/auth_source.rb b/app/models/auth_source.rbdeleted file mode 100644index 92820943f5b..00000000000--- a/app/models/auth_source.rb+++ /dev/null@@ -1,106 +0,0 @@-#-- 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.-#++--class AuthSource < ApplicationRecord- include Redmine::Ciphering-- class Error < ::StandardError; end-- has_many :users-- validates :name,- uniqueness: { case_sensitive: false },- length: { maximum: 60 }-- def self.unique_attribute- :name- end- prepend ::Mixins::UniqueFinder-- def authenticate(_login, _password); end-- def find_user(_login)- raise "subclass repsonsiblity"- end-- # implemented by a subclass, should raise when no connection is possible and not raise on success- def test_connection- raise I18n.t('auth_source.using_abstract_auth_source')- end-- def auth_method_name- 'Abstract'- end-- def account_password- read_ciphered_attribute(:account_password)- end-- def account_password=(arg)- write_ciphered_attribute(:account_password, arg)- end-- def allow_password_changes?- self.class.allow_password_changes?- end-- # Does this auth source backend allow password changes?- def self.allow_password_changes?- false- end-- # Try to authenticate a user not yet registered against available sources- def self.authenticate(login, password)- AuthSource.where(['onthefly_register=?', true]).find_each do |source|- begin- Rails.logger.debug { "Authenticating '#{login}' against '#{source.name}'" }- attrs = source.authenticate(login, password)- rescue StandardError => e- Rails.logger.error "Error during authentication: #{e.message}"- attrs = nil- end- return attrs if attrs- end- nil- end-- def self.find_user(login)- AuthSource.where(['onthefly_register=?', true]).find_each do |source|- begin- Rails.logger.debug { "Looking up '#{login}' in '#{source.name}'" }- attrs = source.find_user login- rescue StandardError => e- Rails.logger.error "Error during authentication: #{e.message}"- attrs = nil- end-- return attrs if attrs- end- nil- end-enddiff --git a/app/models/dummy_auth_source.rb b/app/models/dummy_auth_source.rbindex 65f34e5c03c..8510a413c3c 100644--- a/app/models/dummy_auth_source.rb+++ b/app/models/dummy_auth_source.rb@@ -1,4 +1,4 @@-class DummyAuthSource < AuthSource+class DummyAuthSource < LdapAuthSourcedef test_connection# the dummy connection is always availableend@@ -23,7 +23,7 @@ class DummyAuthSource < AuthSource.find_by(login:).attributes.slice("firstname", "lastname", "mail")- .merge(auth_source_id: id)+ .merge(ldap_auth_source_id: id)enddef find_on_the_fly_user(login)@@ -45,7 +45,7 @@ class DummyAuthSource < AuthSourcefirstname: login.capitalize,lastname: 'Dummy',mail: '[email protected]',- auth_source_id: id+ ldap_auth_source_id: id}enddiff --git a/app/models/ldap_auth_source.rb b/app/models/ldap_auth_source.rbindex cc7c990acbf..743b4760614 100644--- a/app/models/ldap_auth_source.rb+++ b/app/models/ldap_auth_source.rb@@ -28,7 +28,23 @@require 'net/ldap'-class LdapAuthSource < AuthSource+class LdapAuthSource < ApplicationRecord+ class Error < ::StandardError; end++ include Redmine::Ciphering++ has_many :users,+ dependent: :nullify++ validates :name,+ uniqueness: { case_sensitive: false },+ length: { maximum: 60 }++ def self.unique_attribute+ :name+ end+ prepend ::Mixins::UniqueFinder+enum tls_mode: {plain_ldap: 0,simple_tls: 1,@@ -48,6 +64,46 @@ class LdapAuthSource < AuthSourceafter_initialize :set_default_portbefore_validation :strip_ldap_attributes+ # Try to authenticate a user not yet registered against available sources+ def self.authenticate(login, password)+ where(onthefly_register: true).find_each do |source|+ binding.pry+ begin+ Rails.logger.debug { "Authenticating '#{login}' against '#{source.name}'" }+ attrs = source.authenticate(login, password)+ rescue StandardError => e+ Rails.logger.error "Error during authentication: #{e.message}"+ attrs = nil+ end+ return attrs if attrs+ end+ nil+ end++ def self.find_user(login)+ where(onthefly_register: true).find_each do |source|+ binding.pry+ begin+ Rails.logger.debug { "Looking up '#{login}' in '#{source.name}'" }+ attrs = source.find_user login+ rescue StandardError => e+ Rails.logger.error "Error during authentication: #{e.message}"+ attrs = nil+ end++ return attrs if attrs+ end+ nil+ end++ def account_password+ read_ciphered_attribute(:account_password)+ end++ def account_password=(arg)+ write_ciphered_attribute(:account_password, arg)+ end+def authenticate(login, password)return nil if login.blank? || password.blank?@@ -58,7 +114,7 @@ class LdapAuthSource < AuthSourceattrs.except(:dn)endrescue Net::LDAP::Error => e- raise AuthSource::Error, "LdapError: #{e.message}"+ raise LdapAuthSource::Error, "LdapError: #{e.message}"enddef find_user(login)@@ -71,7 +127,7 @@ class LdapAuthSource < AuthSourceattrs.except(:dn)endrescue Net::LDAP::Error => e- raise AuthSource::Error, "LdapError: #{e.message}"+ raise LdapAuthSource::Error, "LdapError: #{e.message}"end# Open and return a system connection@@ -82,10 +138,10 @@ class LdapAuthSource < AuthSource# test the connection to the LDAPdef test_connectionunless authenticate_dn(account, account_password)- raise AuthSource::Error, I18n.t('auth_source.ldap_error', error_message: I18n.t('auth_source.ldap_auth_failed'))+ raise LdapAuthSource::Error, I18n.t('auth_source.ldap_error', error_message: I18n.t('auth_source.ldap_auth_failed'))endrescue Net::LDAP::Error => e- raise AuthSource::Error, I18n.t('auth_source.ldap_error', error_message: e.to_s)+ raise LdapAuthSource::Error, I18n.t('auth_source.ldap_error', error_message: e.to_s)enddef auth_method_name@@ -95,7 +151,7 @@ class LdapAuthSource < AuthSourcedef get_user_attributes_from_ldap_entry(entry)base_attributes = {dn: entry.dn,- auth_source_id: id+ ldap_auth_source_id: id}base_attributes.merge mapped_attributes(entry)diff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rbindex 15e7db58eeb..80f5c2e3733 100644--- a/app/models/permitted_params.rb+++ b/app/models/permitted_params.rb@@ -62,8 +62,8 @@ class PermittedParamsparams.require(:attribute_help_text).permit(*self.class.permitted_attributes[:attribute_help_text])end- def auth_source- params.require(:auth_source).permit(*self.class.permitted_attributes[:auth_source])+ def ldap_auth_source+ params.require(:ldap_auth_source).permit(*self.class.permitted_attributes[:ldap_auth_source])enddef forum@@ -210,7 +210,7 @@ class PermittedParamschange_password_allowed,additional_params = [])- additional_params << :auth_source_id unless external_authentication+ additional_params << :ldap_auth_source_id unless external_authenticationif current_user.admin?additional_params << :force_password_change if change_password_allowed@@ -416,7 +416,7 @@ class PermittedParamsattribute_namehelp_text),- auth_source: %i(+ ldap_auth_source: %i(namehostportdiff --git a/app/models/user.rb b/app/models/user.rbindex ec52d3be99f..ba5e0440919 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -61,7 +61,7 @@ class User < Principal# in order to keep all previously generated ical urls valid and usablehas_many :ical_tokens, class_name: '::Token::ICal', dependent: :destroy- belongs_to :auth_source, optional: true+ belongs_to :ldap_auth_source, optional: true# Authorized OAuth grantshas_many :oauth_grants,@@ -157,7 +157,7 @@ class User < Principal# create new password if password was setdef update_password- if password && auth_source_id.blank?+ if password && ldap_auth_source_id.blank?new_password = passwords.build(type: UserPassword.active_type.to_s)new_password.plain_password = passwordnew_password.save@@ -211,9 +211,9 @@ class User < Principalreturn nil if !user.active? || OpenProject::Configuration.disable_password_login?- if user.auth_source+ if user.ldap_auth_source# user has an external authentication method- return nil unless user.auth_source.authenticate(user.login, password)+ return nil unless user.ldap_auth_source.authenticate(user.login, password)else# authentication with local passwordreturn nil unless user.check_password?(password)@@ -240,7 +240,7 @@ class User < Principaldef self.try_authentication_and_create_user(login, password)return nil if OpenProject::Configuration.disable_password_login?- attrs = AuthSource.authenticate(login, password)+ attrs = LdapAuthSource.authenticate(login, password)return unless attrscall = Users::CreateService@@ -326,7 +326,7 @@ class User < Principal# If +update_legacy+ is set, will automatically save legacy passwords using the current# format.def check_password?(clear_password, update_legacy: true)- if auth_source_id.present?+ if ldap_auth_source_id.present?auth_source.authenticate(login, clear_password)elsereturn false if current_password.nil?@@ -339,9 +339,8 @@ class User < Principaldef change_password_allowed?return false if uses_external_authentication? ||OpenProject::Configuration.disable_password_login?- return true if auth_source_id.blank?- auth_source.allow_password_changes?+ ldap_auth_source_id.blank?end# Is the user authenticated via an external authentication source via OmniAuth?diff --git a/app/services/ldap/import_users_from_list_service.rb b/app/services/ldap/import_users_from_list_service.rbindex 3c948665c26..4bdd5292220 100644--- a/app/services/ldap/import_users_from_list_service.rb+++ b/app/services/ldap/import_users_from_list_service.rb@@ -19,7 +19,7 @@ module Ldapnew_users.each do |login|synchronize_user(User.new(login:), ldap_con)- rescue ::AuthSource::Error => e+ rescue ::LdapAuthSource::Error => eRails.logger.error { "Failed to synchronize user #{ldap.name} due to LDAP error: #{e.message}" }# Reset the LDAP connectionldap_con = new_ldap_connectiondiff --git a/app/services/ldap/synchronize_users_service.rb b/app/services/ldap/synchronize_users_service.rbindex 2e9902f6b39..df7cd722401 100644--- a/app/services/ldap/synchronize_users_service.rb+++ b/app/services/ldap/synchronize_users_service.rb@@ -14,7 +14,7 @@ module Ldapapplicable_users.find_each do |user|synchronize_user(user, ldap_con)- rescue ::AuthSource::Error => e+ rescue ::LdapAuthSource::Error => eRails.logger.error { "Failed to synchronize user #{ldap.name} due to LDAP error: #{e.message}" }# Reset the LDAP connectionldap_con = new_ldap_connectiondiff --git a/app/services/users/register_user_service.rb b/app/services/users/register_user_service.rbindex e20297a1f77..dbac71737aa 100644--- a/app/services/users/register_user_service.rb+++ b/app/services/users/register_user_service.rb@@ -91,7 +91,7 @@ module Users# Try to register a user with an auth source connection# bypassing regular account registration restrictionsdef register_ldap_user- return if user.auth_source_id.blank?+ return if user.ldap_auth_source_id.blank?user.activatediff --git a/app/views/account/_register.html.erb b/app/views/account/_register.html.erbindex 3f3c37f3ceb..610ccdc44b2 100644--- a/app/views/account/_register.html.erb+++ b/app/views/account/_register.html.erb@@ -40,7 +40,7 @@ See COPYRIGHT and LICENSE files for more details.<div class="spot-modal--body spot-container"><h2><%= t(:label_register) %></h2><section class="form--section">- <% if @user.auth_source_id.nil? %>+ <% if @user.ldap_auth_source_id.nil? %><div class="form--field -required -wide-label"><% if Setting.email_login? %><%= email_field(f) %>diff --git a/app/views/auth_sources/_form.html.erb b/app/views/auth_sources/_form.html.erbdeleted file mode 100644index 3cd8b683210..00000000000--- a/app/views/auth_sources/_form.html.erb+++ /dev/null@@ -1,39 +0,0 @@-<%#-- 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.--++#%>--<%#- needs locals:- f: labelled form builder-%>--<%= error_messages_for :auth_source %>-<section class="form--section">- <div class="form--field"><%= f.text_field 'name', required: true %></div>- <div class="form--field"><%= f.check_box 'onthefly_register', label: AuthSource.human_attribute_name(:onthefly) %></div>-</section>diff --git a/app/views/ldap_auth_sources/_form.html.erb b/app/views/ldap_auth_sources/_form.html.erbindex b0a68efb73c..0edc298f8b3 100644--- a/app/views/ldap_auth_sources/_form.html.erb+++ b/app/views/ldap_auth_sources/_form.html.erb@@ -104,7 +104,7 @@ See COPYRIGHT and LICENSE files for more details.</div><div class="form--field"><%= f.text_area :tls_certificate_string,- label: AuthSource.human_attribute_name(:tls_certificate_string),+ label: LdapAuthSource.human_attribute_name(:tls_certificate_string),placeholder: "-----BEGIN CERTIFICATE-----\n ..... \n-----END CERTIFICATE-----",rows: 10,container_class: '-wide' %>@@ -125,7 +125,7 @@ See COPYRIGHT and LICENSE files for more details.</div><div class="form--field"><%= f.password_field 'account_password',- label: AuthSource.human_attribute_name(:password),+ label: LdapAuthSource.human_attribute_name(:password),placeholder: ((@auth_source.new_record? || @auth_source.account_password.blank?) ? '' : ('●' * 15)),autocomplete: 'off',container_class: '-middle' %>@@ -155,7 +155,7 @@ See COPYRIGHT and LICENSE files for more details.</div></div><div class="form--field">- <%= f.check_box 'onthefly_register', label: AuthSource.human_attribute_name(:onthefly) %>+ <%= f.check_box 'onthefly_register', label: LdapAuthSource.human_attribute_name(:onthefly) %><div class="form--field-instructions"><p><%= t('ldap_auth_sources.attribute_texts.onthefly_register') %></p></div>@@ -168,7 +168,7 @@ See COPYRIGHT and LICENSE files for more details.<div class="form--field -required"><%= f.text_field 'attr_login',- label: AuthSource.human_attribute_name(:login),+ label: LdapAuthSource.human_attribute_name(:login),required: true,size: 20,placeholder: 'uid',@@ -179,36 +179,36 @@ See COPYRIGHT and LICENSE files for more details.</div><div class="form--field"><%= f.text_field 'attr_firstname',- label: AuthSource.human_attribute_name(:firstname),+ label: LdapAuthSource.human_attribute_name(:firstname),size: 20,placeholder: 'givenName',container_class: '-middle' %><span class="form--field-instructions">- <%= t('ldap_auth_sources.attribute_texts.generic_map', attribute: AuthSource.human_attribute_name(:firstname)) %>+ <%= t('ldap_auth_sources.attribute_texts.generic_map', attribute: LdapAuthSource.human_attribute_name(:firstname)) %></span></div><div class="form--field"><%= f.text_field 'attr_lastname',- label: AuthSource.human_attribute_name(:lastname),+ label: LdapAuthSource.human_attribute_name(:lastname),size: 20,placeholder: 'sn',container_class: '-middle' %><span class="form--field-instructions">- <%= t('ldap_auth_sources.attribute_texts.generic_map', attribute: AuthSource.human_attribute_name(:lastname)) %>+ <%= t('ldap_auth_sources.attribute_texts.generic_map', attribute: LdapAuthSource.human_attribute_name(:lastname)) %></span></div><div class="form--field"><%= f.text_field 'attr_mail',- label: AuthSource.human_attribute_name(:mail),+ label: LdapAuthSource.human_attribute_name(:mail),size: 20,placeholder: 'mail',container_class: '-middle' %><span class="form--field-instructions">- <%= t('ldap_auth_sources.attribute_texts.generic_map', attribute: AuthSource.human_attribute_name(:mail)) %>+ <%= t('ldap_auth_sources.attribute_texts.generic_map', attribute: LdapAuthSource.human_attribute_name(:mail)) %></span></div><div class="form--field">- <%= f.text_field 'attr_admin', label: AuthSource.human_attribute_name(:admin), size: 20, container_class: '-middle' %>+ <%= f.text_field 'attr_admin', label: LdapAuthSource.human_attribute_name(:admin), size: 20, container_class: '-middle' %><span class="form--field-instructions"><%= t('ldap_auth_sources.attribute_texts.admin_map_html') %></span>diff --git a/app/views/auth_sources/edit.html.erb b/app/views/ldap_auth_sources/edit.html.erbsimilarity index 100%rename from app/views/auth_sources/edit.html.erbrename to app/views/ldap_auth_sources/edit.html.erbdiff --git a/app/views/auth_sources/index.html.erb b/app/views/ldap_auth_sources/index.html.erbsimilarity index 95%rename from app/views/auth_sources/index.html.erbrename to app/views/ldap_auth_sources/index.html.erbindex 7667f4cfe3e..17fa462bc9e 100644--- a/app/views/auth_sources/index.html.erb+++ b/app/views/ldap_auth_sources/index.html.erb@@ -57,7 +57,7 @@ See COPYRIGHT and LICENSE files for more details.<div class="generic-table--sort-header-outer"><div class="generic-table--sort-header"><span>- <%= AuthSource.human_attribute_name(:name) %>+ <%= LdapAuthSource.human_attribute_name(:name) %></span></div></div>@@ -66,7 +66,7 @@ See COPYRIGHT and LICENSE files for more details.<div class="generic-table--sort-header-outer"><div class="generic-table--sort-header"><span>- <%= AuthSource.human_attribute_name(:type) %>+ <%= LdapAuthSource.human_attribute_name(:type) %></span></div></div>@@ -75,7 +75,7 @@ See COPYRIGHT and LICENSE files for more details.<div class="generic-table--sort-header-outer"><div class="generic-table--sort-header"><span>- <%= AuthSource.human_attribute_name(:host) %>+ <%= LdapAuthSource.human_attribute_name(:host) %></span></div></div>diff --git a/app/views/auth_sources/new.html.erb b/app/views/ldap_auth_sources/new.html.erbsimilarity index 100%rename from app/views/auth_sources/new.html.erbrename to app/views/ldap_auth_sources/new.html.erbdiff --git a/app/views/user_mailer/account_information.html.erb b/app/views/user_mailer/account_information.html.erbindex 99f635ded26..5f38dfa86ab 100644--- a/app/views/user_mailer/account_information.html.erb+++ b/app/views/user_mailer/account_information.html.erb@@ -26,8 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.See COPYRIGHT and LICENSE files for more details.++#%>-<% if @user.auth_source %>- <p><%= t(:mail_body_account_information_external, value: @user.auth_source.name) %></p>+<% if @user.ldap_auth_source %>+ <p><%= t(:mail_body_account_information_external, value: @user.ldap_auth_source.name) %></p><% else %><p><%= t(:mail_body_account_information) %>:</p><ul>diff --git a/app/views/user_mailer/account_information.text.erb b/app/views/user_mailer/account_information.text.erbindex 776f64c3d8e..96511014767 100644--- a/app/views/user_mailer/account_information.text.erb+++ b/app/views/user_mailer/account_information.text.erb@@ -26,8 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.See COPYRIGHT and LICENSE files for more details.++#%>-<% if @user.auth_source %>- <%= t(:mail_body_account_information_external, value: @user.auth_source.name) %>+<% if @user.ldap_auth_source %>+ <%= t(:mail_body_account_information_external, value: @user.ldap_auth_source.name) %><% else %><%= t(:mail_body_account_information) %>:* <%= User.human_attribute_name(:login) %>: <%= @user.login %>diff --git a/app/views/users/_general.html.erb b/app/views/users/_general.html.erbindex fdaf74b289d..a0d23762032 100644--- a/app/views/users/_general.html.erb+++ b/app/views/users/_general.html.erb@@ -49,7 +49,7 @@ See COPYRIGHT and LICENSE files for more details.data: {controller: 'admin--users','application-target': 'dynamic',- 'admin--users-password-auth-selected-value': @user.auth_source_id.blank?,+ 'admin--users-password-auth-selected-value': @user.ldap_auth_source_id.blank?,},as: :user do |f| %><%= render partial: 'form', locals: { f: f } %>diff --git a/app/views/users/form/authentication/_auth_source.html.erb b/app/views/users/form/authentication/_auth_source.html.erbindex 8f49d4ca3cd..ec63ba734db 100644--- a/app/views/users/form/authentication/_auth_source.html.erb+++ b/app/views/users/form/authentication/_auth_source.html.erb@@ -1,11 +1,11 @@<% if can_users_have_auth_source? %><div class="form--field">- <%= f.collection_select :auth_source_id,- AuthSource.all,+ <%= f.collection_select :ldap_auth_source_id,+ LdapAuthSource.all,:id,:name,{- label: :'activerecord.attributes.user.auth_source',+ label: :'activerecord.attributes.user.ldap_auth_source',container_class: '-middle',include_blank: t(:label_internal)},diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erbindex edd1e0ec48f..2660681a34c 100644--- a/app/views/users/new.html.erb+++ b/app/views/users/new.html.erb@@ -40,7 +40,7 @@ See COPYRIGHT and LICENSE files for more details.data: {controller: 'admin--users','application-target': 'dynamic',- 'admin--users-password-auth-selected-value': @user.auth_source_id.blank?,+ 'admin--users-password-auth-selected-value': @user.ldap_auth_source_id.blank?,},as: :user do |f| %><%= render partial: 'simple_form', locals: { f: f, auth_sources: @auth_sources, user: @user } %>diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 9ed171b9e54..24052fad8f4 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -624,7 +624,7 @@ en:color: "Color"user:admin: "Administrator"- auth_source: "Authentication mode"+ ldap_auth_source: "Authentication mode"current_password: "Current password"force_password_change: "Enforce password change on next login"language: "Language"diff --git a/config/routes.rb b/config/routes.rbindex a01fb72da39..1b53e7197d7 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -383,7 +383,7 @@ OpenProject::Application.routes.draw doendend- resources :auth_sources, :ldap_auth_sources do+ resources :ldap_auth_sources domember doget :test_connectionenddiff --git a/db/migrate/20180419061910_timestamp_for_caching.rb b/db/migrate/20180419061910_timestamp_for_caching.rbindex 18734869b61..dfe8d1ec8f3 100644--- a/db/migrate/20180419061910_timestamp_for_caching.rb+++ b/db/migrate/20180419061910_timestamp_for_caching.rb@@ -27,8 +27,12 @@#++class TimestampForCaching < ActiveRecord::Migration[5.1]+ class MigratingAuthSource < ApplicationRecord+ self.table_name = 'auth_sources'+ end+def change- [Enumeration, Status, Category, AuthSource].each do |model|+ [Enumeration, Status, Category, MigratingAuthSource].each do |model|add_timestamps(model)endenddiff --git a/db/migrate/20190227163226_add_tls_mode_to_auth_sources.rb b/db/migrate/20190227163226_add_tls_mode_to_auth_sources.rbindex 107f37c8084..e09d021b413 100644--- a/db/migrate/20190227163226_add_tls_mode_to_auth_sources.rb+++ b/db/migrate/20190227163226_add_tls_mode_to_auth_sources.rb@@ -27,18 +27,22 @@#++class AddTlsModeToAuthSources < ActiveRecord::Migration[5.2]+ class MigratingAuthSource < ApplicationRecord+ self.table_name = 'auth_sources'+ end+def changeadd_column :auth_sources, :tls_mode, :integer, default: 0, null: false- LdapAuthSource.reset_column_information+ MigratingAuthSource.reset_column_informationreversible do |dir|dir.up do- LdapAuthSource.where(tls: true).update_all(tls_mode: 1)+ MigratingAuthSource.where(tls: true).update_all(tls_mode: 1)enddir.down do- LdapAuthSource.where(tls_mode: 0).update_all(tls: false)- LdapAuthSource.where(tls_mode: 1).update_all(tls: true)+ MigratingAuthSource.where(tls_mode: 0).update_all(tls: false)+ MigratingAuthSource.where(tls_mode: 1).update_all(tls: true)endenddiff --git a/db/migrate/20221026132134_bigint_primary_and_foreign_keys.rb b/db/migrate/20221026132134_bigint_primary_and_foreign_keys.rbindex 7ccd93dcc00..bc849632548 100644--- a/db/migrate/20221026132134_bigint_primary_and_foreign_keys.rb+++ b/db/migrate/20221026132134_bigint_primary_and_foreign_keys.rb@@ -35,7 +35,7 @@ class BigintPrimaryAndForeignKeys < ActiveRecord::Migration[7.0]Journal::AttachmentJournal => %i[id container_id author_id],Attachment => %i[id container_id author_id],AttributeHelpText => [:id],- AuthSource => [:id],+ :auth_sources => [:id],Journal::BudgetJournal => %i[id project_id author_id],Budget => %i[id project_id author_id],Category => %i[id project_id assigned_to_id],diff --git a/db/migrate/20221115082403_add_ldap_tls_options.rb b/db/migrate/20221115082403_add_ldap_tls_options.rbindex cc9a6cef456..f0005f9e00e 100644--- a/db/migrate/20221115082403_add_ldap_tls_options.rb+++ b/db/migrate/20221115082403_add_ldap_tls_options.rb@@ -27,6 +27,10 @@#++class AddLdapTlsOptions < ActiveRecord::Migration[7.0]+ class MigratingAuthSource < ApplicationRecord+ self.table_name = 'auth_sources'+ end+def changechange_table :auth_sources, bulk: true do |t|t.boolean :verify_peer, default: true, null: false@@ -36,10 +40,10 @@ class AddLdapTlsOptions < ActiveRecord::Migration[7.0]reversible do |dir|dir.up do# Current LDAP library default is to not verify the certificate- LdapAuthSource.reset_column_information+ MigratingAuthSource.reset_column_informationldap_settings = (Setting.ldap_tls_options || {}).with_indifferent_accessverify_peer = ldap_settings[:verify_mode] == OpenSSL::SSL::VERIFY_PEER- LdapAuthSource.update_all(verify_peer:)+ MigratingAuthSource.update_all(verify_peer:)endendenddiff --git a/db/migrate/20230726061920_rename_auth_source_to_ldap_auth_source.rb b/db/migrate/20230726061920_rename_auth_source_to_ldap_auth_source.rbnew file mode 100644index 00000000000..444a0e11c89--- /dev/null+++ b/db/migrate/20230726061920_rename_auth_source_to_ldap_auth_source.rb@@ -0,0 +1,8 @@+class RenameAuthSourceToLdapAuthSource < ActiveRecord::Migration[7.0]+ def change+ rename_table :auth_sources, :ldap_auth_sources+ rename_column :users, :auth_source_id, :ldap_auth_source_id+ rename_column :ldap_groups_synchronized_groups, :auth_source_id, :ldap_auth_source_id+ rename_column :ldap_groups_synchronized_filters, :auth_source_id, :ldap_auth_source_id+ end+enddiff --git a/docs/api/apiv3/tags/users.yml b/docs/api/apiv3/tags/users.ymlindex eaad6c4f4c4..9a1eabdcfc8 100644--- a/docs/api/apiv3/tags/users.yml+++ b/docs/api/apiv3/tags/users.yml@@ -15,7 +15,7 @@ description: |-| Link | Description | Type | Constraints | Supported operations | Condition ||:-----------:|-------------------------------------------------------------- | ------------- | --------------------- | -------------------- | ----------------------------------------- || self | This user | User | not null | READ | |- | auth_source | Link to the user's auth source (endpoint not yet implemented) | AuthSource | | READ / WRITE | **Permission**: Administrator |+ | auth_source | Link to the user's auth source (endpoint not yet implemented) | LdapAuthSource | | READ / WRITE | **Permission**: Administrator || members | Link to collection of all the user's memberships. The list will only include the memberships in projects in which the requesting user has the necessary permissions. | MemberCollection | | READ | **Permission**: view members or manage members in any project |Depending on custom fields defined for users, additional links might exist.diff --git a/docs/development/kerberos/README.md b/docs/development/kerberos/README.mdindex 1bb1172da75..1fb5764192d 100644--- a/docs/development/kerberos/README.md+++ b/docs/development/kerberos/README.md@@ -215,7 +215,7 @@ This is expected, as there is no `user1` login with an auth source connected. To```rubyauth_source = LdapAuthSource.create! name: 'test', host: 'localhost', attr_login: 'uid'-user = User.create! login: 'user1', firstname: 'user', lastname: 'one', mail: '[email protected]', admin: true, auth_source: auth_source+user = User.create! login: 'user1', firstname: 'user', lastname: 'one', mail: '[email protected]', admin: true, ldap_auth_source: auth_source```diff --git a/lib/api/v3/users/user_representer.rb b/lib/api/v3/users/user_representer.rbindex 56cf94c8a5a..3dbe3c8c7ed 100644--- a/lib/api/v3/users/user_representer.rb+++ b/lib/api/v3/users/user_representer.rb@@ -33,7 +33,7 @@ module APIinclude AvatarHelperextend ::API::V3::Utilities::CustomFieldInjector::RepresenterClass- cached_representer key_parts: %i(auth_source),+ cached_representer key_parts: %i(ldap_auth_source),dependencies: ->(*) {[# For the name rendering@@ -97,11 +97,11 @@ module APIlink :auth_source,cache_if: -> { current_user_is_admin? } do- next unless represented.auth_source+ next unless represented.ldap_auth_source{- href: "/api/v3/auth_sources/#{represented.auth_source_id}",- title: represented.auth_source.name+ href: "/api/v3/auth_sources/#{represented.ldap_auth_source_id}",+ title: represented.ldap_auth_source.name}end@@ -182,17 +182,17 @@ module API}##- # Used while parsing JSON to initialize `auth_source_id` through the given link.+ # Used while parsing JSON to initialize `ldap_auth_source_id` through the given link.def initialize_embedded_links!(data)- auth_source_id = parse_auth_source_id data, "auth_source"+ ldap_auth_source_id = parse_auth_source_id data, "auth_source"- if auth_source_id- auth_source = AuthSource.find_by_unique auth_source_id+ if ldap_auth_source_id+ auth_source = LdapAuthSource.find_by_unique(ldap_auth_source_id) # rubocop:disable Rails/DynamicFindByid = auth_source ? auth_source.id : 0# set id to 0 (as opposed to nil) to produce an auth source not found# error further down the line in the user's base contract- represented.auth_source_id = id+ represented.ldap_auth_source_id = idendenddiff --git a/lib/tasks/ciphering.rake b/lib/tasks/ciphering.rakeindex 30a23da35aa..493f7b62afb 100644--- a/lib/tasks/ciphering.rake+++ b/lib/tasks/ciphering.rake@@ -30,7 +30,7 @@ namespace :db dodesc 'Encrypts SCM and LDAP passwords in the database.'task encrypt: :environment dounless Repository.encrypt_all(:password) &&- AuthSource.encrypt_all(:account_password)+ LdapAuthSource.encrypt_all(:account_password)raise 'Some objects could not be saved after encryption, update was rolled back.'endend@@ -38,7 +38,7 @@ namespace :db dodesc 'Decrypts SCM and LDAP passwords in the database.'task decrypt: :environment dounless Repository.decrypt_all(:password) &&- AuthSource.decrypt_all(:account_password)+ LdapAuthSource.decrypt_all(:account_password)raise 'Some objects could not be saved after decryption, update was rolled back.'endenddiff --git a/modules/ldap_groups/app/components/ldap_groups/synchronized_filters/row_component.rb b/modules/ldap_groups/app/components/ldap_groups/synchronized_filters/row_component.rbindex c78c04f2243..5e1cde0fb7d 100644--- a/modules/ldap_groups/app/components/ldap_groups/synchronized_filters/row_component.rb+++ b/modules/ldap_groups/app/components/ldap_groups/synchronized_filters/row_component.rb@@ -42,7 +42,7 @@ module LdapGroupsenddef auth_source- link_to synchronized_filter.auth_source.name, edit_ldap_auth_source_path(synchronized_filter.auth_source)+ link_to synchronized_filter.ldap_auth_source.name, edit_ldap_auth_source_path(synchronized_filter.ldap_auth_source)enddef groupsdiff --git a/modules/ldap_groups/app/components/ldap_groups/synchronized_groups/row_component.rb b/modules/ldap_groups/app/components/ldap_groups/synchronized_groups/row_component.rbindex 35dfa45cf84..7f4711599b1 100644--- a/modules/ldap_groups/app/components/ldap_groups/synchronized_groups/row_component.rb+++ b/modules/ldap_groups/app/components/ldap_groups/synchronized_groups/row_component.rb@@ -39,8 +39,8 @@ module LdapGroupslink_to synchronized_group.dn, ldap_groups_synchronized_group_path(synchronized_group)end- def auth_source- link_to synchronized_group.auth_source.name, edit_ldap_auth_source_path(synchronized_group.auth_source)+ def ldap_auth_source+ link_to synchronized_group.ldap_auth_source.name, edit_ldap_auth_source_path(synchronized_group.ldap_auth_source)enddef groupdiff --git a/modules/ldap_groups/app/components/ldap_groups/synchronized_groups/table_component.rb b/modules/ldap_groups/app/components/ldap_groups/synchronized_groups/table_component.rbindex be208c2c7f0..7110a560966 100644--- a/modules/ldap_groups/app/components/ldap_groups/synchronized_groups/table_component.rb+++ b/modules/ldap_groups/app/components/ldap_groups/synchronized_groups/table_component.rb@@ -31,7 +31,7 @@module LdapGroupsmodule SynchronizedGroupsclass TableComponent < ::TableComponent- columns :dn, :auth_source, :group, :users, :sync_users+ columns :dn, :ldap_auth_source, :group, :users, :sync_usersdef initial_sort%i[id asc]@@ -64,7 +64,7 @@ module LdapGroupsdef headers[['dn', { caption: ::LdapGroups::SynchronizedGroup.human_attribute_name('dn') }],- ['auth_source', { caption: ::LdapGroups::SynchronizedGroup.human_attribute_name('auth_source') }],+ ['ldap_auth_source', { caption: ::LdapGroups::SynchronizedGroup.human_attribute_name('ldap_auth_source') }],['group', { caption: I18n.t(:label_group) }],['users', { caption: I18n.t(:label_user_plural) }],['sync_users', { caption: ::LdapGroups::SynchronizedFilter.human_attribute_name('sync_users') }]diff --git a/modules/ldap_groups/app/controllers/ldap_groups/synchronized_filters_controller.rb b/modules/ldap_groups/app/controllers/ldap_groups/synchronized_filters_controller.rbindex 30127996d4d..fc1008019a9 100644--- a/modules/ldap_groups/app/controllers/ldap_groups/synchronized_filters_controller.rb+++ b/modules/ldap_groups/app/controllers/ldap_groups/synchronized_filters_controller.rb@@ -87,7 +87,7 @@ module LdapGroupsdef permitted_paramsparams.require(:synchronized_filter)- .permit(:filter_string, :name, :auth_source_id, :group_name_attribute, :sync_users, :base_dn)+ .permit(:filter_string, :name, :ldap_auth_source_id, :group_name_attribute, :sync_users, :base_dn)enddef default_breadcrumbdiff --git a/modules/ldap_groups/app/controllers/ldap_groups/synchronized_groups_controller.rb b/modules/ldap_groups/app/controllers/ldap_groups/synchronized_groups_controller.rbindex d68ea70eaa9..eb577d4040c 100644--- a/modules/ldap_groups/app/controllers/ldap_groups/synchronized_groups_controller.rb+++ b/modules/ldap_groups/app/controllers/ldap_groups/synchronized_groups_controller.rb@@ -9,8 +9,8 @@ module LdapGroupsinclude PaginationHelperdef index- @groups = SynchronizedGroup.includes(:auth_source, :group)- @filters = SynchronizedFilter.includes(:auth_source, :groups)+ @groups = SynchronizedGroup.includes(:ldap_auth_source, :group)+ @filters = SynchronizedFilter.includes(:ldap_auth_source, :groups)enddef new@@ -66,7 +66,7 @@ module LdapGroupsdef permitted_paramsparams.require(:synchronized_group)- .permit(:dn, :group_id, :auth_source_id, :sync_users)+ .permit(:dn, :group_id, :ldap_auth_source_id, :sync_users)enddef default_breadcrumbdiff --git a/modules/ldap_groups/app/models/ldap_groups/synchronized_filter.rb b/modules/ldap_groups/app/models/ldap_groups/synchronized_filter.rbindex c91e3db6197..b0e5564be45 100644--- a/modules/ldap_groups/app/models/ldap_groups/synchronized_filter.rb+++ b/modules/ldap_groups/app/models/ldap_groups/synchronized_filter.rb@@ -3,7 +3,7 @@ require 'net/ldap/dn'module LdapGroupsclass SynchronizedFilter < ApplicationRecord- belongs_to :auth_source+ belongs_to :ldap_auth_sourcehas_many :groups,class_name: '::LdapGroups::SynchronizedGroup',@@ -11,7 +11,7 @@ module LdapGroupsdependent: :destroyvalidates_presence_of :filter_string- validates_presence_of :auth_source+ validates_presence_of :ldap_auth_sourcevalidate :validate_filter_syntaxvalidate :validate_base_dn@@ -20,7 +20,7 @@ module LdapGroupsenddef used_base_dn- base_dn.presence || auth_source.base_dn+ base_dn.presence || ldap_auth_source.base_dnendprivate@@ -32,9 +32,9 @@ module LdapGroupsenddef validate_base_dn- return unless base_dn.present? && auth_source.present?+ return unless base_dn.present? && ldap_auth_source.present?- unless base_dn.end_with?(auth_source.base_dn)+ unless base_dn.end_with?(ldap_auth_source.base_dn)errors.add :base_dn, :must_contain_base_dnendenddiff --git a/modules/ldap_groups/app/models/ldap_groups/synchronized_group.rb b/modules/ldap_groups/app/models/ldap_groups/synchronized_group.rbindex 48145feb0d9..dbcd0be5a89 100644--- a/modules/ldap_groups/app/models/ldap_groups/synchronized_group.rb+++ b/modules/ldap_groups/app/models/ldap_groups/synchronized_group.rb@@ -5,7 +5,7 @@ module LdapGroupsclass SynchronizedGroup < ApplicationRecordbelongs_to :group- belongs_to :auth_source+ belongs_to :ldap_auth_sourcebelongs_to :filter,class_name: '::LdapGroups::SynchronizedFilter'@@ -18,7 +18,7 @@ module LdapGroupsvalidates_presence_of :dnvalidates_presence_of :groupvalidates_associated :group- validates_presence_of :auth_source+ validates_presence_of :ldap_auth_sourcebefore_destroy :remove_all_membersdiff --git a/modules/ldap_groups/app/services/ldap_groups/synchronization_service.rb b/modules/ldap_groups/app/services/ldap_groups/synchronization_service.rbindex cbbdf535885..0becf5dc056 100644--- a/modules/ldap_groups/app/services/ldap_groups/synchronization_service.rb+++ b/modules/ldap_groups/app/services/ldap_groups/synchronization_service.rb@@ -10,7 +10,7 @@ module LdapGroupsLdapAuthSource.find_each do |ldap|Rails.logger.info { "[LDAP groups] Retrieving groups from filters for ldap auth source #{ldap.name}" }LdapGroups::SynchronizedFilter- .where(auth_source_id: ldap.id)+ .where(ldap_auth_source_id: ldap.id).find_each do |filter|LdapGroups::SynchronizeFilterService.new(filter)diff --git a/modules/ldap_groups/app/services/ldap_groups/synchronize_filter_service.rb b/modules/ldap_groups/app/services/ldap_groups/synchronize_filter_service.rbindex 62380f1c2e2..2010d084764 100644--- a/modules/ldap_groups/app/services/ldap_groups/synchronize_filter_service.rb+++ b/modules/ldap_groups/app/services/ldap_groups/synchronize_filter_service.rb@@ -47,7 +47,7 @@ module LdapGroups# Find groups by the filter string# and yield them one by onedef each_group- ldap = filter.auth_source+ ldap = filter.ldap_auth_sourceldap.with_connection do |ldap_con|search(filter, ldap_con) do |entry|yield entry.dn, LdapAuthSource.get_attr(entry, filter.group_name_attribute)@@ -74,7 +74,7 @@ module LdapGroups# Always set the filter and auth source, in case multiple filters match the same group# they are simply being re-assigned to the latest onesync.filter_id = filter.id- sync.auth_source_id = filter.auth_source_id+ sync.ldap_auth_source_id = filter.ldap_auth_source_id# Tell the group to synchronize users if the filter has requested it tosync.sync_users = filter.sync_usersdiff --git a/modules/ldap_groups/app/services/ldap_groups/synchronize_groups_service.rb b/modules/ldap_groups/app/services/ldap_groups/synchronize_groups_service.rbindex fc82946d602..3de04be8196 100644--- a/modules/ldap_groups/app/services/ldap_groups/synchronize_groups_service.rb+++ b/modules/ldap_groups/app/services/ldap_groups/synchronize_groups_service.rb@@ -6,7 +6,7 @@ module LdapGroups@ldap = ldap# Get current synced groups in OP- @synced_groups = ::LdapGroups::SynchronizedGroup.where(auth_source: ldap)+ @synced_groups = ::LdapGroups::SynchronizedGroup.where(ldap_auth_source: ldap)enddef calldiff --git a/modules/ldap_groups/app/views/ldap_groups/synchronized_filters/_form.html.erb b/modules/ldap_groups/app/views/ldap_groups/synchronized_filters/_form.html.erbindex b8c905f56c6..59c1e7987d4 100644--- a/modules/ldap_groups/app/views/ldap_groups/synchronized_filters/_form.html.erb+++ b/modules/ldap_groups/app/views/ldap_groups/synchronized_filters/_form.html.erb@@ -32,7 +32,7 @@<legend class="form--fieldset-legend"><%= @filter.class.human_attribute_name :auth_source %></legend><div class="form--field -required">- <%= f.select :auth_source_id,+ <%= f.select :ldap_auth_source_id,LdapAuthSource.pluck(:name, :id),required: true,include_blank: "--- #{t(:actionview_instancetag_blank_option)} ---",diff --git a/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/new.html.erb b/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/new.html.erbindex 1ccba454302..74ca579a3b9 100644--- a/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/new.html.erb+++ b/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/new.html.erb@@ -13,7 +13,7 @@<legend class="form--fieldset-legend"><%= @group.class.human_attribute_name 'auth_source' %></legend><div class="form--field -required">- <%= f.select :auth_source_id,+ <%= f.select :ldap_auth_source_id,LdapAuthSource.pluck(:name, :id),required: true,include_blank: "--- #{t(:actionview_instancetag_blank_option)} ---",diff --git a/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/show.html.erb b/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/show.html.erbindex 48e0303cb5e..06c3b5b6f4a 100644--- a/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/show.html.erb+++ b/modules/ldap_groups/app/views/ldap_groups/synchronized_groups/show.html.erb@@ -13,7 +13,7 @@value: @group.sync_users ? checked_image(@group.sync_users) : t(:general_text_no))component.with_attribute(key: @group.class.human_attribute_name(:auth_source),- value: link_to(@group.auth_source.name, edit_ldap_auth_source_path(@group.auth_source)))+ value: link_to(@group.ldap_auth_source.name, edit_ldap_auth_source_path(@group.ldap_auth_source)))component.with_attribute(key: @group.class.human_attribute_name(:group),value: link_to(@group.group, edit_group_path(@group.group)))diff --git a/modules/ldap_groups/config/locales/en.yml b/modules/ldap_groups/config/locales/en.ymlindex f24e7bbc03b..9399786d4f4 100644--- a/modules/ldap_groups/config/locales/en.yml+++ b/modules/ldap_groups/config/locales/en.yml@@ -3,11 +3,11 @@ en:attributes:ldap_groups/synchronized_group:dn: 'DN'- auth_source: 'LDAP connection'+ ldap_auth_source: 'LDAP connection'sync_users: 'Sync users'ldap_groups/synchronized_filter:filter_string: 'LDAP filter'- auth_source: 'LDAP connection'+ ldap_auth_source: 'LDAP connection'group_name_attribute: "Group name attribute"sync_users: 'Sync users'base_dn: "Search base DN"diff --git a/modules/ldap_groups/db/migrate/20210219092709_move_base_dn_into_filters.rb b/modules/ldap_groups/db/migrate/20210219092709_move_base_dn_into_filters.rbindex 2e45f1ae8c1..c33846cd79f 100644--- a/modules/ldap_groups/db/migrate/20210219092709_move_base_dn_into_filters.rb+++ b/modules/ldap_groups/db/migrate/20210219092709_move_base_dn_into_filters.rb@@ -27,6 +27,10 @@#++class MoveBaseDnIntoFilters < ActiveRecord::Migration[6.1]+ class MigratingAuthSource < ApplicationRecord+ self.table_name = 'auth_sources'+ end+def changeadd_column :ldap_groups_synchronized_filters, :base_dn, :text, null: true@@ -49,15 +53,15 @@ class MoveBaseDnIntoFilters < ActiveRecord::Migration[6.1]# Take over the connection's onthefly setting# for whether to sync users for filters and groups- LdapAuthSource+ MigratingAuthSource.pluck(:id, :onthefly_register).each do |id, onthefly|LdapGroups::SynchronizedFilter- .where(auth_source_id: id)+ .where(ldap_auth_source_id: id).update_all(sync_users: onthefly)LdapGroups::SynchronizedGroup- .where(auth_source_id: id)+ .where(ldap_auth_source_id: id).update_all(sync_users: onthefly)endenddiff --git a/modules/ldap_groups/lib/open_project/ldap_groups/engine.rb b/modules/ldap_groups/lib/open_project/ldap_groups/engine.rbindex 1a2795ad3fd..e462c7464ea 100644--- a/modules/ldap_groups/lib/open_project/ldap_groups/engine.rb+++ b/modules/ldap_groups/lib/open_project/ldap_groups/engine.rb@@ -21,6 +21,6 @@ module OpenProject::LdapGroupsadd_cron_jobs { LdapGroups::SynchronizationJob }- patches %i[AuthSource Group User]+ patches %i[LdapAuthSource Group User]endenddiff --git a/modules/ldap_groups/lib/open_project/ldap_groups/patches/auth_source_patch.rb b/modules/ldap_groups/lib/open_project/ldap_groups/patches/ldap_auth_source_patch.rbsimilarity index 90%rename from modules/ldap_groups/lib/open_project/ldap_groups/patches/auth_source_patch.rbrename to modules/ldap_groups/lib/open_project/ldap_groups/patches/ldap_auth_source_patch.rbindex 53dbb986431..c8effc02dd5 100644--- a/modules/ldap_groups/lib/open_project/ldap_groups/patches/auth_source_patch.rb+++ b/modules/ldap_groups/lib/open_project/ldap_groups/patches/ldap_auth_source_patch.rb@@ -1,6 +1,6 @@module OpenProject::LdapGroupsmodule Patches- module AuthSourcePatch+ module LdapAuthSourcePatchdef self.included(base) # :nodoc:base.class_eval dohas_many :ldap_groups_synchronized_groups,diff --git a/modules/ldap_groups/spec/controllers/synchronized_groups_controller_spec.rb b/modules/ldap_groups/spec/controllers/synchronized_groups_controller_spec.rbindex edfb6063b6b..51d0eb64750 100644--- a/modules/ldap_groups/spec/controllers/synchronized_groups_controller_spec.rb+++ b/modules/ldap_groups/spec/controllers/synchronized_groups_controller_spec.rb@@ -122,7 +122,7 @@ RSpec.describe LdapGroups::SynchronizedGroupsController, with_ee: %i[ldap_groupsendcontext 'with valid params' do- let(:params) { { auth_source_id: 1, group_id: 1, dn: 'cn=foo,ou=groups,dc=example,dc=com' } }+ let(:params) { { ldap_auth_source_id: 1, group_id: 1, dn: 'cn=foo,ou=groups,dc=example,dc=com' } }context 'and saving succeeds' dolet(:save_result) { true }diff --git a/modules/ldap_groups/spec/factories/synchronized_filter_factory.rb b/modules/ldap_groups/spec/factories/synchronized_filter_factory.rbindex 660cb0f9d02..9c17156c117 100644--- a/modules/ldap_groups/spec/factories/synchronized_filter_factory.rb+++ b/modules/ldap_groups/spec/factories/synchronized_filter_factory.rb@@ -4,7 +4,7 @@ FactoryBot.define dofilter_string { '(|(cn=foo)(cn=bar))' }group_name_attribute { 'cn' }base_dn { 'dc=example,dc=com' }- auth_source factory: :ldap_auth_source+ ldap_auth_sourcesync_users { true }endenddiff --git a/modules/ldap_groups/spec/factories/synchronized_group_factory.rb b/modules/ldap_groups/spec/factories/synchronized_group_factory.rbindex bab7846d7e7..9cf539f327f 100644--- a/modules/ldap_groups/spec/factories/synchronized_group_factory.rb+++ b/modules/ldap_groups/spec/factories/synchronized_group_factory.rb@@ -2,7 +2,7 @@ FactoryBot.define dofactory :ldap_synchronized_group, class: '::LdapGroups::SynchronizedGroup' dodn { 'cn=foo,ou=groups,dc=example,dc=com' }group factory: :group- auth_source factory: :ldap_auth_source+ ldap_auth_sourcesync_users { true }endenddiff --git a/modules/ldap_groups/spec/features/administration_spec.rb b/modules/ldap_groups/spec/features/administration_spec.rbindex 5113d940c77..0ed808dff07 100644--- a/modules/ldap_groups/spec/features/administration_spec.rb+++ b/modules/ldap_groups/spec/features/administration_spec.rb@@ -25,7 +25,7 @@ RSpec.describe 'LDAP group sync administration spec', js: true dofind('.button', text: I18n.t('ldap_groups.synchronized_groups.singular')).clickSeleniumHubWaiter.wait- select 'ldap', from: 'synchronized_group_auth_source_id'+ select 'ldap', from: 'synchronized_group_ldap_auth_source_id'select 'foo', from: 'synchronized_group_group_id'fill_in 'synchronized_group_dn', with: 'cn=foo,ou=groups,dc=example,dc=com'check 'synchronized_group_sync_users'@@ -33,7 +33,7 @@ RSpec.describe 'LDAP group sync administration spec', js: true doclick_on 'Create'expect(page).to have_selector('.op-toast.-success', text: I18n.t(:notice_successful_create))expect(page).to have_selector('td.dn', text: 'cn=foo,ou=groups,dc=example,dc=com')- expect(page).to have_selector('td.auth_source', text: 'ldap')+ expect(page).to have_selector('td.ldap_auth_source', text: 'ldap')expect(page).to have_selector('td.group', text: 'foo')expect(page).to have_selector('td.users', text: '0')@@ -45,7 +45,7 @@ RSpec.describe 'LDAP group sync administration spec', js: true do# Check created groupsync = LdapGroups::SynchronizedGroup.lastexpect(sync.group_id).to eq(group.id)- expect(sync.auth_source_id).to eq(auth_source.id)+ expect(sync.ldap_auth_source_id).to eq(auth_source.id)expect(sync.dn).to eq 'cn=foo,ou=groups,dc=example,dc=com'# Assume we have a membershipdiff --git a/modules/ldap_groups/spec/models/synchronized_filter_spec.rb b/modules/ldap_groups/spec/models/synchronized_filter_spec.rbindex 7dead83d118..0ddbd2b0abd 100644--- a/modules/ldap_groups/spec/models/synchronized_filter_spec.rb+++ b/modules/ldap_groups/spec/models/synchronized_filter_spec.rb@@ -2,21 +2,21 @@ require 'spec_helper'RSpec.describe LdapGroups::SynchronizedFilter dodescribe '#used_base_dn' do- let(:auth_source) { build(:ldap_auth_source, base_dn: 'dc=example,dc=com') }- let(:filter) { build(:ldap_synchronized_filter, auth_source:) }+ let(:ldap_auth_source) { build(:ldap_auth_source, base_dn: 'dc=example,dc=com') }+ let(:filter) { build(:ldap_synchronized_filter, ldap_auth_source:) }- it 'validates the end of the base dn matches the auth_source' do+ it 'validates the end of the base dn matches the ldap_auth_source' dofilter.base_dn = nilexpect(filter.base_dn).to be_nil- expect(filter.used_base_dn).to eq(auth_source.base_dn)+ expect(filter.used_base_dn).to eq(ldap_auth_source.base_dn)endenddescribe '#base_dn' do- let(:auth_source) { build(:ldap_auth_source, base_dn: 'dc=example,dc=com') }- let(:filter) { build(:ldap_synchronized_filter, auth_source:) }+ let(:ldap_auth_source) { build(:ldap_auth_source, base_dn: 'dc=example,dc=com') }+ let(:filter) { build(:ldap_synchronized_filter, ldap_auth_source:) }- it 'validates the end of the base dn matches the auth_source' do+ it 'validates the end of the base dn matches the ldap_auth_source' dofilter.base_dn = nilexpect(filter).to be_validdiff --git a/modules/ldap_groups/spec/models/synchronized_group_spec.rb b/modules/ldap_groups/spec/models/synchronized_group_spec.rbindex d9475dde697..4605b8909f4 100644--- a/modules/ldap_groups/spec/models/synchronized_group_spec.rb+++ b/modules/ldap_groups/spec/models/synchronized_group_spec.rb@@ -16,7 +16,7 @@ RSpec.describe LdapGroups::SynchronizedGroup doit 'validates missing attributes' doexpect(subject.save).to be falseexpect(subject.errors[:dn]).to include "can't be blank."- expect(subject.errors[:auth_source]).to include "can't be blank."+ expect(subject.errors[:ldap_auth_source]).to include "can't be blank."expect(subject.errors[:group]).to include "can't be blank."endenddiff --git a/modules/ldap_groups/spec/services/synchronization_spec.rb b/modules/ldap_groups/spec/services/synchronization_spec.rbindex 32684166d4c..af4f4fb75d8 100644--- a/modules/ldap_groups/spec/services/synchronization_spec.rb+++ b/modules/ldap_groups/spec/services/synchronization_spec.rb@@ -11,7 +11,7 @@ RSpec.describe LdapGroups::SynchronizeGroupsService, with_ee: %i[ldap_groups] do# Ldap has:# three users aa729, bb459, cc414# two groups foo (aa729), bar(aa729, bb459, cc414)- let(:auth_source) do+ let(:ldap_auth_source) docreate(:ldap_auth_source,port: ParallelHelper.port_for_ldap.to_s,account: 'uid=admin,ou=system',@@ -29,9 +29,9 @@ RSpec.describe LdapGroups::SynchronizeGroupsService, with_ee: %i[ldap_groups] dolet(:sync_users) { false }let(:ldap_filter) { nil }- let(:user_aa729) { create(:user, login: 'aa729', auth_source:) }- let(:user_bb459) { create(:user, login: 'bb459', auth_source:) }- let(:user_cc414) { create(:user, login: 'cc414', auth_source:) }+ let(:user_aa729) { create(:user, login: 'aa729', ldap_auth_source:) }+ let(:user_bb459) { create(:user, login: 'bb459', ldap_auth_source:) }+ let(:user_cc414) { create(:user, login: 'cc414', ldap_auth_source:) }let(:group_foo) { create(:group, lastname: 'foo_internal') }let(:group_bar) { create(:group, lastname: 'bar') }@@ -41,20 +41,20 @@ RSpec.describe LdapGroups::SynchronizeGroupsService, with_ee: %i[ldap_groups] dodn: 'cn=foo,ou=groups,dc=example,dc=com',group: group_foo,sync_users:,- auth_source:)+ ldap_auth_source:)endlet(:synced_bar) docreate(:ldap_synchronized_group,dn: 'cn=bar,ou=groups,dc=example,dc=com',group: group_bar,sync_users:,- auth_source:)+ ldap_auth_source:)endsubject do# Need the system user for admin permissionUser.system.run_given do- described_class.new(auth_source).call+ described_class.new(ldap_auth_source).callendend@@ -141,7 +141,7 @@ RSpec.describe LdapGroups::SynchronizeGroupsService, with_ee: %i[ldap_groups] doendit 'removes all memberships and groups after removing auth source' do- expect { auth_source.destroy! }+ expect { ldap_auth_source.destroy! }.to change { LdapGroups::Membership.count }.from(4).to(0)expect { synced_foo.reload }.to raise_error ActiveRecord::RecordNotFound@@ -332,7 +332,7 @@ RSpec.describe LdapGroups::SynchronizeGroupsService, with_ee: %i[ldap_groups] doendcontext 'with invalid connection' do- let(:auth_source) { create(:ldap_auth_source) }+ let(:ldap_auth_source) { create(:ldap_auth_source) }before dosynced_foo@@ -351,11 +351,11 @@ RSpec.describe LdapGroups::SynchronizeGroupsService, with_ee: %i[ldap_groups] docontext 'with invalid base' dolet(:synced_foo) docreate(:ldap_synchronized_group, dn: 'cn=foo,ou=invalid,dc=example,dc=com', group: group_foo,- auth_source:)+ ldap_auth_source:)endlet(:synced_bar) docreate(:ldap_synchronized_group, dn: 'cn=bar,ou=invalid,dc=example,dc=com', group: group_bar,- auth_source:)+ ldap_auth_source:)endcontext 'when one synced group exists' dodiff --git a/modules/ldap_groups/spec/services/synchronize_filter_spec.rb b/modules/ldap_groups/spec/services/synchronize_filter_spec.rbindex 07a7156ae1e..08022540f09 100644--- a/modules/ldap_groups/spec/services/synchronize_filter_spec.rb+++ b/modules/ldap_groups/spec/services/synchronize_filter_spec.rb@@ -15,7 +15,7 @@ RSpec.describe LdapGroups::SynchronizeFilterService, with_ee: %i[ldap_groups] do# Ldap has:# three users aa729, bb459, cc414# two groups foo (aa729), bar(aa729, bb459, cc414)- let(:auth_source) do+ let(:ldap_auth_source) docreate(:ldap_auth_source,port: ParallelHelper.port_for_ldap.to_s,account: 'uid=admin,ou=system',@@ -32,7 +32,7 @@ RSpec.describe LdapGroups::SynchronizeFilterService, with_ee: %i[ldap_groups] do:ldap_synchronized_group,dn: 'cn=foo,ou=groups,dc=example,dc=com',group: group_foo,- auth_source:+ ldap_auth_source:)endlet(:synced_bar) do@@ -40,11 +40,11 @@ RSpec.describe LdapGroups::SynchronizeFilterService, with_ee: %i[ldap_groups] do:ldap_synchronized_group,dn: 'cn=bar,ou=groups,dc=example,dc=com',group: group_bar,- auth_source:+ ldap_auth_source:)end- let(:filter_foo_bar) { create(:ldap_synchronized_filter, auth_source:) }+ let(:filter_foo_bar) { create(:ldap_synchronized_filter, ldap_auth_source:) }subject { described_class.new(filter_foo_bar).call }@@ -97,12 +97,12 @@ RSpec.describe LdapGroups::SynchronizeFilterService, with_ee: %i[ldap_groups] dodn: 'cn=foo,ou=groups,dc=example,dc=com',group: group_foo,sync_users: false,- auth_source:)+ ldap_auth_source:)endlet(:filter_foo_bar) docreate(:ldap_synchronized_filter,sync_users: true,- auth_source:)+ ldap_auth_source:)endbefore do@@ -125,7 +125,7 @@ RSpec.describe LdapGroups::SynchronizeFilterService, with_ee: %i[ldap_groups] dodn: 'cn=doesnotexist,ou=groups,dc=example,dc=com',group: group_doesnotexist,filter: filter_foo_bar,- auth_source:)+ ldap_auth_source:)endit 'removes that group' do@@ -135,7 +135,7 @@ RSpec.describe LdapGroups::SynchronizeFilterService, with_ee: %i[ldap_groups] doenddescribe 'when filter has sync_users selected' do- let(:filter_foo_bar) { create(:ldap_synchronized_filter, auth_source:, sync_users: true) }+ let(:filter_foo_bar) { create(:ldap_synchronized_filter, ldap_auth_source:, sync_users: true) }it 'creates the groups with sync_users flag set' doexpect { subject }.not_to raise_error@@ -154,7 +154,7 @@ RSpec.describe LdapGroups::SynchronizeFilterService, with_ee: %i[ldap_groups] dodescribe 'when filter has its own base dn' dolet(:filter_foo_bar) docreate(:ldap_synchronized_filter,- auth_source:,+ ldap_auth_source:,base_dn: 'ou=users,dc=example,dc=com')enddiff --git a/modules/two_factor_authentication/spec/models/user_spec.rb b/modules/two_factor_authentication/spec/models/user_spec.rbindex d6a15efa574..c1a81cfa1d4 100644--- a/modules/two_factor_authentication/spec/models/user_spec.rb+++ b/modules/two_factor_authentication/spec/models/user_spec.rb@@ -3,17 +3,17 @@ require_relative '../spec_helper'module OpenProject::TwoFactorAuthentication::Patchesmodule UserSpecRSpec.describe User do- def create_user(auth_source_id = nil)+ def create_user(ldap_auth_source_id = nil)@user = build(:user)@username = @user.login@password = @user.password- @user.auth_source_id = auth_source_id+ @user.ldap_auth_source_id = ldap_auth_source_id@user.save!allow_any_instance_of(User).to receive_messages(allowed_to?: true, active?: true)enddef create_user_with_auth_source- auth_source = AuthSource.new name: "test"+ auth_source = LdapAuthSource.new name: "test"create_user auth_source.idenddiff --git a/spec/contracts/users/shared_contract_examples.rb b/spec/contracts/users/shared_contract_examples.rbindex 28aa871d8eb..60ebc7b724c 100644--- a/spec/contracts/users/shared_contract_examples.rb+++ b/spec/contracts/users/shared_contract_examples.rb@@ -65,11 +65,11 @@ RSpec.shared_examples_for 'user contract' doenddescribe 'can set the auth_source' do- let!(:auth_source) { create(:auth_source) }+ let!(:auth_source) { create(:ldap_auth_source) }before douser.password = user.password_confirmation = nil- user.auth_source = auth_source+ user.ldap_auth_source = auth_sourceendit_behaves_like 'contract is valid'diff --git a/spec/controllers/account_controller_spec.rb b/spec/controllers/account_controller_spec.rbindex 4a4b4517d41..1c2dde92cac 100644--- a/spec/controllers/account_controller_spec.rb+++ b/spec/controllers/account_controller_spec.rb@@ -219,17 +219,19 @@ RSpec.describe AccountController,let(:auth_source) { create(:ldap_auth_source) }it 'creates the user on the fly' do- allow(AuthSource).to receive(:authenticate).and_return(login: 'foo',- firstname: 'Foo',- lastname: 'Smith',- mail: '[email protected]',- auth_source_id: auth_source.id)+ allow(LdapAuthSource)+ .to(receive(:authenticate))+ .and_return(login: 'foo',+ firstname: 'Foo',+ lastname: 'Smith',+ mail: '[email protected]',+ ldap_auth_source_id: auth_source.id)post :login, params: { username: 'foo', password: 'bar' }expect(response).to redirect_to home_url(first_time_user: true)user = User.find_by(login: 'foo')expect(user).to be_an_instance_of User- expect(user.auth_source_id).to eq(auth_source.id)+ expect(user.ldap_auth_source_id).to eq(auth_source.id)expect(user.current_password).to be_nilendend@@ -438,14 +440,14 @@ RSpec.describe AccountController,firstname: 'Scarlet',lastname: 'Scallywag',mail: '[email protected]',- auth_source_id: auth_source.id+ ldap_auth_source_id: auth_source.id}endlet(:authenticate) { true }before do- allow(AuthSource).to receive(:authenticate).and_return(authenticate ? user_attributes : nil)+ allow(LdapAuthSource).to receive(:authenticate).and_return(authenticate ? user_attributes : nil)# required so that the register view can be renderedallow_any_instance_of(User).to receive(:change_password_allowed?).and_return(false)@@ -867,9 +869,9 @@ RSpec.describe AccountController,with_settings: { self_registration: Setting::SelfRegistration.disabled } dobefore doallow_any_instance_of(User).to receive(:change_password_allowed?).and_return(false)- allow(AuthSource).to receive(:authenticate).and_return(login: 'foo',- lastname: 'Smith',- auth_source_id: 66)+ allow(LdapAuthSource).to receive(:authenticate).and_return(login: 'foo',+ lastname: 'Smith',+ ldap_auth_source_id: 66)endcontext 'with password login enabled' do@@ -894,7 +896,7 @@ RSpec.describe AccountController,user = User.find_by_login('foo')expect(user).to be_an_instance_of(User)- expect(user.auth_source_id).to be 66+ expect(user.ldap_auth_source_id).to be 66expect(user.current_password).to be_nilendend@@ -988,8 +990,8 @@ RSpec.describe AccountController,}end- let(:auth_source) { create(:ldap_auth_source) }- let(:user) { create(:user, status: 2, auth_source:) }+ let(:ldap_auth_source) { create(:ldap_auth_source) }+ let(:user) { create(:user, status: 2, ldap_auth_source:) }let(:login) { user.login }before do@@ -1017,7 +1019,7 @@ RSpec.describe AccountController,endbefore do- allow(AuthSource).to receive(:find_user).and_return attrs+ allow(LdapAuthSource).to receive(:find_user).and_return attrsendit "shows the account creation form with an error" do@@ -1038,7 +1040,7 @@ RSpec.describe AccountController,endbefore do- allow(AuthSource).to receive(:find_user).and_return attrs+ allow(LdapAuthSource).to receive(:find_user).and_return attrsendit "shows the account creation form with an error" dodiff --git a/spec/controllers/auth_sources_controller_spec.rb b/spec/controllers/auth_sources_controller_spec.rbdeleted file mode 100644index 981a5f300c0..00000000000--- a/spec/controllers/auth_sources_controller_spec.rb+++ /dev/null@@ -1,167 +0,0 @@-#-- 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.-#++--require 'spec_helper'--RSpec.describe AuthSourcesController do- let(:current_user) { create(:admin) }-- before do- allow(OpenProject::Configuration).to receive(:disable_password_login?).and_return(false)-- allow(User).to receive(:current).and_return current_user- end-- describe 'index' do- before do- get :index- end-- it { expect(assigns(:auth_source)).to eq @auth_source }- it { is_expected.to respond_with :success }- it { is_expected.to render_template :index }- end-- describe 'new' do- before do- get :new- end-- it { expect(assigns(:auth_source)).not_to be_nil }- it { is_expected.to respond_with :success }- it { is_expected.to render_template :new }-- it 'initializes a new AuthSource' do- expect(assigns(:auth_source).class).to eq(AuthSource)- expect(assigns(:auth_source)).to be_new_record- end- end-- describe 'create' do- before do- post :create, params: { auth_source: { name: 'Test' } }- end-- it { is_expected.to respond_with :redirect }- it { is_expected.to redirect_to auth_sources_path }- it { is_expected.to set_flash.to /success/i }- end-- describe 'edit' do- before do- @auth_source = create(:auth_source, name: 'TestEdit')- get :edit, params: { id: @auth_source.id }- end-- it { expect(assigns(:auth_source)).to eq @auth_source }- it { is_expected.to respond_with :success }- it { is_expected.to render_template :edit }- end-- describe 'update' do- before do- @auth_source = create(:auth_source, name: 'TestEdit')- post :update, params: { id: @auth_source.id, auth_source: { name: 'TestUpdate' } }- end-- it { is_expected.to respond_with :redirect }- it { is_expected.to redirect_to auth_sources_path }- it { is_expected.to set_flash.to /update/i }- end-- describe 'destroy' do- before do- @auth_source = create(:auth_source, name: 'TestEdit')- end-- context 'without users' do- before do- post :destroy, params: { id: @auth_source.id }- end-- it { is_expected.to respond_with :redirect }- it { is_expected.to redirect_to auth_sources_path }- it { is_expected.to set_flash.to /deletion/i }- end-- context 'with users' do- before do- create(:user, auth_source: @auth_source)- post :destroy, params: { id: @auth_source.id }- end-- it { is_expected.to respond_with :redirect }-- it 'doesn not destroy the AuthSource' do- expect(AuthSource.find(@auth_source.id)).not_to be_nil- end- end- end-- context 'with password login disabled' do- before do- allow(OpenProject::Configuration).to receive(:disable_password_login?).and_return(true)- end-- it 'cannot find index' do- get :index-- expect(response.status).to eq 404- end-- it 'cannot find new' do- get :new-- expect(response.status).to eq 404- end-- it 'cannot find create' do- post :create, params: { auth_source: { name: 'Test' } }-- expect(response.status).to eq 404- end-- it 'cannot find edit' do- get :edit, params: { id: 42 }-- expect(response.status).to eq 404- end-- it 'cannot find update' do- post :update, params: { id: 42, auth_source: { name: 'TestUpdate' } }-- expect(response.status).to eq 404- end-- it 'cannot find destroy' do- post :destroy, params: { id: 42 }-- expect(response.status).to eq 404- end- end-enddiff --git a/spec/controllers/concerns/auth_source_slo_spec.rb b/spec/controllers/concerns/auth_source_slo_spec.rbindex 29a1e957998..70dea4f234c 100644--- a/spec/controllers/concerns/auth_source_slo_spec.rb+++ b/spec/controllers/concerns/auth_source_slo_spec.rb@@ -33,7 +33,7 @@ RSpec.describe AccountController, 'Auth header logout' dorender_viewslet!(:auth_source) { DummyAuthSource.create name: "Dummy LDAP" }- let!(:user) { create(:user, login:, auth_source_id: auth_source.id) }+ let!(:user) { create(:user, login:, ldap_auth_source_id: auth_source.id) }let(:login) { "h.wurst" }before dodiff --git a/spec/controllers/concerns/auth_source_sso_spec.rb b/spec/controllers/concerns/auth_source_sso_spec.rbindex 1ffe567fc95..ee768323f3f 100644--- a/spec/controllers/concerns/auth_source_sso_spec.rb+++ b/spec/controllers/concerns/auth_source_sso_spec.rb@@ -42,8 +42,8 @@ RSpec.describe MyController,let(:header) { "X-Remote-User" }let(:secret) { "42" }- let!(:auth_source) { DummyAuthSource.create name: "Dummy LDAP" }- let!(:user) { create(:user, login:, auth_source_id: auth_source.id, last_login_on: 5.days.ago) }+ let!(:ldap_auth_source) { create(:ldap_auth_source) }+ let!(:user) { create(:user, login:, ldap_auth_source:, last_login_on: 5.days.ago) }let(:login) { "h.wurst" }let(:header_login_value) { login }let(:header_value) { "#{header_login_value}#{secret ? ':' : ''}#{secret}" }@@ -131,7 +131,7 @@ RSpec.describe MyController,context 'when the user is invited' dolet!(:user) do- create(:user, login:, status: Principal.statuses[:invited], auth_source_id: auth_source.id)+ create(:user, login:, status: Principal.statuses[:invited], ldap_auth_source:)endit "logs in given user and activate it" do@@ -150,19 +150,19 @@ RSpec.describe MyController,endcontext "with a non-active user user" do- let(:user) { create(:user, login:, auth_source_id: auth_source.id, status: 2) }+ let(:user) { create(:user, login:, ldap_auth_source:, status: 2) }it_behaves_like "auth source sso failure"endcontext "with an invalid user" do- let(:auth_source) { DummyAuthSource.create name: "Onthefly LDAP", onthefly_register: true }+ let(:ldap_auth_source) { create(:ldap_auth_source, onthefly_register: true) }let!(:duplicate) { create(:user, mail: "[email protected]") }let(:login) { "dummy_dupuser" }let(:user) do- build(:user, login:, mail: duplicate.mail, auth_source_id: auth_source.id)+ build(:user, login:, mail: duplicate.mail, ldap_auth_source:)endit_behaves_like "auth source sso failure"diff --git a/spec/controllers/concerns/omniauth_login_spec.rb b/spec/controllers/concerns/omniauth_login_spec.rbindex e8ba08eb976..2a87566c959 100644--- a/spec/controllers/concerns/omniauth_login_spec.rb+++ b/spec/controllers/concerns/omniauth_login_spec.rb@@ -64,7 +64,7 @@ RSpec.describe AccountController,it 'registers the user on-the-fly' douser = User.find_by_login('[email protected]')expect(user).to be_an_instance_of(User)- expect(user.auth_source_id).to be_nil+ expect(user.ldap_auth_source_id).to be_nilexpect(user.current_password).to be_nilexpect(user.identity_url).to eql('google:123545')expect(user.login).to eql('[email protected]')@@ -194,7 +194,7 @@ RSpec.describe AccountController,user = User.find_by_login('[email protected]')expect(user).to be_an_instance_of(User)- expect(user.auth_source_id).to be_nil+ expect(user.ldap_auth_source_id).to be_nilexpect(user.current_password).to be_nilexpect(user.identity_url).to eql('google:123545')enddiff --git a/spec/controllers/ldap_auth_sources_controller_spec.rb b/spec/controllers/ldap_auth_sources_controller_spec.rbindex 5ba8d27aaba..1b3f0c00248 100644--- a/spec/controllers/ldap_auth_sources_controller_spec.rb+++ b/spec/controllers/ldap_auth_sources_controller_spec.rb@@ -32,6 +32,7 @@ RSpec.describe LdapAuthSourcesController dolet(:current_user) { create(:admin) }before do+ allow(OpenProject::Configuration).to receive(:disable_password_login?).and_return(false)allow(User).to receive(:current).and_return current_userend@@ -44,9 +45,123 @@ RSpec.describe LdapAuthSourcesController doit { is_expected.to respond_with :success }it { is_expected.to render_template :new }- it 'initializes a new AuthSource' do+ it 'initializes a new LdapAuthSource' doexpect(assigns(:auth_source).class).to eq LdapAuthSourceexpect(assigns(:auth_source)).to be_new_recordendend++ describe 'index' do+ before do+ get :index+ end++ it { is_expected.to respond_with :success }+ it { is_expected.to render_template :index }+ end++ describe 'create' do+ before do+ post :create, params: { ldap_auth_source: { name: 'Test', host: 'example.com', attr_login: 'foo' } }+ end++ it { is_expected.to respond_with :redirect }+ it { is_expected.to redirect_to ldap_auth_sources_path }+ it { is_expected.to set_flash.to /success/i }+ end++ describe 'edit' do+ let(:ldap) { create(:ldap_auth_source, name: 'TestEdit') }++ before do+ get :edit, params: { id: ldap.id }+ end++ it { expect(assigns(:auth_source)).to eq ldap }+ it { is_expected.to respond_with :success }+ it { is_expected.to render_template :edit }+ end++ describe 'update' do+ let(:ldap) { create(:ldap_auth_source, name: 'TestEdit') }++ before do+ post :update, params: { id: ldap.id, ldap_auth_source: { name: 'TestUpdate' } }+ end++ it { is_expected.to respond_with :redirect }+ it { is_expected.to redirect_to ldap_auth_sources_path }+ it { is_expected.to set_flash.to /update/i }+ end++ describe 'destroy' do+ let(:ldap) { create(:ldap_auth_source, name: 'TestEdit') }++ context 'without users' do+ before do+ post :destroy, params: { id: ldap.id }+ end++ it { is_expected.to respond_with :redirect }+ it { is_expected.to redirect_to ldap_auth_sources_path }+ it { is_expected.to set_flash.to /deletion/i }+ end++ context 'with users' do+ let!(:ldap) { create(:ldap_auth_source, name: 'TestEdit') }+ let!(:user) { create(:user, ldap_auth_source: ldap) }++ before do+ post :destroy, params: { id: ldap.id }+ end++ it { is_expected.to respond_with :redirect }++ it 'does not destroy the LdapAuthSource' do+ expect(LdapAuthSource.find(ldap.id)).not_to be_nil+ end+ end+ end++ context 'with password login disabled' do+ before do+ allow(OpenProject::Configuration).to receive(:disable_password_login?).and_return(true)+ end++ it 'cannot find index' do+ get :index++ expect(response).to have_http_status 404+ end++ it 'cannot find new' do+ get :new++ expect(response).to have_http_status 404+ end++ it 'cannot find create' do+ post :create, params: { ldap_auth_source: { name: 'Test' } }++ expect(response).to have_http_status 404+ end++ it 'cannot find edit' do+ get :edit, params: { id: 42 }++ expect(response).to have_http_status 404+ end++ it 'cannot find update' do+ post :update, params: { id: 42, ldap_auth_source: { name: 'TestUpdate' } }++ expect(response).to have_http_status 404+ end++ it 'cannot find destroy' do+ post :destroy, params: { id: 42 }++ expect(response).to have_http_status 404+ end+ endenddiff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rbindex 276bba89f9a..d567fb5319d 100644--- a/spec/controllers/users_controller_spec.rb+++ b/spec/controllers/users_controller_spec.rb@@ -764,17 +764,17 @@ RSpec.describe UsersController dolet(:ldap_auth_source) { create(:ldap_auth_source) }it 'switchting to internal authentication on a password change' do- user.auth_source = ldap_auth_source+ user.ldap_auth_source = ldap_auth_sourceas_logged_in_user admin doput :update,params: {id: user.id,- user: { auth_source_id: '', password: 'newpassPASS!',+ user: { ldap_auth_source_id: '', password: 'newpassPASS!',password_confirmation: 'newpassPASS!' }}end- expect(user.reload.auth_source).to be_nil+ expect(user.reload.ldap_auth_source).to be_nilexpect(user.check_password?('newpassPASS!')).to be_truthyendenddiff --git a/spec/factories/auth_source_factory.rb b/spec/factories/ldap_auth_source_factory.rbsimilarity index 88%rename from spec/factories/auth_source_factory.rbrename to spec/factories/ldap_auth_source_factory.rbindex 03aa3d32c6e..976bf01b0e8 100644--- a/spec/factories/auth_source_factory.rb+++ b/spec/factories/ldap_auth_source_factory.rb@@ -27,18 +27,11 @@#++FactoryBot.define do- factory :auth_source do- name { 'Test AuthSource' }- endfactory :ldap_auth_source, class: 'LdapAuthSource' do- name { 'Test LDAP AuthSource' }+ name { 'Test LDAP LdapAuthSource' }host { '127.0.0.1' }port { 225 } # a reserved port, should not be in useattr_login { 'uid' }tls_mode { 'plain_ldap' }end-- factory :dummy_auth_source, class: 'DummyAuthSource' do- name { 'DerpLAP' }- endenddiff --git a/spec/features/auth/auth_source_sso_logout_spec.rb b/spec/features/auth/auth_source_sso_logout_spec.rbindex 1ea4b4c0fca..15cba722adb 100644--- a/spec/features/auth/auth_source_sso_logout_spec.rb+++ b/spec/features/auth/auth_source_sso_logout_spec.rb@@ -47,8 +47,8 @@ RSpec.describe 'Login with auth source SSO',}end- let(:auth_source) { create(:auth_source) }- let!(:user) { create(:user, login: 'bob', auth_source:) }+ let(:ldap_auth_source) { create(:ldap_auth_source) }+ let!(:user) { create(:user, login: 'bob', ldap_auth_source:) }it 'can log out after multiple visits' dovisit home_pathdiff --git a/spec/features/users/create_spec.rb b/spec/features/users/create_spec.rbindex 9884c14fad6..dc8d1efb68a 100644--- a/spec/features/users/create_spec.rb+++ b/spec/features/users/create_spec.rb@@ -105,7 +105,7 @@ RSpec.describe 'create users', with_cuprite: true dolast_name: 'boblast',email: '[email protected]',login: 'bob',- auth_source: auth_source.name+ ldap_auth_source: auth_source.nameperform_enqueued_jobs donew_user_page.submit!diff --git a/spec/features/users/edit_users_spec.rb b/spec/features/users/edit_users_spec.rbindex fe3be1a5447..4e5336d4ae3 100644--- a/spec/features/users/edit_users_spec.rb+++ b/spec/features/users/edit_users_spec.rb@@ -33,14 +33,14 @@ RSpec.describe 'edit users', js: true, with_cuprite: true dolet(:current_user) { admin }let(:user) { create(:user, mail: '[email protected]') }- let!(:auth_source) { create(:auth_source) }+ let!(:auth_source) { create(:ldap_auth_source) }before doallow(User).to receive(:current).and_return current_userenddef auth_select- find 'select#user_auth_source_id'+ find 'select#user_ldap_auth_source_id'enddef user_password@@ -66,7 +66,7 @@ RSpec.describe 'edit users', js: true, with_cuprite: true docontext 'with external authentication' dobefore do- user.auth_source = auth_source+ user.ldap_auth_source = auth_sourceuser.save!visit edit_user_path(user)@@ -95,7 +95,7 @@ RSpec.describe 'edit users', js: true, with_cuprite: true doexpect(page).not_to have_selector('.users-and-permissions-menu-item', text: 'Users and permissions')expect(page).to have_selector('.users-menu-item.selected', text: 'Users')- expect(page).to have_select(id: 'user_auth_source_id')+ expect(page).to have_select(id: 'user_ldap_auth_source_id')expect(page).not_to have_field '#user_password'expect(page).to have_selector '#user_login'@@ -108,7 +108,7 @@ RSpec.describe 'edit users', js: true, with_cuprite: true dofirstname_field.send_keys(:backspace)endfirstname_field.set 'NewName'- select auth_source.name, from: 'user[auth_source_id]'+ select auth_source.name, from: 'user[ldap_auth_source_id]'click_on 'Save'@@ -117,7 +117,7 @@ RSpec.describe 'edit users', js: true, with_cuprite: true douser.reloadexpect(user.firstname).to eq 'NewName'- expect(user.auth_source).to eq auth_source+ expect(user.ldap_auth_source).to eq auth_sourceendit 'can reinvite the user' dodiff --git a/spec/lib/api/v3/users/user_representer_spec.rb b/spec/lib/api/v3/users/user_representer_spec.rbindex f6810caad13..71c065405a5 100644--- a/spec/lib/api/v3/users/user_representer_spec.rb+++ b/spec/lib/api/v3/users/user_representer_spec.rb@@ -285,11 +285,11 @@ RSpec.describe API::V3::Users::UserRepresenter doenddescribe '#json_cache_key' do- let(:auth_source) { build_stubbed(:auth_source) }+ let(:auth_source) { build_stubbed(:ldap_auth_source) }let(:former_cache_key) { representer.json_cache_key }before do- user.auth_source = auth_source+ user.ldap_auth_source = auth_sourceformer_cache_keyend@@ -341,7 +341,7 @@ RSpec.describe API::V3::Users::UserRepresenter doendit 'changes when the user\'s auth_source is updated' do- user.auth_source.updated_at = Time.now + 20.seconds+ user.ldap_auth_source.updated_at = 20.seconds.from_nowexpect(representer.json_cache_key).not_to eql former_cache_keydiff --git a/spec/models/ldap_auth_source_spec.rb b/spec/models/ldap_auth_source_spec.rbindex 7f03c5faac7..a9c08b1da0d 100644--- a/spec/models/ldap_auth_source_spec.rb+++ b/spec/models/ldap_auth_source_spec.rb@@ -275,7 +275,7 @@ RSpec.describe LdapAuthSource doexpect(attributes[:firstname]).to eq 'Belle'expect(attributes[:lastname]).to eq 'Baldwin'expect(attributes[:mail]).to eq '[email protected]'- expect(attributes[:auth_source_id]).to eq ldap.id+ expect(attributes[:ldap_auth_source_id]).to eq ldap.idexpect { User.new(attributes) }.not_to raise_errorenddiff --git a/spec/models/permitted_params_spec.rb b/spec/models/permitted_params_spec.rbindex f4c3d2c3cbd..2a3a709c18e 100644--- a/spec/models/permitted_params_spec.rb+++ b/spec/models/permitted_params_spec.rb@@ -513,12 +513,12 @@ RSpec.describe PermittedParams do'mail','language','custom_fields',- 'auth_source_id',+ 'ldap_auth_source_id','force_password_change']describe :user_create_as_admin dolet(:attribute) { :user_create_as_admin }- let(:default_permissions) { %w[custom_fields firstname lastname language mail auth_source_id] }+ let(:default_permissions) { %w[custom_fields firstname lastname language mail ldap_auth_source_id] }context 'for a non-admin' dolet(:hash) { all_permissions.zip(all_permissions).to_h }@@ -560,10 +560,10 @@ RSpec.describe PermittedParams doendcontext 'with external authentication' do- let(:hash) { { 'auth_source_id' => 'true' } }+ let(:hash) { { 'ldap_auth_source_id' => 'true' } }let(:external_authentication) { true }- it 'does not permit auth_source_id' do+ it 'does not permit ldap_auth_source_id' doexpect(subject).to eq({})endenddiff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rbindex c283c1bf26a..34e2b5a5f1e 100644--- a/spec/models/user_spec.rb+++ b/spec/models/user_spec.rb@@ -33,16 +33,18 @@ RSpec.describe User dolet(:project) { create(:project_with_types) }let(:role) { create(:role, permissions: [:view_work_packages]) }let(:member) do- build(:member, project:,- roles: [role],- principal: user)+ build(:member,+ project:,+ roles: [role],+ principal: user)endlet(:status) { create(:status) }let(:issue) do- build(:work_package, type: project.types.first,- author: user,- project:,- status:)+ build(:work_package,+ type: project.types.first,+ author: user,+ project:,+ status:)enddescribe 'with long but allowed attributes' do@@ -319,7 +321,7 @@ RSpec.describe User docontext 'for user without auth source' dobefore do- user.auth_source = nil+ user.ldap_auth_source = nilendit 'is true' do@@ -328,36 +330,20 @@ RSpec.describe User doendcontext 'for user with an auth source' do- let(:allowed_auth_source) { create(:auth_source) }+ let(:auth_source) { create(:ldap_auth_source) }- context 'that allows password changes' do- before do- def allowed_auth_source.allow_password_changes?; true; end- user.auth_source = allowed_auth_source- end-- it 'allows password changes' do- expect(user).to be_change_password_allowed- end+ before do+ user.ldap_auth_source = auth_sourceend- context 'that does not allow password changes' do- let(:denied_auth_source) { create(:auth_source) }-- before do- def denied_auth_source.allow_password_changes?; false; end- user.auth_source = denied_auth_source- end-- it 'does not allow password changes' do- expect(user).not_to be_change_password_allowed- end+ it 'does not allow password changes' do+ expect(user).not_to be_change_password_allowedendend- context 'for user without authsource and with external authentication' do+ context 'for user without LdapAuthSource and with external authentication' dobefore do- user.auth_source = nil+ user.ldap_auth_source = nilallow(user).to receive(:uses_external_authentication?).and_return(true)end@@ -457,7 +443,7 @@ RSpec.describe User douser_double = double('User')allow(user_double).to receive(:check_password?).and_return(true)allow(user_double).to receive(:active?).and_return(true)- allow(user_double).to receive(:auth_source).and_return(nil)+ allow(user_double).to receive(:ldap_auth_source).and_return(nil)allow(user_double).to receive(:force_password_change).and_return(false)# check for expired password should always happen@@ -483,10 +469,10 @@ RSpec.describe User doendcontext 'with an external auth source' do- let(:auth_source) { build(:auth_source) }+ let(:auth_source) { build(:ldap_auth_source) }let(:user_with_external_auth_source) douser = build(:user, login: 'user')- allow(user).to receive(:auth_source).and_return(auth_source)+ allow(user).to receive(:ldap_auth_source).and_return(auth_source)userend@@ -697,9 +683,7 @@ RSpec.describe User doical_tokenanother_ical_token- expect(user.ical_tokens).to contain_exactly(- ical_token, another_ical_token- )+ expect(user.ical_tokens).to contain_exactly(ical_token, another_ical_token)endit 'are destroyed when the user is destroyed' dodiff --git a/spec/requests/api/v3/user/create_user_resource_spec.rb b/spec/requests/api/v3/user/create_user_resource_spec.rbindex 8dcfb53e777..6a3a2812f94 100644--- a/spec/requests/api/v3/user/create_user_resource_spec.rb+++ b/spec/requests/api/v3/user/create_user_resource_spec.rb@@ -59,8 +59,8 @@ RSpec.describe API::V3::Users::UsersAPI doit_behaves_like 'create user request flow'context 'with auth_source' do- let(:auth_source_id) { 'some_ldap' }- let(:auth_source) { create(:auth_source, name: auth_source_id) }+ let(:ldap_auth_source_id) { 'some_ldap' }+ let(:auth_source) { create(:ldap_auth_source, name: ldap_auth_source_id) }context 'ID' dobefore do@@ -76,7 +76,7 @@ RSpec.describe API::V3::Users::UsersAPI douser = User.find_by(login: parameters[:login])- expect(user.auth_source).to eq auth_source+ expect(user.ldap_auth_source).to eq auth_sourceendit_behaves_like 'represents the created user'@@ -96,7 +96,7 @@ RSpec.describe API::V3::Users::UsersAPI douser = User.find_by(login: parameters[:login])- expect(user.auth_source).to eq auth_source+ expect(user.ldap_auth_source).to eq auth_sourceendit_behaves_like 'represents the created user'@@ -220,8 +220,8 @@ RSpec.describe API::V3::Users::UsersAPI doendcontext 'with auth_source' do- let(:auth_source_id) { 'some_ldap' }- let(:auth_source) { create(:auth_source, name: auth_source_id) }+ let(:ldap_auth_source_id) { 'some_ldap' }+ let(:auth_source) { create(:ldap_auth_source, name: ldap_auth_source_id) }before doparameters[:_links] = {@@ -236,7 +236,7 @@ RSpec.describe API::V3::Users::UsersAPI douser = User.find_by(login: parameters[:login])- expect(user.auth_source).to eq auth_source+ expect(user.ldap_auth_source).to eq auth_sourceendendenddiff --git a/spec/requests/auth/auth_source_sso_spec.rb b/spec/requests/auth/auth_source_sso_spec.rbindex d15f019f065..e9ee4b205e5 100644--- a/spec/requests/auth/auth_source_sso_spec.rb+++ b/spec/requests/auth/auth_source_sso_spec.rb@@ -38,8 +38,8 @@ RSpec.describe AuthSourceSSO,}end- let(:auth_source) { create(:auth_source) }- let(:user) { create(:user, login: 'bob', auth_source:) }+ let(:ldap_auth_source) { create(:ldap_auth_source) }+ let(:user) { create(:user, login: 'bob', ldap_auth_source:) }before doallow(OpenProject::Configuration)diff --git a/spec/services/ldap/import_user_list_service_integration_spec.rb b/spec/services/ldap/import_user_list_service_integration_spec.rbindex 4b14bbf07ef..45f8a57789a 100644--- a/spec/services/ldap/import_user_list_service_integration_spec.rb+++ b/spec/services/ldap/import_user_list_service_integration_spec.rb@@ -4,7 +4,7 @@ RSpec.describe Ldap::ImportUsersFromListService doinclude_context 'with temporary LDAP'subject do- described_class.new(auth_source, user_list).call+ described_class.new(ldap_auth_source, user_list).callendlet(:user_list) do@@ -31,8 +31,8 @@ RSpec.describe Ldap::ImportUsersFromListService doendcontext 'when two users already exist' do- let!(:user_aa729) { create(:user, login: 'aa729', firstname: 'Foobar', auth_source:) }- let!(:user_bb459) { create(:user, login: 'bb459', firstname: 'Bla', auth_source:) }+ let!(:user_aa729) { create(:user, login: 'aa729', firstname: 'Foobar', ldap_auth_source:) }+ let!(:user_bb459) { create(:user, login: 'bb459', firstname: 'Bla', ldap_auth_source:) }it 'adds the third one, but does not update the other two' dosubjectdiff --git a/spec/services/ldap/import_users_from_filter_service_integration_spec.rb b/spec/services/ldap/import_users_from_filter_service_integration_spec.rbindex 19b20b08033..5ed8193ad79 100644--- a/spec/services/ldap/import_users_from_filter_service_integration_spec.rb+++ b/spec/services/ldap/import_users_from_filter_service_integration_spec.rb@@ -4,7 +4,7 @@ RSpec.describe Ldap::ImportUsersFromFilterService doinclude_context 'with temporary LDAP'subject do- described_class.new(auth_source, filter).call+ described_class.new(ldap_auth_source, filter).callendlet(:filter) { Net::LDAP::Filter.from_rfc2254 '(uid=aa729)' }diff --git a/spec/services/ldap/synchronize_users_service_integration_spec.rb b/spec/services/ldap/synchronize_users_service_integration_spec.rbindex 28bc517f47c..8c64e4ace88 100644--- a/spec/services/ldap/synchronize_users_service_integration_spec.rb+++ b/spec/services/ldap/synchronize_users_service_integration_spec.rb@@ -4,11 +4,11 @@ RSpec.describe Ldap::SynchronizeUsersService doinclude_context 'with temporary LDAP'subject do- described_class.new(auth_source).call+ described_class.new(ldap_auth_source).callendcontext 'when updating an admin' do- let!(:user_aa729) { create(:user, login: 'aa729', firstname: 'Foobar', auth_source:, admin: true) }+ let!(:user_aa729) { create(:user, login: 'aa729', firstname: 'Foobar', ldap_auth_source:, admin: true) }it 'does not update the admin attribute if not defined (Regression #42396)' doexpect(user_aa729).to be_admin@@ -20,8 +20,8 @@ RSpec.describe Ldap::SynchronizeUsersService doendcontext 'when updating users' do- let!(:user_aa729) { create(:user, login: 'aa729', firstname: 'Foobar', auth_source:) }- let!(:user_bb459) { create(:user, login: 'bb459', firstname: 'Bla', auth_source:) }+ let!(:user_aa729) { create(:user, login: 'aa729', firstname: 'Foobar', ldap_auth_source:) }+ let!(:user_bb459) { create(:user, login: 'bb459', firstname: 'Bla', ldap_auth_source:) }context 'when user sync status is enabled',with_config: { ldap_users_sync_status: true } do@@ -76,7 +76,7 @@ RSpec.describe Ldap::SynchronizeUsersService docontext 'with a user that is in another LDAP' dolet(:auth_source2) { create(:ldap_auth_source, name: 'Another LDAP') }- let(:user_foo) { create(:user, login: 'login', auth_source: auth_source2) }+ let(:user_foo) { create(:user, login: 'login', ldap_auth_source: auth_source2) }it 'does not touch that user' doexpect(user_foo).to be_active@@ -103,10 +103,10 @@ RSpec.describe Ldap::SynchronizeUsersService doendcontext 'when requesting only a subset of users' do- let!(:user_cc414) { create(:user, login: 'cc414', auth_source:) }+ let!(:user_cc414) { create(:user, login: 'cc414', ldap_auth_source:) }subject do- described_class.new(auth_source, %w[Aa729 cc414]).call+ described_class.new(ldap_auth_source, %w[Aa729 cc414]).callendit 'syncs all case-insensitive users' do@@ -131,7 +131,7 @@ RSpec.describe Ldap::SynchronizeUsersService doendcontext 'with a user that is no longer in LDAP' do- let(:user_foo) { create(:user, login: 'login', auth_source:) }+ let(:user_foo) { create(:user, login: 'login', ldap_auth_source:) }context 'when user sync status is enabled',with_config: { ldap_users_sync_status: true } dodiff --git a/spec/services/users/register_user_service_spec.rb b/spec/services/users/register_user_service_spec.rbindex 796f016884a..0e93116f2bd 100644--- a/spec/services/users/register_user_service_spec.rb+++ b/spec/services/users/register_user_service_spec.rb@@ -64,7 +64,7 @@ RSpec.describe Users::RegisterUserService douser = User.new(status: Principal.statuses[:registered])instance = described_class.new(user)- allow(user).to receive(:auth_source_id).and_return 1234+ allow(user).to receive(:ldap_auth_source_id).and_return 1234expect(user).to receive(:activate)expect(user).to receive(:save).and_return truediff --git a/spec/support/shared/with_test_ldap.rb b/spec/support/shared/with_test_ldap.rbindex 1b15db0bef1..50f1098efe5 100644--- a/spec/support/shared/with_test_ldap.rb+++ b/spec/support/shared/with_test_ldap.rb@@ -45,7 +45,7 @@ RSpec.shared_context 'with temporary LDAP' do# Ldap has:# three users aa729, bb459, cc414# two groups foo (aa729), bar(aa729, bb459, cc414)- let(:auth_source) do+ let(:ldap_auth_source) docreate(:ldap_auth_source,port: ParallelHelper.port_for_ldap.to_s,account: 'uid=admin,ou=system',diff --git a/spec/views/account/register.html.erb_spec.rb b/spec/views/account/register.html.erb_spec.rbindex d9b4e041851..6879be92269 100644--- a/spec/views/account/register.html.erb_spec.rb+++ b/spec/views/account/register.html.erb_spec.rb@@ -29,7 +29,7 @@require 'spec_helper'RSpec.describe 'account/register' do- let(:user) { build(:user, auth_source: nil) }+ let(:user) { build(:user, ldap_auth_source: nil) }context 'with the email_login setting disabled (default value)' dobefore do@@ -40,8 +40,8 @@ RSpec.describe 'account/register' doendcontext 'with auth source' do- let(:auth_source) { create(:auth_source) }- let(:user) { build(:user, auth_source:) }+ let(:ldap_auth_source) { create(:ldap_auth_source) }+ let(:user) { build(:user, ldap_auth_source:) }it 'does not show a login field' doexpect(rendered).not_to include('user[login]')@@ -64,8 +64,8 @@ RSpec.describe 'account/register' doendcontext 'with auth source' do- let(:auth_source) { create(:auth_source) }- let(:user) { build(:user, auth_source:) }+ let(:ldap_auth_source) { create(:ldap_auth_source) }+ let(:user) { build(:user, ldap_auth_source:) }it 'does not show a login field' doexpect(rendered).not_to include('user[login]')diff --git a/spec/views/users/edit.html.erb_spec.rb b/spec/views/users/edit.html.erb_spec.rbindex 102bac0578c..7ec285015b0 100644--- a/spec/views/users/edit.html.erb_spec.rb+++ b/spec/views/users/edit.html.erb_spec.rb@@ -136,7 +136,7 @@ RSpec.describe 'users/edit' doendcontext 'with auth sources' do- let(:auth_sources) { [create(:auth_source)] }+ let(:auth_sources) { create_list(:ldap_auth_source, 1) }before doassign :auth_sources, auth_sources@@ -162,7 +162,7 @@ RSpec.describe 'users/edit' doendcontext 'with auth sources' do- let(:auth_sources) { [create(:auth_source)] }+ let(:auth_sources) { create_list(:ldap_auth_source, 1) }before doassign :auth_sources, auth_sources@@ -171,7 +171,7 @@ RSpec.describe 'users/edit' doit 'shows the auth source selection' dorender- expect(rendered).to have_selector('#user_auth_source_id')+ expect(rendered).to have_selector('#user_ldap_auth_source_id')endend