All files / app/assets/javascripts/members/components/modals remove_member_modal.vue

100% Statements 22/22
100% Branches 6/6
100% Functions 15/15
100% Lines 22/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132    8x                                         39x     31x     39x               37x     39x     21x     39x     39x       37x     39x 8x   31x 8x     23x     39x 2x     37x                 37x     37x           4x       4x                                                                              
<script>
import { GlFormCheckbox, GlModal } from '@gitlab/ui';
// eslint-disable-next-line no-restricted-imports
import { mapActions, mapState } from 'vuex';
import csrf from '~/lib/utils/csrf';
import { s__, __ } from '~/locale';
import UserDeletionObstaclesList from '~/vue_shared/components/user_deletion_obstacles/user_deletion_obstacles_list.vue';
import { MEMBER_MODEL_TYPE_GROUP_MEMBER } from '../../constants';
 
export default {
  actionCancel: {
    text: __('Cancel'),
  },
  csrf,
  components: {
    GlFormCheckbox,
    GlModal,
    UserDeletionObstaclesList,
  },
  inject: ['namespace'],
  computed: {
    ...mapState({
      isAccessRequest(state) {
        return state[this.namespace].removeMemberModalData.isAccessRequest;
      },
      isInvite(state) {
        return state[this.namespace].removeMemberModalData.isInvite;
      },
      memberPath(state) {
        return state[this.namespace].removeMemberModalData.memberPath;
      },
      /**
       * `GroupMember` (`app/models/members/group_member.rb`)
       * or
       * `ProjectMember` (`app/models/members/project_member.rb`).
       */
      memberModelType(state) {
        return state[this.namespace].removeMemberModalData.memberModelType;
      },
      message(state) {
        return state[this.namespace].removeMemberModalData.message;
      },
      userDeletionObstacles(state) {
        return state[this.namespace].removeMemberModalData.userDeletionObstacles ?? {};
      },
      preventRemoval(state) {
        return state[this.namespace].removeMemberModalData.preventRemoval;
      },
      removeMemberModalVisible(state) {
        return state[this.namespace].removeMemberModalVisible;
      },
    }),
    isGroupMember() {
      return this.memberModelType === MEMBER_MODEL_TYPE_GROUP_MEMBER;
    },
    actionText() {
      if (this.isAccessRequest) {
        return __('Deny access request');
      }
      if (this.isInvite) {
        return s__('Member|Revoke invite');
      }
 
      return __('Remove member');
    },
    actionPrimary() {
      if (this.preventRemoval) {
        return null;
      }
 
      return {
        text: this.actionText,
        attributes: {
          variant: 'danger',
          'data-testid': 'remove-member-button',
        },
      };
    },
    hasWorkspaceAccess() {
      return !this.isAccessRequest && !this.isInvite;
    },
    hasObstaclesToUserDeletion() {
      return this.hasWorkspaceAccess && this.userDeletionObstacles.obstacles?.length;
    },
  },
  methods: {
    ...mapActions({
      hideRemoveMemberModal(dispatch) {
        return dispatch(`${this.namespace}/hideRemoveMemberModal`);
      },
    }),
    submitForm() {
      this.$refs.form.submit();
    },
  },
};
</script>
 
<template>
  <gl-modal
    ref="modal"
    modal-id="remove-member-modal"
    :action-cancel="$options.actionCancel"
    :action-primary="actionPrimary"
    :title="actionText"
    :visible="removeMemberModalVisible"
    data-testid="remove-member-modal"
    @primary="submitForm"
    @hide="hideRemoveMemberModal"
  >
    <form ref="form" :action="memberPath" method="post">
      <p>{{ message }}</p>
      <template v-if="!preventRemoval">
        <user-deletion-obstacles-list
          v-if="hasObstaclesToUserDeletion"
          :obstacles="userDeletionObstacles.obstacles"
          :user-name="userDeletionObstacles.name"
        />
 
        <input ref="method" type="hidden" name="_method" value="delete" />
        <input :value="$options.csrf.token" type="hidden" name="authenticity_token" />
        <gl-form-checkbox v-if="isGroupMember" name="remove_sub_memberships">
          {{ __('Also remove direct user membership from subgroups and projects') }}
        </gl-form-checkbox>
        <gl-form-checkbox v-if="hasWorkspaceAccess" name="unassign_issuables">
          {{ __('Also unassign this user from related issues and merge requests') }}
        </gl-form-checkbox>
      </template>
    </form>
  </gl-modal>
</template>