diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-27 03:09:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-27 03:09:33 +0300 |
commit | 760a58cc78d5646d957bf10d8e86d940d423dfbe (patch) | |
tree | ca34030f1d7ee4a4081540e29849e976e9015bc5 /app | |
parent | f57bd3d34851023628f4b2f3402720f8f404641f (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
7 files changed, 88 insertions, 60 deletions
diff --git a/app/assets/javascripts/work_items/components/work_item_actions.vue b/app/assets/javascripts/work_items/components/work_item_actions.vue index 6ca487d5427..e8fe64c932b 100644 --- a/app/assets/javascripts/work_items/components/work_item_actions.vue +++ b/app/assets/javascripts/work_items/components/work_item_actions.vue @@ -8,6 +8,7 @@ import { GlModalDirective, GlToggle, } from '@gitlab/ui'; +import { produce } from 'immer'; import * as Sentry from '@sentry/browser'; @@ -15,6 +16,7 @@ import { __, s__ } from '~/locale'; import Tracking from '~/tracking'; import toast from '~/vue_shared/plugins/global_toast'; import { isLoggedIn } from '~/lib/utils/common_utils'; +import workItemByIidQuery from '~/work_items/graphql/work_item_by_iid.query.graphql'; import { sprintfWorkItem, @@ -127,6 +129,10 @@ export default { required: false, default: false, }, + workItemIid: { + type: String, + required: true, + }, }, apollo: { workItemTypes: { @@ -168,16 +174,6 @@ export default { return this.workItemTypes.find((type) => type.name === WORK_ITEM_TYPE_VALUE_OBJECTIVE).id; }, }, - watch: { - subscribedToNotifications() { - /** - * To toggle the value if mutation fails, assign the - * subscribedToNotifications boolean value directly - * to data prop. - */ - this.initialSubscribed = this.subscribedToNotifications; - }, - }, methods: { copyToClipboard(text, message) { if (this.isModal) { @@ -203,10 +199,9 @@ export default { }, toggleNotifications(subscribed) { const inputVariables = { - id: this.workItemId, - notificationsWidget: { - subscribed, - }, + projectPath: this.fullPath, + iid: this.workItemIid, + subscribedState: subscribed, }; this.$apollo .mutate({ @@ -215,27 +210,34 @@ export default { input: inputVariables, }, optimisticResponse: { - workItemUpdate: { - errors: [], - workItem: { + updateWorkItemNotificationsSubscription: { + issue: { id: this.workItemId, - widgets: [ - { - type: WIDGET_TYPE_NOTIFICATIONS, - subscribed, - __typename: 'WorkItemWidgetNotifications', - }, - ], - __typename: 'WorkItem', + subscribed, + }, + errors: [], + }, + }, + update: ( + cache, + { + data: { + updateWorkItemNotificationsSubscription: { issue = {} }, }, - __typename: 'WorkItemUpdatePayload', }, + ) => { + // As the mutation and the query both are different, + // overwrite the subscribed value in the cache + this.updateWorkItemNotificationsWidgetCache({ + cache, + issue, + }); }, }) .then( ({ data: { - workItemUpdate: { errors }, + updateWorkItemNotificationsSubscription: { errors }, }, }) => { if (errors?.length) { @@ -251,6 +253,25 @@ export default { Sentry.captureException(error); }); }, + updateWorkItemNotificationsWidgetCache({ cache, issue }) { + const query = { + query: workItemByIidQuery, + variables: { fullPath: this.fullPath, iid: this.workItemIid }, + }; + // Read the work item object + const sourceData = cache.readQuery(query); + + const newData = produce(sourceData, (draftState) => { + const { widgets } = draftState.workspace.workItems.nodes[0]; + + const widgetNotifications = widgets.find(({ type }) => type === WIDGET_TYPE_NOTIFICATIONS); + // overwrite the subscribed value + widgetNotifications.subscribed = issue.subscribed; + }); + + // write to the cache + cache.writeQuery({ ...query, data: newData }); + }, throwConvertError() { this.$emit('error', this.i18n.convertError); }, diff --git a/app/assets/javascripts/work_items/components/work_item_detail.vue b/app/assets/javascripts/work_items/components/work_item_detail.vue index 04e7814e650..dc4065f9812 100644 --- a/app/assets/javascripts/work_items/components/work_item_detail.vue +++ b/app/assets/javascripts/work_items/components/work_item_detail.vue @@ -465,6 +465,7 @@ export default { :work-item-reference="workItem.reference" :work-item-create-note-email="workItem.createNoteEmail" :is-modal="isModal" + :work-item-iid="workItemIid" @deleteWorkItem="$emit('deleteWorkItem', { workItemType, workItemId: workItem.id })" @toggleWorkItemConfidentiality="toggleConfidentiality" @error="updateError = $event" @@ -539,6 +540,7 @@ export default { :work-item-reference="workItem.reference" :work-item-create-note-email="workItem.createNoteEmail" :is-modal="isModal" + :work-item-iid="workItemIid" @deleteWorkItem=" $emit('deleteWorkItem', { workItemType, workItemId: workItem.id }) " diff --git a/app/assets/javascripts/work_items/graphql/update_work_item_notifications.mutation.graphql b/app/assets/javascripts/work_items/graphql/update_work_item_notifications.mutation.graphql index f8952b62f28..f28317b79b5 100644 --- a/app/assets/javascripts/work_items/graphql/update_work_item_notifications.mutation.graphql +++ b/app/assets/javascripts/work_items/graphql/update_work_item_notifications.mutation.graphql @@ -1,13 +1,9 @@ -mutation updateWorkItemNotificationsWidget($input: WorkItemUpdateInput!) { - workItemUpdate(input: $input) { - workItem { +mutation updateWorkItemNotificationsWidget($input: IssueSetSubscriptionInput!) { + updateWorkItemNotificationsSubscription: issueSetSubscription(input: $input) { + issue { id - widgets { - ... on WorkItemWidgetNotifications { - type - subscribed - } - } + subscribed } + errors } } diff --git a/app/controllers/admin/identities_controller.rb b/app/controllers/admin/identities_controller.rb index 0745ba328c6..15c4103a781 100644 --- a/app/controllers/admin/identities_controller.rb +++ b/app/controllers/admin/identities_controller.rb @@ -23,6 +23,8 @@ class Admin::IdentitiesController < Admin::ApplicationController def index @identities = @user.identities + @can_impersonate = helpers.can_impersonate_user(user, impersonation_in_progress?) + @impersonation_error_text = @can_impersonate ? nil : helpers.impersonation_error_text(user, impersonation_in_progress?) end def edit diff --git a/app/controllers/admin/impersonation_tokens_controller.rb b/app/controllers/admin/impersonation_tokens_controller.rb index dae3337d19b..1f25dad3428 100644 --- a/app/controllers/admin/impersonation_tokens_controller.rb +++ b/app/controllers/admin/impersonation_tokens_controller.rb @@ -8,6 +8,8 @@ class Admin::ImpersonationTokensController < Admin::ApplicationController def index set_index_vars + @can_impersonate = helpers.can_impersonate_user(user, impersonation_in_progress?) + @impersonation_error_text = @can_impersonate ? nil : helpers.impersonation_error_text(user, impersonation_in_progress?) end def create diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index b75ca2649c3..f05b03c2787 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -7,6 +7,7 @@ class Admin::UsersController < Admin::ApplicationController before_action :user, except: [:index, :new, :create] before_action :check_impersonation_availability, only: :impersonate before_action :ensure_destroy_prerequisites_met, only: [:destroy] + before_action :set_shared_view_parameters, only: [:show, :projects, :keys] feature_category :user_management @@ -24,10 +25,7 @@ class Admin::UsersController < Admin::ApplicationController @users = @users.without_count if paginate_without_count? end - def show - @can_impersonate = can_impersonate_user - @impersonation_error_text = @can_impersonate ? nil : impersonation_error_text - end + def show; end # rubocop: disable CodeReuse/ActiveRecord def projects @@ -48,7 +46,7 @@ class Admin::UsersController < Admin::ApplicationController end def impersonate - if can_impersonate_user + if helpers.can_impersonate_user(user, impersonation_in_progress?) session[:impersonator_id] = current_user.id warden.set_user(user, scope: :user) @@ -60,7 +58,7 @@ class Admin::UsersController < Admin::ApplicationController redirect_to root_path else - flash[:alert] = impersonation_error_text + flash[:alert] = helpers.impersonation_error_text(user, impersonation_in_progress?) redirect_to admin_user_path(user) end @@ -384,28 +382,17 @@ class Admin::UsersController < Admin::ApplicationController Gitlab::AppLogger.info(format(_("User %{current_user_username} has started impersonating %{username}"), current_user_username: current_user.username, username: user.username)) end - def can_impersonate_user - can?(user, :log_in) && !user.password_expired? && !impersonation_in_progress? - end - - def impersonation_error_text - if impersonation_in_progress? - _("You are already impersonating another user") - elsif user.blocked? - _("You cannot impersonate a blocked user") - elsif user.password_expired? - _("You cannot impersonate a user with an expired password") - elsif user.internal? - _("You cannot impersonate an internal user") - else - _("You cannot impersonate a user who cannot log in") - end - end - # method overriden in EE def unlock_user update_user(&:unlock_access!) end + + private + + def set_shared_view_parameters + @can_impersonate = helpers.can_impersonate_user(user, impersonation_in_progress?) + @impersonation_error_text = @can_impersonate ? nil : helpers.impersonation_error_text(user, impersonation_in_progress?) + end end Admin::UsersController.prepend_mod_with('Admin::UsersController') diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 29998a996e2..95419c81a35 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -104,6 +104,24 @@ module UsersHelper Gitlab.config.gitlab.impersonation_enabled end + def can_impersonate_user(user, impersonation_in_progress) + can?(user, :log_in) && !user.password_expired? && !impersonation_in_progress + end + + def impersonation_error_text(user, impersonation_in_progress) + if impersonation_in_progress + _("You are already impersonating another user") + elsif user.blocked? + _("You cannot impersonate a blocked user") + elsif user.password_expired? + _("You cannot impersonate a user with an expired password") + elsif user.internal? + _("You cannot impersonate an internal user") + else + _("You cannot impersonate a user who cannot log in") + end + end + def user_badges_in_admin_section(user) [].tap do |badges| badges << blocked_user_badge(user) if user.blocked? |