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
e4f1c001
Commit
e4f1c001
authored
Mar 17, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restrict access to confidential issues through API
parent
7ee52833
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
112 additions
and
3 deletions
+112
-3
lib/api/issues.rb
lib/api/issues.rb
+2
-1
spec/requests/api/issues_spec.rb
spec/requests/api/issues_spec.rb
+110
-2
No files found.
lib/api/issues.rb
View file @
e4f1c001
...
...
@@ -82,7 +82,7 @@ module API
# GET /projects/:id/issues?milestone=1.0.0&state=closed
# GET /issues?iid=42
get
":id/issues"
do
issues
=
user_project
.
issues
issues
=
user_project
.
issues
.
visible_to_user
(
current_user
)
issues
=
filter_issues_state
(
issues
,
params
[
:state
])
unless
params
[
:state
].
nil?
issues
=
filter_issues_labels
(
issues
,
params
[
:labels
])
unless
params
[
:labels
].
nil?
issues
=
filter_by_iid
(
issues
,
params
[
:iid
])
unless
params
[
:iid
].
nil?
...
...
@@ -104,6 +104,7 @@ module API
# GET /projects/:id/issues/:issue_id
get
":id/issues/:issue_id"
do
@issue
=
user_project
.
issues
.
find
(
params
[
:issue_id
])
not_found!
unless
can?
(
current_user
,
:read_issue
,
@issue
)
present
@issue
,
with:
Entities
::
Issue
end
...
...
spec/requests/api/issues_spec.rb
View file @
e4f1c001
...
...
@@ -3,7 +3,11 @@ require 'spec_helper'
describe
API
::
API
,
api:
true
do
include
ApiHelpers
let
(
:user
)
{
create
(
:user
)
}
let!
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
let
(
:non_member
)
{
create
(
:user
)
}
let
(
:author
)
{
create
(
:author
)
}
let
(
:assignee
)
{
create
(
:assignee
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let!
(
:project
)
{
create
(
:project
,
:public
,
namespace:
user
.
namespace
)
}
let!
(
:closed_issue
)
do
create
:closed_issue
,
author:
user
,
...
...
@@ -12,6 +16,13 @@ describe API::API, api: true do
state: :closed
,
milestone:
milestone
end
let!
(
:confidential_issue
)
do
create
:issue
,
:confidential
,
project:
project
,
author:
author
,
assignee:
assignee
end
let!
(
:issue
)
do
create
:issue
,
author:
user
,
...
...
@@ -123,10 +134,43 @@ describe API::API, api: true do
let
(
:base_url
)
{
"/projects/
#{
project
.
id
}
"
}
let
(
:title
)
{
milestone
.
title
}
it
"should return project issues"
do
it
'should return project issues without confidential issues for non project members'
do
get
api
(
"
#{
base_url
}
/issues"
,
non_member
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
2
)
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
issue
.
title
)
end
it
'should return project confidential issues for author'
do
get
api
(
"
#{
base_url
}
/issues"
,
author
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
3
)
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
issue
.
title
)
end
it
'should return project confidential issues for assignee'
do
get
api
(
"
#{
base_url
}
/issues"
,
assignee
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
3
)
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
issue
.
title
)
end
it
'should return project issues with confidential issues for project members'
do
get
api
(
"
#{
base_url
}
/issues"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
3
)
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
issue
.
title
)
end
it
'should return project confidential issues for admin'
do
get
api
(
"
#{
base_url
}
/issues"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
3
)
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
issue
.
title
)
end
...
...
@@ -206,6 +250,41 @@ describe API::API, api: true do
get
api
(
"/projects/
#{
project
.
id
}
/issues/54321"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
end
context
'confidential issues'
do
it
"should return 404 for non project members"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
confidential_issue
.
id
}
"
,
non_member
)
expect
(
response
.
status
).
to
eq
(
404
)
end
it
"should return confidential issue for project members"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
confidential_issue
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
confidential_issue
.
title
)
expect
(
json_response
[
'iid'
]).
to
eq
(
confidential_issue
.
iid
)
end
it
"should return confidential issue for author"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
confidential_issue
.
id
}
"
,
author
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
confidential_issue
.
title
)
expect
(
json_response
[
'iid'
]).
to
eq
(
confidential_issue
.
iid
)
end
it
"should return confidential issue for assignee"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
confidential_issue
.
id
}
"
,
assignee
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
confidential_issue
.
title
)
expect
(
json_response
[
'iid'
]).
to
eq
(
confidential_issue
.
iid
)
end
it
"should return confidential issue for admin"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
confidential_issue
.
id
}
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
confidential_issue
.
title
)
expect
(
json_response
[
'iid'
]).
to
eq
(
confidential_issue
.
iid
)
end
end
end
describe
"POST /projects/:id/issues"
do
...
...
@@ -294,6 +373,35 @@ describe API::API, api: true do
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
json_response
[
'message'
][
'labels'
][
'?'
][
'title'
]).
to
eq
([
'is invalid'
])
end
context
'confidential issues'
do
it
"should return 403 for non project members"
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
confidential_issue
.
id
}
"
,
non_member
),
title:
'updated title'
expect
(
response
.
status
).
to
eq
(
403
)
end
it
"should update a confidential issue for project members"
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
confidential_issue
.
id
}
"
,
user
),
title:
'updated title'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
'updated title'
)
end
it
"should update a confidential issue for author"
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
confidential_issue
.
id
}
"
,
author
),
title:
'updated title'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
'updated title'
)
end
it
"should update a confidential issue for admin"
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
confidential_issue
.
id
}
"
,
admin
),
title:
'updated title'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
'updated title'
)
end
end
end
describe
'PUT /projects/:id/issues/:issue_id to update labels'
do
...
...
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