diff options
| author | Rémy Coutable <remy@rymai.me> | 2016-04-13 15:54:31 +0000 |
|---|---|---|
| committer | Rémy Coutable <remy@rymai.me> | 2016-04-13 15:54:31 +0000 |
| commit | c8560894f7242d53f8fb63c32d5bcef4ab4a6b8a (patch) | |
| tree | df6e83bfb0692e9755e57bd6730ffb92165b02ce /lib/api | |
| parent | 3463ffde9e3ef425fbaa6093f01212cccb01707b (diff) | |
| parent | a9200d93d3e3d586302887fcaa0cf8f5fbd9a613 (diff) | |
| download | gitlab-ce-c8560894f7242d53f8fb63c32d5bcef4ab4a6b8a.tar.gz | |
Merge branch 'api-subscribe-issue-mr' into 'master'
API: Subscribe and unsubscribe from issues and merge requests
* Closes #6024
This MR is based on !3611, which must be merged first.
See merge request !3615
Diffstat (limited to 'lib/api')
| -rw-r--r-- | lib/api/issues.rb | 36 | ||||
| -rw-r--r-- | lib/api/merge_requests.rb | 36 |
2 files changed, 72 insertions, 0 deletions
diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 850e99981ff..4cdecadfe0f 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -231,6 +231,42 @@ module API authorize!(:destroy_issue, issue) issue.destroy end + + # Subscribes to a project issue + # + # Parameters: + # id (required) - The ID of a project + # issue_id (required) - The ID of a project issue + # Example Request: + # POST /projects/:id/issues/:issue_id/subscription + post ':id/issues/:issue_id/subscription' do + issue = user_project.issues.find(params[:issue_id]) + + if issue.subscribed?(current_user) + not_modified! + else + issue.toggle_subscription(current_user) + present issue, with: Entities::Issue, current_user: current_user + end + end + + # Unsubscribes from a project issue + # + # Parameters: + # id (required) - The ID of a project + # issue_id (required) - The ID of a project issue + # Example Request: + # DELETE /projects/:id/issues/:issue_id/subscription + delete ':id/issues/:issue_id/subscription' do + issue = user_project.issues.find(params[:issue_id]) + + if issue.subscribed?(current_user) + issue.unsubscribe(current_user) + present issue, with: Entities::Issue, current_user: current_user + else + not_modified! + end + end end end end diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb index 4e7de8867b4..7e78609ecb9 100644 --- a/lib/api/merge_requests.rb +++ b/lib/api/merge_requests.rb @@ -327,6 +327,42 @@ module API issues = ::Kaminari.paginate_array(merge_request.closes_issues(current_user)) present paginate(issues), with: Entities::Issue, current_user: current_user end + + # Subscribes to a merge request + # + # Parameters: + # id (required) - The ID of a project + # merge_request_id (required) - The ID of a merge request + # Example Request: + # POST /projects/:id/issues/:merge_request_id/subscription + post "#{path}/subscription" do + merge_request = user_project.merge_requests.find(params[:merge_request_id]) + + if merge_request.subscribed?(current_user) + not_modified! + else + merge_request.toggle_subscription(current_user) + present merge_request, with: Entities::MergeRequest, current_user: current_user + end + end + + # Unsubscribes from a merge request + # + # Parameters: + # id (required) - The ID of a project + # merge_request_id (required) - The ID of a merge request + # Example Request: + # DELETE /projects/:id/merge_requests/:merge_request_id/subscription + delete "#{path}/subscription" do + merge_request = user_project.merge_requests.find(params[:merge_request_id]) + + if merge_request.subscribed?(current_user) + merge_request.unsubscribe(current_user) + present merge_request, with: Entities::MergeRequest, current_user: current_user + else + not_modified! + end + end end end end |
