diff options
Diffstat (limited to 'lib/api/entities')
-rw-r--r-- | lib/api/entities/ci/job_request/service.rb | 1 | ||||
-rw-r--r-- | lib/api/entities/deploy_key.rb | 3 | ||||
-rw-r--r-- | lib/api/entities/environment.rb | 37 | ||||
-rw-r--r-- | lib/api/entities/group_detail.rb | 10 | ||||
-rw-r--r-- | lib/api/entities/hook.rb | 5 | ||||
-rw-r--r-- | lib/api/entities/issue.rb | 4 | ||||
-rw-r--r-- | lib/api/entities/project.rb | 1 | ||||
-rw-r--r-- | lib/api/entities/terraform/module_version.rb | 18 | ||||
-rw-r--r-- | lib/api/entities/unleash/client_feature_flags.rb | 12 | ||||
-rw-r--r-- | lib/api/entities/user.rb | 2 |
10 files changed, 48 insertions, 45 deletions
diff --git a/lib/api/entities/ci/job_request/service.rb b/lib/api/entities/ci/job_request/service.rb index d9da2c92ec7..7d494c7e516 100644 --- a/lib/api/entities/ci/job_request/service.rb +++ b/lib/api/entities/ci/job_request/service.rb @@ -8,6 +8,7 @@ module API expose :name, :entrypoint expose :ports, using: Entities::Ci::JobRequest::Port + expose :pull_policy, if: ->(_) { ::Feature.enabled?(:ci_docker_image_pull_policy) } expose :alias, :command expose :variables end diff --git a/lib/api/entities/deploy_key.rb b/lib/api/entities/deploy_key.rb index e8537c4c677..2c9c33549a1 100644 --- a/lib/api/entities/deploy_key.rb +++ b/lib/api/entities/deploy_key.rb @@ -4,7 +4,8 @@ module API module Entities class DeployKey < Entities::SSHKey expose :key - expose :fingerprint + expose :fingerprint, if: ->(key, _) { key.fingerprint.present? } + expose :fingerprint_sha256 expose :projects_with_write_access, using: Entities::ProjectIdentity, if: -> (_, options) { options[:include_projects_with_write_access] } end diff --git a/lib/api/entities/environment.rb b/lib/api/entities/environment.rb index b1a720ac6bb..3b6ed94c3f1 100644 --- a/lib/api/entities/environment.rb +++ b/lib/api/entities/environment.rb @@ -4,48 +4,11 @@ module API module Entities class Environment < Entities::EnvironmentBasic include RequestAwareEntity - include Gitlab::Utils::StrongMemoize expose :tier expose :project, using: Entities::BasicProjectDetails expose :last_deployment, using: Entities::Deployment, if: { last_deployment: true } expose :state - - expose :enable_advanced_logs_querying, if: -> (*) { can_read_pod_logs? } do |environment| - environment.elastic_stack_available? - end - - expose :logs_api_path, if: -> (*) { can_read_pod_logs? } do |environment| - if environment.elastic_stack_available? - elasticsearch_project_logs_path(environment.project, environment_name: environment.name, format: :json) - else - k8s_project_logs_path(environment.project, environment_name: environment.name, format: :json) - end - end - - expose :gitlab_managed_apps_logs_path, if: -> (*) { can_read_pod_logs? && cluster } do |environment| - ::Clusters::ClusterPresenter.new(cluster, current_user: current_user).gitlab_managed_apps_logs_path # rubocop: disable CodeReuse/Presenter - end - - private - - alias_method :environment, :object - - def can_read_pod_logs? - strong_memoize(:can_read_pod_logs) do - current_user&.can?(:read_pod_logs, environment.project) - end - end - - def cluster - strong_memoize(:cluster) do - environment&.last_deployment&.cluster - end - end - - def current_user - options[:current_user] - end end end end diff --git a/lib/api/entities/group_detail.rb b/lib/api/entities/group_detail.rb index e6872709432..e521de0d572 100644 --- a/lib/api/entities/group_detail.rb +++ b/lib/api/entities/group_detail.rb @@ -6,10 +6,12 @@ module API expose :shared_with_groups do |group, options| SharedGroupWithGroup.represent(group.shared_with_group_links_visible_to_user(options[:current_user])) end - expose :runners_token, if: lambda { |group, options| options[:user_can_admin_group] } + expose :runners_token, if: ->(_, options) { options[:user_can_admin_group] } expose :prevent_sharing_groups_outside_hierarchy, if: ->(group) { group.root? } - expose :projects, using: Entities::Project do |group, options| + expose :projects, + if: ->(_, options) { options[:with_projects] }, + using: Entities::Project do |group, options| projects = GroupProjectsFinder.new( group: group, current_user: options[:current_user], @@ -19,7 +21,9 @@ module API Entities::Project.prepare_relation(projects, options) end - expose :shared_projects, using: Entities::Project do |group, options| + expose :shared_projects, + if: ->(_, options) { options[:with_projects] }, + using: Entities::Project do |group, options| projects = GroupProjectsFinder.new( group: group, current_user: options[:current_user], diff --git a/lib/api/entities/hook.rb b/lib/api/entities/hook.rb index d176e76b321..95924321221 100644 --- a/lib/api/entities/hook.rb +++ b/lib/api/entities/hook.rb @@ -8,6 +8,11 @@ module API expose :alert_status expose :disabled_until + expose :url_variables + + def url_variables + object.url_variables.keys.map { { key: _1 } } + end end end end diff --git a/lib/api/entities/issue.rb b/lib/api/entities/issue.rb index 1060b2c517a..7630fd1e94e 100644 --- a/lib/api/entities/issue.rb +++ b/lib/api/entities/issue.rb @@ -31,9 +31,7 @@ module API end expose :closed_as_duplicate_of do |issue| - if ::Feature.enabled?(:closed_as_duplicate_of_issues_api, issue.project) && - issue.duplicated? && - options[:current_user]&.can?(:read_issue, issue.duplicated_to) + if issue.duplicated? && options[:current_user]&.can?(:read_issue, issue.duplicated_to) expose_url( api_v4_project_issue_path(id: issue.duplicated_to.project_id, issue_iid: issue.duplicated_to.iid) ) diff --git a/lib/api/entities/project.rb b/lib/api/entities/project.rb index 9e216b0aed5..906c252d7f9 100644 --- a/lib/api/entities/project.rb +++ b/lib/api/entities/project.rb @@ -104,6 +104,7 @@ module API expose :ci_forward_deployment_enabled expose :ci_job_token_scope_enabled expose :ci_separated_caches + expose :ci_opt_in_jwt expose :public_builds, as: :public_jobs expose :build_git_strategy, if: lambda { |project, options| options[:user_can_admin_project] } do |project, options| project.build_allow_git_fetch ? 'fetch' : 'clone' diff --git a/lib/api/entities/terraform/module_version.rb b/lib/api/entities/terraform/module_version.rb new file mode 100644 index 00000000000..411fa09465e --- /dev/null +++ b/lib/api/entities/terraform/module_version.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module API + module Entities + module Terraform + class ModuleVersion < Grape::Entity + expose :name + expose :provider + expose :providers + expose :root + expose :source + expose :submodules + expose :version + expose :versions + end + end + end +end diff --git a/lib/api/entities/unleash/client_feature_flags.rb b/lib/api/entities/unleash/client_feature_flags.rb new file mode 100644 index 00000000000..8c96d0610a4 --- /dev/null +++ b/lib/api/entities/unleash/client_feature_flags.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module API + module Entities + module Unleash + class ClientFeatureFlags < Grape::Entity + expose :unleash_api_version, as: :version + expose :unleash_api_features, as: :features, using: ::API::Entities::UnleashFeature + end + end + end +end diff --git a/lib/api/entities/user.rb b/lib/api/entities/user.rb index 2366d137cc2..a86039b856a 100644 --- a/lib/api/entities/user.rb +++ b/lib/api/entities/user.rb @@ -19,7 +19,7 @@ module API user.followees.size end expose :is_followed, if: ->(user, opts) { Ability.allowed?(opts[:current_user], :read_user_profile, user) && opts[:current_user] } do |user, opts| - opts[:current_user].following?(user) + user.followed_by?(opts[:current_user]) end expose :local_time do |user| local_time(user.timezone) |