Read about our upcoming Code of Conduct on this issue

Commit a3f645ef authored by skv's avatar skv
Browse files

Remove deprecated finders

parent fd7bd12feb01
......@@ -51,7 +51,7 @@ def handle_project_member_errors(errors)
@branch = user_project.repository.find_branch(params[:branch])
not_found! unless @branch
protected_branch = user_project.protected_branches.find_by_name(@branch.name)
protected_branch = user_project.protected_branches.find_by(name: @branch.name)
user_project.protected_branches.create(name: @branch.name) unless protected_branch
present @branch, with: Entities::RepoObject, project: user_project
......@@ -69,7 +69,7 @@ def handle_project_member_errors(errors)
@branch = user_project.repository.find_branch(params[:branch])
not_found! unless @branch
protected_branch = user_project.protected_branches.find_by_name(@branch.name)
protected_branch = user_project.protected_branches.find_by(name: @branch.name)
protected_branch.destroy if protected_branch
present @branch, with: Entities::RepoObject, project: user_project
......
......@@ -117,7 +117,7 @@ class Users < Grape::API
# DELETE /users/:id
delete ":id" do
authenticated_as_admin!
user = User.find_by_id(params[:id])
user = User.find_by(id: params[:id])
if user
user.destroy
......
module Gitlab
class Auth
def find(login, password)
user = User.find_by_email(login) || User.find_by_username(login)
user = User.find_by(email: login) || User.find_by(username: login)
if user.nil? || user.ldap_user?
# Second chance - try LDAP authentication
......
......@@ -6,17 +6,17 @@ def identify(identifier, project, newrev)
if identifier.blank?
# Local push from gitlab
email = project.repository.commit(newrev).author_email rescue nil
User.find_by_email(email) if email
User.find_by(email: email) if email
elsif identifier =~ /\Auser-\d+\Z/
# git push over http
user_id = identifier.gsub("user-", "")
User.find_by_id(user_id)
User.find_by(id: user_id)
elsif identifier =~ /\Akey-\d+\Z/
# git push over ssh
key_id = identifier.gsub("key-", "")
Key.find_by_id(key_id).try(:user)
Key.find_by(id: key_id).try(:user)
end
end
end
......
......@@ -44,13 +44,13 @@ def find_or_create(auth)
end
def find_user(email)
user = model.find_by_email(email)
user = model.find_by(email: email)
# If no user found and allow_username_or_email_login is true
# we look for user by extracting part of their email
if !user && email && ldap_conf['allow_username_or_email_login']
uname = email.partition('@').first
user = model.find_by_username(uname)
user = model.find_by(username: uname)
end
user
......
......@@ -15,7 +15,7 @@ namespace :gitlab do
desc "GITLAB | Add a specific user to all projects (as a developer)"
task :user_to_projects, [:email] => :environment do |t, args|
user = User.find_by_email args.email
user = User.find_by(email: args.email)
project_ids = Project.pluck(:id)
puts "Importing #{user.email} users into #{project_ids.size} projects"
UsersProject.add_users_into_projects(project_ids, Array.wrap(user.id), UsersProject::DEVELOPER)
......
......@@ -43,13 +43,13 @@ namespace :gitlab do
username.gsub!("+", ".")
# return username if no matches
return username unless User.find_by_username(username)
return username unless User.find_by(username: username)
# look for same username
(1..10).each do |i|
suffixed_username = "#{username}#{i}"
return suffixed_username unless User.find_by_username(suffixed_username)
return suffixed_username unless User.find_by(username: suffixed_username)
end
end
......
......@@ -50,7 +50,7 @@ namespace :gitlab do
# find group namespace
if group_name
group = Group.find_by_path(group_name)
group = Group.find_by(path: group_name)
# create group namespace
if !group
group = Group.new(:name => group_name)
......
......@@ -25,7 +25,7 @@
it "should update credentials by email if missing uid" do
user = double('User')
User.stub find_by_extern_uid_and_provider: nil
User.stub find_by_email: user
User.stub(:find_by).with(hash_including(email: anything())) { user }
user.should_receive :update_attributes
gl_auth.find_or_create(@auth)
end
......@@ -35,8 +35,8 @@
value = Gitlab.config.ldap.allow_username_or_email_login
Gitlab.config.ldap['allow_username_or_email_login'] = true
User.stub find_by_extern_uid_and_provider: nil
User.stub find_by_email: nil
User.stub find_by_username: user
User.stub(:find_by).with(hash_including(email: anything())) { nil }
User.stub(:find_by).with(hash_including(username: anything())) { user }
user.should_receive :update_attributes
gl_auth.find_or_create(@auth)
Gitlab.config.ldap['allow_username_or_email_login'] = value
......@@ -47,8 +47,8 @@
value = Gitlab.config.ldap.allow_username_or_email_login
Gitlab.config.ldap['allow_username_or_email_login'] = false
User.stub find_by_extern_uid_and_provider: nil
User.stub find_by_email: nil
User.stub find_by_username: user
User.stub(:find_by).with(hash_including(email: anything())) { nil }
User.stub(:find_by).with(hash_including(username: anything())) { user }
user.should_not_receive :update_attributes
gl_auth.find_or_create(@auth)
Gitlab.config.ldap['allow_username_or_email_login'] = value
......
......@@ -93,7 +93,7 @@
expect {
post api("/users", admin), attr
}.to change { User.count }.by(1)
user = User.find_by_username(attr[:username])
user = User.find_by(username: attr[:username])
user.projects_limit.should == limit
user.theme_id.should == Gitlab::Theme::MARS
Gitlab.config.gitlab.unstub(:default_projects_limit)
......
......@@ -19,7 +19,7 @@
end
it "does not run if the author is not in the project" do
Key.stub(find_by_id: nil)
Key.stub(:find_by).with(hash_including(id: anything())) { nil }
project.should_not_receive(:execute_hooks)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment