#7896 - 24.36 Dev To Test #2884

Merged
jsegarra merged 118 commits from dev into test 2024-08-27 10:32:53 +00:00
8 changed files with 468 additions and 0 deletions
Showing only changes of commit 3ee377156b - Show all commits

View File

@ -0,0 +1,4 @@
<slot-descriptor>
<vn-user-descriptor>
</vn-user-descriptor>
</slot-descriptor>

View File

@ -0,0 +1,9 @@
import ngModule from '../module';
import DescriptorPopover from 'salix/components/descriptor-popover';
class Controller extends DescriptorPopover {}
ngModule.vnComponent('vnAccountDescriptorPopover', {
slotTemplate: require('./index.html'),
controller: Controller
});

View File

@ -0,0 +1,192 @@
<vn-descriptor-content
module="account"
description="$ctrl.user.nickname"
summary="$ctrl.$.summary">
<slot-before>
<vn-user-photo user-id="{{$ctrl.id}}"/>
</slot-before>
<slot-menu>
<vn-item
ng-click="deleteUser.show()"
name="deleteUser"
vn-acl="itManagement"
vn-acl-action="remove"
translate>
Delete
</vn-item>
<vn-item
ng-if="::$root.user.id == $ctrl.id"
ng-click="$ctrl.onChangePassClick(true)"
name="changePassword"
vn-acl="sysadmin"
vn-acl-action="remove"
translate>
Change password
</vn-item>
<vn-item
ng-click="$ctrl.onChangePassClick(false)"
name="setPassword"
vn-acl="sysadmin"
vn-acl-action="remove"
translate>
Set password
</vn-item>
<vn-item
ng-if="!$ctrl.hasAccount"
ng-click="enableAccount.show()"
name="enableAccount"
vn-acl="sysadmin"
vn-acl-action="remove"
translate>
Enable account
</vn-item>
<vn-item
ng-if="$ctrl.hasAccount"
ng-click="disableAccount.show()"
name="disableAccount"
vn-acl="sysadmin"
vn-acl-action="remove"
translate>
Disable account
</vn-item>
<vn-item
ng-if="!$ctrl.user.active"
ng-click="activateUser.show()"
name="activateUser"
vn-acl="itManagement"
vn-acl-action="remove"
translate>
Activate user
</vn-item>
<vn-item
ng-if="$ctrl.user.active"
ng-click="deactivateUser.show()"
name="deactivateUser"
vn-acl="itManagement"
vn-acl-action="remove"
translate>
Deactivate user
</vn-item>
<vn-item
ng-click="syncUser.show()"
name="synchronizeUser"
vn-acl="it"
vn-acl-action="remove"
translate>
Synchronize
</vn-item>
</slot-menu>
<slot-body>
<div class="attributes">
<vn-label-value
label="User"
value="{{$ctrl.user.name}}">
</vn-label-value>
<vn-label-value
label="Role"
value="{{$ctrl.user.role.name}}">
</vn-label-value>
</div>
<div class="icons">
<vn-icon
vn-tooltip="User deactivated"
icon="icon-disabled"
ng-if="!$ctrl.user.active">
</vn-icon>
<vn-icon
vn-tooltip="Account enabled"
icon="contact_mail"
ng-if="$ctrl.hasAccount">
</vn-icon>
</div>
</slot-body>
</vn-descriptor-content>
<vn-confirm
vn-id="deleteUser"
on-accept="$ctrl.onDelete()"
question="Are you sure you want to continue?"
message="User will be removed">
</vn-confirm>
<vn-confirm
vn-id="enableAccount"
on-accept="$ctrl.onEnableAccount()"
question="Are you sure you want to continue?"
message="Account will be enabled">
</vn-confirm>
<vn-confirm
vn-id="disableAccount"
on-accept="$ctrl.onDisableAccount()"
question="Are you sure you want to continue?"
message="Account will be disabled">
</vn-confirm>
<vn-confirm
vn-id="activateUser"
on-accept="$ctrl.onSetActive(true)"
question="Are you sure you want to continue?"
message="User will activated">
</vn-confirm>
<vn-confirm
vn-id="deactivateUser"
on-accept="$ctrl.onSetActive(false)"
question="Are you sure you want to continue?"
message="User will be deactivated">
</vn-confirm>
<vn-dialog
vn-id="changePass"
on-accept="$ctrl.onPassChange()"
on-close="$ctrl.onPassClose()">
<tpl-body>
<vn-textfield
ng-if="$ctrl.askOldPass"
label="Old password"
ng-model="$ctrl.oldPassword"
type="password"
vn-focus>
</vn-textfield>
<vn-textfield
label="New password"
ng-model="$ctrl.newPassword"
type="password"
info="{{'Password requirements' | translate:$ctrl.passRequirements}}"
vn-focus>
</vn-textfield>
<vn-textfield
label="Repeat password"
ng-model="$ctrl.repeatPassword"
type="password">
</vn-textfield>
</tpl-body>
<tpl-buttons>
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
<button response="accept" translate>Change password</button>
</tpl-buttons>
</vn-dialog>
<vn-dialog
vn-id="syncUser"
on-accept="$ctrl.onSync()"
on-close="$ctrl.onSyncClose()">
<tpl-title translate>
Do you want to synchronize user?
</tpl-title>
<tpl-body>
<vn-check
label="Synchronize password"
ng-model="$ctrl.shouldSyncPassword"
info="If password is not specified, just user attributes are synchronized"
vn-focus>
</vn-check>
<vn-textfield
label="Password"
ng-model="$ctrl.syncPassword"
type="password"
ng-if="$ctrl.shouldSyncPassword">
</vn-textfield>
</tpl-body>
<tpl-buttons>
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
<button response="accept" translate>Synchronize</button>
</tpl-buttons>
</vn-dialog>
<vn-popup vn-id="summary">
<vn-user-summary user="$ctrl.user"></vn-user-summary>
</vn-popup>

