summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOswaldo Ferreira <oswaldo@gitlab.com>2017-02-23 17:49:37 -0300
committerOswaldo Ferreira <oswaldo@gitlab.com>2017-02-23 20:52:38 -0300
commit86cf4cd68b950259e40c80694a08a542a9a9a10b (patch)
tree730db34628498abe30624e8eeb2d450178f50d7e
parentdaf617e4e1c32b22af35575b13560d941aa64171 (diff)
downloadgitlab-ce-22600-related-resources-uris.tar.gz
Pass request properly to grape endpoints using Issue entity22600-related-resources-uris
-rw-r--r--lib/api/helpers.rb9
-rw-r--r--lib/api/issues.rb34
-rw-r--r--lib/api/merge_requests.rb6
-rw-r--r--lib/api/milestones.rb6
-rw-r--r--lib/api/subscriptions.rb12
-rw-r--r--lib/api/todos.rb9
-rw-r--r--lib/api/v3/entities.rb18
-rw-r--r--lib/api/v3/issues.rb28
-rw-r--r--lib/api/v3/merge_requests.rb3
-rw-r--r--spec/requests/api/issues_spec.rb6
10 files changed, 100 insertions, 31 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index d0efa7b993b..68b93f306e2 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -376,6 +376,15 @@ module API
header(*Gitlab::Workhorse.send_git_archive(repository, ref: ref, format: format))
end
+ # TODO: Please, remove this when V3 API is gone.
+ def v3_issue_entity(project)
+ if project.has_external_issue_tracker?
+ Entities::ExternalIssue
+ else
+ ::API::V3::Entities::Issue
+ end
+ end
+
def issue_entity(project)
if project.has_external_issue_tracker?
Entities::ExternalIssue
diff --git a/lib/api/issues.rb b/lib/api/issues.rb
index 3bc417f9997..6a8e011ad43 100644
--- a/lib/api/issues.rb
+++ b/lib/api/issues.rb
@@ -50,7 +50,10 @@ module API
get do
issues = find_issues(scope: 'authored')
- present paginate(issues), with: Entities::Issue, current_user: current_user
+ present paginate(issues),
+ with: Entities::Issue,
+ current_user: current_user,
+ request: request
end
end
@@ -71,7 +74,10 @@ module API
issues = find_issues(group_id: group.id, state: params[:state] || 'opened')
- present paginate(issues), with: Entities::Issue, current_user: current_user
+ present paginate(issues),
+ with: Entities::Issue,
+ current_user: current_user,
+ request: request
end
end
@@ -94,7 +100,11 @@ module API
issues = find_issues(project_id: project.id)
- present paginate(issues), with: Entities::Issue, current_user: current_user, project: user_project
+ present paginate(issues),
+ with: Entities::Issue,
+ current_user: current_user,
+ project: user_project,
+ request: request
end
desc 'Get a single project issue' do
@@ -146,7 +156,11 @@ module API
end
if issue.valid?
- present issue, with: Entities::Issue, current_user: current_user, project: user_project
+ present issue,
+ with: Entities::Issue,
+ current_user: current_user,
+ project: user_project,
+ request: request
else
render_validation_error!(issue)
end
@@ -183,7 +197,11 @@ module API
render_spam_error! if issue.spam?
if issue.valid?
- present issue, with: Entities::Issue, current_user: current_user, project: user_project
+ present issue,
+ with: Entities::Issue,
+ current_user: current_user,
+ project: user_project,
+ request: request
else
render_validation_error!(issue)
end
@@ -205,7 +223,11 @@ module API
begin
issue = ::Issues::MoveService.new(user_project, current_user).execute(issue, new_project)
- present issue, with: Entities::Issue, current_user: current_user, project: user_project
+ present issue,
+ with: Entities::Issue,
+ current_user: current_user,
+ project: user_project,
+ request: request
rescue ::Issues::MoveService::MoveError => error
render_api_error!(error.message, 400)
end
diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb
index bdd764abfeb..8ed92f12317 100644
--- a/lib/api/merge_requests.rb
+++ b/lib/api/merge_requests.rb
@@ -262,7 +262,11 @@ module API
get ':id/merge_requests/:merge_request_id/closes_issues' do
merge_request = find_merge_request_with_access(params[:merge_request_id])
issues = ::Kaminari.paginate_array(merge_request.closes_issues(current_user))
- present paginate(issues), with: issue_entity(user_project), current_user: current_user
+
+ present paginate(issues),
+ with: issue_entity(user_project),
+ current_user: current_user,
+ request: request
end
end
end
diff --git a/lib/api/milestones.rb b/lib/api/milestones.rb
index 0b4ed76b35c..1e8c753961f 100644
--- a/lib/api/milestones.rb
+++ b/lib/api/milestones.rb
@@ -118,7 +118,11 @@ module API
}
issues = IssuesFinder.new(current_user, finder_params).execute
- present paginate(issues), with: Entities::Issue, current_user: current_user, project: user_project
+ present paginate(issues),
+ with: Entities::Issue,
+ current_user: current_user,
+ project: user_project,
+ request: request
end
desc 'Get all merge requests for a single project milestone' do
diff --git a/lib/api/subscriptions.rb b/lib/api/subscriptions.rb
index 772b5cca017..d48de51731f 100644
--- a/lib/api/subscriptions.rb
+++ b/lib/api/subscriptions.rb
@@ -27,7 +27,11 @@ module API
not_modified!
else
resource.subscribe(current_user, user_project)
- present resource, with: entity_class, current_user: current_user, project: user_project
+ present resource,
+ with: entity_class,
+ current_user: current_user,
+ project: user_project,
+ request: request
end
end
@@ -41,7 +45,11 @@ module API
not_modified!
else
resource.unsubscribe(current_user, user_project)
- present resource, with: entity_class, current_user: current_user, project: user_project
+ present resource,
+ with: entity_class,
+ current_user: current_user,
+ project: user_project,
+ request: request
end
end
end
diff --git a/lib/api/todos.rb b/lib/api/todos.rb
index e59030428da..65d8771fed3 100644
--- a/lib/api/todos.rb
+++ b/lib/api/todos.rb
@@ -27,7 +27,7 @@ module API
todo = TodoService.new.mark_todo(issuable, current_user).first
if todo
- present todo, with: Entities::Todo, current_user: current_user
+ present todo, with: Entities::Todo, current_user: current_user, request: request
else
not_modified!
end
@@ -49,7 +49,10 @@ module API
use :pagination
end
get do
- present paginate(find_todos), with: Entities::Todo, current_user: current_user
+ present paginate(find_todos),
+ with: Entities::Todo,
+ current_user: current_user,
+ request: request
end
desc 'Mark a todo as done' do
@@ -62,7 +65,7 @@ module API
todo = current_user.todos.find(params[:id])
TodoService.new.mark_todos_as_done([todo], current_user)
- present todo.reload, with: Entities::Todo, current_user: current_user
+ present todo.reload, with: Entities::Todo, current_user: current_user, request: request
end
desc 'Mark all todos as done'
diff --git a/lib/api/v3/entities.rb b/lib/api/v3/entities.rb
index 11d0e6dbf71..4d9cb00b131 100644
--- a/lib/api/v3/entities.rb
+++ b/lib/api/v3/entities.rb
@@ -45,6 +45,24 @@ module API
expose :created_at, :updated_at
expose :awardable_id, :awardable_type
end
+
+ class Issue < ::API::Entities::ProjectEntity
+ expose :label_names, as: :labels
+ expose :milestone, using: ::API::Entities::Milestone
+ expose :assignee, :author, using: ::API::Entities::UserBasic
+
+ expose :subscribed do |issue, options|
+ issue.subscribed?(options[:current_user], options[:project] || issue.project)
+ end
+ expose :user_notes_count
+ expose :upvotes, :downvotes
+ expose :due_date
+ expose :confidential
+
+ expose :web_url do |issue, options|
+ Gitlab::UrlBuilder.build(issue)
+ end
+ end
end
end
end
diff --git a/lib/api/v3/issues.rb b/lib/api/v3/issues.rb
index d0af09f0e1e..5169de7cee8 100644
--- a/lib/api/v3/issues.rb
+++ b/lib/api/v3/issues.rb
@@ -51,7 +51,7 @@ module API
resource :issues do
desc "Get currently authenticated user's issues" do
- success ::API::Entities::Issue
+ success ::API::V3::Entities::Issue
end
params do
optional :state, type: String, values: %w[opened closed all], default: 'all',
@@ -61,7 +61,7 @@ module API
get do
issues = find_issues(scope: 'authored')
- present paginate(issues), with: ::API::Entities::Issue, current_user: current_user
+ present paginate(issues), with: ::API::V3::Entities::Issue, current_user: current_user
end
end
@@ -70,7 +70,7 @@ module API
end
resource :groups do
desc 'Get a list of group issues' do
- success ::API::Entities::Issue
+ success ::API::V3::Entities::Issue
end
params do
optional :state, type: String, values: %w[opened closed all], default: 'opened',
@@ -82,7 +82,7 @@ module API
issues = find_issues(group_id: group.id, state: params[:state] || 'opened', match_all_labels: true)
- present paginate(issues), with: ::API::Entities::Issue, current_user: current_user
+ present paginate(issues), with: ::API::V3::Entities::Issue, current_user: current_user
end
end
@@ -94,7 +94,7 @@ module API
desc 'Get a list of project issues' do
detail 'iid filter is deprecated have been removed on V4'
- success ::API::Entities::Issue
+ success ::API::V3::Entities::Issue
end
params do
optional :state, type: String, values: %w[opened closed all], default: 'all',
@@ -107,22 +107,22 @@ module API
issues = find_issues(project_id: project.id)
- present paginate(issues), with: ::API::Entities::Issue, current_user: current_user, project: user_project
+ present paginate(issues), with: ::API::V3::Entities::Issue, current_user: current_user, project: user_project
end
desc 'Get a single project issue' do
- success ::API::Entities::Issue
+ success ::API::V3::Entities::Issue
end
params do
requires :issue_id, type: Integer, desc: 'The ID of a project issue'
end
get ":id/issues/:issue_id" do
issue = find_project_issue(params[:issue_id])
- present issue, with: ::API::Entities::Issue, current_user: current_user, project: user_project
+ present issue, with: ::API::V3::Entities::Issue, current_user: current_user, project: user_project
end
desc 'Create a new project issue' do
- success ::API::Entities::Issue
+ success ::API::V3::Entities::Issue
end
params do
requires :title, type: String, desc: 'The title of an issue'
@@ -152,14 +152,14 @@ module API
render_spam_error! if issue.spam?
if issue.valid?
- present issue, with: ::API::Entities::Issue, current_user: current_user, project: user_project
+ present issue, with: ::API::V3::Entities::Issue, current_user: current_user, project: user_project
else
render_validation_error!(issue)
end
end
desc 'Update an existing issue' do
- success ::API::Entities::Issue
+ success ::API::V3::Entities::Issue
end
params do
requires :issue_id, type: Integer, desc: 'The ID of a project issue'
@@ -189,14 +189,14 @@ module API
render_spam_error! if issue.spam?
if issue.valid?
- present issue, with: ::API::Entities::Issue, current_user: current_user, project: user_project
+ present issue, with: ::API::V3::Entities::Issue, current_user: current_user, project: user_project
else
render_validation_error!(issue)
end
end
desc 'Move an existing issue' do
- success ::API::Entities::Issue
+ success ::API::V3::Entities::Issue
end
params do
requires :issue_id, type: Integer, desc: 'The ID of a project issue'
@@ -211,7 +211,7 @@ module API
begin
issue = ::Issues::MoveService.new(user_project, current_user).execute(issue, new_project)
- present issue, with: ::API::Entities::Issue, current_user: current_user, project: user_project
+ present issue, with: ::API::V3::Entities::Issue, current_user: current_user, project: user_project
rescue ::Issues::MoveService::MoveError => error
render_api_error!(error.message, 400)
end
diff --git a/lib/api/v3/merge_requests.rb b/lib/api/v3/merge_requests.rb
index 129f9d850e9..87b7c522633 100644
--- a/lib/api/v3/merge_requests.rb
+++ b/lib/api/v3/merge_requests.rb
@@ -271,7 +271,8 @@ module API
get "#{path}/closes_issues" do
merge_request = find_merge_request_with_access(params[:merge_request_id])
issues = ::Kaminari.paginate_array(merge_request.closes_issues(current_user))
- present paginate(issues), with: issue_entity(user_project), current_user: current_user
+
+ present paginate(issues), with: v3_issue_entity(user_project), current_user: current_user
end
end
end
diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb
index 23df19d1fc1..74e6ae363a1 100644
--- a/spec/requests/api/issues_spec.rb
+++ b/spec/requests/api/issues_spec.rb
@@ -719,9 +719,9 @@ describe API::Issues, api: true do
relationship_urls = json_response.fetch('relationship_urls')
expect(relationship_urls).to eql({
- "issues_url" => "http://www.example.com/api/v4/projects/1/issues",
- "merge_requests_url" => "http://www.example.com/api/v4/projects/1/merge_requests",
- "repo_branches_url" => "http://www.example.com/api/v4/projects/1/repository/branches",
+ "issues_url" => "http://www.example.com/api/v4/projects/#{project.id}/issues",
+ "merge_requests_url" => "http://www.example.com/api/v4/projects/#{project.id}/merge_requests",
+ "repo_branches_url" => "http://www.example.com/api/v4/projects/#{project.id}/repository/branches",
})
end