Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
924a6b7d
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
924a6b7d
编写于
7月 28, 2016
作者:
R
Rémy Coutable
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
New AccessRequestsFinder
Signed-off-by:
N
Rémy Coutable
<
remy@rymai.me
>
上级
9a28756c
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
124 addition
and
6 deletion
+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
未找到文件。
app/controllers/admin/groups_controller.rb
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录