Commit ccbbc100 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'resolve-lib-differences' into 'master'

Resolve CE to EE differences in the lib/api directory

See merge request gitlab-org/gitlab-ce!25430
parents 17364563 a7004e28
...@@ -7,9 +7,7 @@ module API ...@@ -7,9 +7,7 @@ module API
before { authenticate! } before { authenticate! }
NOTEABLE_TYPES = [Issue, Snippet, MergeRequest, Commit].freeze Helpers::DiscussionsHelpers.noteable_types.each do |noteable_type|
NOTEABLE_TYPES.each do |noteable_type|
parent_type = noteable_type.parent_class.to_s.underscore parent_type = noteable_type.parent_class.to_s.underscore
noteables_str = noteable_type.to_s.underscore.pluralize noteables_str = noteable_type.to_s.underscore.pluralize
noteables_path = noteable_type == Commit ? "repository/#{noteables_str}" : noteables_str noteables_path = noteable_type == Commit ? "repository/#{noteables_str}" : noteables_str
......
...@@ -58,6 +58,22 @@ module API ...@@ -58,6 +58,22 @@ module API
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def create_group
# This is a separate method so that EE can extend its behaviour, without
# having to modify this code directly.
::Groups::CreateService
.new(current_user, declared_params(include_missing: false))
.execute
end
def update_group(group)
# This is a separate method so that EE can extend its behaviour, without
# having to modify this code directly.
::Groups::UpdateService
.new(group, current_user, declared_params(include_missing: false))
.execute
end
def find_group_projects(params) def find_group_projects(params)
group = find_group!(params[:id]) group = find_group!(params[:id])
options = { options = {
...@@ -127,7 +143,7 @@ module API ...@@ -127,7 +143,7 @@ module API
authorize! :create_group authorize! :create_group
end end
group = ::Groups::CreateService.new(current_user, declared_params(include_missing: false)).execute group = create_group
if group.persisted? if group.persisted?
present group, with: Entities::GroupDetail, current_user: current_user present group, with: Entities::GroupDetail, current_user: current_user
...@@ -153,7 +169,7 @@ module API ...@@ -153,7 +169,7 @@ module API
group = find_group!(params[:id]) group = find_group!(params[:id])
authorize! :admin_group, group authorize! :admin_group, group
if ::Groups::UpdateService.new(group, current_user, declared_params(include_missing: false)).execute if update_group(group)
present group, with: Entities::GroupDetail, current_user: current_user present group, with: Entities::GroupDetail, current_user: current_user
else else
render_validation_error!(group) render_validation_error!(group)
......
# frozen_string_literal: true
module API
module Helpers
module DiscussionsHelpers
def self.noteable_types
# This is a method instead of a constant, allowing EE to more easily
# extend it.
[Issue, Snippet, MergeRequest, Commit]
end
end
end
end
...@@ -3,6 +3,12 @@ ...@@ -3,6 +3,12 @@
module API module API
module Helpers module Helpers
module NotesHelpers module NotesHelpers
def self.noteable_types
# This is a method instead of a constant, allowing EE to more easily
# extend it.
[Issue, MergeRequest, Snippet]
end
def update_note(noteable, note_id) def update_note(noteable, note_id)
note = noteable.notes.find(params[:note_id]) note = noteable.notes.find(params[:note_id])
......
# frozen_string_literal: true
module API
module Helpers
module ResourceLabelEventsHelpers
def self.eventable_types
# This is a method instead of a constant, allowing EE to more easily
# extend it.
[Issue, MergeRequest]
end
end
end
end
# frozen_string_literal: true
module API
module Helpers
module SearchHelpers
def self.global_search_scopes
# This is a separate method so that EE can redefine it.
%w(projects issues merge_requests milestones snippet_titles snippet_blobs)
end
def self.group_search_scopes
# This is a separate method so that EE can redefine it.
%w(projects issues merge_requests milestones)
end
def self.project_search_scopes
# This is a separate method so that EE can redefine it.
%w(issues merge_requests milestones notes wiki_blobs commits blobs)
end
end
end
end
This diff is collapsed.
...@@ -15,6 +15,12 @@ module API ...@@ -15,6 +15,12 @@ module API
status code status code
{ status: success, message: message }.merge(extra_options).compact { status: success, message: message }.merge(extra_options).compact
end end
def lfs_authentication_url(project)
# This is a separate method so that EE can alter its behaviour more
# easily.
project.http_url_to_repo
end
end end
namespace 'internal' do namespace 'internal' do
...@@ -113,7 +119,9 @@ module API ...@@ -113,7 +119,9 @@ module API
raise ActiveRecord::RecordNotFound.new("No key_id or user_id passed!") raise ActiveRecord::RecordNotFound.new("No key_id or user_id passed!")
end end
Gitlab::LfsToken.new(actor).authentication_payload(project.http_url_to_repo) Gitlab::LfsToken
.new(actor)
.authentication_payload(lfs_authentication_url(project))
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -7,9 +7,7 @@ module API ...@@ -7,9 +7,7 @@ module API
before { authenticate! } before { authenticate! }
NOTEABLE_TYPES = [Issue, MergeRequest, Snippet].freeze Helpers::NotesHelpers.noteable_types.each do |noteable_type|
NOTEABLE_TYPES.each do |noteable_type|
parent_type = noteable_type.parent_class.to_s.underscore parent_type = noteable_type.parent_class.to_s.underscore
noteables_str = noteable_type.to_s.underscore.pluralize noteables_str = noteable_type.to_s.underscore.pluralize
......
...@@ -7,9 +7,7 @@ module API ...@@ -7,9 +7,7 @@ module API
before { authenticate! } before { authenticate! }
EVENTABLE_TYPES = [Issue, MergeRequest].freeze Helpers::ResourceLabelEventsHelpers.eventable_types.each do |eventable_type|
EVENTABLE_TYPES.each do |eventable_type|
parent_type = eventable_type.parent_class.to_s.underscore parent_type = eventable_type.parent_class.to_s.underscore
eventables_str = eventable_type.to_s.underscore.pluralize eventables_str = eventable_type.to_s.underscore.pluralize
......
...@@ -45,6 +45,12 @@ module API ...@@ -45,6 +45,12 @@ module API
def entity def entity
SCOPE_ENTITY[params[:scope].to_sym] SCOPE_ENTITY[params[:scope].to_sym]
end end
def verify_search_scope!
# In EE we have additional validation requirements for searches.
# Defining this method here as a noop allows us to easily extend it in
# EE, without having to modify this file directly.
end
end end
resource :search do resource :search do
...@@ -55,12 +61,13 @@ module API ...@@ -55,12 +61,13 @@ module API
requires :search, type: String, desc: 'The expression it should be searched for' requires :search, type: String, desc: 'The expression it should be searched for'
requires :scope, requires :scope,
type: String, type: String,
desc: 'The scope of search, available scopes: desc: 'The scope of the search',
projects, issues, merge_requests, milestones, snippet_titles, snippet_blobs', values: Helpers::SearchHelpers.global_search_scopes
values: %w(projects issues merge_requests milestones snippet_titles snippet_blobs)
use :pagination use :pagination
end end
get do get do
verify_search_scope!
present search, with: entity present search, with: entity
end end
end end
...@@ -74,12 +81,13 @@ module API ...@@ -74,12 +81,13 @@ module API
requires :search, type: String, desc: 'The expression it should be searched for' requires :search, type: String, desc: 'The expression it should be searched for'
requires :scope, requires :scope,
type: String, type: String,
desc: 'The scope of search, available scopes: desc: 'The scope of the search',
projects, issues, merge_requests, milestones', values: Helpers::SearchHelpers.group_search_scopes
values: %w(projects issues merge_requests milestones)
use :pagination use :pagination
end end
get ':id/(-/)search' do get ':id/(-/)search' do
verify_search_scope!
present search(group_id: user_group.id), with: entity present search(group_id: user_group.id), with: entity
end end
end end
...@@ -93,9 +101,8 @@ module API ...@@ -93,9 +101,8 @@ module API
requires :search, type: String, desc: 'The expression it should be searched for' requires :search, type: String, desc: 'The expression it should be searched for'
requires :scope, requires :scope,
type: String, type: String,
desc: 'The scope of search, available scopes: desc: 'The scope of the search',
issues, merge_requests, milestones, notes, wiki_blobs, commits, blobs', values: Helpers::SearchHelpers.project_search_scopes
values: %w(issues merge_requests milestones notes wiki_blobs commits blobs)
use :pagination use :pagination
end end
get ':id/(-/)search' do get ':id/(-/)search' do
......
This diff is collapsed.
...@@ -9,6 +9,11 @@ module API ...@@ -9,6 +9,11 @@ module API
@current_setting ||= @current_setting ||=
(ApplicationSetting.current_without_cache || ApplicationSetting.create_from_defaults) (ApplicationSetting.current_without_cache || ApplicationSetting.create_from_defaults)
end end
def filter_attributes_using_license(attrs)
# This method will be redefined in EE.
attrs
end
end end
desc 'Get the current application settings' do desc 'Get the current application settings' do
...@@ -156,6 +161,8 @@ module API ...@@ -156,6 +161,8 @@ module API
attrs[:password_authentication_enabled_for_web] = attrs.delete(:password_authentication_enabled) attrs[:password_authentication_enabled_for_web] = attrs.delete(:password_authentication_enabled)
end end
attrs = filter_attributes_using_license(attrs)
if ApplicationSettings::UpdateService.new(current_settings, current_user, attrs).execute if ApplicationSettings::UpdateService.new(current_settings, current_user, attrs).execute
present current_settings, with: Entities::ApplicationSetting present current_settings, with: Entities::ApplicationSetting
else else
......
...@@ -13,7 +13,7 @@ module API ...@@ -13,7 +13,7 @@ module API
end end
params do params do
requires :ref, type: String, desc: 'The commit sha or name of a branch or tag', allow_blank: false requires :ref, type: String, desc: 'The commit sha or name of a branch or tag', allow_blank: false
requires :token, type: String, desc: 'The unique token of trigger' requires :token, type: String, desc: 'The unique token of trigger or job token'
optional :variables, type: Hash, desc: 'The list of variables to be injected into build' optional :variables, type: Hash, desc: 'The list of variables to be injected into build'
end end
post ":id/(ref/:ref/)trigger/pipeline", requirements: { ref: /.+/ } do post ":id/(ref/:ref/)trigger/pipeline", requirements: { ref: /.+/ } do
......
...@@ -7,6 +7,14 @@ module API ...@@ -7,6 +7,14 @@ module API
before { authenticate! } before { authenticate! }
before { authorize! :admin_build, user_project } before { authorize! :admin_build, user_project }
helpers do
def filter_variable_parameters(params)
# This method exists so that EE can more easily filter out certain
# parameters, without having to modify the source code directly.
params
end
end
params do params do
requires :id, type: String, desc: 'The ID of a project' requires :id, type: String, desc: 'The ID of a project'
end end
...@@ -50,6 +58,7 @@ module API ...@@ -50,6 +58,7 @@ module API
end end
post ':id/variables' do post ':id/variables' do
variable_params = declared_params(include_missing: false) variable_params = declared_params(include_missing: false)
variable_params = filter_variable_parameters(variable_params)
variable = user_project.variables.create(variable_params) variable = user_project.variables.create(variable_params)
...@@ -75,6 +84,7 @@ module API ...@@ -75,6 +84,7 @@ module API
break not_found!('Variable') unless variable break not_found!('Variable') unless variable
variable_params = declared_params(include_missing: false).except(:key) variable_params = declared_params(include_missing: false).except(:key)
variable_params = filter_variable_parameters(variable_params)
if variable.update(variable_params) if variable.update(variable_params)
present variable, with: Entities::Variable present variable, with: Entities::Variable
......
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