2021-01-22 13:09:10 -05:00
|
|
|
<script>
|
|
|
|
import {
|
|
|
|
GlButton,
|
|
|
|
GlDropdown,
|
|
|
|
GlDropdownItem,
|
|
|
|
GlDropdownSectionHeader,
|
|
|
|
GlDropdownDivider,
|
2021-07-19 14:08:23 -04:00
|
|
|
GlTooltipDirective,
|
2021-01-22 13:09:10 -05:00
|
|
|
} from '@gitlab/ui';
|
|
|
|
import { convertArrayToCamelCase } from '~/lib/utils/common_utils';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { capitalizeFirstCharacter } from '~/lib/utils/text_utility';
|
2021-10-04 05:11:20 -04:00
|
|
|
import { parseUserDeletionObstacles } from '~/vue_shared/components/user_deletion_obstacles/utils';
|
2021-02-10 07:09:45 -05:00
|
|
|
import { I18N_USER_ACTIONS } from '../constants';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { generateUserPaths } from '../utils';
|
2021-02-10 07:09:45 -05:00
|
|
|
import Actions from './actions';
|
2021-01-22 13:09:10 -05:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
GlButton,
|
|
|
|
GlDropdown,
|
|
|
|
GlDropdownItem,
|
|
|
|
GlDropdownSectionHeader,
|
|
|
|
GlDropdownDivider,
|
2021-02-10 07:09:45 -05:00
|
|
|
...Actions,
|
2021-01-22 13:09:10 -05:00
|
|
|
},
|
2021-07-19 14:08:23 -04:00
|
|
|
directives: {
|
|
|
|
GlTooltip: GlTooltipDirective,
|
|
|
|
},
|
2021-01-22 13:09:10 -05:00
|
|
|
props: {
|
|
|
|
user: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
paths: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-07-19 14:08:23 -04:00
|
|
|
showButtonLabels: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2021-01-22 13:09:10 -05:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
userActions() {
|
|
|
|
return convertArrayToCamelCase(this.user.actions);
|
|
|
|
},
|
|
|
|
dropdownActions() {
|
|
|
|
return this.userActions.filter((a) => a !== 'edit');
|
|
|
|
},
|
|
|
|
dropdownDeleteActions() {
|
|
|
|
return this.dropdownActions.filter((a) => a.includes('delete'));
|
|
|
|
},
|
|
|
|
dropdownSafeActions() {
|
|
|
|
return this.dropdownActions.filter((a) => !this.dropdownDeleteActions.includes(a));
|
|
|
|
},
|
|
|
|
hasDropdownActions() {
|
|
|
|
return this.dropdownActions.length > 0;
|
|
|
|
},
|
|
|
|
hasDeleteActions() {
|
|
|
|
return this.dropdownDeleteActions.length > 0;
|
|
|
|
},
|
|
|
|
hasEditAction() {
|
|
|
|
return this.userActions.includes('edit');
|
|
|
|
},
|
|
|
|
userPaths() {
|
|
|
|
return generateUserPaths(this.paths, this.user.username);
|
|
|
|
},
|
2021-07-19 14:08:23 -04:00
|
|
|
editButtonAttrs() {
|
|
|
|
return {
|
|
|
|
'data-testid': 'edit',
|
|
|
|
href: this.userPaths.edit,
|
|
|
|
};
|
|
|
|
},
|
2021-10-04 05:11:20 -04:00
|
|
|
obstaclesForUserDeletion() {
|
|
|
|
return parseUserDeletionObstacles(this.user);
|
|
|
|
},
|
2021-01-22 13:09:10 -05:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
isLdapAction(action) {
|
|
|
|
return action === 'ldapBlocked';
|
|
|
|
},
|
2021-02-10 07:09:45 -05:00
|
|
|
getActionComponent(action) {
|
|
|
|
return Actions[capitalizeFirstCharacter(action)];
|
|
|
|
},
|
2021-01-22 13:09:10 -05:00
|
|
|
},
|
2021-02-10 07:09:45 -05:00
|
|
|
i18n: I18N_USER_ACTIONS,
|
2021-01-22 13:09:10 -05:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2021-07-19 14:08:23 -04:00
|
|
|
<div
|
|
|
|
class="gl-display-flex gl-justify-content-end gl-my-n2 gl-mx-n2"
|
|
|
|
:data-testid="`user-actions-${user.id}`"
|
|
|
|
>
|
|
|
|
<div v-if="hasEditAction" class="gl-p-2">
|
2022-07-07 20:09:36 -04:00
|
|
|
<gl-button v-if="showButtonLabels" v-bind="editButtonAttrs" icon="pencil-square">{{
|
2021-07-19 14:08:23 -04:00
|
|
|
$options.i18n.edit
|
|
|
|
}}</gl-button>
|
|
|
|
<gl-button
|
|
|
|
v-else
|
|
|
|
v-gl-tooltip="$options.i18n.edit"
|
2022-07-07 20:09:36 -04:00
|
|
|
icon="pencil-square"
|
2021-07-19 14:08:23 -04:00
|
|
|
v-bind="editButtonAttrs"
|
|
|
|
:aria-label="$options.i18n.edit"
|
|
|
|
/>
|
|
|
|
</div>
|
2021-01-22 13:09:10 -05:00
|
|
|
|
2021-07-19 14:08:23 -04:00
|
|
|
<div v-if="hasDropdownActions" class="gl-p-2">
|
|
|
|
<gl-dropdown
|
2022-07-07 20:09:36 -04:00
|
|
|
:text="$options.i18n.userAdministration"
|
2021-07-19 14:08:23 -04:00
|
|
|
data-testid="dropdown-toggle"
|
|
|
|
data-qa-selector="user_actions_dropdown_toggle"
|
|
|
|
:data-qa-username="user.username"
|
2022-07-07 20:09:36 -04:00
|
|
|
left
|
2021-07-19 14:08:23 -04:00
|
|
|
>
|
|
|
|
<template v-for="action in dropdownSafeActions">
|
|
|
|
<component
|
|
|
|
:is="getActionComponent(action)"
|
|
|
|
v-if="getActionComponent(action)"
|
|
|
|
:key="action"
|
|
|
|
:path="userPaths[action]"
|
|
|
|
:username="user.name"
|
|
|
|
:data-testid="action"
|
|
|
|
>
|
|
|
|
{{ $options.i18n[action] }}
|
|
|
|
</component>
|
|
|
|
<gl-dropdown-item v-else-if="isLdapAction(action)" :key="action" :data-testid="action">
|
|
|
|
{{ $options.i18n[action] }}
|
|
|
|
</gl-dropdown-item>
|
|
|
|
</template>
|
2021-01-22 13:09:10 -05:00
|
|
|
|
2021-07-19 14:08:23 -04:00
|
|
|
<gl-dropdown-divider v-if="hasDeleteActions" />
|
2021-01-22 13:09:10 -05:00
|
|
|
|
2021-07-19 14:08:23 -04:00
|
|
|
<template v-for="action in dropdownDeleteActions">
|
|
|
|
<component
|
|
|
|
:is="getActionComponent(action)"
|
|
|
|
v-if="getActionComponent(action)"
|
|
|
|
:key="action"
|
|
|
|
:paths="userPaths"
|
|
|
|
:username="user.name"
|
2021-10-04 05:11:20 -04:00
|
|
|
:user-deletion-obstacles="obstaclesForUserDeletion"
|
2021-07-19 14:08:23 -04:00
|
|
|
:data-testid="`delete-${action}`"
|
|
|
|
>
|
|
|
|
{{ $options.i18n[action] }}
|
|
|
|
</component>
|
|
|
|
</template>
|
|
|
|
</gl-dropdown>
|
|
|
|
</div>
|
2021-01-22 13:09:10 -05:00
|
|
|
</div>
|
|
|
|
</template>
|