Il creatore del Gruppo deve già appartenere al Gruppo stesso
Non permettere di aggiungere un Gruppo con lo stesso nome o codice quando cancelli un Gruppo, cancella anche tutti i riferimenti sugli utenti di quel gruppo. Errore caricamento Immagini !
This commit is contained in:
@@ -233,7 +233,7 @@ router.post('/testServer', authenticate_noerror, (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.post('/settable', authenticate, (req, res) => {
|
||||
router.post('/settable', authenticate, async (req, res) => {
|
||||
const params = req.body;
|
||||
const mytable = globalTables.getTableByTableName(params.table);
|
||||
const mydata = req.body.data;
|
||||
@@ -281,7 +281,7 @@ router.post('/settable', authenticate, (req, res) => {
|
||||
}
|
||||
|
||||
if (shared_consts.TABLES_USER_INCLUDE_MY.includes(params.table)) {
|
||||
if (!mydata.admins) {
|
||||
if (mydata.admins.length <= 0) {
|
||||
// Aggiungi solo se non esistono Admin:
|
||||
mydata.admins = [];
|
||||
const indfind = mydata.admins.findIndex(
|
||||
@@ -314,19 +314,43 @@ router.post('/settable', authenticate, (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
const isnewrec = mytablerec.isNew;
|
||||
|
||||
if (params.table === shared_consts.TAB_MYGROUPS && isnewrec) {
|
||||
// Controlla se esiste già con lo stesso nome
|
||||
let alreadyexist = await MyGroup.findOne({idapp, groupname: mydata.groupname});
|
||||
if (alreadyexist) {
|
||||
return res.send({code: server_constants.RIS_CODE_REC_ALREADY_EXIST_CODE });
|
||||
}
|
||||
alreadyexist = await MyGroup.findOne({idapp, title: mydata.title});
|
||||
if (alreadyexist) {
|
||||
return res.send({code: server_constants.RIS_CODE_REC_ALREADY_EXIST_NAME });
|
||||
}
|
||||
}
|
||||
|
||||
return mytablerec.save().
|
||||
then(async (rec) => {
|
||||
|
||||
if (shared_consts.TABLES_GETCOMPLETEREC.includes(params.table)) {
|
||||
const myrec = await mytablestrutt.getCompleteRecord(rec.idapp,
|
||||
rec._id);
|
||||
return res.send(myrec);
|
||||
return await mytablestrutt.getCompleteRecord(rec.idapp, rec._id);
|
||||
} else {
|
||||
return res.send(rec);
|
||||
return rec;
|
||||
}
|
||||
|
||||
// tools.mylog('rec', rec);
|
||||
}).then((myrec) => {
|
||||
|
||||
if (params.table === shared_consts.TAB_MYGROUPS && isnewrec) {
|
||||
// nuovo Record:
|
||||
// aggiungi il creatore al gruppo stesso
|
||||
return User.setGroupsCmd(mydata.idapp, req.user.username,
|
||||
myrec.groupname,
|
||||
shared_consts.GROUPSCMD.SETGROUP, true).then((ris) => {
|
||||
return res.send(myrec);
|
||||
});
|
||||
}
|
||||
|
||||
return res.send(myrec);
|
||||
}).catch((e) => {
|
||||
console.error('settable', e.message);
|
||||
if (e.code === 11000) {
|
||||
@@ -880,6 +904,12 @@ router.delete('/delrec/:table/:id', authenticate, async (req, res) => {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (tablename === shared_consts.TAB_MYGROUPS) {
|
||||
// Se è un gruppo, allora cancella anche tutti i suoi riferimenti
|
||||
User.removeAllUsersFromMyGroups(rec.idapp, rec.groupname);
|
||||
}
|
||||
|
||||
cancellato = true;
|
||||
|
||||
tools.mylog('DELETED ', rec._id);
|
||||
@@ -1315,7 +1345,7 @@ router.post('/upload_from_other_server/:dir', authenticate, (req, res) => {
|
||||
function uploadFile(req, res, version) {
|
||||
// console.log('/upload dir:' + dir);
|
||||
const dir = tools.invertescapeslash(req.params.dir);
|
||||
const idapp = req.body.idapp;
|
||||
const idapp = req.user.idapp;
|
||||
|
||||
const form = new formidable.IncomingForm();
|
||||
|
||||
@@ -1370,44 +1400,47 @@ function uploadFile(req, res, version) {
|
||||
// Move in the folder application !
|
||||
// tools.move(oldpath, newname, (err) => {
|
||||
tools.move(oldpath, newname, (err) => {
|
||||
if (err)
|
||||
if (err) {
|
||||
console.log('err:', err);
|
||||
res.status(400).send();
|
||||
} else {
|
||||
|
||||
// Salva le immagini in formato compresso
|
||||
try {
|
||||
let resized_img_small = tools.extractFilePath(newname) + '/' +
|
||||
server_constants.PREFIX_IMG_SMALL +
|
||||
tools.extractFileName(newname);
|
||||
// SMALL
|
||||
sharp(newname).
|
||||
resize(64, 64).
|
||||
toFile(resized_img_small);
|
||||
// Salva le immagini in formato compresso
|
||||
try {
|
||||
let resized_img_small = tools.extractFilePath(newname) + '/' +
|
||||
server_constants.PREFIX_IMG_SMALL +
|
||||
tools.extractFileName(newname);
|
||||
// SMALL
|
||||
sharp(newname).
|
||||
resize(64, 64).
|
||||
toFile(resized_img_small);
|
||||
|
||||
// MEDIUM
|
||||
let resized_img = tools.extractFilePath(newname) + '/' +
|
||||
server_constants.PREFIX_IMG + tools.extractFileName(newname);
|
||||
sharp(newname).
|
||||
resize(512, 512).
|
||||
toFile(resized_img, function(err) {
|
||||
// MEDIUM
|
||||
let resized_img = tools.extractFilePath(newname) + '/' +
|
||||
server_constants.PREFIX_IMG + tools.extractFileName(newname);
|
||||
sharp(newname).
|
||||
resize(512, 512).
|
||||
toFile(resized_img, function(err) {
|
||||
|
||||
if (tools.isFileExists(resized_img)) {
|
||||
// DELETE THE ORIGINAL BIG
|
||||
tools.delete(newname, false, () => {});
|
||||
if (tools.isFileExists(resized_img)) {
|
||||
// DELETE THE ORIGINAL BIG
|
||||
tools.delete(newname, false, () => {});
|
||||
|
||||
// RENAME THE MEDIUM IN THE ORIGINAL NAME
|
||||
tools.move(resized_img, newname, (err) => {
|
||||
if (err)
|
||||
console.error('err', err);
|
||||
else
|
||||
console.log('move', newname);
|
||||
});
|
||||
}
|
||||
// RENAME THE MEDIUM IN THE ORIGINAL NAME
|
||||
tools.move(resized_img, newname, (err) => {
|
||||
if (err)
|
||||
console.error('err', err);
|
||||
else
|
||||
console.log('move', newname);
|
||||
});
|
||||
}
|
||||
|
||||
if (err)
|
||||
console.error('Error Upload: ', err);
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('newname', e);
|
||||
if (err)
|
||||
console.error('Error Upload: ', err);
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('newname', e);
|
||||
}
|
||||
}
|
||||
|
||||
res.end();
|
||||
|
||||
Reference in New Issue
Block a user