OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
lookup existing user for mapping case insensitive
ulfertsc54e895ad416
diff --git a/app/models/user.rb b/app/models/user.rbindex e27d83e1fec..4973b627d18 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -31,6 +31,8 @@require 'digest/sha1'class User < Principal+ include ::Scopes::Scoped+USER_FORMATS_STRUCTURE = {firstname_lastname: [:firstname, :lastname],firstname: [:firstname],@@ -95,6 +97,8 @@ class User < Principalscope :blocked, -> { create_blocked_scope(self, true) }scope :not_blocked, -> { create_blocked_scope(self, false) }+ scope_classes Users::Scopes::FindByLogin+def self.create_blocked_scope(scope, blocked)scope.where(blocked_condition(blocked))enddiff --git a/app/models/users/scopes/find_by_login.rb b/app/models/users/scopes/find_by_login.rbnew file mode 100644index 00000000000..9a235305781--- /dev/null+++ b/app/models/users/scopes/find_by_login.rb@@ -0,0 +1,38 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 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-2017 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 docs/COPYRIGHT.rdoc for more details.+#++++# Find a user account by matching case-insensitive.+module Users::Scopes+ class FindByLogin+ def self.fetch(login)+ User.where(["LOWER(login) = ?", login.to_s.downcase]).first+ end+ end+enddiff --git a/app/services/authentication/omniauth_service.rb b/app/services/authentication/omniauth_service.rbindex 408d25fbb67..34d76077c1f 100644--- a/app/services/authentication/omniauth_service.rb+++ b/app/services/authentication/omniauth_service.rb@@ -141,7 +141,7 @@ module Authenticationdef remap_existing_userreturn unless Setting.oauth_allow_remapping_of_existing_users?- User.find_by(login: user_attributes[:login])+ User.find_by_login(user_attributes[:login])end##diff --git a/modules/documents/spec/features/attachment_upload_spec.rb b/modules/documents/spec/features/attachment_upload_spec.rbindex d912f4301a4..6bc74ed970d 100644--- a/modules/documents/spec/features/attachment_upload_spec.rb+++ b/modules/documents/spec/features/attachment_upload_spec.rb@@ -52,7 +52,7 @@ describe 'Upload attachment to documents', js: true doit 'can upload an image' dovisit project_documents_path(project)- # Saveguard to ensure the page is properly loaded before clicking on the "+ Document" button+ # Safeguard to ensure the page is properly loaded before clicking on the "+ Document" button# which sometimes seems to come to early.expect(find_field(I18n.t(:'attributes.category'))).to be_checkeddiff --git a/spec/models/users/scopes/find_by_login_spec.rb b/spec/models/users/scopes/find_by_login_spec.rbnew file mode 100644index 00000000000..4431dc449ee--- /dev/null+++ b/spec/models/users/scopes/find_by_login_spec.rb@@ -0,0 +1,68 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 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-2017 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 docs/COPYRIGHT.rdoc for more details.+#++++require 'spec_helper'++describe Users::Scopes::FindByLogin, type: :model do+ let!(:activity) { FactoryBot.create(:time_entry_activity) }+ let!(:project) { FactoryBot.create(:project) }+ let!(:user) { FactoryBot.create(:user, login: login) }+ let(:login) { 'Some string' }+ let(:search_login) { login }++ describe '.fetch' do+ subject { described_class.fetch(search_login) }++ context 'with the exact same login' do+ it 'returns the user' do+ expect(subject)+ .to eql user+ end+ end++ context 'with a non existing login' do+ let(:search_login) { 'nothing' }++ it 'returns nil' do+ expect(subject)+ .to be_nil+ end+ end++ context 'with a lowercase login' do+ let(:search_login) { login.downcase }++ it 'returns the user with the matching login' do+ expect(subject)+ .to eql user+ end+ end+ end+enddiff --git a/spec/services/authentication/omniauth_service_spec.rb b/spec/services/authentication/omniauth_service_spec.rbindex dc6d11df073..9daa4553129 100644--- a/spec/services/authentication/omniauth_service_spec.rb+++ b/spec/services/authentication/omniauth_service_spec.rb@@ -85,7 +85,7 @@ describe Authentication::OmniauthService doendend- describe 'activiation of users' do+ describe 'activation of users' dolet(:call) { instance.call }context 'with an active found user' do@@ -121,8 +121,8 @@ describe Authentication::OmniauthService do# Remap findexpect(User)- .not_to(receive(:find_by))- .with(login: '[email protected]')+ .not_to(receive(:find_by_login))+ .with('[email protected]')callend@@ -141,8 +141,8 @@ describe Authentication::OmniauthService do# Remap findexpect(User)- .to(receive(:find_by))- .with(login: '[email protected]')+ .to(receive(:find_by_login))+ .with('[email protected]').and_return(user)expect(Users::RegisterUserService).not_to receive(:new)