diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-06 21:09:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-06 21:09:02 +0300 |
commit | 2d181003830956f5e690cce74be50bb4d96048f8 (patch) | |
tree | cd72c53f6cb3753fc1bd28521e89af66c420f08a /app/serializers | |
parent | c79da5142f46e6e9187f75c329e2c81a8568c581 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/serializers')
-rw-r--r-- | app/serializers/deploy_key_entity.rb | 39 | ||||
-rw-r--r-- | app/serializers/deploy_key_serializer.rb | 5 | ||||
-rw-r--r-- | app/serializers/deploy_keys/basic_deploy_key_entity.rb | 28 | ||||
-rw-r--r-- | app/serializers/deploy_keys/basic_deploy_key_serializer.rb | 7 | ||||
-rw-r--r-- | app/serializers/deploy_keys/deploy_key_entity.rb | 22 | ||||
-rw-r--r-- | app/serializers/deploy_keys/deploy_key_serializer.rb | 7 |
6 files changed, 64 insertions, 44 deletions
diff --git a/app/serializers/deploy_key_entity.rb b/app/serializers/deploy_key_entity.rb deleted file mode 100644 index 486189b84ca..00000000000 --- a/app/serializers/deploy_key_entity.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -class DeployKeyEntity < Grape::Entity - expose :id - expose :user_id - expose :title - expose :fingerprint - expose :fingerprint_sha256 - expose :destroyed_when_orphaned?, as: :destroyed_when_orphaned - expose :almost_orphaned?, as: :almost_orphaned - expose :created_at - expose :updated_at - expose :deploy_keys_projects, using: DeployKeysProjectEntity do |deploy_key| - deploy_key.deploy_keys_projects.select do |deploy_key_project| - !deploy_key_project.project&.pending_delete? && (allowed_to_read_project?(deploy_key_project.project) || options[:user].admin?) - end - end - expose :can_edit - expose :user, as: :owner, using: ::API::Entities::UserBasic, if: -> (_, opts) { can_read_owner?(opts) } - - private - - def can_edit - Ability.allowed?(options[:user], :update_deploy_key, object) || - Ability.allowed?(options[:user], :update_deploy_keys_project, object.deploy_keys_project_for(options[:project])) - end - - def can_read_owner?(opts) - opts[:with_owner] && Ability.allowed?(options[:user], :read_user, object.user) - end - - def allowed_to_read_project?(project) - if options[:readable_project_ids] - options[:readable_project_ids].include?(project.id) - else - Ability.allowed?(options[:user], :read_project, project) - end - end -end diff --git a/app/serializers/deploy_key_serializer.rb b/app/serializers/deploy_key_serializer.rb deleted file mode 100644 index a1cd98b631b..00000000000 --- a/app/serializers/deploy_key_serializer.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -class DeployKeySerializer < BaseSerializer - entity DeployKeyEntity -end diff --git a/app/serializers/deploy_keys/basic_deploy_key_entity.rb b/app/serializers/deploy_keys/basic_deploy_key_entity.rb new file mode 100644 index 00000000000..9184bc5f0ce --- /dev/null +++ b/app/serializers/deploy_keys/basic_deploy_key_entity.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +module DeployKeys + class BasicDeployKeyEntity < Grape::Entity + expose :id + expose :user_id + expose :title + expose :fingerprint + expose :fingerprint_sha256 + expose :destroyed_when_orphaned?, as: :destroyed_when_orphaned + expose :almost_orphaned?, as: :almost_orphaned + expose :created_at + expose :updated_at + expose :can_edit + expose :user, as: :owner, using: ::API::Entities::UserBasic, if: -> (_, opts) { can_read_owner?(opts) } + + private + + def can_edit + Ability.allowed?(options[:user], :update_deploy_key, object) || + Ability.allowed?(options[:user], :update_deploy_keys_project, object.deploy_keys_project_for(options[:project])) + end + + def can_read_owner?(opts) + opts[:with_owner] && Ability.allowed?(options[:user], :read_user, object.user) + end + end +end diff --git a/app/serializers/deploy_keys/basic_deploy_key_serializer.rb b/app/serializers/deploy_keys/basic_deploy_key_serializer.rb new file mode 100644 index 00000000000..699f3baac78 --- /dev/null +++ b/app/serializers/deploy_keys/basic_deploy_key_serializer.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module DeployKeys + class BasicDeployKeySerializer < BaseSerializer + entity BasicDeployKeyEntity + end +end diff --git a/app/serializers/deploy_keys/deploy_key_entity.rb b/app/serializers/deploy_keys/deploy_key_entity.rb new file mode 100644 index 00000000000..79f386d1529 --- /dev/null +++ b/app/serializers/deploy_keys/deploy_key_entity.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module DeployKeys + class DeployKeyEntity < BasicDeployKeyEntity + expose :deploy_keys_projects, using: DeployKeysProjectEntity do |deploy_key| + deploy_key.deploy_keys_projects.select do |deploy_key_project| + !deploy_key_project.project&.pending_delete? && + (allowed_to_read_project?(deploy_key_project.project) || options[:user].can_admin_all_resources?) + end + end + + private + + def allowed_to_read_project?(project) + if options[:readable_project_ids] + options[:readable_project_ids].include?(project.id) + else + Ability.allowed?(options[:user], :read_project, project) + end + end + end +end diff --git a/app/serializers/deploy_keys/deploy_key_serializer.rb b/app/serializers/deploy_keys/deploy_key_serializer.rb new file mode 100644 index 00000000000..b00ef65696f --- /dev/null +++ b/app/serializers/deploy_keys/deploy_key_serializer.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module DeployKeys + class DeployKeySerializer < BaseSerializer + entity DeployKeyEntity + end +end |