2018-05-09 12:01:36 +05:30
|
|
|
<script>
|
2020-05-24 23:13:21 +05:30
|
|
|
import { escape } from 'lodash';
|
2021-01-29 00:20:46 +05:30
|
|
|
import { GlSafeHtmlDirective as SafeHtml, GlButton, GlModal, GlModalDirective } from '@gitlab/ui';
|
2018-05-09 12:01:36 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import { s__, sprintf } from '~/locale';
|
2020-10-24 23:57:45 +05:30
|
|
|
import { deprecatedCreateFlash as Flash } from '~/flash';
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
2021-01-29 00:20:46 +05:30
|
|
|
GlModal,
|
2021-01-03 14:25:43 +05:30
|
|
|
GlButton,
|
2018-05-09 12:01:36 +05:30
|
|
|
},
|
2021-01-29 00:20:46 +05:30
|
|
|
directives: {
|
|
|
|
GlModalDirective,
|
|
|
|
SafeHtml,
|
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
props: {
|
|
|
|
actionUrl: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
rootUrl: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
initialUsername: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isRequestPending: false,
|
|
|
|
username: this.initialUsername,
|
|
|
|
newUsername: this.initialUsername,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
path() {
|
|
|
|
return sprintf(s__('Profiles|Current path: %{path}'), {
|
|
|
|
path: `${this.rootUrl}${this.username}`,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
modalText() {
|
|
|
|
return sprintf(
|
|
|
|
s__(`Profiles|
|
|
|
|
You are going to change the username %{currentUsernameBold} to %{newUsernameBold}.
|
|
|
|
Profile and projects will be redirected to the %{newUsername} namespace but this redirect will expire once the %{currentUsername} namespace is registered by another user or group.
|
|
|
|
Please update your Git repository remotes as soon as possible.`),
|
|
|
|
{
|
2020-05-24 23:13:21 +05:30
|
|
|
currentUsernameBold: `<strong>${escape(this.username)}</strong>`,
|
|
|
|
newUsernameBold: `<strong>${escape(this.newUsername)}</strong>`,
|
|
|
|
currentUsername: escape(this.username),
|
|
|
|
newUsername: escape(this.newUsername),
|
2018-05-09 12:01:36 +05:30
|
|
|
},
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
},
|
2021-01-29 00:20:46 +05:30
|
|
|
primaryProps() {
|
|
|
|
return {
|
|
|
|
text: s__('Update username'),
|
|
|
|
attributes: [
|
|
|
|
{ variant: 'warning' },
|
|
|
|
{ category: 'primary' },
|
|
|
|
{ disabled: this.isRequestPending },
|
|
|
|
],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
cancelProps() {
|
|
|
|
return {
|
|
|
|
text: s__('Cancel'),
|
|
|
|
};
|
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onConfirm() {
|
|
|
|
this.isRequestPending = true;
|
|
|
|
const username = this.newUsername;
|
|
|
|
const putData = {
|
|
|
|
user: {
|
|
|
|
username,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
return axios
|
|
|
|
.put(this.actionUrl, putData)
|
2021-03-08 18:12:59 +05:30
|
|
|
.then((result) => {
|
2018-05-09 12:01:36 +05:30
|
|
|
Flash(result.data.message, 'notice');
|
|
|
|
this.username = username;
|
|
|
|
this.isRequestPending = false;
|
|
|
|
})
|
2021-03-08 18:12:59 +05:30
|
|
|
.catch((error) => {
|
2018-05-09 12:01:36 +05:30
|
|
|
Flash(error.response.data.message);
|
|
|
|
this.isRequestPending = false;
|
|
|
|
throw error;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
modalId: 'username-change-confirmation-modal',
|
|
|
|
inputId: 'username-change-input',
|
|
|
|
buttonText: s__('Profiles|Update username'),
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<div class="form-group">
|
|
|
|
<label :for="$options.inputId">{{ s__('Profiles|Path') }}</label>
|
|
|
|
<div class="input-group">
|
2018-11-08 19:23:39 +05:30
|
|
|
<div class="input-group-prepend">
|
2019-02-15 15:39:39 +05:30
|
|
|
<div class="input-group-text">{{ rootUrl }}</div>
|
2018-11-08 19:23:39 +05:30
|
|
|
</div>
|
2018-05-09 12:01:36 +05:30
|
|
|
<input
|
|
|
|
:id="$options.inputId"
|
|
|
|
v-model="newUsername"
|
|
|
|
:disabled="isRequestPending"
|
2018-11-08 19:23:39 +05:30
|
|
|
class="form-control"
|
|
|
|
required="required"
|
2018-05-09 12:01:36 +05:30
|
|
|
/>
|
|
|
|
</div>
|
2019-02-15 15:39:39 +05:30
|
|
|
<p class="form-text text-muted">{{ path }}</p>
|
2018-05-09 12:01:36 +05:30
|
|
|
</div>
|
2021-01-03 14:25:43 +05:30
|
|
|
<gl-button
|
2021-01-29 00:20:46 +05:30
|
|
|
v-gl-modal-directive="$options.modalId"
|
2018-11-08 19:23:39 +05:30
|
|
|
:disabled="isRequestPending || newUsername === username"
|
2021-01-03 14:25:43 +05:30
|
|
|
category="primary"
|
|
|
|
variant="warning"
|
2021-01-29 00:20:46 +05:30
|
|
|
data-testid="username-change-confirmation-modal"
|
|
|
|
>{{ $options.buttonText }}</gl-button
|
2018-05-09 12:01:36 +05:30
|
|
|
>
|
|
|
|
<gl-modal
|
2021-01-29 00:20:46 +05:30
|
|
|
:modal-id="$options.modalId"
|
|
|
|
:title="s__('Profiles|Change username') + '?'"
|
|
|
|
:action-primary="primaryProps"
|
|
|
|
:action-cancel="cancelProps"
|
|
|
|
@primary="onConfirm"
|
2018-05-09 12:01:36 +05:30
|
|
|
>
|
2021-01-29 00:20:46 +05:30
|
|
|
<span v-safe-html="modalText"></span>
|
2018-05-09 12:01:36 +05:30
|
|
|
</gl-modal>
|
|
|
|
</div>
|
|
|
|
</template>
|