Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
12420a22
Commit
12420a22
authored
Oct 16, 2013
by
Nihad Abbasov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor by_username_or_id
parent
e09cc195
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
10 deletions
+2
-10
app/models/user.rb
app/models/user.rb
+1
-5
lib/api/helpers.rb
lib/api/helpers.rb
+1
-5
No files found.
app/models/user.rb
View file @
12420a22
...
...
@@ -199,11 +199,7 @@ class User < ActiveRecord::Base
end
def
by_username_or_id
(
name_or_id
)
if
(
name_or_id
.
is_a?
(
Integer
))
User
.
find_by_id
(
name_or_id
)
else
User
.
find_by_username
(
name_or_id
)
end
where
(
'username = ? OR id = ?'
,
name_or_id
,
name_or_id
).
first
end
def
build_user
(
attrs
=
{},
options
=
{})
...
...
lib/api/helpers.rb
View file @
12420a22
...
...
@@ -11,11 +11,7 @@ module API
# If the sudo is the current user do nothing
if
(
identifier
&&
!
(
@current_user
.
id
==
identifier
||
@current_user
.
username
==
identifier
))
render_api_error!
(
'403 Forbidden: Must be admin to use sudo'
,
403
)
unless
@current_user
.
is_admin?
begin
@current_user
=
User
.
by_username_or_id
(
identifier
)
rescue
=>
ex
not_found!
(
"No user id or username for:
#{
identifier
}
"
)
end
not_found!
(
"No user id or username for:
#{
identifier
}
"
)
if
@current_user
.
nil?
end
@current_user
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment