feat: sistema de bloque para ficheros mdb
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
66b932d1ae
commit
32f28e91b5
|
@ -0,0 +1,4 @@
|
||||||
|
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||||
|
VALUES
|
||||||
|
('MdbApp', 'lock', 'WRITE', 'ALLOW', 'ROLE', 'developer'),
|
||||||
|
('MdbApp', 'unlock', 'WRITE', 'ALLOW', 'ROLE', 'developer');
|
|
@ -0,0 +1,11 @@
|
||||||
|
CREATE TABLE `vn`.`mdbApp` (
|
||||||
|
`app` varchar(100) COLLATE utf8mb3_unicode_ci DEFAULT NULL,
|
||||||
|
`baselineBranchFk` varchar(255) COLLATE utf8mb3_unicode_ci DEFAULT NULL,
|
||||||
|
`userFk` int(10) unsigned DEFAULT NULL,
|
||||||
|
`locked` datetime DEFAULT NULL,
|
||||||
|
UNIQUE KEY `app_UN` (`app`),
|
||||||
|
KEY `mdbApp_FK` (`userFk`),
|
||||||
|
KEY `mdbApp_FK_1` (`baselineBranchFk`),
|
||||||
|
CONSTRAINT `mdbApp_FK` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `mdbApp_FK_1` FOREIGN KEY (`baselineBranchFk`) REFERENCES `mdbBranch` (`name`) ON UPDATE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
|
@ -2731,3 +2731,8 @@ UPDATE `account`.`user`
|
||||||
INSERT INTO `vn`.`osTicketConfig` (`id`, `host`, `user`, `password`, `oldStatus`, `newStatusId`, `day`, `comment`, `hostDb`, `userDb`, `passwordDb`, `portDb`, `responseType`, `fromEmailId`, `replyTo`)
|
INSERT INTO `vn`.`osTicketConfig` (`id`, `host`, `user`, `password`, `oldStatus`, `newStatusId`, `day`, `comment`, `hostDb`, `userDb`, `passwordDb`, `portDb`, `responseType`, `fromEmailId`, `replyTo`)
|
||||||
VALUES
|
VALUES
|
||||||
(0, 'http://localhost:56596/scp', 'ostadmin', 'Admin1', 'open', 3, 60, 'Este CAU se ha cerrado automáticamente. Si el problema persiste responda a este mensaje.', 'localhost', 'osticket', 'osticket', 40003, 'reply', 1, 'all');
|
(0, 'http://localhost:56596/scp', 'ostadmin', 'Admin1', 'open', 3, 60, 'Este CAU se ha cerrado automáticamente. Si el problema persiste responda a este mensaje.', 'localhost', 'osticket', 'osticket', 40003, 'reply', 1, 'all');
|
||||||
|
|
||||||
|
INSERT INTO `vn`.`mdbApp` (`app`, `baselineBranchFk`, `userFk`, `locked`)
|
||||||
|
VALUES
|
||||||
|
('com', 'master', NULL, NULL),
|
||||||
|
('ent', 'test', NULL, NULL);
|
||||||
|
|
|
@ -138,5 +138,6 @@
|
||||||
"You don't have grant privilege": "You don't have grant privilege",
|
"You don't have grant privilege": "You don't have grant privilege",
|
||||||
"You don't own the role and you can't assign it to another user": "You don't own the role and you can't assign it to another user",
|
"You don't own the role and you can't assign it to another user": "You don't own the role and you can't assign it to another user",
|
||||||
"Ticket merged": "Ticket [{{id}}]({{{fullPath}}}) ({{{originDated}}}) merged with [{{tfId}}]({{{fullPathFuture}}}) ({{{futureDated}}})",
|
"Ticket merged": "Ticket [{{id}}]({{{fullPath}}}) ({{{originDated}}}) merged with [{{tfId}}]({{{fullPathFuture}}}) ({{{futureDated}}})",
|
||||||
"Sale(s) blocked, please contact production": "Sale(s) blocked, please contact production"
|
"Sale(s) blocked, please contact production": "Sale(s) blocked, please contact production",
|
||||||
|
"App locked": "App locked by user {{userId}}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,5 +244,6 @@
|
||||||
"Ticket merged": "Ticket [{{id}}]({{{fullPath}}}) ({{{originDated}}}) fusionado con [{{tfId}}]({{{fullPathFuture}}}) ({{{futureDated}}})",
|
"Ticket merged": "Ticket [{{id}}]({{{fullPath}}}) ({{{originDated}}}) fusionado con [{{tfId}}]({{{fullPathFuture}}}) ({{{futureDated}}})",
|
||||||
"Already has this status": "Ya tiene este estado",
|
"Already has this status": "Ya tiene este estado",
|
||||||
"There aren't records for this week": "No existen registros para esta semana",
|
"There aren't records for this week": "No existen registros para esta semana",
|
||||||
"Empty data source": "Origen de datos vacio"
|
"Empty data source": "Origen de datos vacio",
|
||||||
|
"App locked": "Aplicación bloquada por el usuario {{userId}}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('lock', {
|
||||||
|
description: 'Lock an app for the user',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'appName',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
description: 'The app name',
|
||||||
|
http: {source: 'path'}
|
||||||
|
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/:appName/lock`,
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.lock = async(ctx, appName, options) => {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
let tx;
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const mdbApp = await models.MdbApp.findById(appName, null, myOptions);
|
||||||
|
const updatedMdbApp = await mdbApp.updateAttributes({
|
||||||
|
userFk: userId,
|
||||||
|
locked: new Date()
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
return updatedMdbApp;
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,55 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('unlock', {
|
||||||
|
description: 'Unlock an app for the user',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'appName',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
description: 'The app name',
|
||||||
|
http: {source: 'path'}
|
||||||
|
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/:appName/unlock`,
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.unlock = async(appName, options) => {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
let tx;
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const mdbApp = await models.MdbApp.findById(appName, null, myOptions);
|
||||||
|
const updatedMdbApp = await mdbApp.updateAttributes({
|
||||||
|
userFk: null,
|
||||||
|
locked: null
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
return updatedMdbApp;
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
|
@ -23,6 +23,12 @@ module.exports = Self => {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
description: `The branch name`
|
description: `The branch name`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'unlock',
|
||||||
|
type: 'boolean',
|
||||||
|
required: false,
|
||||||
|
description: `It allows unlock the app`
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
|
@ -35,9 +41,11 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.upload = async(ctx, appName, newVersion, branch, options) => {
|
Self.upload = async(ctx, appName, newVersion, branch, unlock, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
const $t = ctx.req.__; // $translate
|
||||||
|
|
||||||
const TempContainer = models.TempContainer;
|
const TempContainer = models.TempContainer;
|
||||||
const AccessContainer = models.AccessContainer;
|
const AccessContainer = models.AccessContainer;
|
||||||
|
@ -55,6 +63,12 @@ module.exports = Self => {
|
||||||
|
|
||||||
let srcFile;
|
let srcFile;
|
||||||
try {
|
try {
|
||||||
|
const mdbApp = await models.MdbApp.findById(appName, null, myOptions);
|
||||||
|
const message = $t('App locked', {
|
||||||
|
userId: userId
|
||||||
|
});
|
||||||
|
if (mdbApp.locked && mdbApp.userFk != userId) throw new UserError(message);
|
||||||
|
|
||||||
const tempContainer = await TempContainer.container('access');
|
const tempContainer = await TempContainer.container('access');
|
||||||
const uploaded = await TempContainer.upload(tempContainer.name, ctx.req, ctx.result, fileOptions);
|
const uploaded = await TempContainer.upload(tempContainer.name, ctx.req, ctx.result, fileOptions);
|
||||||
const files = Object.values(uploaded.files).map(file => {
|
const files = Object.values(uploaded.files).map(file => {
|
||||||
|
@ -79,7 +93,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
const existBranch = await models.MdbBranch.findOne({
|
const existBranch = await models.MdbBranch.findOne({
|
||||||
where: {name: branch}
|
where: {name: branch}
|
||||||
});
|
}, myOptions);
|
||||||
|
|
||||||
if (!existBranch)
|
if (!existBranch)
|
||||||
throw new UserError('Not exist this branch');
|
throw new UserError('Not exist this branch');
|
||||||
|
@ -108,7 +122,9 @@ module.exports = Self => {
|
||||||
app: appName,
|
app: appName,
|
||||||
branchFk: branch,
|
branchFk: branch,
|
||||||
version: newVersion
|
version: newVersion
|
||||||
});
|
}, myOptions);
|
||||||
|
|
||||||
|
if (unlock) await models.MdbApp.unlock(appName, myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
{
|
{
|
||||||
|
"MdbApp": {
|
||||||
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
"MdbBranch": {
|
"MdbBranch": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
require('../methods/mdbApp/lock')(Self);
|
||||||
|
require('../methods/mdbApp/unlock')(Self);
|
||||||
|
};
|
|
@ -0,0 +1,31 @@
|
||||||
|
{
|
||||||
|
"name": "MdbApp",
|
||||||
|
"base": "VnModel",
|
||||||
|
"options": {
|
||||||
|
"mysql": {
|
||||||
|
"table": "mdbApp"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"app": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The app name",
|
||||||
|
"id": true
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"type": "date"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"relations": {
|
||||||
|
"branch": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "MdbBranch",
|
||||||
|
"foreignKey": "baselineBranchFk"
|
||||||
|
},
|
||||||
|
"user": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "MdbBranch",
|
||||||
|
"foreignKey": "userFk"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue