diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
commit | 4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch) | |
tree | 5423a1c7516cffe36384133ade12572cf709398d /app/finders/deploy_tokens/tokens_finder.rb | |
parent | e570267f2f6b326480d284e0164a6464ba4081bc (diff) |
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'app/finders/deploy_tokens/tokens_finder.rb')
-rw-r--r-- | app/finders/deploy_tokens/tokens_finder.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/app/finders/deploy_tokens/tokens_finder.rb b/app/finders/deploy_tokens/tokens_finder.rb new file mode 100644 index 00000000000..98456628375 --- /dev/null +++ b/app/finders/deploy_tokens/tokens_finder.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +# Arguments: +# current_user: The currently logged in user. +# scope: A Project or Group to scope deploy tokens to (or :all for all tokens). +# params: +# active: Boolean - When true, only return active deployments. +module DeployTokens + class TokensFinder + attr_reader :current_user, :params, :scope + + def initialize(current_user, scope, params = {}) + @current_user = current_user + @scope = scope + @params = params + end + + def execute + by_active(init_collection) + end + + private + + def init_collection + case scope + when Group, Project + raise Gitlab::Access::AccessDeniedError unless current_user.can?(:read_deploy_token, scope) + + scope.deploy_tokens + when :all + raise Gitlab::Access::AccessDeniedError unless current_user.can_read_all_resources? + + DeployToken.all + else + raise ArgumentError, "Scope must be a Group, a Project, or the :all symbol." + end + end + + def by_active(items) + params[:active] ? items.active : items + end + end +end |