Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove AuthSource base namespace, model #13248

Merged
merged 5 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions app/components/ldap_auth_sources/row_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# frozen_string_literal: true

#-- 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.
#++

module LdapAuthSources
class RowComponent < ::RowComponent
def name
link_to model.name, edit_ldap_auth_source_path(model)
end

delegate :host, to: :model

def users
model.users.size
end

def row_css_id
"ldap-auth-source-#{model.id}"
end

def button_links
[test_link, delete_link].compact
end

def test_link
link_to t(:button_test), { controller: 'ldap_auth_sources', action: 'test_connection', id: model }
end

def delete_link
return if users > 0

link_to I18n.t(:button_delete),
{ controller: 'ldap_auth_sources', id: model.id, action: :destroy },
method: :delete,
data: { confirm: I18n.t(:text_are_you_sure) },
class: 'icon icon-delete',
title: I18n.t(:button_delete)
end
end
end
63 changes: 63 additions & 0 deletions app/components/ldap_auth_sources/table_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# frozen_string_literal: true

#-- 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.
#++

module LdapAuthSources
class TableComponent < ::TableComponent
columns :name, :host, :users

def initial_sort
%i[id asc]
end

def sortable?
true
end

def sortable_column?(_column)
false
end

def inline_create_link
link_to(new_ldap_auth_source_path,
class: 'budget-add-row wp-inline-create--add-link',
title: I18n.t(:label_ldap_auth_source_new)) do
helpers.op_icon('icon icon-add')
end
end

def headers
[
['name', { caption: LdapAuthSource.human_attribute_name('name') }],
['host', { caption: LdapAuthSource.human_attribute_name('host') }],
['users', { caption: I18n.t(:label_user_plural) }]
]
end
end
end
4 changes: 2 additions & 2 deletions app/contracts/users/base_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class BaseContract < ::ModelContract
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,
Expand Down Expand Up @@ -91,7 +91,7 @@ def validate_password_writable

# 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
Expand Down
2 changes: 1 addition & 1 deletion app/contracts/users/create_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def authentication_defined
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

##
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/account_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def activate_invited(token)
session[:invitation_token] = token.value
user = token.user

if user.auth_source && user.auth_source.auth_method_name == 'LDAP'
if user.ldap_auth_source
activate_through_ldap user
else
activate_user user
Expand All @@ -247,7 +247,7 @@ def activate_user(user)
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
Expand Down Expand Up @@ -276,7 +276,7 @@ def auth_source_sso_failed
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
Expand Down Expand Up @@ -360,7 +360,7 @@ def register_with_auth_source(user)
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
Expand Down Expand Up @@ -437,7 +437,7 @@ def password_authentication(username, password)
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)
Expand Down
122 changes: 0 additions & 122 deletions app/controllers/auth_sources_controller.rb

This file was deleted.

6 changes: 3 additions & 3 deletions app/controllers/concerns/auth_source_sso.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ def find_or_create_sso_user(login, save: false)
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
Expand All @@ -143,7 +143,7 @@ def create_user_from_auth_source(login, save:)
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

Expand Down
Loading
Loading