View File

@ -0,0 +1,145 @@
import ngModule from '../module';
import Descriptor from 'salix/components/descriptor';
import UserError from 'core/lib/user-error';
class Controller extends Descriptor {
get user() {
return this.entity;
}
set user(value) {
this.entity = value;
}
get entity() {
return super.entity;
}
set entity(value) {
super.entity = value;
this.hasAccount = null;
if (!value) return;
this.$http.get(`Accounts/${value.id}/exists`)
.then(res => this.hasAccount = res.data.exists);
}
loadData() {
const filter = {
where: {id: this.$params.id},
include: {
relation: 'role',
scope: {
fields: ['id', 'name']
}
}
};
return Promise.all([
this.$http.get(`VnUsers/preview`, {filter})
.then(res => {
const [user] = res.data;
this.user = user;
}),
this.$http.get(`Accounts/${this.$params.id}/exists`)
.then(res => this.hasAccount = res.data.exists)
]);
}
onDelete() {
return this.$http.delete(`VnUsers/${this.id}`)
.then(() => this.$state.go('account.index'))
.then(() => this.vnApp.showSuccess(this.$t('User removed')));
}
onChangePassClick(askOldPass) {
this.$http.get('UserPasswords/findOne')
.then(res => {
this.passRequirements = res.data;
this.askOldPass = askOldPass;
this.$.changePass.show();
});
}
onPassChange() {
if (!this.newPassword)
throw new UserError(`You must enter a new password`);
if (this.newPassword != this.repeatPassword)
throw new UserError(`Passwords don't match`);
let method;
const params = {newPassword: this.newPassword};
if (this.askOldPass) {
method = 'change-password';
params.oldPassword = this.oldPassword;
} else
method = 'setPassword';
return this.$http.patch(`Accounts/${this.id}/${method}`, params)
.then(() => {
this.emit('change');
this.vnApp.showSuccess(this.$t('Password changed succesfully!'));
});
}
onPassClose() {
this.oldPassword = '';
this.newPassword = '';
this.repeatPassword = '';
this.$.$apply();
}
onEnableAccount() {
return this.$http.post(`Accounts`, {id: this.id})
.then(() => this.onSwitchAccount(true));
}
onDisableAccount() {
return this.$http.delete(`Accounts/${this.id}`)
.then(() => this.onSwitchAccount(false));
}
onSwitchAccount(enable) {
this.hasAccount = enable;
const message = enable
? 'Account enabled!'
: 'Account disabled!';
this.emit('change');
this.vnApp.showSuccess(this.$t(message));
}
onSetActive(active) {
return this.$http.patch(`VnUsers/${this.id}`, {active})
.then(() => {
this.user.active = active;
const message = active
? 'User activated!'
: 'User deactivated!';
this.emit('change');
this.vnApp.showSuccess(this.$t(message));
});
}
onSync() {
const params = {force: true};
if (this.shouldSyncPassword)
params.password = this.syncPassword;
return this.$http.patch(`Accounts/${this.user.name}/sync`, params)
.then(() => this.vnApp.showSuccess(this.$t('User synchronized!')));
}
onSyncClose() {
this.shouldSyncPassword = false;
this.syncPassword = undefined;
}
}
ngModule.component('vnUserDescriptor', {
template: require('./index.html'),
controller: Controller,
bindings: {
user: '<'
}
});

View File

@ -0,0 +1,35 @@
User will be removed: El usuario será eliminado
User removed: Usuario eliminado
Are you sure you want to continue?: ¿Seguro que quieres continuar?
Account will be enabled: La cuenta será habilitada
Account will be disabled: La cuenta será deshabilitada
Account enabled!: ¡Cuenta habilitada!
Account disabled!: ¡Cuenta deshabilitada!
User will activated: El usuario será activado
User will be deactivated: El usuario será desactivado
User activated!: ¡Usuario activado!
User deactivated!: ¡Usuario desactivado!
Account enabled: Cuenta habilitada
User deactivated: Usuario desactivado
Change role: Modificar rol
Change password: Cambiar contraseña
Set password: Establecer contraseña
Enable account: Habilitar cuenta
Disable account: Deshabilitar cuenta
Activate user: Activar usuario
Deactivate user: Desactivar usuario
Old password: Contraseña antigua
New password: Nueva contraseña
Repeat password: Repetir contraseña
Password changed succesfully!: ¡Contraseña modificada correctamente!
Synchronize: Sincronizar
Do you want to synchronize user?: ¿Quieres sincronizar el usuario?
Synchronize password: Sincronizar contraseña
User synchronized!: ¡Usuario sincronizado!
Role changed succesfully!: ¡Rol modificado correctamente!
Password requirements: >
La contraseña debe tener al menos {{ length }} caracteres de longitud,
{{nAlpha}} caracteres alfabéticos, {{nUpper}} letras mayúsculas, {{nDigits}}
dígitos y {{nPunct}} símbolos (Ej: $%&.)
You must enter a new password: Debes introducir la nueva contraseña
Passwords don't match: Las contraseñas no coinciden

View File

@ -1,3 +1,6 @@
export * from './module';
import './main';
import './descriptor';
import './descriptor-popover';
import './summary';

View File

@ -0,0 +1,40 @@
<vn-card class="summary">
<h5>
<a
ng-if="::summary.id"
vn-tooltip="Go to the user"
ui-sref="account.card.summary({id: {{::summary.id}}})"
name="goToSummary">
<vn-icon-button icon="launch"></vn-icon-button>
</a>
<span>{{summary.id}} - {{summary.nickname}}</span>
</h5>
<vn-horizontal class="vn-pa-md">
<vn-one>
<h4 ng-show="$ctrl.isHr">
<a
ui-sref="account.card.basicData({id:summary.id})"
target="_self">
<span translate vn-tooltip="Go to">Basic Data</span>
</a>
</h4>
<h4
translate
ng-show="!$ctrl.isHr">
Basic Data
</h4>
<vn-label-value
label="Id"
value="{{summary.id}}">
</vn-label-value>
<vn-label-value
label="User"
value="{{summary.name}}">
</vn-label-value>
<vn-label-value
label="Role"
value="{{summary.role.name}}">
</vn-label-value>
</vn-one>
</vn-horizontal>
</vn-card>

View File

@ -0,0 +1,40 @@
import ngModule from '../module';
import Summary from 'salix/components/summary';
class Controller extends Summary {
set user(value) {
this._user = value;
this.$.summary = null;
if (!value) return;
const filter = {
where: {id: value.id},
include: {
relation: 'role',
scope: {
fields: ['id', 'name']
}
}
};
this.$http.get(`VnUsers/preview`, {filter})
.then(res => {
const [summary] = res.data;
this.$.summary = summary;
});
}
get isHr() {
return this.aclService.hasAny(['hr']);
}
get user() {
return this._user;
}
}
ngModule.component('vnUserSummary', {
template: require('./index.html'),
controller: Controller,
bindings: {
user: '<'
}
});