Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
b5399517
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,发现更多精彩内容 >>
提交
b5399517
编写于
7月 18, 2017
作者:
S
Shinya Maeda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ini
上级
045e4de4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
321 addition
and
0 deletion
+321
-0
lib/api/api.rb
lib/api/api.rb
+1
-0
lib/api/group_variables.rb
lib/api/group_variables.rb
+95
-0
lib/api/helpers.rb
lib/api/helpers.rb
+4
-0
spec/requests/api/group_variables_spec.rb
spec/requests/api/group_variables_spec.rb
+221
-0
未找到文件。
lib/api/api.rb
浏览文件 @
b5399517
...
...
@@ -134,6 +134,7 @@ module API
mount
::
API
::
Triggers
mount
::
API
::
Users
mount
::
API
::
Variables
mount
::
API
::
GroupVariables
mount
::
API
::
Version
route
:any
,
'*path'
do
...
...
lib/api/group_variables.rb
0 → 100644
浏览文件 @
b5399517
module
API
class
GroupVariables
<
Grape
::
API
include
PaginationParams
before
{
authenticate!
}
before
{
authorize!
:admin_build
,
user_group
}
params
do
requires
:id
,
type:
String
,
desc:
'The ID of a group'
end
resource
:groups
,
requirements:
{
id:
%r{[^/]+}
}
do
desc
'Get group-level variables'
do
success
Entities
::
Variable
end
params
do
use
:pagination
end
get
':id/variables'
do
variables
=
user_group
.
variables
present
paginate
(
variables
),
with:
Entities
::
Variable
end
desc
'Get a specific variable from a group'
do
success
Entities
::
Variable
end
params
do
requires
:key
,
type:
String
,
desc:
'The key of the variable'
end
get
':id/variables/:key'
do
key
=
params
[
:key
]
variable
=
user_group
.
variables
.
find_by
(
key:
key
)
return
not_found!
(
'GroupVariable'
)
unless
variable
present
variable
,
with:
Entities
::
Variable
end
desc
'Create a new variable in a group'
do
success
Entities
::
Variable
end
params
do
requires
:key
,
type:
String
,
desc:
'The key of the variable'
requires
:value
,
type:
String
,
desc:
'The value of the variable'
optional
:protected
,
type:
String
,
desc:
'Whether the variable is protected'
end
post
':id/variables'
do
variable_params
=
declared_params
(
include_missing:
false
)
variable
=
user_group
.
variables
.
create
(
variable_params
)
if
variable
.
valid?
present
variable
,
with:
Entities
::
Variable
else
render_validation_error!
(
variable
)
end
end
desc
'Update an existing variable from a group'
do
success
Entities
::
Variable
end
params
do
optional
:key
,
type:
String
,
desc:
'The key of the variable'
optional
:value
,
type:
String
,
desc:
'The value of the variable'
optional
:protected
,
type:
String
,
desc:
'Whether the variable is protected'
end
put
':id/variables/:key'
do
variable
=
user_group
.
variables
.
find_by
(
key:
params
[
:key
])
return
not_found!
(
'GroupVariable'
)
unless
variable
variable_params
=
declared_params
(
include_missing:
false
).
except
(
:key
)
if
variable
.
update
(
variable_params
)
present
variable
,
with:
Entities
::
Variable
else
render_validation_error!
(
variable
)
end
end
desc
'Delete an existing variable from a group'
do
success
Entities
::
Variable
end
params
do
requires
:key
,
type:
String
,
desc:
'The key of the variable'
end
delete
':id/variables/:key'
do
variable
=
user_group
.
variables
.
find_by
(
key:
params
[
:key
])
not_found!
(
'GroupVariable'
)
unless
variable
variable
.
destroy
end
end
end
end
lib/api/helpers.rb
浏览文件 @
b5399517
...
...
@@ -29,6 +29,10 @@ module API
@project
||=
find_project!
(
params
[
:id
])
end
def
user_group
@group
||=
find_group!
(
params
[
:id
])
end
def
available_labels
@available_labels
||=
LabelsFinder
.
new
(
current_user
,
project_id:
user_project
.
id
).
execute
end
...
...
spec/requests/api/group_variables_spec.rb
0 → 100644
浏览文件 @
b5399517
require
'spec_helper'
describe
API
::
GroupVariables
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:user
)
{
create
(
:user
)
}
describe
'GET /groups/:id/variables'
do
let!
(
:variable
)
{
create
(
:ci_group_variable
,
group:
group
)
}
context
'authorized user with proper permissions'
do
before
do
group
.
add_master
(
user
)
end
it
'returns group variables'
do
get
api
(
"/groups/
#{
group
.
id
}
/variables"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_a
(
Array
)
end
end
context
'authorized user with invalid permissions'
do
it
'does not return group variables'
do
get
api
(
"/groups/
#{
group
.
id
}
/variables"
,
user
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
context
'unauthorized user'
do
it
'does not return group variables'
do
get
api
(
"/groups/
#{
group
.
id
}
/variables"
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
describe
'GET /groups/:id/variables/:key'
do
let!
(
:variable
)
{
create
(
:ci_group_variable
,
group:
group
)
}
context
'authorized user with proper permissions'
do
before
do
group
.
add_master
(
user
)
end
it
'returns group variable details'
do
get
api
(
"/groups/
#{
group
.
id
}
/variables/
#{
variable
.
key
}
"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'value'
]).
to
eq
(
variable
.
value
)
expect
(
json_response
[
'protected'
]).
to
eq
(
variable
.
protected?
)
end
it
'responds with 404 Not Found if requesting non-existing variable'
do
get
api
(
"/groups/
#{
group
.
id
}
/variables/non_existing_variable"
,
user
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
'authorized user with invalid permissions'
do
it
'does not return group variable details'
do
get
api
(
"/groups/
#{
group
.
id
}
/variables/
#{
variable
.
key
}
"
,
user
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
context
'unauthorized user'
do
it
'does not return group variable details'
do
get
api
(
"/groups/
#{
group
.
id
}
/variables/
#{
variable
.
key
}
"
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
describe
'POST /groups/:id/variables'
do
context
'authorized user with proper permissions'
do
let!
(
:variable
)
{
create
(
:ci_group_variable
,
group:
group
)
}
before
do
group
.
add_master
(
user
)
end
it
'creates variable'
do
expect
do
post
api
(
"/groups/
#{
group
.
id
}
/variables"
,
user
),
key:
'TEST_VARIABLE_2'
,
value:
'VALUE_2'
,
protected:
true
end
.
to
change
{
group
.
variables
.
count
}.
by
(
1
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'key'
]).
to
eq
(
'TEST_VARIABLE_2'
)
expect
(
json_response
[
'value'
]).
to
eq
(
'VALUE_2'
)
expect
(
json_response
[
'protected'
]).
to
be_truthy
end
it
'creates variable with optional attributes'
do
expect
do
post
api
(
"/groups/
#{
group
.
id
}
/variables"
,
user
),
key:
'TEST_VARIABLE_2'
,
value:
'VALUE_2'
end
.
to
change
{
group
.
variables
.
count
}.
by
(
1
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'key'
]).
to
eq
(
'TEST_VARIABLE_2'
)
expect
(
json_response
[
'value'
]).
to
eq
(
'VALUE_2'
)
expect
(
json_response
[
'protected'
]).
to
be_falsey
end
it
'does not allow to duplicate variable key'
do
expect
do
post
api
(
"/groups/
#{
group
.
id
}
/variables"
,
user
),
key:
variable
.
key
,
value:
'VALUE_2'
end
.
to
change
{
group
.
variables
.
count
}.
by
(
0
)
expect
(
response
).
to
have_http_status
(
400
)
end
end
context
'authorized user with invalid permissions'
do
it
'does not create variable'
do
post
api
(
"/groups/
#{
group
.
id
}
/variables"
,
user
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
context
'unauthorized user'
do
it
'does not create variable'
do
post
api
(
"/groups/
#{
group
.
id
}
/variables"
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
describe
'PUT /groups/:id/variables/:key'
do
let!
(
:variable
)
{
create
(
:ci_group_variable
,
group:
group
)
}
context
'authorized user with proper permissions'
do
before
do
group
.
add_master
(
user
)
end
it
'updates variable data'
do
initial_variable
=
group
.
variables
.
first
value_before
=
initial_variable
.
value
put
api
(
"/groups/
#{
group
.
id
}
/variables/
#{
variable
.
key
}
"
,
user
),
value:
'VALUE_1_UP'
,
protected:
true
updated_variable
=
group
.
variables
.
first
expect
(
response
).
to
have_http_status
(
200
)
expect
(
value_before
).
to
eq
(
variable
.
value
)
expect
(
updated_variable
.
value
).
to
eq
(
'VALUE_1_UP'
)
expect
(
updated_variable
).
to
be_protected
end
it
'responds with 404 Not Found if requesting non-existing variable'
do
put
api
(
"/groups/
#{
group
.
id
}
/variables/non_existing_variable"
,
user
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
'authorized user with invalid permissions'
do
it
'does not update variable'
do
put
api
(
"/groups/
#{
group
.
id
}
/variables/
#{
variable
.
key
}
"
,
user
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
context
'unauthorized user'
do
it
'does not update variable'
do
put
api
(
"/groups/
#{
group
.
id
}
/variables/
#{
variable
.
key
}
"
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
describe
'DELETE /groups/:id/variables/:key'
do
let!
(
:variable
)
{
create
(
:ci_group_variable
,
group:
group
)
}
context
'authorized user with proper permissions'
do
before
do
group
.
add_master
(
user
)
end
it
'deletes variable'
do
expect
do
delete
api
(
"/groups/
#{
group
.
id
}
/variables/
#{
variable
.
key
}
"
,
user
)
expect
(
response
).
to
have_http_status
(
204
)
end
.
to
change
{
group
.
variables
.
count
}.
by
(
-
1
)
end
it
'responds with 404 Not Found if requesting non-existing variable'
do
delete
api
(
"/groups/
#{
group
.
id
}
/variables/non_existing_variable"
,
user
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
'authorized user with invalid permissions'
do
it
'does not delete variable'
do
delete
api
(
"/groups/
#{
group
.
id
}
/variables/
#{
variable
.
key
}
"
,
user
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
context
'unauthorized user'
do
it
'does not delete variable'
do
delete
api
(
"/groups/
#{
group
.
id
}
/variables/
#{
variable
.
key
}
"
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录