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
896c57f8
Commit
896c57f8
authored
Jul 14, 2021
by
Serena Fang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor bot in resource method
parent
db23316e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
6 deletions
+12
-6
lib/gitlab/auth.rb
lib/gitlab/auth.rb
+12
-6
No files found.
lib/gitlab/auth.rb
View file @
896c57f8
...
...
@@ -199,20 +199,26 @@ module Gitlab
return
unless
valid_scoped_token?
(
token
,
all_available_scopes
)
return
unless
token_bot_in_resource
(
token
,
project
)
if
project
&&
token
.
user
.
project_bot?
return
unless
token_bot_in_project?
(
token
.
user
,
project
)
||
token_bot_in_group?
(
token
.
user
,
project
)
end
if
can_user_login_with_non_expired_password?
(
token
.
user
)
||
token
.
user
.
project_bot?
Gitlab
::
Auth
::
Result
.
new
(
token
.
user
,
nil
,
:personal_access_token
,
abilities_for_scopes
(
token
.
scopes
))
end
end
# rubocop: disable CodeReuse/ActiveRecord
def
token_bot_in_resource
(
token
,
project
)
return
true
unless
project
&&
token
.
user
.
project_bot?
&&
!
project
.
bots
.
include?
(
token
.
user
)
def
token_bot_in_project?
(
user
,
project
)
project
.
bots
.
include?
(
user
)
end
return
false
unless
project
.
group
# rubocop: disable CodeReuse/ActiveRecord
project
.
group
.
self_and_ancestors
.
where
(
id:
token
.
user
.
groups
).
exists?
# The generic implementation of resource access token is functional
# but requires an additional check to verify if the token user is a member of
# the project's group, its ancestor groups, or its shared groups.
def
token_bot_in_group?
(
user
,
project
)
project
.
group
&&
project
.
group
.
members_with_parents
.
where
(
user_id:
user
.
id
).
exists?
end
# rubocop: enable CodeReuse/ActiveRecord
...
...
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