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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
924a6b7d
Commit
924a6b7d
authored
Jul 28, 2016
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New AccessRequestsFinder
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
9a28756c
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
124 additions
and
6 deletions
+124
-6
app/controllers/admin/groups_controller.rb
app/controllers/admin/groups_controller.rb
+1
-1
app/controllers/admin/projects_controller.rb
app/controllers/admin/projects_controller.rb
+1
-1
app/controllers/groups/group_members_controller.rb
app/controllers/groups/group_members_controller.rb
+1
-1
app/controllers/projects/project_members_controller.rb
app/controllers/projects/project_members_controller.rb
+1
-1
app/finders/access_requests_finder.rb
app/finders/access_requests_finder.rb
+29
-0
lib/api/access_requests.rb
lib/api/access_requests.rb
+2
-2
spec/finders/access_requests_finder_spec.rb
spec/finders/access_requests_finder_spec.rb
+89
-0
No files found.
app/controllers/admin/groups_controller.rb
View file @
924a6b7d
...
...
@@ -10,7 +10,7 @@ class Admin::GroupsController < Admin::ApplicationController
def
show
@members
=
@group
.
members
.
order
(
"access_level DESC"
).
page
(
params
[
:members_page
])
@requesters
=
@group
.
requesters
@requesters
=
AccessRequestsFinder
.
new
(
@group
).
execute
(
current_user
)
@projects
=
@group
.
projects
.
page
(
params
[
:projects_page
])
end
...
...
app/controllers/admin/projects_controller.rb
View file @
924a6b7d
...
...
@@ -22,7 +22,7 @@ class Admin::ProjectsController < Admin::ApplicationController
end
@project_members
=
@project
.
members
.
page
(
params
[
:project_members_page
])
@requesters
=
@project
.
requesters
@requesters
=
AccessRequestsFinder
.
new
(
@project
).
execute
(
current_user
)
end
def
transfer
...
...
app/controllers/groups/group_members_controller.rb
View file @
924a6b7d
...
...
@@ -15,7 +15,7 @@ class Groups::GroupMembersController < Groups::ApplicationController
end
@members
=
@members
.
order
(
'access_level DESC'
).
page
(
params
[
:page
]).
per
(
50
)
@requesters
=
@group
.
requesters
if
can?
(
current_user
,
:admin_group
,
@group
)
@requesters
=
AccessRequestsFinder
.
new
(
@group
).
execute
(
current_user
)
@group_member
=
@group
.
group_members
.
new
end
...
...
app/controllers/projects/project_members_controller.rb
View file @
924a6b7d
...
...
@@ -29,7 +29,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController
@group_members
=
@group_members
.
order
(
'access_level DESC'
)
end
@requesters
=
@project
.
requesters
if
can?
(
current_user
,
:admin_project
,
@project
)
@requesters
=
AccessRequestsFinder
.
new
(
@project
).
execute
(
current_user
)
@project_member
=
@project
.
project_members
.
new
@project_group_links
=
@project
.
project_group_links
...
...
app/finders/access_requests_finder.rb
0 → 100644
View file @
924a6b7d
class
AccessRequestsFinder
attr_accessor
:source
# Arguments:
# source - a Group or Project
def
initialize
(
source
)
@source
=
source
end
def
execute
(
current_user
,
raise_error:
false
)
if
cannot_see_access_requests?
(
current_user
)
raise
Gitlab
::
Access
::
AccessDeniedError
if
raise_error
return
[]
end
source
.
requesters
end
def
execute!
(
current_user
)
execute
(
current_user
,
raise_error:
true
)
end
private
def
cannot_see_access_requests?
(
current_user
)
!
source
||
!
current_user
||
!
current_user
.
can?
(
:"admin_
#{
source
.
class
.
to_s
.
underscore
}
"
,
source
)
end
end
lib/api/access_requests.rb
View file @
924a6b7d
...
...
@@ -16,9 +16,9 @@ module API
# GET /projects/:id/access_requests
get
":id/access_requests"
do
source
=
find_source
(
source_type
,
params
[
:id
])
authorize_admin_source!
(
source_type
,
source
)
access_requesters
=
paginate
(
source
.
requesters
.
includes
(
:user
))
access_requesters
=
AccessRequestsFinder
.
new
(
source
).
execute!
(
current_user
)
access_requesters
=
paginate
(
access_requesters
.
includes
(
:user
))
present
access_requesters
.
map
(
&
:user
),
with:
Entities
::
AccessRequester
,
source:
source
end
...
...
spec/finders/access_requests_finder_spec.rb
0 → 100644
View file @
924a6b7d
require
'spec_helper'
describe
AccessRequestsFinder
,
services:
true
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:access_requester
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:group
)
{
create
(
:group
)
}
before
do
project
.
request_access
(
access_requester
)
group
.
request_access
(
access_requester
)
end
shared_examples
'a finder returning access requesters'
do
|
method_name
|
it
'returns access requesters'
do
access_requesters
=
described_class
.
new
(
source
).
public_send
(
method_name
,
user
)
expect
(
access_requesters
.
size
).
to
eq
(
1
)
expect
(
access_requesters
.
first
).
to
be_a
"
#{
source
.
class
.
to_s
}
Member"
.
constantize
expect
(
access_requesters
.
first
.
user
).
to
eq
(
access_requester
)
end
end
shared_examples
'a finder returning no results'
do
|
method_name
|
it
'raises Gitlab::Access::AccessDeniedError'
do
expect
(
described_class
.
new
(
source
).
public_send
(
method_name
,
user
)).
to
be_empty
end
end
shared_examples
'a finder raising Gitlab::Access::AccessDeniedError'
do
|
method_name
|
it
'raises Gitlab::Access::AccessDeniedError'
do
expect
{
described_class
.
new
(
source
).
public_send
(
method_name
,
user
)
}.
to
raise_error
(
Gitlab
::
Access
::
AccessDeniedError
)
end
end
describe
'#execute'
do
context
'when current user cannot see project access requests'
do
it_behaves_like
'a finder returning no results'
,
:execute
do
let
(
:source
)
{
project
}
end
it_behaves_like
'a finder returning no results'
,
:execute
do
let
(
:source
)
{
group
}
end
end
context
'when current user can see access requests'
do
before
do
project
.
team
<<
[
user
,
:master
]
group
.
add_owner
(
user
)
end
it_behaves_like
'a finder returning access requesters'
,
:execute
do
let
(
:source
)
{
project
}
end
it_behaves_like
'a finder returning access requesters'
,
:execute
do
let
(
:source
)
{
group
}
end
end
end
describe
'#execute!'
do
context
'when current user cannot see access requests'
do
it_behaves_like
'a finder raising Gitlab::Access::AccessDeniedError'
,
:execute!
do
let
(
:source
)
{
project
}
end
it_behaves_like
'a finder raising Gitlab::Access::AccessDeniedError'
,
:execute!
do
let
(
:source
)
{
group
}
end
end
context
'when current user can see access requests'
do
before
do
project
.
team
<<
[
user
,
:master
]
group
.
add_owner
(
user
)
end
it_behaves_like
'a finder returning access requesters'
,
:execute!
do
let
(
:source
)
{
project
}
end
it_behaves_like
'a finder returning access requesters'
,
:execute!
do
let
(
:source
)
{
group
}
end
end
end
end
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