All files / ee/app/assets/javascripts/members/components/ldap ldap_override_confirmation_modal.vue

89.47% Statements 17/19
100% Branches 2/2
90% Functions 9/10
89.47% Lines 17/19

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  5x 5x 5x 5x                                   54x             54x     54x       59x                       3x     6x     3x 3x   3x   2x 2x 2x                     205x                                      
<script>
import { GlModal, GlSprintf } from '@gitlab/ui';
import { mapState, mapActions } from 'vuex';
import { __, s__ } from '~/locale';
import { LDAP_OVERRIDE_CONFIRMATION_MODAL_ID } from '../../constants';
 
export default {
  name: 'LdapOverrideConfirmationModal',
  i18n: {
    editPermissions: s__('Members|Edit permissions'),
    modalBody: s__(
      'Members|%{userName} is currently an LDAP user. Editing their permissions will override the settings from the LDAP group sync.',
    ),
    toastMessage: s__('Members|LDAP override enabled.'),
  },
  actionCancel: {
    text: __('Cancel'),
  },
  modalId: LDAP_OVERRIDE_CONFIRMATION_MODAL_ID,
  components: { GlModal, GlSprintf },
  inject: ['namespace'],
  data() {
    return {
      busy: false,
    };
  },
  computed: {
    ...mapState({
      memberToOverride(state) {
        return state[this.namespace].memberToOverride;
      },
      ldapOverrideConfirmationModalVisible(state) {
        return state[this.namespace].ldapOverrideConfirmationModalVisible;
      },
    }),
    actionPrimary() {
      return {
        text: this.$options.i18n.editPermissions,
        attributes: {
          variant: 'warning',
          loading: this.busy,
        },
      };
    },
  },
  methods: {
    ...mapActions({
      updateLdapOverride(dispatch, payload) {
        return dispatch(`${this.namespace}/updateLdapOverride`, payload);
      },
      hideLdapOverrideConfirmationModal(dispatch) {
        return dispatch(`${this.namespace}/hideLdapOverrideConfirmationModal`);
      },
    }),
    handlePrimary() {
      this.busy = true;
 
      this.updateLdapOverride({ memberId: this.memberToOverride.id, override: true })
        .then(() => {
          this.busy = false;
          this.hideLdapOverrideConfirmationModal();
          this.$toast.show(this.$options.i18n.toastMessage);
        })
        .catch(() => {
          this.hideLdapOverrideConfirmationModal();
          this.busy = false;
        });
    },
  },
};
</script>
 
<template>
  <gl-modal
    v-bind="$attrs"
    :modal-id="$options.modalId"
    :title="$options.i18n.editPermissions"
    :visible="ldapOverrideConfirmationModalVisible"
    :action-primary="actionPrimary"
    :action-cancel="$options.actionCancel"
    size="sm"
    @primary="handlePrimary"
    @hide="hideLdapOverrideConfirmationModal"
  >
    <p v-if="memberToOverride">
      <gl-sprintf :message="$options.i18n.modalBody">
        <template #userName>{{ memberToOverride.user.name }}</template>
      </gl-sprintf>
    </p>
  </gl-modal>
</template>