dsql-admin/dsql-app/.local_dist/server/chunks/8999.js

85 lines
3.3 KiB
JavaScript
Raw Normal View History

2024-11-05 11:12:42 +00:00
"use strict";
exports.id = 8999;
exports.ids = [8999];
exports.modules = {
/***/ 8999:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
const DB_HANDLER = __webpack_require__(2224);
const serverError = __webpack_require__(2163);
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
* ==============================================================================
* Main Function
* ==============================================================================
* @async
*
* @param {{
* user: {id:number},
* confirmedDelegetedUser: any,
* database: string,
* table: string,
* priviledgeRegex: RegExp,
* dbId: number,
* }} params - parameters
*
* @returns {Promise<boolean>} does user have the rights for this operation? true if yes, false if no
*/ module.exports = async function checkUserRights({ user , confirmedDelegetedUser , database , table , priviledgeRegex , dbId , }) {
/**
* Fetch user
*
* @description Fetch user from db
*/ let userConfirmation, priviledge;
try {
if (confirmedDelegetedUser?.delegated) {
userConfirmation = await DB_HANDLER(`SELECT priviledge FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=? AND \`database\`=? AND \`table\`=?`, [
confirmedDelegetedUser.rootUserId,
user.id,
database,
table
]);
priviledge = userConfirmation[0]?.priviledge?.match(priviledgeRegex);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} else {
userConfirmation = await DB_HANDLER(`SELECT table_slug FROM user_database_tables WHERE user_id=? AND table_slug=? AND db_id=?`, [
user.id,
table,
dbId
]);
priviledge = true;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
}
} catch (/** @type {any} */ error) {
serverError({
component: "checkUserRights",
message: error.message,
user: user
});
}
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
if (userConfirmation && userConfirmation[0] && priviledge) {
return true;
} else {
return false;
}
}; ////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/***/ })
};
;