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
Boxiang Sun
gitlab-ce
Commits
eed79986
Commit
eed79986
authored
Aug 25, 2018
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add subscription API for the group label API
parent
f66fec1d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
117 additions
and
16 deletions
+117
-16
lib/api/entities.rb
lib/api/entities.rb
+2
-2
lib/api/helpers.rb
lib/api/helpers.rb
+2
-2
lib/api/subscriptions.rb
lib/api/subscriptions.rb
+24
-11
spec/requests/api/group_labels_spec.rb
spec/requests/api/group_labels_spec.rb
+89
-1
No files found.
lib/api/entities.rb
View file @
eed79986
...
...
@@ -1019,12 +1019,12 @@ module API
label
.
open_merge_requests_count
(
options
[
:current_user
])
end
expose
:priority
do
|
label
,
options
|
expose
:priority
,
if:
lambda
{
|
_
,
options
|
options
[
:project
].
is_a?
(
::
Project
)
}
do
|
label
,
options
|
label
.
priority
(
options
[
:project
])
end
expose
:subscribed
do
|
label
,
options
|
label
.
subscribed?
(
options
[
:current_user
],
options
[
:p
aren
t
])
label
.
subscribed?
(
options
[
:current_user
],
options
[
:p
rojec
t
])
end
end
...
...
lib/api/helpers.rb
View file @
eed79986
...
...
@@ -170,8 +170,8 @@ module API
end
end
def
find_
project_label
(
id
)
labels
=
available_labels_for
(
user_projec
t
)
def
find_
label
(
parent
,
id
)
labels
=
available_labels_for
(
paren
t
)
label
=
labels
.
find_by_id
(
id
)
||
labels
.
find_by_title
(
id
)
label
||
not_found!
(
'Label'
)
...
...
lib/api/subscriptions.rb
View file @
eed79986
...
...
@@ -4,11 +4,12 @@ module API
class
Subscriptions
<
Grape
::
API
before
{
authenticate!
}
subscribable_types
=
{
'merge_requests'
=>
proc
{
|
id
|
find_merge_request_with_access
(
id
,
:update_merge_request
)
},
'issues'
=>
proc
{
|
id
|
find_project_issue
(
id
)
},
'labels'
=>
proc
{
|
id
|
find_project_label
(
id
)
}
}
subscribables
=
[
[
'merge_requests'
,
Project
,
proc
{
|
id
|
find_merge_request_with_access
(
id
,
:update_merge_request
)
},
proc
{
user_project
}],
[
'issues'
,
Project
,
proc
{
|
id
|
find_project_issue
(
id
)
},
proc
{
user_project
}],
[
'labels'
,
Project
,
proc
{
|
id
|
find_label
(
user_project
,
id
)
},
proc
{
user_project
}],
[
'labels'
,
Group
,
proc
{
|
id
|
find_label
(
user_group
,
id
)
},
proc
{
nil
}]
]
params
do
requires
:id
,
type:
String
,
desc:
'The ID of a project'
...
...
@@ -19,17 +20,27 @@ module API
type_singularized
=
type
.
singularize
entity_class
=
Entities
.
const_get
(
type_singularized
.
camelcase
)
subscribables
.
each
do
|
subscribable
|
source_type
=
subscribable
[
:source
].
name
.
underscore
entity_class
=
Entities
.
const_get
(
subscribable
[
:type
].
singularize
.
camelcase
)
params
do
requires
:id
,
type:
String
,
desc:
"The
#{
source_type
}
ID"
requires
:subscribable_id
,
type:
String
,
desc:
'The ID of a resource'
end
resource
source_type
.
pluralize
,
requirements:
API
::
NAMESPACE_OR_PROJECT_REQUIREMENTS
do
desc
'Subscribe to a resource'
do
success
entity_class
end
post
":id/
#{
type
}
/:subscribable_id/subscribe"
do
parent
=
instance_exec
(
&
parent_ressource
)
resource
=
instance_exec
(
params
[
:subscribable_id
],
&
finder
)
if
resource
.
subscribed?
(
current_user
,
user_projec
t
)
if
resource
.
subscribed?
(
current_user
,
paren
t
)
not_modified!
else
resource
.
subscribe
(
current_user
,
user_projec
t
)
present
resource
,
with:
entity_class
,
current_user:
current_user
,
project:
user_projec
t
resource
.
subscribe
(
current_user
,
paren
t
)
present
resource
,
with:
entity_class
,
current_user:
current_user
,
project:
paren
t
end
end
...
...
@@ -37,13 +48,15 @@ module API
success
entity_class
end
post
":id/
#{
type
}
/:subscribable_id/unsubscribe"
do
parent
=
instance_exec
(
&
parent_ressource
)
resource
=
instance_exec
(
params
[
:subscribable_id
],
&
finder
)
if
!
resource
.
subscribed?
(
current_user
,
user_project
)
if
!
resource
.
subscribed?
(
current_user
,
parent
)
not_modified!
else
resource
.
unsubscribe
(
current_user
,
user_projec
t
)
present
resource
,
with:
entity_class
,
current_user:
current_user
,
project:
user_projec
t
resource
.
unsubscribe
(
current_user
,
paren
t
)
present
resource
,
with:
entity_class
,
current_user:
current_user
,
project:
paren
t
end
end
end
...
...
spec/requests/api/group_labels_spec.rb
View file @
eed79986
...
...
@@ -209,4 +209,92 @@ describe API::GroupLabels do
expect
(
json_response
[
'message'
][
'color'
]).
to
eq
([
'must be a valid color code'
])
end
end
end
\ No newline at end of file
describe
'POST /groups/:id/labels/:label_id/subscribe'
do
context
'when label_id is a label title'
do
it
'subscribes to the label'
do
post
api
(
"/groups/
#{
group
.
id
}
/labels/
#{
label1
.
title
}
/subscribe"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
label1
.
title
)
expect
(
json_response
[
'subscribed'
]).
to
be_truthy
end
end
context
'when label_id is a label ID'
do
it
'subscribes to the label'
do
post
api
(
"/groups/
#{
group
.
id
}
/labels/
#{
label1
.
id
}
/subscribe"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
label1
.
title
)
expect
(
json_response
[
'subscribed'
]).
to
be_truthy
end
end
context
'when user is already subscribed to label'
do
before
do
label1
.
subscribe
(
user
)
end
it
'returns 304'
do
post
api
(
"/groups/
#{
group
.
id
}
/labels/
#{
label1
.
id
}
/subscribe"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
304
)
end
end
context
'when label ID is not found'
do
it
'returns 404 error'
do
post
api
(
"/groups/
#{
group
.
id
}
/labels/1234/subscribe"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
end
describe
'POST /groups/:id/labels/:label_id/unsubscribe'
do
before
do
label1
.
subscribe
(
user
)
end
context
'when label_id is a label title'
do
it
'unsubscribes from the label'
do
post
api
(
"/groups/
#{
group
.
id
}
/labels/
#{
label1
.
title
}
/unsubscribe"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
label1
.
title
)
expect
(
json_response
[
'subscribed'
]).
to
be_falsey
end
end
context
'when label_id is a label ID'
do
it
'unsubscribes from the label'
do
post
api
(
"/groups/
#{
group
.
id
}
/labels/
#{
label1
.
id
}
/unsubscribe"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
label1
.
title
)
expect
(
json_response
[
'subscribed'
]).
to
be_falsey
end
end
context
'when user is already unsubscribed from label'
do
before
do
label1
.
unsubscribe
(
user
)
end
it
'returns 304'
do
post
api
(
"/groups/
#{
group
.
id
}
/labels/
#{
label1
.
id
}
/unsubscribe"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
304
)
end
end
context
'when label ID is not found'
do
it
'returns 404 error'
do
post
api
(
"/groups/
#{
group
.
id
}
/labels/1234/unsubscribe"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
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