Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-11 03:09:06 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-11 03:09:06 +0300
commita9104a50136e485c8dda7af37106332f9010a1e8 (patch)
tree26880b70033a0952d7801c9554b99cea827820dd /lib
parent696b36294520f8a311586f99e838b6a61b1b3f32 (diff)
Add latest changes from gitlab-org/gitlab@master76926-follow-up-from-resolve-multi-selection-for-delete-on-registry-page
Diffstat (limited to 'lib')
-rw-r--r--lib/api/entities.rb80
-rw-r--r--lib/api/entities/event.rb23
-rw-r--r--lib/api/entities/namespace_basic.rb17
-rw-r--r--lib/api/entities/project_group_link.rb9
-rw-r--r--lib/api/entities/push_event_payload.rb10
-rw-r--r--lib/api/entities/todo.rb46
6 files changed, 105 insertions, 80 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 98c0f78de1f..5c46a9f21e8 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -129,86 +129,6 @@ module API
end
end
- class PushEventPayload < Grape::Entity
- expose :commit_count, :action, :ref_type, :commit_from, :commit_to, :ref,
- :commit_title, :ref_count
- end
-
- class Event < Grape::Entity
- expose :project_id, :action_name
- expose :target_id, :target_iid, :target_type, :author_id
- expose :target_title
- expose :created_at
- expose :note, using: Entities::Note, if: ->(event, options) { event.note? }
- expose :author, using: Entities::UserBasic, if: ->(event, options) { event.author }
-
- expose :push_event_payload,
- as: :push_data,
- using: PushEventPayload,
- if: -> (event, _) { event.push_action? }
-
- expose :author_username do |event, options|
- event.author&.username
- end
- end
-
- class ProjectGroupLink < Grape::Entity
- expose :id, :project_id, :group_id, :group_access, :expires_at
- end
-
- class Todo < Grape::Entity
- expose :id
- expose :project, using: Entities::ProjectIdentity, if: -> (todo, _) { todo.project_id }
- expose :group, using: 'API::Entities::NamespaceBasic', if: -> (todo, _) { todo.group_id }
- expose :author, using: Entities::UserBasic
- expose :action_name
- expose :target_type
-
- expose :target do |todo, options|
- todo_options = options.fetch(todo.target_type, {})
- todo_target_class(todo.target_type).represent(todo.target, todo_options)
- end
-
- expose :target_url do |todo, options|
- todo_target_url(todo)
- end
-
- expose :body
- expose :state
- expose :created_at
-
- def todo_target_class(target_type)
- # false as second argument prevents looking up in module hierarchy
- # see also https://gitlab.com/gitlab-org/gitlab-foss/issues/59719
- ::API::Entities.const_get(target_type, false)
- end
-
- def todo_target_url(todo)
- target_type = todo.target_type.underscore
- target_url = "#{todo.resource_parent.class.to_s.underscore}_#{target_type}_url"
-
- Gitlab::Routing
- .url_helpers
- .public_send(target_url, todo.resource_parent, todo.target, anchor: todo_target_anchor(todo)) # rubocop:disable GitlabSecurity/PublicSend
- end
-
- def todo_target_anchor(todo)
- "note_#{todo.note_id}" if todo.note_id?
- end
- end
-
- class NamespaceBasic < Grape::Entity
- expose :id, :name, :path, :kind, :full_path, :parent_id, :avatar_url
-
- expose :web_url do |namespace|
- if namespace.user?
- Gitlab::Routing.url_helpers.user_url(namespace.owner)
- else
- namespace.web_url
- end
- end
- end
-
class Namespace < NamespaceBasic
expose :members_count_with_descendants, if: -> (namespace, opts) { expose_members_count_with_descendants?(namespace, opts) } do |namespace, _|
namespace.users_with_descendants.count
diff --git a/lib/api/entities/event.rb b/lib/api/entities/event.rb
new file mode 100644
index 00000000000..9c2d766b7f1
--- /dev/null
+++ b/lib/api/entities/event.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class Event < Grape::Entity
+ expose :project_id, :action_name
+ expose :target_id, :target_iid, :target_type, :author_id
+ expose :target_title
+ expose :created_at
+ expose :note, using: Entities::Note, if: ->(event, options) { event.note? }
+ expose :author, using: Entities::UserBasic, if: ->(event, options) { event.author }
+
+ expose :push_event_payload,
+ as: :push_data,
+ using: Entities::PushEventPayload,
+ if: -> (event, _) { event.push_action? }
+
+ expose :author_username do |event, options|
+ event.author&.username
+ end
+ end
+ end
+end
diff --git a/lib/api/entities/namespace_basic.rb b/lib/api/entities/namespace_basic.rb
new file mode 100644
index 00000000000..f968a074bd2
--- /dev/null
+++ b/lib/api/entities/namespace_basic.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class NamespaceBasic < Grape::Entity
+ expose :id, :name, :path, :kind, :full_path, :parent_id, :avatar_url
+
+ expose :web_url do |namespace|
+ if namespace.user?
+ Gitlab::Routing.url_helpers.user_url(namespace.owner)
+ else
+ namespace.web_url
+ end
+ end
+ end
+ end
+end
diff --git a/lib/api/entities/project_group_link.rb b/lib/api/entities/project_group_link.rb
new file mode 100644
index 00000000000..89138854e67
--- /dev/null
+++ b/lib/api/entities/project_group_link.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class ProjectGroupLink < Grape::Entity
+ expose :id, :project_id, :group_id, :group_access, :expires_at
+ end
+ end
+end
diff --git a/lib/api/entities/push_event_payload.rb b/lib/api/entities/push_event_payload.rb
new file mode 100644
index 00000000000..6aad5f10177
--- /dev/null
+++ b/lib/api/entities/push_event_payload.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class PushEventPayload < Grape::Entity
+ expose :commit_count, :action, :ref_type, :commit_from, :commit_to, :ref,
+ :commit_title, :ref_count
+ end
+ end
+end
diff --git a/lib/api/entities/todo.rb b/lib/api/entities/todo.rb
new file mode 100644
index 00000000000..820d1ceaadd
--- /dev/null
+++ b/lib/api/entities/todo.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class Todo < Grape::Entity
+ expose :id
+ expose :project, using: Entities::ProjectIdentity, if: -> (todo, _) { todo.project_id }
+ expose :group, using: 'API::Entities::NamespaceBasic', if: -> (todo, _) { todo.group_id }
+ expose :author, using: Entities::UserBasic
+ expose :action_name
+ expose :target_type
+
+ expose :target do |todo, options|
+ todo_options = options.fetch(todo.target_type, {})
+ todo_target_class(todo.target_type).represent(todo.target, todo_options)
+ end
+
+ expose :target_url do |todo, options|
+ todo_target_url(todo)
+ end
+
+ expose :body
+ expose :state
+ expose :created_at
+
+ def todo_target_class(target_type)
+ # false as second argument prevents looking up in module hierarchy
+ # see also https://gitlab.com/gitlab-org/gitlab-foss/issues/59719
+ ::API::Entities.const_get(target_type, false)
+ end
+
+ def todo_target_url(todo)
+ target_type = todo.target_type.underscore
+ target_url = "#{todo.resource_parent.class.to_s.underscore}_#{target_type}_url"
+
+ Gitlab::Routing
+ .url_helpers
+ .public_send(target_url, todo.resource_parent, todo.target, anchor: todo_target_anchor(todo)) # rubocop:disable GitlabSecurity/PublicSend
+ end
+
+ def todo_target_anchor(todo)
+ "note_#{todo.note_id}" if todo.note_id?
+ end
+ end
+ end
+end