summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-04-08 14:36:54 +0000
committerRémy Coutable <remy@rymai.me>2016-04-08 14:36:54 +0000
commit312a09e7aa8ad74481f52c632a976a2218fbf025 (patch)
tree5c39fcf4d09a2eb9ed0e4d0d23a0bf9cb70de0c9
parent4d04e91814fefe24c186250b7962a7c9aa918d1f (diff)
parentfb2fde9d62a599f08c065c54de236eacb6558d60 (diff)
downloadgitlab-ce-312a09e7aa8ad74481f52c632a976a2218fbf025.tar.gz
Merge branch 'api-expose-subscribed' into 'master'
API: Expose subscribed? on issues and merge requests This is the first start for the new `subscribable` API. It exposes the `subscribed` field for issues and merge requests. Related to #6024 See merge request !3611
-rw-r--r--CHANGELOG1
-rw-r--r--doc/api/issues.md17
-rw-r--r--doc/api/merge_requests.md19
-rw-r--r--lib/api/entities.rb8
-rw-r--r--lib/api/issues.rb10
-rw-r--r--lib/api/merge_requests.rb14
-rw-r--r--lib/api/milestones.rb2
7 files changed, 46 insertions, 25 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 54d79259b30..35c5417da22 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -12,6 +12,7 @@ v 8.7.0 (unreleased)
- Allow back dating on issues when created through the API
- Fix Error 500 after renaming a project path (Stan Hu)
- Fix avatar stretching by providing a cropping feature
+ - API: Expose `subscribed` for issues and merge requests (Robert Schilling)
- Allow SAML to handle external users based on user's information !3530
- Add endpoints to archive or unarchive a project !3372
- Add links to CI setup documentation from project settings and builds pages
diff --git a/doc/api/issues.md b/doc/api/issues.md
index cc6355d34ef..1c635a6cdcf 100644
--- a/doc/api/issues.md
+++ b/doc/api/issues.md
@@ -76,8 +76,9 @@ Example response:
"title" : "Consequatur vero maxime deserunt laboriosam est voluptas dolorem.",
"created_at" : "2016-01-04T15:31:51.081Z",
"iid" : 6,
- "labels" : []
- },
+ "labels" : [],
+ "subscribed" : false
+ }
]
```
@@ -152,7 +153,8 @@ Example response:
"id" : 41,
"title" : "Ut commodi ullam eos dolores perferendis nihil sunt.",
"updated_at" : "2016-01-04T15:31:46.176Z",
- "created_at" : "2016-01-04T15:31:46.176Z"
+ "created_at" : "2016-01-04T15:31:46.176Z",
+ "subscribed" : false
}
]
```
@@ -213,7 +215,8 @@ Example response:
"id" : 41,
"title" : "Ut commodi ullam eos dolores perferendis nihil sunt.",
"updated_at" : "2016-01-04T15:31:46.176Z",
- "created_at" : "2016-01-04T15:31:46.176Z"
+ "created_at" : "2016-01-04T15:31:46.176Z",
+ "subscribed": false
}
```
@@ -267,7 +270,8 @@ Example response:
},
"description" : null,
"updated_at" : "2016-01-07T12:44:33.959Z",
- "milestone" : null
+ "milestone" : null,
+ "subscribed" : true
}
```
@@ -323,7 +327,8 @@ Example response:
],
"id" : 85,
"assignee" : null,
- "milestone" : null
+ "milestone" : null,
+ "subscribed" : true
}
```
diff --git a/doc/api/merge_requests.md b/doc/api/merge_requests.md
index b20a6300b7a..20db73ea6c0 100644
--- a/doc/api/merge_requests.md
+++ b/doc/api/merge_requests.md
@@ -66,7 +66,8 @@ Parameters:
"due_date": null
},
"merge_when_build_succeeds": true,
- "merge_status": "can_be_merged"
+ "merge_status": "can_be_merged",
+ "subscribed" : false
}
]
```
@@ -128,7 +129,8 @@ Parameters:
"due_date": null
},
"merge_when_build_succeeds": true,
- "merge_status": "can_be_merged"
+ "merge_status": "can_be_merged",
+ "subscribed" : true
}
```
@@ -227,6 +229,7 @@ Parameters:
},
"merge_when_build_succeeds": true,
"merge_status": "can_be_merged",
+ "subscribed" : true,
"changes": [
{
"old_path": "VERSION",
@@ -304,7 +307,8 @@ Parameters:
"due_date": null
},
"merge_when_build_succeeds": true,
- "merge_status": "can_be_merged"
+ "merge_status": "can_be_merged",
+ "subscribed" : true
}
```
@@ -373,7 +377,8 @@ Parameters:
"due_date": null
},
"merge_when_build_succeeds": true,
- "merge_status": "can_be_merged"
+ "merge_status": "can_be_merged",
+ "subscribed" : true
}
```
@@ -466,7 +471,8 @@ Parameters:
"due_date": null
},
"merge_when_build_succeeds": true,
- "merge_status": "can_be_merged"
+ "merge_status": "can_be_merged",
+ "subscribed" : true
}
```
@@ -530,7 +536,8 @@ Parameters:
"due_date": null
},
"merge_when_build_succeeds": true,
- "merge_status": "can_be_merged"
+ "merge_status": "can_be_merged",
+ "subscribed" : true
}
```
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 4c49442bf8b..d76b46b8836 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -170,6 +170,10 @@ module API
expose :label_names, as: :labels
expose :milestone, using: Entities::Milestone
expose :assignee, :author, using: Entities::UserBasic
+
+ expose :subscribed do |issue, options|
+ issue.subscribed?(options[:current_user])
+ end
end
class MergeRequest < ProjectEntity
@@ -183,6 +187,10 @@ module API
expose :milestone, using: Entities::Milestone
expose :merge_when_build_succeeds
expose :merge_status
+
+ expose :subscribed do |merge_request, options|
+ merge_request.subscribed?(options[:current_user])
+ end
end
class MergeRequestChanges < MergeRequest
diff --git a/lib/api/issues.rb b/lib/api/issues.rb
index 1fee1dee1a6..c4ea05ee6cf 100644
--- a/lib/api/issues.rb
+++ b/lib/api/issues.rb
@@ -55,7 +55,7 @@ module API
issues = filter_issues_state(issues, params[:state]) unless params[:state].nil?
issues = filter_issues_labels(issues, params[:labels]) unless params[:labels].nil?
issues.reorder(issuable_order_by => issuable_sort)
- present paginate(issues), with: Entities::Issue
+ present paginate(issues), with: Entities::Issue, current_user: current_user
end
end
@@ -92,7 +92,7 @@ module API
end
issues.reorder(issuable_order_by => issuable_sort)
- present paginate(issues), with: Entities::Issue
+ present paginate(issues), with: Entities::Issue, current_user: current_user
end
# Get a single project issue
@@ -105,7 +105,7 @@ module API
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
+ present @issue, with: Entities::Issue, current_user: current_user
end
# Create a new project issue
@@ -149,7 +149,7 @@ module API
issue.add_labels_by_names(params[:labels].split(','))
end
- present issue, with: Entities::Issue
+ present issue, with: Entities::Issue, current_user: current_user
else
render_validation_error!(issue)
end
@@ -189,7 +189,7 @@ module API
issue.add_labels_by_names(params[:labels].split(','))
end
- present issue, with: Entities::Issue
+ present issue, with: Entities::Issue, current_user: current_user
else
render_validation_error!(issue)
end
diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb
index 93052fba06b..4e7de8867b4 100644
--- a/lib/api/merge_requests.rb
+++ b/lib/api/merge_requests.rb
@@ -56,7 +56,7 @@ module API
end
merge_requests = merge_requests.reorder(issuable_order_by => issuable_sort)
- present paginate(merge_requests), with: Entities::MergeRequest
+ present paginate(merge_requests), with: Entities::MergeRequest, current_user: current_user
end
# Create MR
@@ -94,7 +94,7 @@ module API
merge_request.add_labels_by_names(params[:labels].split(","))
end
- present merge_request, with: Entities::MergeRequest
+ present merge_request, with: Entities::MergeRequest, current_user: current_user
else
handle_merge_request_errors! merge_request.errors
end
@@ -130,7 +130,7 @@ module API
authorize! :read_merge_request, merge_request
- present merge_request, with: Entities::MergeRequest
+ present merge_request, with: Entities::MergeRequest, current_user: current_user
end
# Show MR commits
@@ -162,7 +162,7 @@ module API
merge_request = user_project.merge_requests.
find(params[:merge_request_id])
authorize! :read_merge_request, merge_request
- present merge_request, with: Entities::MergeRequestChanges
+ present merge_request, with: Entities::MergeRequestChanges, current_user: current_user
end
# Update MR
@@ -204,7 +204,7 @@ module API
merge_request.add_labels_by_names(params[:labels].split(","))
end
- present merge_request, with: Entities::MergeRequest
+ present merge_request, with: Entities::MergeRequest, current_user: current_user
else
handle_merge_request_errors! merge_request.errors
end
@@ -246,7 +246,7 @@ module API
execute(merge_request)
end
- present merge_request, with: Entities::MergeRequest
+ present merge_request, with: Entities::MergeRequest, current_user: current_user
end
# Cancel Merge if Merge When build succeeds is enabled
@@ -325,7 +325,7 @@ module API
get "#{path}/closes_issues" do
merge_request = user_project.merge_requests.find(params[:merge_request_id])
issues = ::Kaminari.paginate_array(merge_request.closes_issues(current_user))
- present paginate(issues), with: Entities::Issue
+ present paginate(issues), with: Entities::Issue, current_user: current_user
end
end
end
diff --git a/lib/api/milestones.rb b/lib/api/milestones.rb
index afb6ffa3609..0f3f505fa05 100644
--- a/lib/api/milestones.rb
+++ b/lib/api/milestones.rb
@@ -103,7 +103,7 @@ module API
authorize! :read_milestone, user_project
@milestone = user_project.milestones.find(params[:milestone_id])
- present paginate(@milestone.issues), with: Entities::Issue
+ present paginate(@milestone.issues), with: Entities::Issue, current_user: current_user
end
end