diff options
author | Toon Claes <toon@gitlab.com> | 2017-03-01 16:16:29 +0100 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2017-03-02 09:33:24 +0100 |
commit | b2c2dfe545526a1857e9605761f6d256ef73e190 (patch) | |
tree | ba3ec9ea7ce38a4c2ca09b6d92a3d67bb492daf1 /lib | |
parent | fc287191451bb6aac80d759ab521b5834d27df43 (diff) | |
download | gitlab-ce-b2c2dfe545526a1857e9605761f6d256ef73e190.tar.gz |
Expose Project's & ProjectSnippet's VisibilityLevel as String
Instead of exposing the VisibilityLevel as Integer, expose it as
String `visibility` for Project and ProjectSnippet.
Filter queries also accept the `visibility` as String instead of
`visibility_level` as Integer.
Also remove the `public` boolean.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/entities.rb | 4 | ||||
-rw-r--r-- | lib/api/helpers.rb | 8 | ||||
-rw-r--r-- | lib/api/project_snippets.rb | 20 | ||||
-rw-r--r-- | lib/api/projects.rb | 16 |
4 files changed, 24 insertions, 24 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 9dccaff369e..bcdd0573e57 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -69,9 +69,9 @@ module API class Project < Grape::Entity expose :id, :description, :default_branch, :tag_list - expose :public?, as: :public expose :archived?, as: :archived - expose :visibility_level, :ssh_url_to_repo, :http_url_to_repo, :web_url + expose :ssh_url_to_repo, :http_url_to_repo, :web_url + expose(:visibility) { |project, _options| Gitlab::VisibilityLevel.string_level(project.visibility_level) } expose :owner, using: Entities::UserBasic, unless: ->(project, options) { project.group } expose :name, :name_with_namespace expose :path, :path_with_namespace diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 72d2b320077..7a39c640c5a 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -268,6 +268,14 @@ module API projects.reorder(params[:order_by] => params[:sort]) end + def map_visibility_level(attrs) + visibility = attrs.delete(:visibility) + if visibility + attrs[:visibility_level] = Gitlab::VisibilityLevel.string_options[visibility] + end + attrs + end + # file helpers def uploaded_file(field, uploads_path) diff --git a/lib/api/project_snippets.rb b/lib/api/project_snippets.rb index 2a1cce73f3f..31919a6270d 100644 --- a/lib/api/project_snippets.rb +++ b/lib/api/project_snippets.rb @@ -50,15 +50,13 @@ module API requires :title, type: String, desc: 'The title of the snippet' requires :file_name, type: String, desc: 'The file name of the snippet' requires :code, type: String, desc: 'The content of the snippet' - requires :visibility_level, type: Integer, - values: [Gitlab::VisibilityLevel::PRIVATE, - Gitlab::VisibilityLevel::INTERNAL, - Gitlab::VisibilityLevel::PUBLIC], - desc: 'The visibility level of the snippet' + requires :visibility, type: String, + values: Gitlab::VisibilityLevel.string_values, + desc: 'The visibility of the snippet' end post ":id/snippets" do authorize! :create_project_snippet, user_project - snippet_params = declared_params.merge(request: request, api: true) + snippet_params = map_visibility_level(declared_params).merge(request: request, api: true) snippet_params[:content] = snippet_params.delete(:code) snippet = CreateSnippetService.new(user_project, current_user, snippet_params).execute @@ -80,11 +78,9 @@ module API optional :title, type: String, desc: 'The title of the snippet' optional :file_name, type: String, desc: 'The file name of the snippet' optional :code, type: String, desc: 'The content of the snippet' - optional :visibility_level, type: Integer, - values: [Gitlab::VisibilityLevel::PRIVATE, - Gitlab::VisibilityLevel::INTERNAL, - Gitlab::VisibilityLevel::PUBLIC], - desc: 'The visibility level of the snippet' + optional :visibility, type: String, + values: Gitlab::VisibilityLevel.string_values, + desc: 'The visibility of the snippet' at_least_one_of :title, :file_name, :code, :visibility_level end put ":id/snippets/:snippet_id" do @@ -93,7 +89,7 @@ module API authorize! :update_project_snippet, snippet - snippet_params = declared_params(include_missing: false) + snippet_params = map_visibility_level(declared_params(include_missing: false)) .merge(request: request, api: true) snippet_params[:content] = snippet_params.delete(:code) if snippet_params[:code].present? diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 996404e0e49..743dcac41f9 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -16,11 +16,7 @@ module API optional :shared_runners_enabled, type: Boolean, desc: 'Flag indication if shared runners are enabled for that project' optional :container_registry_enabled, type: Boolean, desc: 'Flag indication if the container registry is enabled for that project' optional :lfs_enabled, type: Boolean, desc: 'Flag indication if Git LFS is enabled for that project' - optional :visibility_level, type: Integer, values: [ - Gitlab::VisibilityLevel::PRIVATE, - Gitlab::VisibilityLevel::INTERNAL, - Gitlab::VisibilityLevel::PUBLIC - ], desc: 'Create a public project. The same as visibility_level = 20.' + optional :visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: 'The visibility of the project.' optional :public_builds, type: Boolean, desc: 'Perform public builds' optional :request_access_enabled, type: Boolean, desc: 'Allow users to request member access' optional :only_allow_merge_if_pipeline_succeeds, type: Boolean, desc: 'Only allow to merge if builds succeed' @@ -48,7 +44,7 @@ module API params :filter_params do optional :archived, type: Boolean, default: false, desc: 'Limit by archived status' - optional :visibility, type: String, values: %w[public internal private], + optional :visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: 'Limit by visibility' optional :search, type: String, desc: 'Return list of authorized projects matching the search criteria' optional :owned, type: Boolean, default: false, desc: 'Limit by owned by authenticated user' @@ -101,7 +97,7 @@ module API use :create_params end post do - attrs = declared_params(include_missing: false) + attrs = map_visibility_level(declared_params(include_missing: false)) project = ::Projects::CreateService.new(current_user, attrs).execute if project.saved? @@ -130,7 +126,7 @@ module API user = User.find_by(id: params.delete(:user_id)) not_found!('User') unless user - attrs = declared_params(include_missing: false) + attrs = map_visibility_level(declared_params(include_missing: false)) project = ::Projects::CreateService.new(user, attrs).execute if project.saved? @@ -208,14 +204,14 @@ module API at_least_one_of :name, :description, :issues_enabled, :merge_requests_enabled, :wiki_enabled, :builds_enabled, :snippets_enabled, :shared_runners_enabled, :container_registry_enabled, - :lfs_enabled, :visibility_level, :public_builds, + :lfs_enabled, :visibility, :public_builds, :request_access_enabled, :only_allow_merge_if_pipeline_succeeds, :only_allow_merge_if_all_discussions_are_resolved, :path, :default_branch end put ':id' do authorize_admin_project - attrs = declared_params(include_missing: false) + attrs = map_visibility_level(declared_params(include_missing: false)) authorize! :rename_project, user_project if attrs[:name].present? authorize! :change_visibility_level, user_project if attrs[:visibility_level].present? |