summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/award_emoji.rb2
-rw-r--r--lib/api/entities.rb1
-rw-r--r--lib/api/helpers/notes_helpers.rb10
-rw-r--r--lib/api/helpers/projects_helpers.rb2
-rw-r--r--lib/api/project_snippets.rb6
-rw-r--r--lib/api/snippets.rb4
6 files changed, 19 insertions, 6 deletions
diff --git a/lib/api/award_emoji.rb b/lib/api/award_emoji.rb
index 7a815fa3dde..8e3b3ff8ce5 100644
--- a/lib/api/award_emoji.rb
+++ b/lib/api/award_emoji.rb
@@ -127,6 +127,8 @@ module API
case awardable
when Note
read_ability(awardable.noteable)
+ when Snippet, ProjectSnippet
+ :read_snippet
else
:"read_#{awardable.class.to_s.underscore}"
end
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 52ff819924b..e6bc4ed69a1 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -311,6 +311,7 @@ module API
expose(:wiki_access_level) { |project, options| project.project_feature.string_access_level(:wiki) }
expose(:builds_access_level) { |project, options| project.project_feature.string_access_level(:builds) }
expose(:snippets_access_level) { |project, options| project.project_feature.string_access_level(:snippets) }
+ expose(:pages_access_level) { |project, options| project.project_feature.string_access_level(:pages) }
expose :shared_runners_enabled
expose :lfs_enabled?, as: :lfs_enabled
diff --git a/lib/api/helpers/notes_helpers.rb b/lib/api/helpers/notes_helpers.rb
index 8adfac346f6..2dd95aba6bc 100644
--- a/lib/api/helpers/notes_helpers.rb
+++ b/lib/api/helpers/notes_helpers.rb
@@ -72,7 +72,15 @@ module API
end
def noteable_read_ability_name(noteable)
- "read_#{noteable.class.to_s.underscore}".to_sym
+ "read_#{ability_name(noteable)}".to_sym
+ end
+
+ def ability_name(noteable)
+ if noteable.respond_to?(:to_ability_name)
+ noteable.to_ability_name
+ else
+ noteable.class.to_s.underscore
+ end
end
def find_noteable(parent_type, parent_id, noteable_type, noteable_id)
diff --git a/lib/api/helpers/projects_helpers.rb b/lib/api/helpers/projects_helpers.rb
index 6333e00daf5..6717f33f3e1 100644
--- a/lib/api/helpers/projects_helpers.rb
+++ b/lib/api/helpers/projects_helpers.rb
@@ -27,6 +27,7 @@ module API
optional :wiki_access_level, type: String, values: %w(disabled private enabled), desc: 'Wiki access level. One of `disabled`, `private` or `enabled`'
optional :builds_access_level, type: String, values: %w(disabled private enabled), desc: 'Builds access level. One of `disabled`, `private` or `enabled`'
optional :snippets_access_level, type: String, values: %w(disabled private enabled), desc: 'Snippets access level. One of `disabled`, `private` or `enabled`'
+ optional :pages_access_level, type: String, values: %w(disabled private enabled public), desc: 'Pages access level. One of `disabled`, `private`, `enabled` or `public`'
optional :shared_runners_enabled, type: Boolean, desc: 'Flag indication if shared runners are enabled for that project'
optional :resolve_outdated_diff_discussions, type: Boolean, desc: 'Automatically resolve merge request diffs discussions on lines changed with a push'
@@ -107,6 +108,7 @@ module API
:name,
:only_allow_merge_if_all_discussions_are_resolved,
:only_allow_merge_if_pipeline_succeeds,
+ :pages_access_level,
:path,
:printing_merge_request_link_enabled,
:public_builds,
diff --git a/lib/api/project_snippets.rb b/lib/api/project_snippets.rb
index ecada843972..3040c3c27c6 100644
--- a/lib/api/project_snippets.rb
+++ b/lib/api/project_snippets.rb
@@ -60,7 +60,7 @@ module API
mutually_exclusive :code, :content
end
post ":id/snippets" do
- authorize! :create_project_snippet, user_project
+ authorize! :create_snippet, user_project
snippet_params = declared_params(include_missing: false).merge(request: request, api: true)
snippet_params[:content] = snippet_params.delete(:code) if snippet_params[:code].present?
@@ -97,7 +97,7 @@ module API
snippet = snippets_for_current_user.find_by(id: params.delete(:snippet_id))
not_found!('Snippet') unless snippet
- authorize! :update_project_snippet, snippet
+ authorize! :update_snippet, snippet
snippet_params = declared_params(include_missing: false)
.merge(request: request, api: true)
@@ -126,7 +126,7 @@ module API
snippet = snippets_for_current_user.find_by(id: params[:snippet_id])
not_found!('Snippet') unless snippet
- authorize! :admin_project_snippet, snippet
+ authorize! :admin_snippet, snippet
destroy_conditionally!(snippet) do |snippet|
service = ::Snippets::DestroyService.new(current_user, snippet)
diff --git a/lib/api/snippets.rb b/lib/api/snippets.rb
index a7dab373b7f..b5df036c5ca 100644
--- a/lib/api/snippets.rb
+++ b/lib/api/snippets.rb
@@ -106,7 +106,7 @@ module API
snippet = snippets_for_current_user.find_by_id(params.delete(:id))
break not_found!('Snippet') unless snippet
- authorize! :update_personal_snippet, snippet
+ authorize! :update_snippet, snippet
attrs = declared_params(include_missing: false).merge(request: request, api: true)
service_response = ::Snippets::UpdateService.new(nil, current_user, attrs).execute(snippet)
@@ -132,7 +132,7 @@ module API
snippet = snippets_for_current_user.find_by_id(params.delete(:id))
break not_found!('Snippet') unless snippet
- authorize! :admin_personal_snippet, snippet
+ authorize! :admin_snippet, snippet
destroy_conditionally!(snippet) do |snippet|
service = ::Snippets::DestroyService.new(current_user, snippet)