refs #5468 feat: no depender del modulo worker
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
ea1c860a18
commit
81a8f383aa
|
@ -5,5 +5,4 @@ DELETE
|
||||||
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
||||||
VALUES
|
VALUES
|
||||||
('Account', '*', 'WRITE', 'ALLOW', 'ROLE', 'sysadmin'),
|
('Account', '*', 'WRITE', 'ALLOW', 'ROLE', 'sysadmin'),
|
||||||
('Account', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
('Account', '*', 'READ', 'ALLOW', 'ROLE', 'employee');
|
||||||
('Account', 'changeMailForwarding', 'WRITE', 'ALLOW', 'ROLE', 'employee');
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
DELETE FROM `salix`.`ACL` WHERE model = 'MailAliasAccount';
|
DELETE FROM `salix`.`ACL` WHERE model = 'MailAliasAccount';
|
||||||
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||||
VALUES
|
VALUES
|
||||||
('MailAliasAccount', '*', 'READ', 'ALLOW', 'ROLE', 'employee');
|
('MailAliasAccount', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('MailAliasAccount', '*', 'WRITE', 'ALLOW', 'ROLE', 'itManagement');
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
DELETE FROM `salix`.`ACL` WHERE model = 'MailForward';
|
DELETE FROM `salix`.`ACL` WHERE model = 'MailForward';
|
||||||
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||||
VALUES
|
VALUES
|
||||||
('MailForward', '*', 'READ', 'ALLOW', 'ROLE', 'employee');
|
('MailForward', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('MailForward', '*', 'WRITE', 'ALLOW', 'ROLE', 'itManagement');
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
|
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
|
||||||
Self.remoteMethodCtx('addMailAlias', {
|
|
||||||
description: 'Add a mail alias',
|
|
||||||
accessType: 'WRITE',
|
|
||||||
accepts: [{
|
|
||||||
arg: 'id',
|
|
||||||
type: 'number',
|
|
||||||
description: 'The user id',
|
|
||||||
http: {source: 'path'}
|
|
||||||
}, {
|
|
||||||
arg: 'mailAlias',
|
|
||||||
type: 'number',
|
|
||||||
description: 'The mail alias',
|
|
||||||
required: true
|
|
||||||
}],
|
|
||||||
http: {
|
|
||||||
path: `/:id/addMailAlias`,
|
|
||||||
verb: 'POST'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Self.addMailAlias = async function(ctx, id, mailAlias) {
|
|
||||||
const models = Self.app.models;
|
|
||||||
|
|
||||||
const isAuthorized = await models.Worker.isAuthorized(ctx, id);
|
|
||||||
if (!isAuthorized)
|
|
||||||
throw new UserError(`You don't have enough privileges`);
|
|
||||||
|
|
||||||
return models.MailAliasAccount.create({mailAlias: mailAlias, account: id});
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -1,38 +0,0 @@
|
||||||
|
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
|
||||||
Self.remoteMethodCtx('changeMailForwarding', {
|
|
||||||
description: 'Changes the mail forwarding',
|
|
||||||
accessType: 'WRITE',
|
|
||||||
accepts: [{
|
|
||||||
arg: 'id',
|
|
||||||
type: 'number',
|
|
||||||
description: 'The user id',
|
|
||||||
http: {source: 'path'}
|
|
||||||
}, {
|
|
||||||
arg: 'forwardTo',
|
|
||||||
type: 'string',
|
|
||||||
description: 'The mail forward'
|
|
||||||
}],
|
|
||||||
http: {
|
|
||||||
path: `/:id/changeMailForwarding`,
|
|
||||||
verb: 'POST'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Self.changeMailForwarding = async function(ctx, id, forwardTo) {
|
|
||||||
const models = Self.app.models;
|
|
||||||
|
|
||||||
const isSubordinate = await models.Worker.isSubordinate(ctx, id);
|
|
||||||
if (!isSubordinate)
|
|
||||||
throw new UserError(`You don't have enough privileges`);
|
|
||||||
|
|
||||||
if (!forwardTo) return models.MailForward.destroyById(id);
|
|
||||||
|
|
||||||
const mailForward = await models.MailForward.findById(id);
|
|
||||||
|
|
||||||
if (mailForward) return mailForward.updateAttribute('forwardTo', forwardTo);
|
|
||||||
else return models.MailForward.create({account: id, forwardTo: forwardTo});
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -1,29 +0,0 @@
|
||||||
|
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
|
||||||
Self.remoteMethodCtx('deleteMailAlias', {
|
|
||||||
description: 'Delete a mail alias',
|
|
||||||
accessType: 'WRITE',
|
|
||||||
accepts: [{
|
|
||||||
arg: 'id',
|
|
||||||
type: 'number',
|
|
||||||
description: 'The mail alias account to id',
|
|
||||||
http: {source: 'path'}
|
|
||||||
}],
|
|
||||||
http: {
|
|
||||||
path: `/:id/deleteMailAlias`,
|
|
||||||
verb: 'POST'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Self.deleteMailAlias = async function(ctx, id) {
|
|
||||||
const models = Self.app.models;
|
|
||||||
|
|
||||||
const isAuthorized = await models.Worker.isAuthorized(ctx, id);
|
|
||||||
if (!isAuthorized)
|
|
||||||
throw new UserError(`You don't have enough privileges`);
|
|
||||||
|
|
||||||
return models.MailAliasAccount.destroyById(id);
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -1,26 +0,0 @@
|
||||||
const {models} = require('vn-loopback/server/server');
|
|
||||||
|
|
||||||
describe('Account addMailAlias()', () => {
|
|
||||||
it('should throw an error when the user is not a superior', async() => {
|
|
||||||
const ctx = {req: {accessToken: {userId: 1}}};
|
|
||||||
const employeeId = 1;
|
|
||||||
|
|
||||||
let error;
|
|
||||||
try {
|
|
||||||
await models.Account.addMailAlias(ctx, employeeId, 1);
|
|
||||||
} catch (e) {
|
|
||||||
error = e.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(error).toEqual(`You don't have enough privileges`);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should add a mail alias', async() => {
|
|
||||||
const ctx = {req: {accessToken: {userId: 9}}};
|
|
||||||
const employeeId = 1;
|
|
||||||
|
|
||||||
const result = await models.Account.addMailAlias(ctx, employeeId, 2);
|
|
||||||
|
|
||||||
expect(result).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,35 +0,0 @@
|
||||||
const {models} = require('vn-loopback/server/server');
|
|
||||||
|
|
||||||
describe('Account changeMailForwarding()', () => {
|
|
||||||
it('should throw an error when the user is not himself or a superior', async() => {
|
|
||||||
const ctx = {req: {accessToken: {userId: 1}}};
|
|
||||||
const developerId = 9;
|
|
||||||
|
|
||||||
let error;
|
|
||||||
try {
|
|
||||||
await models.Account.changeMailForwarding(ctx, developerId, 'alias@test.test');
|
|
||||||
} catch (e) {
|
|
||||||
error = e.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(error).toEqual(`You don't have enough privileges`);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should change a mail forwarding when the user is himself', async() => {
|
|
||||||
const ctx = {req: {accessToken: {userId: 1}}};
|
|
||||||
const employeeId = 1;
|
|
||||||
|
|
||||||
const result = await models.Account.changeMailForwarding(ctx, employeeId, 'alias@test.test');
|
|
||||||
|
|
||||||
expect(result).toBeDefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should change a mail forwarding when the user is a superior', async() => {
|
|
||||||
const ctx = {req: {accessToken: {userId: 9}}};
|
|
||||||
const employeeId = 1;
|
|
||||||
|
|
||||||
const result = await models.Account.changeMailForwarding(ctx, employeeId, 'alias@test.test');
|
|
||||||
|
|
||||||
expect(result).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,24 +0,0 @@
|
||||||
const {models} = require('vn-loopback/server/server');
|
|
||||||
|
|
||||||
describe('Account deleteMailAlias()', () => {
|
|
||||||
it('should throw an error when the user is not a superior', async() => {
|
|
||||||
const ctx = {req: {accessToken: {userId: 1}}};
|
|
||||||
|
|
||||||
let error;
|
|
||||||
try {
|
|
||||||
await models.Account.deleteMailAlias(ctx, 1);
|
|
||||||
} catch (e) {
|
|
||||||
error = e.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(error).toEqual(`You don't have enough privileges`);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should delete a mail alias', async() => {
|
|
||||||
const ctx = {req: {accessToken: {userId: 9}}};
|
|
||||||
|
|
||||||
const result = await models.Account.deleteMailAlias(ctx, 1);
|
|
||||||
|
|
||||||
expect(result).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -15,10 +15,11 @@
|
||||||
</vn-item-section>
|
</vn-item-section>
|
||||||
<vn-item-section side>
|
<vn-item-section side>
|
||||||
<vn-icon-button
|
<vn-icon-button
|
||||||
ng-if="$ctrl.isAuthorized"
|
|
||||||
icon="delete"
|
icon="delete"
|
||||||
translate-attr="{title: 'Unsubscribe'}"
|
translate-attr="{title: 'Unsubscribe'}"
|
||||||
ng-click="removeConfirm.show(row)">
|
ng-click="removeConfirm.show(row)"
|
||||||
|
vn-acl="itManagement"
|
||||||
|
vn-acl-action="remove">
|
||||||
</vn-icon-button>
|
</vn-icon-button>
|
||||||
</vn-item-section>
|
</vn-item-section>
|
||||||
</vn-item>
|
</vn-item>
|
||||||
|
@ -27,12 +28,13 @@
|
||||||
</vn-card>
|
</vn-card>
|
||||||
</vn-data-viewer>
|
</vn-data-viewer>
|
||||||
<vn-float-button
|
<vn-float-button
|
||||||
ng-if="$ctrl.isAuthorized"
|
|
||||||
icon="add"
|
icon="add"
|
||||||
translate-attr="{title: 'Add'}"
|
translate-attr="{title: 'Add'}"
|
||||||
vn-bind="+"
|
vn-bind="+"
|
||||||
ng-click="$ctrl.onAddClick()"
|
ng-click="$ctrl.onAddClick()"
|
||||||
fixed-bottom-right>
|
fixed-bottom-right
|
||||||
|
vn-acl="itManagement"
|
||||||
|
vn-acl-action="remove">
|
||||||
</vn-float-button>
|
</vn-float-button>
|
||||||
<vn-dialog
|
<vn-dialog
|
||||||
vn-id="dialog"
|
vn-id="dialog"
|
||||||
|
|
|
@ -4,14 +4,6 @@ import Section from 'salix/components/section';
|
||||||
export default class Controller extends Section {
|
export default class Controller extends Section {
|
||||||
$onInit() {
|
$onInit() {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
this.getIsSubordinate();
|
|
||||||
}
|
|
||||||
|
|
||||||
getIsSubordinate() {
|
|
||||||
this.$http.get(`Workers/${this.$params.id}/isAuthorized`)
|
|
||||||
.then(res => {
|
|
||||||
this.isAuthorized = res.data;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh() {
|
refresh() {
|
||||||
|
@ -34,10 +26,7 @@ export default class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
onAddSave() {
|
onAddSave() {
|
||||||
const params = {
|
return this.$http.post(`MailAliasAccounts`, this.addData)
|
||||||
mailAlias: this.addData.mailAlias
|
|
||||||
};
|
|
||||||
return this.$http.post(`Accounts/${this.$params.id}/addMailAlias`, params)
|
|
||||||
.then(() => this.refresh())
|
.then(() => this.refresh())
|
||||||
.then(() => this.vnApp.showSuccess(
|
.then(() => this.vnApp.showSuccess(
|
||||||
this.$t('Subscribed to alias!'))
|
this.$t('Subscribed to alias!'))
|
||||||
|
@ -45,7 +34,7 @@ export default class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
onRemove(row) {
|
onRemove(row) {
|
||||||
return this.$http.post(`Accounts/${row.id}/deleteMailAlias`)
|
return this.$http.delete(`MailAliasAccounts/${row.id}`)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.$.data.splice(this.$.data.indexOf(row), 1);
|
this.$.data.splice(this.$.data.indexOf(row), 1);
|
||||||
this.vnApp.showSuccess(this.$t('Unsubscribed from alias!'));
|
this.vnApp.showSuccess(this.$t('Unsubscribed from alias!'));
|
||||||
|
|
|
@ -9,7 +9,6 @@ describe('component vnUserAliases', () => {
|
||||||
beforeEach(inject(($componentController, _$httpBackend_) => {
|
beforeEach(inject(($componentController, _$httpBackend_) => {
|
||||||
$httpBackend = _$httpBackend_;
|
$httpBackend = _$httpBackend_;
|
||||||
controller = $componentController('vnUserAliases', {$element: null});
|
controller = $componentController('vnUserAliases', {$element: null});
|
||||||
controller.$params.id = 1;
|
|
||||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -27,7 +26,7 @@ describe('component vnUserAliases', () => {
|
||||||
it('should add the new row', () => {
|
it('should add the new row', () => {
|
||||||
controller.addData = {account: 1};
|
controller.addData = {account: 1};
|
||||||
|
|
||||||
$httpBackend.expectPOST(`Accounts/${controller.$params.id}/addMailAlias`).respond();
|
$httpBackend.expectPOST('MailAliasAccounts').respond();
|
||||||
$httpBackend.expectGET('MailAliasAccounts').respond('foo');
|
$httpBackend.expectGET('MailAliasAccounts').respond('foo');
|
||||||
controller.onAddSave();
|
controller.onAddSave();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
@ -43,7 +42,7 @@ describe('component vnUserAliases', () => {
|
||||||
{id: 2, alias: 'bar'}
|
{id: 2, alias: 'bar'}
|
||||||
];
|
];
|
||||||
|
|
||||||
$httpBackend.expectPOST(`Accounts/${controller.$params.id}/deleteMailAlias`).respond();
|
$httpBackend.expectDELETE('MailAliasAccounts/1').respond();
|
||||||
controller.onRemove(controller.$.data[0]);
|
controller.onRemove(controller.$.data[0]);
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,12 @@
|
||||||
url="MailForwards"
|
url="MailForwards"
|
||||||
id-field="account"
|
id-field="account"
|
||||||
id-value="$ctrl.$params.id"
|
id-value="$ctrl.$params.id"
|
||||||
data="$ctrl.data"
|
data="data"
|
||||||
form="form">
|
form="form">
|
||||||
</vn-watcher>
|
</vn-watcher>
|
||||||
<form
|
<form
|
||||||
name="form"
|
name="form"
|
||||||
ng-submit="$ctrl.onSubmit()"
|
ng-submit="watcher.submit()"
|
||||||
class="vn-w-md">
|
class="vn-w-md">
|
||||||
<vn-card class="vn-pa-lg">
|
<vn-card class="vn-pa-lg">
|
||||||
<vn-vertical>
|
<vn-vertical>
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
<vn-textfield
|
<vn-textfield
|
||||||
ng-if="watcher.hasData"
|
ng-if="watcher.hasData"
|
||||||
label="Forward email"
|
label="Forward email"
|
||||||
ng-model="$ctrl.data.forwardTo"
|
ng-model="data.forwardTo"
|
||||||
info="All emails will be forwarded to the specified address."
|
info="All emails will be forwarded to the specified address."
|
||||||
rule="MailForward"
|
rule="MailForward"
|
||||||
vn-focus>
|
vn-focus>
|
||||||
|
|
|
@ -1,20 +1,7 @@
|
||||||
import ngModule from '../module';
|
import ngModule from '../module';
|
||||||
import Section from 'salix/components/section';
|
import Section from 'salix/components/section';
|
||||||
import UserError from 'core/lib/user-error';
|
|
||||||
|
|
||||||
export default class Controller extends Section {
|
export default class Controller extends Section {}
|
||||||
onSubmit() {
|
|
||||||
const query = `Accounts/${this.$params.id}/changeMailForwarding`;
|
|
||||||
const params = {
|
|
||||||
forwardTo: this.data?.forwardTo || undefined
|
|
||||||
};
|
|
||||||
this.$http.post(query, params)
|
|
||||||
.then(() => {
|
|
||||||
this.$.watcher.notifySaved();
|
|
||||||
this.$.watcher.updateOriginalData();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ngModule.component('vnUserMailForwarding', {
|
ngModule.component('vnUserMailForwarding', {
|
||||||
template: require('./index.html'),
|
template: require('./index.html'),
|
||||||
|
|
Loading…
Reference in New Issue