Commit 34558315 authored by Z.J. van de Weg's avatar Z.J. van de Weg

Sort API endpoints and implement feedback

parent 3f88221c
...@@ -48,6 +48,7 @@ v 8.9.0 (unreleased) ...@@ -48,6 +48,7 @@ v 8.9.0 (unreleased)
- Upgrade to jQuery 2 - Upgrade to jQuery 2
- Adds selected branch name to the dropdown toggle - Adds selected branch name to the dropdown toggle
- Add API endpoint for Sidekiq Metrics !4653 - Add API endpoint for Sidekiq Metrics !4653
- Refactoring Award Emoji with API support for Issues and MergeRequests
- Use Knapsack to evenly distribute tests across multiple nodes - Use Knapsack to evenly distribute tests across multiple nodes
- Add `sha` parameter to MR merge API, to ensure only reviewed changes are merged - Add `sha` parameter to MR merge API, to ensure only reviewed changes are merged
- Don't allow MRs to be merged when commits were added since the last review / page load - Don't allow MRs to be merged when commits were added since the last review / page load
......
...@@ -26,40 +26,41 @@ module API ...@@ -26,40 +26,41 @@ module API
# Ensure the namespace is right, otherwise we might load Grape::API::Helpers # Ensure the namespace is right, otherwise we might load Grape::API::Helpers
helpers ::API::Helpers helpers ::API::Helpers
mount ::API::Groups # Sort these alphabetically
mount ::API::AwardEmoji
mount ::API::Branches
mount ::API::Builds
mount ::API::CommitStatuses
mount ::API::Commits
mount ::API::DeployKeys
mount ::API::Files
mount ::API::Gitignores
mount ::API::GroupMembers mount ::API::GroupMembers
mount ::API::Users mount ::API::Groups
mount ::API::Projects mount ::API::Internal
mount ::API::Repositories
mount ::API::Issues mount ::API::Issues
mount ::API::Milestones mount ::API::Keys
mount ::API::Session mount ::API::Labels
mount ::API::Licenses
mount ::API::MergeRequests mount ::API::MergeRequests
mount ::API::Milestones
mount ::API::Namespaces
mount ::API::Notes mount ::API::Notes
mount ::API::AwardEmoji
mount ::API::Internal
mount ::API::SystemHooks
mount ::API::ProjectSnippets
mount ::API::ProjectMembers
mount ::API::DeployKeys
mount ::API::ProjectHooks mount ::API::ProjectHooks
mount ::API::ProjectMembers
mount ::API::ProjectSnippets
mount ::API::Projects
mount ::API::Repositories
mount ::API::Runners
mount ::API::Services mount ::API::Services
mount ::API::Files mount ::API::Session
mount ::API::Commits
mount ::API::CommitStatuses
mount ::API::Namespaces
mount ::API::Branches
mount ::API::Labels
mount ::API::Settings mount ::API::Settings
mount ::API::Keys mount ::API::SidekiqMetrics
mount ::API::Subscriptions
mount ::API::SystemHooks
mount ::API::Tags mount ::API::Tags
mount ::API::Triggers mount ::API::Triggers
mount ::API::Builds mount ::API::Users
mount ::API::Variables mount ::API::Variables
mount ::API::Runners
mount ::API::Licenses
mount ::API::Subscriptions
mount ::API::Gitignores
mount ::API::SidekiqMetrics
end end
end end
...@@ -17,9 +17,9 @@ module API ...@@ -17,9 +17,9 @@ module API
# Example Request: # Example Request:
# GET /projects/:id/issues/:awardable_id/award_emoji # GET /projects/:id/issues/:awardable_id/award_emoji
get ":id/#{awardable_string}/:#{awardable_id_string}/award_emoji" do get ":id/#{awardable_string}/:#{awardable_id_string}/award_emoji" do
awardable = user_project.send(awardable_string.to_sym).find(params[awardable_id_string.to_sym]) awardable = user_project.send(awardable_string.to_sym).find(params[awardable_id_string])
if can?(current_user, awardable_read_ability_name(awardable), awardable) if can_read_awardable?(awardable)
awards = paginate(awardable.award_emoji) awards = paginate(awardable.award_emoji)
present awards, with: Entities::AwardEmoji present awards, with: Entities::AwardEmoji
else else
...@@ -38,7 +38,7 @@ module API ...@@ -38,7 +38,7 @@ module API
get ":id/#{awardable_string}/:#{awardable_id_string}/award_emoji/:award_id" do get ":id/#{awardable_string}/:#{awardable_id_string}/award_emoji/:award_id" do
awardable = user_project.send(awardable_string.to_sym).find(params[awardable_id_string.to_sym]) awardable = user_project.send(awardable_string.to_sym).find(params[awardable_id_string.to_sym])
if can?(current_user, awardable_read_ability_name(awardable), awardable) if can_read_awardable?(awardable)
present awardable.award_emoji.find(params[:award_id]), with: Entities::AwardEmoji present awardable.award_emoji.find(params[:award_id]), with: Entities::AwardEmoji
else else
not_found!("Award Emoji") not_found!("Award Emoji")
...@@ -49,16 +49,15 @@ module API ...@@ -49,16 +49,15 @@ module API
# #
# Parameters: # Parameters:
# id (required) - The ID of a project # id (required) - The ID of a project
# noteable_id (required) - The ID of an issue or snippet # awardable_id (required) - The ID of an issue or mr
# name (required) - The name of a award_emoji (without colons) # name (required) - The name of a award_emoji (without colons)
# Example Request: # Example Request:
# POST /projects/:id/issues/:noteable_id/notes # POST /projects/:id/issues/:awardable_id/notes
# POST /projects/:id/snippets/:noteable_id/notes
post ":id/#{awardable_string}/:#{awardable_id_string}/award_emoji" do post ":id/#{awardable_string}/:#{awardable_id_string}/award_emoji" do
required_attributes! [:name] required_attributes! [:name]
awardable = user_project.send(awardable_string.to_sym).find(params[awardable_id_string.to_sym]) awardable = user_project.send(awardable_string.to_sym).find(params[awardable_id_string.to_sym])
not_found!('Award Emoji') unless can?(current_user, awardable_read_ability_name(awardable), awardable) not_found!('Award Emoji') unless can_read_awardable?(awardable)
award = awardable.award_emoji.new(name: params[:name], user: current_user) award = awardable.award_emoji.new(name: params[:name], user: current_user)
...@@ -90,7 +89,12 @@ module API ...@@ -90,7 +89,12 @@ module API
end end
helpers do helpers do
def awardable_read_ability_name(awardable) def awardable_read_ability_name(awardable)
"read_#{awardable.class.to_s.underscore.downcase}".to_sym end
def can_read_awardable?(awardable)
ability = "read_#{awardable.class.to_s.underscore}".to_sym
can?(current_user, ability, awardable)
end end
end end
end end
......
module API module API
# Issues API # Issues API
class Issues < Grape::API class Issues < Grape::API
before { authenticate! } before { authenticate! }
helpers ::Gitlab::AkismetHelper helpers ::Gitlab::AkismetHelper
......
...@@ -144,7 +144,7 @@ module API ...@@ -144,7 +144,7 @@ module API
helpers do helpers do
def noteable_read_ability_name(noteable) def noteable_read_ability_name(noteable)
"read_#{noteable.class.to_s.underscore.downcase}".to_sym "read_#{noteable.class.to_s.underscore}".to_sym
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment