diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-01 06:09:04 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-01 06:09:04 +0300 |
commit | d0356412dfc91d02585f0a177c65677dbe2944a3 (patch) | |
tree | 5a2ac806b6ea6113475bb2a759f6b15c186fb482 /app | |
parent | 72817fd7c07d1b812623f8d5e27fc7bcecb4eed5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/monitoring/components/dashboard.vue | 5 | ||||
-rw-r--r-- | app/assets/javascripts/monitoring/stores/getters.js | 2 | ||||
-rw-r--r-- | app/controllers/projects/environments_controller.rb | 1 | ||||
-rw-r--r-- | app/graphql/mutations/todos/restore_many.rb | 75 | ||||
-rw-r--r-- | app/graphql/types/mutation_type.rb | 1 | ||||
-rw-r--r-- | app/models/todo.rb | 2 |
6 files changed, 78 insertions, 8 deletions
diff --git a/app/assets/javascripts/monitoring/components/dashboard.vue b/app/assets/javascripts/monitoring/components/dashboard.vue index 5f410c487e9..391cd6dd15e 100644 --- a/app/assets/javascripts/monitoring/components/dashboard.vue +++ b/app/assets/javascripts/monitoring/components/dashboard.vue @@ -235,9 +235,6 @@ export default { this.externalDashboardUrl.length ); }, - shouldRenderSearchableEnvironmentsDropdown() { - return this.glFeatures.searchableEnvironmentsDropdown; - }, shouldShowEnvironmentsDropdownNoMatchedMsg() { return !this.environmentsLoading && this.filteredEnvironments.length === 0; }, @@ -405,7 +402,6 @@ export default { }}</gl-dropdown-header> <gl-dropdown-divider /> <gl-search-box-by-type - v-if="shouldRenderSearchableEnvironmentsDropdown" ref="monitorEnvironmentsDropdownSearch" class="m-2" @input="debouncedEnvironmentsSearch" @@ -426,7 +422,6 @@ export default { > </div> <div - v-if="shouldRenderSearchableEnvironmentsDropdown" v-show="shouldShowEnvironmentsDropdownNoMatchedMsg" ref="monitorEnvironmentsDropdownMsg" class="text-secondary no-matches-message" diff --git a/app/assets/javascripts/monitoring/stores/getters.js b/app/assets/javascripts/monitoring/stores/getters.js index ed1e3e3ffec..3801149e49d 100644 --- a/app/assets/javascripts/monitoring/stores/getters.js +++ b/app/assets/javascripts/monitoring/stores/getters.js @@ -62,8 +62,6 @@ export const metricsWithData = state => groupKey => { * Filter environments by names. * * This is used in the environments dropdown with searchable input. - * Also, this searchable dropdown is behind `searchable_environments_dropdown` - * feature flag * * @param {Object} state * @returns {Array} List of environments diff --git a/app/controllers/projects/environments_controller.rb b/app/controllers/projects/environments_controller.rb index b4b2bf01831..70c4b536854 100644 --- a/app/controllers/projects/environments_controller.rb +++ b/app/controllers/projects/environments_controller.rb @@ -14,7 +14,6 @@ class Projects::EnvironmentsController < Projects::ApplicationController before_action :expire_etag_cache, only: [:index], unless: -> { request.format.json? } before_action only: [:metrics, :additional_metrics, :metrics_dashboard] do push_frontend_feature_flag(:prometheus_computed_alerts) - push_frontend_feature_flag(:searchable_environments_dropdown) end before_action do push_frontend_feature_flag(:auto_stop_environments) diff --git a/app/graphql/mutations/todos/restore_many.rb b/app/graphql/mutations/todos/restore_many.rb new file mode 100644 index 00000000000..8a6265207cd --- /dev/null +++ b/app/graphql/mutations/todos/restore_many.rb @@ -0,0 +1,75 @@ +# frozen_string_literal: true + +module Mutations + module Todos + class RestoreMany < ::Mutations::Todos::Base + graphql_name 'TodoRestoreMany' + + MAX_UPDATE_AMOUNT = 50 + + argument :ids, + [GraphQL::ID_TYPE], + required: true, + description: 'The global ids of the todos to restore (a maximum of 50 is supported at once)' + + field :updated_ids, [GraphQL::ID_TYPE], + null: false, + description: 'The ids of the updated todo items' + + def resolve(ids:) + check_update_amount_limit!(ids) + + todos = authorized_find_all_pending_by_current_user(model_ids_of(ids)) + updated_ids = restore(todos) + + { + updated_ids: gids_of(updated_ids), + errors: errors_on_objects(todos) + } + end + + private + + def gids_of(ids) + ids.map { |id| ::URI::GID.build(app: GlobalID.app, model_name: Todo.name, model_id: id, params: nil).to_s } + end + + def model_ids_of(ids) + ids.map do |gid| + parsed_gid = ::URI::GID.parse(gid) + parsed_gid.model_id.to_i if accessible_todo?(parsed_gid) + end.compact + end + + def accessible_todo?(gid) + gid.app == GlobalID.app && todo?(gid) + end + + def todo?(gid) + GlobalID.parse(gid)&.model_class&.ancestors&.include?(Todo) + end + + def raise_too_many_todos_requested_error + raise Gitlab::Graphql::Errors::ArgumentError, 'Too many todos requested.' + end + + def check_update_amount_limit!(ids) + raise_too_many_todos_requested_error if ids.size > MAX_UPDATE_AMOUNT + end + + def errors_on_objects(todos) + todos.flat_map { |todo| errors_on_object(todo) } + end + + def authorized_find_all_pending_by_current_user(ids) + return Todo.none if ids.blank? || current_user.nil? + + Todo.for_ids(ids).for_user(current_user).done + end + + def restore(todos) + TodoService.new.mark_todos_as_pending(todos, current_user) + end + end + end +end diff --git a/app/graphql/types/mutation_type.rb b/app/graphql/types/mutation_type.rb index 0a9c0143945..fc0a2a099df 100644 --- a/app/graphql/types/mutation_type.rb +++ b/app/graphql/types/mutation_type.rb @@ -25,6 +25,7 @@ module Types mount_mutation Mutations::Todos::MarkDone mount_mutation Mutations::Todos::Restore mount_mutation Mutations::Todos::MarkAllDone + mount_mutation Mutations::Todos::RestoreMany mount_mutation Mutations::Snippets::Destroy mount_mutation Mutations::Snippets::Update mount_mutation Mutations::Snippets::Create diff --git a/app/models/todo.rb b/app/models/todo.rb index f217c942e8e..d337ef33051 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -51,10 +51,12 @@ class Todo < ApplicationRecord validates :project, presence: true, unless: :group_id validates :group, presence: true, unless: :project_id + scope :for_ids, -> (ids) { where(id: ids) } scope :pending, -> { with_state(:pending) } scope :done, -> { with_state(:done) } scope :for_action, -> (action) { where(action: action) } scope :for_author, -> (author) { where(author: author) } + scope :for_user, -> (user) { where(user: user) } scope :for_project, -> (projects) { where(project: projects) } scope :for_undeleted_projects, -> { joins(:project).merge(Project.without_deleted) } scope :for_group, -> (group) { where(group: group) } |