diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-21 02:50:22 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-21 02:50:22 +0300 |
commit | 9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch) | |
tree | 70467ae3692a0e35e5ea56bcb803eb512a10bedb /lib/api/entities | |
parent | 4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff) |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'lib/api/entities')
-rw-r--r-- | lib/api/entities/basic_project_details.rb | 9 | ||||
-rw-r--r-- | lib/api/entities/clusters/agent.rb | 12 | ||||
-rw-r--r-- | lib/api/entities/email.rb | 2 | ||||
-rw-r--r-- | lib/api/entities/job_request/job_info.rb | 2 | ||||
-rw-r--r-- | lib/api/entities/namespace_existence.rb | 9 | ||||
-rw-r--r-- | lib/api/entities/project.rb | 5 | ||||
-rw-r--r-- | lib/api/entities/project_import_failed_relation.rb | 6 | ||||
-rw-r--r-- | lib/api/entities/user.rb | 4 | ||||
-rw-r--r-- | lib/api/entities/user_preferences.rb | 9 | ||||
-rw-r--r-- | lib/api/entities/user_public.rb | 1 |
10 files changed, 47 insertions, 12 deletions
diff --git a/lib/api/entities/basic_project_details.rb b/lib/api/entities/basic_project_details.rb index cf0b32bed26..2de49d6ed40 100644 --- a/lib/api/entities/basic_project_details.rb +++ b/lib/api/entities/basic_project_details.rb @@ -8,11 +8,10 @@ module API expose :default_branch, if: -> (project, options) { Ability.allowed?(options[:current_user], :download_code, project) } # Avoids an N+1 query: https://github.com/mbleigh/acts-as-taggable-on/issues/91#issuecomment-168273770 expose :tag_list do |project| - # project.tags.order(:name).pluck(:name) is the most suitable option - # to avoid loading all the ActiveRecord objects but, if we use it here - # it override the preloaded associations and makes a query - # (fixed in https://github.com/rails/rails/pull/25976). - project.tags.map(&:name).sort + # Tags is a preloaded association. If we perform then sorting + # through the database, it will trigger a new query, ending up + # in an N+1 if we have several projects + project.tags.pluck(:name).sort # rubocop:disable CodeReuse/ActiveRecord end expose :ssh_url_to_repo, :http_url_to_repo, :web_url, :readme_url diff --git a/lib/api/entities/clusters/agent.rb b/lib/api/entities/clusters/agent.rb new file mode 100644 index 00000000000..3b4538b81c2 --- /dev/null +++ b/lib/api/entities/clusters/agent.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module API + module Entities + module Clusters + class Agent < Grape::Entity + expose :id + expose :project, with: Entities::ProjectIdentity, as: :config_project + end + end + end +end diff --git a/lib/api/entities/email.rb b/lib/api/entities/email.rb index 5ba425def3d..46ebc458bcd 100644 --- a/lib/api/entities/email.rb +++ b/lib/api/entities/email.rb @@ -3,7 +3,7 @@ module API module Entities class Email < Grape::Entity - expose :id, :email + expose :id, :email, :confirmed_at end end end diff --git a/lib/api/entities/job_request/job_info.rb b/lib/api/entities/job_request/job_info.rb index 09c13aa8471..a4bcc9726d0 100644 --- a/lib/api/entities/job_request/job_info.rb +++ b/lib/api/entities/job_request/job_info.rb @@ -4,7 +4,7 @@ module API module Entities module JobRequest class JobInfo < Grape::Entity - expose :name, :stage + expose :id, :name, :stage expose :project_id, :project_name end end diff --git a/lib/api/entities/namespace_existence.rb b/lib/api/entities/namespace_existence.rb new file mode 100644 index 00000000000..d93078ecdac --- /dev/null +++ b/lib/api/entities/namespace_existence.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module API + module Entities + class NamespaceExistence < Grape::Entity + expose :exists, :suggests + end + end +end diff --git a/lib/api/entities/project.rb b/lib/api/entities/project.rb index e332e5e40fa..690bc5d419d 100644 --- a/lib/api/entities/project.rb +++ b/lib/api/entities/project.rb @@ -127,15 +127,16 @@ module API # as `:tags` are defined as: `has_many :tags, through: :taggings` # N+1 is solved then by using `subject.tags.map(&:name)` # MR describing the solution: https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/20555 - super(projects_relation).preload(:group) + super(projects_relation).preload(group: :namespace_settings) .preload(:ci_cd_settings) .preload(:project_setting) .preload(:container_expiration_policy) .preload(:auto_devops) + .preload(:service_desk_setting) .preload(project_group_links: { group: :route }, fork_network: :root_project, fork_network_member: :forked_from_project, - forked_from_project: [:route, :forks, :tags, namespace: :route]) + forked_from_project: [:route, :forks, :tags, :group, :project_feature, namespace: [:route, :owner]]) end # rubocop: enable CodeReuse/ActiveRecord diff --git a/lib/api/entities/project_import_failed_relation.rb b/lib/api/entities/project_import_failed_relation.rb index 16b26ad0efa..b8f842c1646 100644 --- a/lib/api/entities/project_import_failed_relation.rb +++ b/lib/api/entities/project_import_failed_relation.rb @@ -3,7 +3,11 @@ module API module Entities class ProjectImportFailedRelation < Grape::Entity - expose :id, :created_at, :exception_class, :exception_message, :source + expose :id, :created_at, :exception_class, :source + + expose :exception_message do |_| + nil + end expose :relation_key, as: :relation_name end diff --git a/lib/api/entities/user.rb b/lib/api/entities/user.rb index 248a86751d2..3ce6d03e236 100644 --- a/lib/api/entities/user.rb +++ b/lib/api/entities/user.rb @@ -11,10 +11,10 @@ module API work_information(user) end expose :followers, if: ->(user, opts) { Ability.allowed?(opts[:current_user], :read_user_profile, user) } do |user| - user.followers.count + user.followers.size end expose :following, if: ->(user, opts) { Ability.allowed?(opts[:current_user], :read_user_profile, user) } do |user| - user.followees.count + user.followees.size end end end diff --git a/lib/api/entities/user_preferences.rb b/lib/api/entities/user_preferences.rb new file mode 100644 index 00000000000..7a6df9b6c59 --- /dev/null +++ b/lib/api/entities/user_preferences.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module API + module Entities + class UserPreferences < Grape::Entity + expose :id, :user_id, :view_diffs_file_by_file + end + end +end diff --git a/lib/api/entities/user_public.rb b/lib/api/entities/user_public.rb index 15e9b905bef..685adb1dd10 100644 --- a/lib/api/entities/user_public.rb +++ b/lib/api/entities/user_public.rb @@ -14,6 +14,7 @@ module API expose :two_factor_enabled?, as: :two_factor_enabled expose :external expose :private_profile + expose :commit_email end end end |