Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Remove AuthSource base namespace, model

Oliver Günthere32d2d005898
diff --git a/app/contracts/users/base_contract.rb b/app/contracts/users/base_contract.rb
index 262604fc3ed..a96c873e505 100644
--- a/app/contracts/users/base_contract.rb
+++ b/app/contracts/users/base_contract.rb
@@ -42,7 +42,7 @@ module Users
writable: ->(*) { 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/DynamicFindBy
def 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_found
end
end
diff --git a/app/contracts/users/create_contract.rb b/app/contracts/users/create_contract.rb
index 179bbb5fef2..09e9b432d08 100644
--- a/app/contracts/users/create_contract.rb
+++ b/app/contracts/users/create_contract.rb
@@ -62,7 +62,7 @@ module Users
end
def 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.rb
index 237cea34400..885c6abef45 100644
--- a/app/controllers/account_controller.rb
+++ b/app/controllers/account_controller.rb
@@ -225,7 +225,7 @@ class AccountController < ApplicationController
session[:invitation_token] = token.value
user = 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 user
else
activate_user user
@@ -247,7 +247,7 @@ class AccountController < ApplicationController
def 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 < ApplicationController
user = 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_id
end
show_sso_error_for user
@@ -360,7 +360,7 @@ class AccountController < ApplicationController
user.attributes = permitted_params.user
user.activate
user.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 < ApplicationController
flash_and_log_invalid_credentials
end
elsif 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 user
successful_authentication(user)
diff --git a/app/controllers/auth_sources_controller.rb b/app/controllers/auth_sources_controller.rb
deleted file mode 100644
index 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
-end
diff --git a/app/controllers/concerns/auth_source_sso.rb b/app/controllers/concerns/auth_source_sso.rb
index 9b6c7f6759c..0eb726e02da 100644
--- a/app/controllers/concerns/auth_source_sso.rb
+++ b/app/controllers/concerns/auth_source_sso.rb
@@ -117,12 +117,12 @@ module AuthSourceSSO
def find_user_from_auth_source(login)
User
.by_login(login)
- .where.not(auth_source_id: nil)
+ .where.not(ldap_auth_source_id: nil)
.first
end
def create_user_from_auth_source(login, save:)
- attrs = AuthSource.find_user(login)
+ attrs = LdapAuthSource.find_user(login)
return unless attrs
attrs[:login] = login
@@ -143,7 +143,7 @@ module AuthSourceSSO
call.on_success do
logger.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}"
)
end
diff --git a/app/controllers/ldap_auth_sources_controller.rb b/app/controllers/ldap_auth_sources_controller.rb
index 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 < ApplicationController
menu_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'
+ end
protected
- 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?
end
end
diff --git a/app/helpers/accounts_helper.rb b/app/helpers/accounts_helper.rb
index 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/HelperInstanceVariable
end
def registration_footer
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
index 56dcdb06ce8..9afc395ab1c 100644
--- a/app/helpers/users_helper.rb
+++ b/app/helpers/users_helper.rb
@@ -135,6 +135,6 @@ module UsersHelper
end
def can_users_have_auth_source?
- AuthSource.any? && !OpenProject::Configuration.disable_password_login?
+ LdapAuthSource.any? && !OpenProject::Configuration.disable_password_login?
end
end
diff --git a/app/models/auth_source.rb b/app/models/auth_source.rb
deleted file mode 100644
index 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
-end
diff --git a/app/models/dummy_auth_source.rb b/app/models/dummy_auth_source.rb
index 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 < LdapAuthSource
def test_connection
# the dummy connection is always available
end
@@ -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)
end
def find_on_the_fly_user(login)
@@ -45,7 +45,7 @@ class DummyAuthSource < AuthSource
firstname: login.capitalize,
lastname: 'Dummy',
- auth_source_id: id
+ ldap_auth_source_id: id
}
end
diff --git a/app/models/ldap_auth_source.rb b/app/models/ldap_auth_source.rb
index 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 < AuthSource
after_initialize :set_default_port
before_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 < AuthSource
attrs.except(:dn)
end
rescue Net::LDAP::Error => e
- raise AuthSource::Error, "LdapError: #{e.message}"
+ raise LdapAuthSource::Error, "LdapError: #{e.message}"
end
def find_user(login)
@@ -71,7 +127,7 @@ class LdapAuthSource < AuthSource
attrs.except(:dn)
end
rescue 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 LDAP
def test_connection
unless 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'))
end
rescue 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)
end
def auth_method_name
@@ -95,7 +151,7 @@ class LdapAuthSource < AuthSource
def 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.rb
index 15e7db58eeb..80f5c2e3733 100644
--- a/app/models/permitted_params.rb
+++ b/app/models/permitted_params.rb
@@ -62,8 +62,8 @@ class PermittedParams
params.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])
end
def forum
@@ -210,7 +210,7 @@ class PermittedParams
change_password_allowed,
additional_params = [])
- additional_params << :auth_source_id unless external_authentication
+ additional_params << :ldap_auth_source_id unless external_authentication
if current_user.admin?
additional_params << :force_password_change if change_password_allowed
@@ -416,7 +416,7 @@ class PermittedParams
attribute_name
help_text
),
- auth_source: %i(
+ ldap_auth_source: %i(
name
host
port
diff --git a/app/models/user.rb b/app/models/user.rb
index 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 usable
has_many :ical_tokens, class_name: '::Token::ICal', dependent: :destroy
- belongs_to :auth_source, optional: true
+ belongs_to :ldap_auth_source, optional: true
# Authorized OAuth grants
has_many :oauth_grants,
@@ -157,7 +157,7 @@ class User < Principal
# create new password if password was set
def 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 = password
new_password.save
@@ -211,9 +211,9 @@ class User < Principal
return 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 password
return nil unless user.check_password?(password)
@@ -240,7 +240,7 @@ class User < Principal
def 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 attrs
call = 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)
else
return false if current_password.nil?
@@ -339,9 +339,8 @@ class User < Principal
def 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.rb
index 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 Ldap
new_users.each do |login|
synchronize_user(User.new(login:), ldap_con)
- rescue ::AuthSource::Error => e
+ rescue ::LdapAuthSource::Error => e
Rails.logger.error { "Failed to synchronize user #{ldap.name} due to LDAP error: #{e.message}" }
# Reset the LDAP connection
ldap_con = new_ldap_connection
diff --git a/app/services/ldap/synchronize_users_service.rb b/app/services/ldap/synchronize_users_service.rb
index 2e9902f6b39..df7cd722401 100644
--- a/app/services/ldap/synchronize_users_service.rb
+++ b/app/services/ldap/synchronize_users_service.rb
@@ -14,7 +14,7 @@ module Ldap
applicable_users.find_each do |user|
synchronize_user(user, ldap_con)
- rescue ::AuthSource::Error => e
+ rescue ::LdapAuthSource::Error => e
Rails.logger.error { "Failed to synchronize user #{ldap.name} due to LDAP error: #{e.message}" }
# Reset the LDAP connection
ldap_con = new_ldap_connection
diff --git a/app/services/users/register_user_service.rb b/app/services/users/register_user_service.rb
index 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 restrictions
def register_ldap_user
- return if user.auth_source_id.blank?
+ return if user.ldap_auth_source_id.blank?
user.activate
diff --git a/app/views/account/_register.html.erb b/app/views/account/_register.html.erb
index 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.erb
deleted file mode 100644
index 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.erb
index 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.erb
similarity index 100%
rename from app/views/auth_sources/edit.html.erb
rename to app/views/ldap_auth_sources/edit.html.erb
diff --git a/app/views/auth_sources/index.html.erb b/app/views/ldap_auth_sources/index.html.erb
similarity index 95%
rename from app/views/auth_sources/index.html.erb
rename to app/views/ldap_auth_sources/index.html.erb
index 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.erb
similarity index 100%
rename from app/views/auth_sources/new.html.erb
rename to app/views/ldap_auth_sources/new.html.erb
diff --git a/app/views/user_mailer/account_information.html.erb b/app/views/user_mailer/account_information.html.erb
index 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.erb
index 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.erb
index 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.erb
index 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.erb
index 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.yml
index 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.rb
index a01fb72da39..1b53e7197d7 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -383,7 +383,7 @@ OpenProject::Application.routes.draw do
end
end
- resources :auth_sources, :ldap_auth_sources do
+ resources :ldap_auth_sources do
member do
get :test_connection
end
diff --git a/db/migrate/20180419061910_timestamp_for_caching.rb b/db/migrate/20180419061910_timestamp_for_caching.rb
index 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)
end
end
diff --git a/db/migrate/20190227163226_add_tls_mode_to_auth_sources.rb b/db/migrate/20190227163226_add_tls_mode_to_auth_sources.rb
index 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 change
add_column :auth_sources, :tls_mode, :integer, default: 0, null: false
- LdapAuthSource.reset_column_information
+ MigratingAuthSource.reset_column_information
reversible do |dir|
dir.up do
- LdapAuthSource.where(tls: true).update_all(tls_mode: 1)
+ MigratingAuthSource.where(tls: true).update_all(tls_mode: 1)
end
dir.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)
end
end
diff --git a/db/migrate/20221026132134_bigint_primary_and_foreign_keys.rb b/db/migrate/20221026132134_bigint_primary_and_foreign_keys.rb
index 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.rb
index 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 change
change_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_information
ldap_settings = (Setting.ldap_tls_options || {}).with_indifferent_access
verify_peer = ldap_settings[:verify_mode] == OpenSSL::SSL::VERIFY_PEER
- LdapAuthSource.update_all(verify_peer:)
+ MigratingAuthSource.update_all(verify_peer:)
end
end
end
diff --git a/db/migrate/20230726061920_rename_auth_source_to_ldap_auth_source.rb b/db/migrate/20230726061920_rename_auth_source_to_ldap_auth_source.rb
new file mode 100644
index 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
+end
diff --git a/docs/api/apiv3/tags/users.yml b/docs/api/apiv3/tags/users.yml
index 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.md
index 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
```ruby
auth_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.rb
index 56cf94c8a5a..3dbe3c8c7ed 100644
--- a/lib/api/v3/users/user_representer.rb
+++ b/lib/api/v3/users/user_representer.rb
@@ -33,7 +33,7 @@ module API
include AvatarHelper
extend ::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 API
link :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/DynamicFindBy
id = 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 = id
end
end
diff --git a/lib/tasks/ciphering.rake b/lib/tasks/ciphering.rake
index 30a23da35aa..493f7b62afb 100644
--- a/lib/tasks/ciphering.rake
+++ b/lib/tasks/ciphering.rake
@@ -30,7 +30,7 @@ namespace :db do
desc 'Encrypts SCM and LDAP passwords in the database.'
task encrypt: :environment do
unless 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.'
end
end
@@ -38,7 +38,7 @@ namespace :db do
desc 'Decrypts SCM and LDAP passwords in the database.'
task decrypt: :environment do
unless 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.'
end
end
diff --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.rb
index 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 LdapGroups
end
def 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)
end
def groups
diff --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.rb
index 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 LdapGroups
link_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)
end
def group
diff --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.rb
index 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 LdapGroups
module SynchronizedGroups
class TableComponent < ::TableComponent
- columns :dn, :auth_source, :group, :users, :sync_users
+ columns :dn, :ldap_auth_source, :group, :users, :sync_users
def initial_sort
%i[id asc]
@@ -64,7 +64,7 @@ module LdapGroups
def 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.rb
index 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 LdapGroups
def permitted_params
params
.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)
end
def default_breadcrumb
diff --git a/modules/ldap_groups/app/controllers/ldap_groups/synchronized_groups_controller.rb b/modules/ldap_groups/app/controllers/ldap_groups/synchronized_groups_controller.rb
index 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 LdapGroups
include PaginationHelper
def 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)
end
def new
@@ -66,7 +66,7 @@ module LdapGroups
def permitted_params
params
.require(:synchronized_group)
- .permit(:dn, :group_id, :auth_source_id, :sync_users)
+ .permit(:dn, :group_id, :ldap_auth_source_id, :sync_users)
end
def default_breadcrumb
diff --git a/modules/ldap_groups/app/models/ldap_groups/synchronized_filter.rb b/modules/ldap_groups/app/models/ldap_groups/synchronized_filter.rb
index 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 LdapGroups
class SynchronizedFilter < ApplicationRecord
- belongs_to :auth_source
+ belongs_to :ldap_auth_source
has_many :groups,
class_name: '::LdapGroups::SynchronizedGroup',
@@ -11,7 +11,7 @@ module LdapGroups
dependent: :destroy
validates_presence_of :filter_string
- validates_presence_of :auth_source
+ validates_presence_of :ldap_auth_source
validate :validate_filter_syntax
validate :validate_base_dn
@@ -20,7 +20,7 @@ module LdapGroups
end
def used_base_dn
- base_dn.presence || auth_source.base_dn
+ base_dn.presence || ldap_auth_source.base_dn
end
private
@@ -32,9 +32,9 @@ module LdapGroups
end
def 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_dn
end
end
diff --git a/modules/ldap_groups/app/models/ldap_groups/synchronized_group.rb b/modules/ldap_groups/app/models/ldap_groups/synchronized_group.rb
index 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 LdapGroups
class SynchronizedGroup < ApplicationRecord
belongs_to :group
- belongs_to :auth_source
+ belongs_to :ldap_auth_source
belongs_to :filter,
class_name: '::LdapGroups::SynchronizedFilter'
@@ -18,7 +18,7 @@ module LdapGroups
validates_presence_of :dn
validates_presence_of :group
validates_associated :group
- validates_presence_of :auth_source
+ validates_presence_of :ldap_auth_source
before_destroy :remove_all_members
diff --git a/modules/ldap_groups/app/services/ldap_groups/synchronization_service.rb b/modules/ldap_groups/app/services/ldap_groups/synchronization_service.rb
index 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 LdapGroups
LdapAuthSource.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.rb
index 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 one
def each_group
- ldap = filter.auth_source
+ ldap = filter.ldap_auth_source
ldap.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 one
sync.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 to
sync.sync_users = filter.sync_users
diff --git a/modules/ldap_groups/app/services/ldap_groups/synchronize_groups_service.rb b/modules/ldap_groups/app/services/ldap_groups/synchronize_groups_service.rb
index 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)
end
def call
diff --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.erb
index 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.erb
index 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.erb
index 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.yml
index 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.rb
index 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 change
add_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)
end
end
diff --git a/modules/ldap_groups/lib/open_project/ldap_groups/engine.rb b/modules/ldap_groups/lib/open_project/ldap_groups/engine.rb
index 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::LdapGroups
add_cron_jobs { LdapGroups::SynchronizationJob }
- patches %i[AuthSource Group User]
+ patches %i[LdapAuthSource Group User]
end
end
diff --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.rb
similarity index 90%
rename from modules/ldap_groups/lib/open_project/ldap_groups/patches/auth_source_patch.rb
rename to modules/ldap_groups/lib/open_project/ldap_groups/patches/ldap_auth_source_patch.rb
index 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::LdapGroups
module Patches
- module AuthSourcePatch
+ module LdapAuthSourcePatch
def self.included(base) # :nodoc:
base.class_eval do
has_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.rb
index 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_groups
end
context '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' do
let(:save_result) { true }
diff --git a/modules/ldap_groups/spec/factories/synchronized_filter_factory.rb b/modules/ldap_groups/spec/factories/synchronized_filter_factory.rb
index 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 do
filter_string { '(|(cn=foo)(cn=bar))' }
group_name_attribute { 'cn' }
base_dn { 'dc=example,dc=com' }
- auth_source factory: :ldap_auth_source
+ ldap_auth_source
sync_users { true }
end
end
diff --git a/modules/ldap_groups/spec/factories/synchronized_group_factory.rb b/modules/ldap_groups/spec/factories/synchronized_group_factory.rb
index 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 do
factory :ldap_synchronized_group, class: '::LdapGroups::SynchronizedGroup' do
dn { 'cn=foo,ou=groups,dc=example,dc=com' }
group factory: :group
- auth_source factory: :ldap_auth_source
+ ldap_auth_source
sync_users { true }
end
end
diff --git a/modules/ldap_groups/spec/features/administration_spec.rb b/modules/ldap_groups/spec/features/administration_spec.rb
index 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 do
find('.button', text: I18n.t('ldap_groups.synchronized_groups.singular')).click
SeleniumHubWaiter.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 do
click_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 group
sync = LdapGroups::SynchronizedGroup.last
expect(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 membership
diff --git a/modules/ldap_groups/spec/models/synchronized_filter_spec.rb b/modules/ldap_groups/spec/models/synchronized_filter_spec.rb
index 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 do
describe '#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' do
filter.base_dn = nil
expect(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)
end
end
describe '#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' do
filter.base_dn = nil
expect(filter).to be_valid
diff --git a/modules/ldap_groups/spec/models/synchronized_group_spec.rb b/modules/ldap_groups/spec/models/synchronized_group_spec.rb
index 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 do
it 'validates missing attributes' do
expect(subject.save).to be false
expect(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."
end
end
diff --git a/modules/ldap_groups/spec/services/synchronization_spec.rb b/modules/ldap_groups/spec/services/synchronization_spec.rb
index 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) do
create(: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] do
let(: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] do
dn: 'cn=foo,ou=groups,dc=example,dc=com',
group: group_foo,
sync_users:,
- auth_source:)
+ ldap_auth_source:)
end
let(:synced_bar) do
create(:ldap_synchronized_group,
dn: 'cn=bar,ou=groups,dc=example,dc=com',
group: group_bar,
sync_users:,
- auth_source:)
+ ldap_auth_source:)
end
subject do
# Need the system user for admin permission
User.system.run_given do
- described_class.new(auth_source).call
+ described_class.new(ldap_auth_source).call
end
end
@@ -141,7 +141,7 @@ RSpec.describe LdapGroups::SynchronizeGroupsService, with_ee: %i[ldap_groups] do
end
it '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] do
end
context 'with invalid connection' do
- let(:auth_source) { create(:ldap_auth_source) }
+ let(:ldap_auth_source) { create(:ldap_auth_source) }
before do
synced_foo
@@ -351,11 +351,11 @@ RSpec.describe LdapGroups::SynchronizeGroupsService, with_ee: %i[ldap_groups] do
context 'with invalid base' do
let(:synced_foo) do
create(:ldap_synchronized_group, dn: 'cn=foo,ou=invalid,dc=example,dc=com', group: group_foo,
- auth_source:)
+ ldap_auth_source:)
end
let(:synced_bar) do
create(:ldap_synchronized_group, dn: 'cn=bar,ou=invalid,dc=example,dc=com', group: group_bar,
- auth_source:)
+ ldap_auth_source:)
end
context 'when one synced group exists' do
diff --git a/modules/ldap_groups/spec/services/synchronize_filter_spec.rb b/modules/ldap_groups/spec/services/synchronize_filter_spec.rb
index 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) do
create(: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:
)
end
let(: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] do
dn: 'cn=foo,ou=groups,dc=example,dc=com',
group: group_foo,
sync_users: false,
- auth_source:)
+ ldap_auth_source:)
end
let(:filter_foo_bar) do
create(:ldap_synchronized_filter,
sync_users: true,
- auth_source:)
+ ldap_auth_source:)
end
before do
@@ -125,7 +125,7 @@ RSpec.describe LdapGroups::SynchronizeFilterService, with_ee: %i[ldap_groups] do
dn: 'cn=doesnotexist,ou=groups,dc=example,dc=com',
group: group_doesnotexist,
filter: filter_foo_bar,
- auth_source:)
+ ldap_auth_source:)
end
it 'removes that group' do
@@ -135,7 +135,7 @@ RSpec.describe LdapGroups::SynchronizeFilterService, with_ee: %i[ldap_groups] do
end
describe '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' do
expect { subject }.not_to raise_error
@@ -154,7 +154,7 @@ RSpec.describe LdapGroups::SynchronizeFilterService, with_ee: %i[ldap_groups] do
describe 'when filter has its own base dn' do
let(:filter_foo_bar) do
create(:ldap_synchronized_filter,
- auth_source:,
+ ldap_auth_source:,
base_dn: 'ou=users,dc=example,dc=com')
end
diff --git a/modules/two_factor_authentication/spec/models/user_spec.rb b/modules/two_factor_authentication/spec/models/user_spec.rb
index 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::Patches
module UserSpec
RSpec.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)
end
def create_user_with_auth_source
- auth_source = AuthSource.new name: "test"
+ auth_source = LdapAuthSource.new name: "test"
create_user auth_source.id
end
diff --git a/spec/contracts/users/shared_contract_examples.rb b/spec/contracts/users/shared_contract_examples.rb
index 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' do
end
describe 'can set the auth_source' do
- let!(:auth_source) { create(:auth_source) }
+ let!(:auth_source) { create(:ldap_auth_source) }
before do
user.password = user.password_confirmation = nil
- user.auth_source = auth_source
+ user.ldap_auth_source = auth_source
end
it_behaves_like 'contract is valid'
diff --git a/spec/controllers/account_controller_spec.rb b/spec/controllers/account_controller_spec.rb
index 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',
- auth_source_id: auth_source.id)
+ allow(LdapAuthSource)
+ .to(receive(:authenticate))
+ .and_return(login: 'foo',
+ firstname: 'Foo',
+ lastname: 'Smith',
+ 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_nil
end
end
@@ -438,14 +440,14 @@ RSpec.describe AccountController,
firstname: 'Scarlet',
lastname: 'Scallywag',
- auth_source_id: auth_source.id
+ ldap_auth_source_id: auth_source.id
}
end
let(: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 rendered
allow_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 } do
before do
allow_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)
end
context '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 66
expect(user.current_password).to be_nil
end
end
@@ -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,
end
before do
- allow(AuthSource).to receive(:find_user).and_return attrs
+ allow(LdapAuthSource).to receive(:find_user).and_return attrs
end
it "shows the account creation form with an error" do
@@ -1038,7 +1040,7 @@ RSpec.describe AccountController,
end
before do
- allow(AuthSource).to receive(:find_user).and_return attrs
+ allow(LdapAuthSource).to receive(:find_user).and_return attrs
end
it "shows the account creation form with an error" do
diff --git a/spec/controllers/auth_sources_controller_spec.rb b/spec/controllers/auth_sources_controller_spec.rb
deleted file mode 100644
index 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
-end
diff --git a/spec/controllers/concerns/auth_source_slo_spec.rb b/spec/controllers/concerns/auth_source_slo_spec.rb
index 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' do
render_views
let!(: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 do
diff --git a/spec/controllers/concerns/auth_source_sso_spec.rb b/spec/controllers/concerns/auth_source_sso_spec.rb
index 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' do
let!(: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:)
end
it "logs in given user and activate it" do
@@ -150,19 +150,19 @@ RSpec.describe MyController,
end
context "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"
end
context "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:)
end
it_behaves_like "auth source sso failure"
diff --git a/spec/controllers/concerns/omniauth_login_spec.rb b/spec/controllers/concerns/omniauth_login_spec.rb
index 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' do
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_nil
expect(user.current_password).to be_nil
expect(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_nil
expect(user.current_password).to be_nil
expect(user.identity_url).to eql('google:123545')
end
diff --git a/spec/controllers/ldap_auth_sources_controller_spec.rb b/spec/controllers/ldap_auth_sources_controller_spec.rb
index 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 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
@@ -44,9 +45,123 @@ RSpec.describe LdapAuthSourcesController do
it { is_expected.to respond_with :success }
it { is_expected.to render_template :new }
- it 'initializes a new AuthSource' do
+ it 'initializes a new LdapAuthSource' do
expect(assigns(:auth_source).class).to eq LdapAuthSource
expect(assigns(:auth_source)).to be_new_record
end
end
+
+ 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
+ end
end
diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb
index 276bba89f9a..d567fb5319d 100644
--- a/spec/controllers/users_controller_spec.rb
+++ b/spec/controllers/users_controller_spec.rb
@@ -764,17 +764,17 @@ RSpec.describe UsersController do
let(: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_source
as_logged_in_user admin do
put :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_nil
expect(user.check_password?('newpassPASS!')).to be_truthy
end
end
diff --git a/spec/factories/auth_source_factory.rb b/spec/factories/ldap_auth_source_factory.rb
similarity index 88%
rename from spec/factories/auth_source_factory.rb
rename to spec/factories/ldap_auth_source_factory.rb
index 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' }
- end
factory :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 use
attr_login { 'uid' }
tls_mode { 'plain_ldap' }
end
-
- factory :dummy_auth_source, class: 'DummyAuthSource' do
- name { 'DerpLAP' }
- end
end
diff --git a/spec/features/auth/auth_source_sso_logout_spec.rb b/spec/features/auth/auth_source_sso_logout_spec.rb
index 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' do
visit home_path
diff --git a/spec/features/users/create_spec.rb b/spec/features/users/create_spec.rb
index 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 do
last_name: 'boblast',
login: 'bob',
- auth_source: auth_source.name
+ ldap_auth_source: auth_source.name
perform_enqueued_jobs do
new_user_page.submit!
diff --git a/spec/features/users/edit_users_spec.rb b/spec/features/users/edit_users_spec.rb
index 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 do
let(:current_user) { admin }
let(:user) { create(:user, mail: '[email protected]') }
- let!(:auth_source) { create(:auth_source) }
+ let!(:auth_source) { create(:ldap_auth_source) }
before do
allow(User).to receive(:current).and_return current_user
end
def auth_select
- find 'select#user_auth_source_id'
+ find 'select#user_ldap_auth_source_id'
end
def user_password
@@ -66,7 +66,7 @@ RSpec.describe 'edit users', js: true, with_cuprite: true do
context 'with external authentication' do
before do
- user.auth_source = auth_source
+ user.ldap_auth_source = auth_source
user.save!
visit edit_user_path(user)
@@ -95,7 +95,7 @@ RSpec.describe 'edit users', js: true, with_cuprite: true do
expect(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 do
firstname_field.send_keys(:backspace)
end
firstname_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 do
user.reload
expect(user.firstname).to eq 'NewName'
- expect(user.auth_source).to eq auth_source
+ expect(user.ldap_auth_source).to eq auth_source
end
it 'can reinvite the user' do
diff --git a/spec/lib/api/v3/users/user_representer_spec.rb b/spec/lib/api/v3/users/user_representer_spec.rb
index 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 do
end
describe '#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_source
former_cache_key
end
@@ -341,7 +341,7 @@ RSpec.describe API::V3::Users::UserRepresenter do
end
it '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_now
expect(representer.json_cache_key)
.not_to eql former_cache_key
diff --git a/spec/models/ldap_auth_source_spec.rb b/spec/models/ldap_auth_source_spec.rb
index 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 do
expect(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.id
expect { User.new(attributes) }.not_to raise_error
end
diff --git a/spec/models/permitted_params_spec.rb b/spec/models/permitted_params_spec.rb
index 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 do
let(: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' do
let(:hash) { all_permissions.zip(all_permissions).to_h }
@@ -560,10 +560,10 @@ RSpec.describe PermittedParams do
end
context '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' do
expect(subject).to eq({})
end
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index c283c1bf26a..34e2b5a5f1e 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -33,16 +33,18 @@ RSpec.describe User do
let(: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)
end
let(: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:)
end
describe 'with long but allowed attributes' do
@@ -319,7 +321,7 @@ RSpec.describe User do
context 'for user without auth source' do
before do
- user.auth_source = nil
+ user.ldap_auth_source = nil
end
it 'is true' do
@@ -328,36 +330,20 @@ RSpec.describe User do
end
context '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_source
end
- 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_allowed
end
end
- context 'for user without authsource and with external authentication' do
+ context 'for user without LdapAuthSource and with external authentication' do
before do
- user.auth_source = nil
+ user.ldap_auth_source = nil
allow(user).to receive(:uses_external_authentication?).and_return(true)
end
@@ -457,7 +443,7 @@ RSpec.describe User do
user_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 do
end
context '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) do
user = 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)
user
end
@@ -697,9 +683,7 @@ RSpec.describe User do
ical_token
another_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)
end
it 'are destroyed when the user is destroyed' do
diff --git a/spec/requests/api/v3/user/create_user_resource_spec.rb b/spec/requests/api/v3/user/create_user_resource_spec.rb
index 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 do
it_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' do
before do
@@ -76,7 +76,7 @@ RSpec.describe API::V3::Users::UsersAPI do
user = User.find_by(login: parameters[:login])
- expect(user.auth_source).to eq auth_source
+ expect(user.ldap_auth_source).to eq auth_source
end
it_behaves_like 'represents the created user'
@@ -96,7 +96,7 @@ RSpec.describe API::V3::Users::UsersAPI do
user = User.find_by(login: parameters[:login])
- expect(user.auth_source).to eq auth_source
+ expect(user.ldap_auth_source).to eq auth_source
end
it_behaves_like 'represents the created user'
@@ -220,8 +220,8 @@ RSpec.describe API::V3::Users::UsersAPI do
end
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) }
before do
parameters[:_links] = {
@@ -236,7 +236,7 @@ RSpec.describe API::V3::Users::UsersAPI do
user = User.find_by(login: parameters[:login])
- expect(user.auth_source).to eq auth_source
+ expect(user.ldap_auth_source).to eq auth_source
end
end
end
diff --git a/spec/requests/auth/auth_source_sso_spec.rb b/spec/requests/auth/auth_source_sso_spec.rb
index 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 do
allow(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.rb
index 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 do
include_context 'with temporary LDAP'
subject do
- described_class.new(auth_source, user_list).call
+ described_class.new(ldap_auth_source, user_list).call
end
let(:user_list) do
@@ -31,8 +31,8 @@ RSpec.describe Ldap::ImportUsersFromListService do
end
context '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' do
subject
diff --git a/spec/services/ldap/import_users_from_filter_service_integration_spec.rb b/spec/services/ldap/import_users_from_filter_service_integration_spec.rb
index 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 do
include_context 'with temporary LDAP'
subject do
- described_class.new(auth_source, filter).call
+ described_class.new(ldap_auth_source, filter).call
end
let(: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.rb
index 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 do
include_context 'with temporary LDAP'
subject do
- described_class.new(auth_source).call
+ described_class.new(ldap_auth_source).call
end
context '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)' do
expect(user_aa729).to be_admin
@@ -20,8 +20,8 @@ RSpec.describe Ldap::SynchronizeUsersService do
end
context '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 do
context 'with a user that is in another LDAP' do
let(: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' do
expect(user_foo).to be_active
@@ -103,10 +103,10 @@ RSpec.describe Ldap::SynchronizeUsersService do
end
context '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]).call
end
it 'syncs all case-insensitive users' do
@@ -131,7 +131,7 @@ RSpec.describe Ldap::SynchronizeUsersService do
end
context '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 } do
diff --git a/spec/services/users/register_user_service_spec.rb b/spec/services/users/register_user_service_spec.rb
index 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 do
user = 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 1234
expect(user).to receive(:activate)
expect(user).to receive(:save).and_return true
diff --git a/spec/support/shared/with_test_ldap.rb b/spec/support/shared/with_test_ldap.rb
index 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) do
create(: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.rb
index 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)' do
before do
@@ -40,8 +40,8 @@ RSpec.describe 'account/register' do
end
context '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' do
expect(rendered).not_to include('user[login]')
@@ -64,8 +64,8 @@ RSpec.describe 'account/register' do
end
context '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' do
expect(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.rb
index 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' do
end
context 'with auth sources' do
- let(:auth_sources) { [create(:auth_source)] }
+ let(:auth_sources) { create_list(:ldap_auth_source, 1) }
before do
assign :auth_sources, auth_sources
@@ -162,7 +162,7 @@ RSpec.describe 'users/edit' do
end
context 'with auth sources' do
- let(:auth_sources) { [create(:auth_source)] }
+ let(:auth_sources) { create_list(:ldap_auth_source, 1) }
before do
assign :auth_sources, auth_sources
@@ -171,7 +171,7 @@ RSpec.describe 'users/edit' do
it 'shows the auth source selection' do
render
- expect(rendered).to have_selector('#user_auth_source_id')
+ expect(rendered).to have_selector('#user_ldap_auth_source_id')
end
end