diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /app/finders/design_management/versions_finder.rb | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'app/finders/design_management/versions_finder.rb')
-rw-r--r-- | app/finders/design_management/versions_finder.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/app/finders/design_management/versions_finder.rb b/app/finders/design_management/versions_finder.rb new file mode 100644 index 00000000000..c4aefd3078e --- /dev/null +++ b/app/finders/design_management/versions_finder.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +module DesignManagement + class VersionsFinder + attr_reader :design_or_collection, :current_user, :params + + # The `design_or_collection` argument should be either a: + # + # - DesignManagement::Design, or + # - DesignManagement::DesignCollection + # + # The object will have `#versions` called on it to set up the + # initial scope of the versions. + # + # valid params: + # - earlier_or_equal_to: Version + # - sha: String + # - version_id: Integer + # + def initialize(design_or_collection, current_user, params = {}) + @design_or_collection = design_or_collection + @current_user = current_user + @params = params + end + + def execute + unless Ability.allowed?(current_user, :read_design, design_or_collection) + return ::DesignManagement::Version.none + end + + items = design_or_collection.versions + items = by_earlier_or_equal_to(items) + items = by_sha(items) + items = by_version_id(items) + items.ordered + end + + private + + def by_earlier_or_equal_to(items) + return items unless params[:earlier_or_equal_to] + + items.earlier_or_equal_to(params[:earlier_or_equal_to]) + end + + def by_version_id(items) + return items unless params[:version_id] + + items.id_in(params[:version_id]) + end + + def by_sha(items) + return items unless params[:sha] + + items.by_sha(params[:sha]) + end + end +end |