debian-mirror-gitlab/app/assets/javascripts/members/components/modals/leave_modal.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

130 lines
3.5 KiB
Vue
Raw Normal View History

2021-01-03 14:25:43 +05:30
<script>
import { GlModal, GlForm, GlSprintf, GlTooltipDirective } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { mapState } from 'vuex';
2021-01-03 14:25:43 +05:30
import csrf from '~/lib/utils/csrf';
import { __, s__, sprintf } from '~/locale';
2021-11-18 22:05:49 +05:30
import UserDeletionObstaclesList from '~/vue_shared/components/user_deletion_obstacles/user_deletion_obstacles_list.vue';
import { parseUserDeletionObstacles } from '~/vue_shared/components/user_deletion_obstacles/utils';
2023-03-17 16:20:25 +05:30
import {
LEAVE_MODAL_ID,
MEMBER_MODEL_TYPE_GROUP_MEMBER,
MEMBER_MODEL_TYPE_PROJECT_MEMBER,
} from '../../constants';
2021-01-03 14:25:43 +05:30
export default {
name: 'LeaveModal',
actionCancel: {
text: __('Cancel'),
},
csrf,
modalId: LEAVE_MODAL_ID,
2023-03-17 16:20:25 +05:30
i18n: {
title: s__('Members|Leave "%{source}"'),
body: s__('Members|Are you sure you want to leave "%{source}"?'),
preventedTitle: s__('Members|Cannot leave "%{source}"'),
preventedBodyProjectMemberModelType: s__(
'Members|You cannot remove yourself from a personal project.',
),
preventedBodyGroupMemberModelType: s__(
'Members|A group must have at least one owner. To leave this group, assign a new owner.',
),
},
2021-11-18 22:05:49 +05:30
components: { GlModal, GlForm, GlSprintf, UserDeletionObstaclesList },
2021-01-03 14:25:43 +05:30
directives: {
GlTooltip: GlTooltipDirective,
},
2021-04-29 21:17:54 +05:30
inject: ['namespace'],
2021-01-03 14:25:43 +05:30
props: {
member: {
type: Object,
required: true,
},
2023-03-17 16:20:25 +05:30
permissions: {
type: Object,
required: true,
},
2021-01-03 14:25:43 +05:30
},
computed: {
2021-04-29 21:17:54 +05:30
...mapState({
memberPath(state) {
return state[this.namespace].memberPath;
},
}),
2021-01-03 14:25:43 +05:30
leavePath() {
return this.memberPath.replace(/:id$/, 'leave');
},
modalTitle() {
2023-03-17 16:20:25 +05:30
return sprintf(
this.permissions.canRemoveBlockedByLastOwner
? this.$options.i18n.preventedTitle
: this.$options.i18n.title,
{ source: this.member.source.fullName },
);
},
preventedModalBody() {
if (this.member.type === MEMBER_MODEL_TYPE_PROJECT_MEMBER) {
return this.$options.i18n.preventedBodyProjectMemberModelType;
}
if (this.member.type === MEMBER_MODEL_TYPE_GROUP_MEMBER) {
return this.$options.i18n.preventedBodyGroupMemberModelType;
}
return null;
},
actionPrimary() {
if (this.permissions.canRemoveBlockedByLastOwner) {
return null;
}
return {
text: __('Leave'),
attributes: {
variant: 'danger',
},
};
2021-01-03 14:25:43 +05:30
},
2021-11-18 22:05:49 +05:30
obstacles() {
return parseUserDeletionObstacles(this.member.user);
2021-04-29 21:17:54 +05:30
},
2021-11-18 22:05:49 +05:30
hasObstaclesToUserDeletion() {
return this.obstacles?.length;
2021-04-29 21:17:54 +05:30
},
2021-01-03 14:25:43 +05:30
},
methods: {
handlePrimary() {
this.$refs.form.$el.submit();
},
},
};
</script>
<template>
<gl-modal
v-bind="$attrs"
:modal-id="$options.modalId"
:title="modalTitle"
2023-03-17 16:20:25 +05:30
:action-primary="actionPrimary"
2021-01-03 14:25:43 +05:30
:action-cancel="$options.actionCancel"
@primary="handlePrimary"
>
<gl-form ref="form" :action="leavePath" method="post">
<p>
2023-03-17 16:20:25 +05:30
<template v-if="permissions.canRemoveBlockedByLastOwner">{{ preventedModalBody }}</template>
<gl-sprintf v-else :message="$options.i18n.body">
2021-03-08 18:12:59 +05:30
<template #source>{{ member.source.fullName }}</template>
2021-01-03 14:25:43 +05:30
</gl-sprintf>
</p>
2021-11-18 22:05:49 +05:30
<user-deletion-obstacles-list
v-if="hasObstaclesToUserDeletion"
:obstacles="obstacles"
2021-04-29 21:17:54 +05:30
:is-current-user="true"
/>
2021-01-03 14:25:43 +05:30
<input type="hidden" name="_method" value="delete" />
<input :value="$options.csrf.token" type="hidden" name="authenticity_token" />
</gl-form>
</gl-modal>
</template>