Commit 09916aea authored by Robert Speicher's avatar Robert Speicher

Merge branch 'if-10137-ee_specific_lines_projects_api' into 'master'

CE port of Move EE specific lines in API::Projects

See merge request gitlab-org/gitlab-ce!28596
parents 9302485e 9cd70ec1
...@@ -4,9 +4,8 @@ module API ...@@ -4,9 +4,8 @@ module API
module Helpers module Helpers
module ProjectsHelpers module ProjectsHelpers
extend ActiveSupport::Concern extend ActiveSupport::Concern
extend Grape::API::Helpers
included do
helpers do
params :optional_project_params_ce do params :optional_project_params_ce do
optional :description, type: String, desc: 'The description of the project' optional :description, type: String, desc: 'The description of the project'
optional :ci_config_path, type: String, desc: 'The path to CI config file. Defaults to `.gitlab-ci.yml`' optional :ci_config_path, type: String, desc: 'The path to CI config file. Defaults to `.gitlab-ci.yml`'
...@@ -32,20 +31,18 @@ module API ...@@ -32,20 +31,18 @@ module API
optional :external_authorization_classification_label, type: String, desc: 'The classification label for the project' optional :external_authorization_classification_label, type: String, desc: 'The classification label for the project'
end end
if Gitlab.ee?
params :optional_project_params_ee do params :optional_project_params_ee do
optional :repository_storage, type: String, desc: 'Which storage shard the repository is on. Available only to admins'
optional :approvals_before_merge, type: Integer, desc: 'How many approvers should approve merge request by default'
optional :mirror, type: Boolean, desc: 'Enables pull mirroring in a project'
optional :mirror_trigger_builds, type: Boolean, desc: 'Pull mirroring triggers builds'
end
end end
params :optional_project_params do params :optional_project_params do
use :optional_project_params_ce use :optional_project_params_ce
use :optional_project_params_ee if Gitlab.ee? use :optional_project_params_ee
end end
params :optional_filter_params_ee do
end end
params :optional_update_params_ee do
end end
def self.update_params_at_least_one_of def self.update_params_at_least_one_of
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
module API module API
class ProjectImport < Grape::API class ProjectImport < Grape::API
include PaginationParams include PaginationParams
include Helpers::ProjectsHelpers
helpers Helpers::ProjectsHelpers
helpers do helpers do
def import_params def import_params
......
...@@ -6,27 +6,12 @@ module API ...@@ -6,27 +6,12 @@ module API
class Projects < Grape::API class Projects < Grape::API
include PaginationParams include PaginationParams
include Helpers::CustomAttributes include Helpers::CustomAttributes
include Helpers::ProjectsHelpers
helpers Helpers::ProjectsHelpers
before { authenticate_non_get! } before { authenticate_non_get! }
helpers do helpers do
if Gitlab.ee?
params :optional_filter_params_ee do
optional :wiki_checksum_failed, type: Grape::API::Boolean, default: false, desc: 'Limit by projects where wiki checksum is failed'
optional :repository_checksum_failed, type: Grape::API::Boolean, default: false, desc: 'Limit by projects where repository checksum is failed'
end
params :optional_update_params_ee do
optional :mirror_user_id, type: Integer, desc: 'User responsible for all the activity surrounding a pull mirror event'
optional :only_mirror_protected_branches, type: Grape::API::Boolean, desc: 'Only mirror protected branches'
optional :mirror_overwrites_diverged_branches, type: Grape::API::Boolean, desc: 'Pull mirror overwrites diverged branches'
optional :import_url, type: String, desc: 'URL from which the project is imported'
optional :packages_enabled, type: Grape::API::Boolean, desc: 'Enable project packages feature'
optional :fallback_approvals_required, type: Integer, desc: 'Overall approvals required when no rule is present'
end
end
# EE::API::Projects would override this method # EE::API::Projects would override this method
def apply_filters(projects) def apply_filters(projects)
projects = projects.with_issues_available_for_user(current_user) if params[:with_issues_enabled] projects = projects.with_issues_available_for_user(current_user) if params[:with_issues_enabled]
...@@ -77,7 +62,7 @@ module API ...@@ -77,7 +62,7 @@ module API
optional :with_programming_language, type: String, desc: 'Limit to repositories which use the given programming language' optional :with_programming_language, type: String, desc: 'Limit to repositories which use the given programming language'
optional :min_access_level, type: Integer, values: Gitlab::Access.all_values, desc: 'Limit by minimum access level of authenticated user' optional :min_access_level, type: Integer, values: Gitlab::Access.all_values, desc: 'Limit by minimum access level of authenticated user'
use :optional_filter_params_ee if Gitlab.ee? use :optional_filter_params_ee
end end
params :create_params do params :create_params do
...@@ -296,7 +281,7 @@ module API ...@@ -296,7 +281,7 @@ module API
optional :path, type: String, desc: 'The path of the repository' optional :path, type: String, desc: 'The path of the repository'
use :optional_project_params use :optional_project_params
use :optional_update_params_ee if Gitlab.ee? use :optional_update_params_ee
at_least_one_of(*Helpers::ProjectsHelpers.update_params_at_least_one_of) at_least_one_of(*Helpers::ProjectsHelpers.update_params_at_least_one_of)
end end
......
...@@ -1025,7 +1025,54 @@ describe API::Projects do ...@@ -1025,7 +1025,54 @@ describe API::Projects do
end end
end end
context 'when authenticated' do context 'when authenticated as an admin' do
it 'returns a project by id' do
project
project_member
group = create(:group)
link = create(:project_group_link, project: project, group: group)
get api("/projects/#{project.id}", admin)
expect(response).to have_gitlab_http_status(200)
expect(json_response['id']).to eq(project.id)
expect(json_response['description']).to eq(project.description)
expect(json_response['default_branch']).to eq(project.default_branch)
expect(json_response['tag_list']).to be_an Array
expect(json_response['archived']).to be_falsey
expect(json_response['visibility']).to be_present
expect(json_response['ssh_url_to_repo']).to be_present
expect(json_response['http_url_to_repo']).to be_present
expect(json_response['web_url']).to be_present
expect(json_response['owner']).to be_a Hash
expect(json_response['name']).to eq(project.name)
expect(json_response['path']).to be_present
expect(json_response['issues_enabled']).to be_present
expect(json_response['merge_requests_enabled']).to be_present
expect(json_response['wiki_enabled']).to be_present
expect(json_response['jobs_enabled']).to be_present
expect(json_response['snippets_enabled']).to be_present
expect(json_response['container_registry_enabled']).to be_present
expect(json_response['created_at']).to be_present
expect(json_response['last_activity_at']).to be_present
expect(json_response['shared_runners_enabled']).to be_present
expect(json_response['creator_id']).to be_present
expect(json_response['namespace']).to be_present
expect(json_response['avatar_url']).to be_nil
expect(json_response['star_count']).to be_present
expect(json_response['forks_count']).to be_present
expect(json_response['public_jobs']).to be_present
expect(json_response['shared_with_groups']).to be_an Array
expect(json_response['shared_with_groups'].length).to eq(1)
expect(json_response['shared_with_groups'][0]['group_id']).to eq(group.id)
expect(json_response['shared_with_groups'][0]['group_name']).to eq(group.name)
expect(json_response['shared_with_groups'][0]['group_access_level']).to eq(link.group_access)
expect(json_response['only_allow_merge_if_pipeline_succeeds']).to eq(project.only_allow_merge_if_pipeline_succeeds)
expect(json_response['only_allow_merge_if_all_discussions_are_resolved']).to eq(project.only_allow_merge_if_all_discussions_are_resolved)
end
end
context 'when authenticated as a regular user' do
before do before do
project project
project_member project_member
......
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