rbac build

This commit is contained in:
2026-04-29 15:44:20 +02:00
parent 90497deebf
commit bbd9441b31
14 changed files with 1006 additions and 635 deletions

View File

@@ -237,207 +237,216 @@ class RBACManager {
//#region CRUD
// =========================================================
// 👤 AUTH CRUD
// =========================================================
// =========================================================
// 👤 AUTH CRUD
// =========================================================
async createAuth(data) {
const Auth = this.db.get('authentication');
async getAuth() {
const Auth = this.db.get('authenticationOverviewView');
return await Auth.findAll({ raw: true });
}
return await Auth.create({
sAMAccountName: data.sAMAccountName,
mail: data.mail,
sn: data.sn,
givenName: data.givenName,
active: true
});
}
async createAuth(data) {
const Auth = this.db.get('authentication');
async updateAuth(id, data) {
const Auth = this.db.get('authentication');
return await Auth.create({
sAMAccountName: data.sAMAccountName,
mail: data.mail,
sn: data.sn,
givenName: data.givenName,
ObjectSource_ID: 1,
active: true
});
}
return await Auth.update(data, {
where: { ObjectGUID: id }
});
}
async updateAuth(id, data) {
const Auth = this.db.get('authentication');
async deleteAuth(id) {
const Auth = this.db.get('authentication');
return await Auth.update(data, {
where: { ObjectGUID: id }
});
}
return await Auth.destroy({
where: { ObjectGUID: id }
});
}
async deleteAuth(id) {
const Auth = this.db.get('authentication');
// =========================================================
// 👥 GROUP CRUD
// =========================================================
return await Auth.destroy({
where: { ObjectGUID: id }
});
}
async createGroup(data) {
const Group = this.db.get('groupsModel');
// =========================================================
// 👥 GROUP CRUD
// =========================================================
async getGroup() {
const group = this.db.get('groupOverviewView');
return await group.findAll({ raw: true }) || [];
}
return await Group.create({
Name: data.name,
Description: data.description || null
});
}
async createGroup(data) {
const group = this.db.get('group');
return await group.create({
Name: data.name,
ObjectSource_ID: 1
});
}
async updateGroup(id, data) {
const Group = this.db.get('groupsModel');
async updateGroup(id, data) {
const Group = this.db.get('group');
return await Group.update(data, {
where: { ObjectGUID: id }
});
}
return await Group.update(data, {
where: { ObjectGUID: id }
});
}
async deleteGroup(id) {
const Group = this.db.get('groupsModel');
async deleteGroup(id) {
const Group = this.db.get('group');
return await Group.destroy({
where: { ObjectGUID: id }
});
}
return await Group.destroy({
where: { ObjectGUID: id }
});
}
// =========================================================
// 🔗 AUTH ↔ GROUP RELATION
// =========================================================
// =========================================================
// 🔗 AUTH ↔ GROUP RELATION
// =========================================================
async addUserToGroup(authId, groupId) {
const AuthGroups = this.db.get('authenticationGroupsModel');
async addUserToGroup(authId, groupId) {
const AuthGroups = this.db.get('authenticationGroupsModel');
return await AuthGroups.create({
return await AuthGroups.create({
Authentication_ObjectGUID: authId,
Group_ObjectGUID: groupId
});
}
async removeUserFromGroup(authId, groupId) {
const AuthGroups = this.db.get('authenticationGroupsModel');
return await AuthGroups.destroy({
where: {
Authentication_ObjectGUID: authId,
Group_ObjectGUID: groupId
});
}
}
});
}
async removeUserFromGroup(authId, groupId) {
const AuthGroups = this.db.get('authenticationGroupsModel');
// =========================================================
// 🎭 ROLE CRUD
// =========================================================
return await AuthGroups.destroy({
where: {
Authentication_ObjectGUID: authId,
Group_ObjectGUID: groupId
}
});
}
async createRole(data) {
const Role = this.db.get('rolesModel');
// =========================================================
// 🎭 ROLE CRUD
// =========================================================
return await Role.create({
Name: data.name,
Description: data.description || null
});
}
async createRole(data) {
const Role = this.db.get('rolesModel');
async updateRole(id, data) {
const Role = this.db.get('rolesModel');
return await Role.create({
Name: data.name,
Description: data.description || null
});
}
return await Role.update(data, {
where: { ID: id }
});
}
async updateRole(id, data) {
const Role = this.db.get('rolesModel');
async deleteRole(id) {
const Role = this.db.get('rolesModel');
return await Role.update(data, {
where: { ID: id }
});
}
return await Role.destroy({
where: { ID: id }
});
}
async deleteRole(id) {
const Role = this.db.get('rolesModel');
// =========================================================
// 🔗 ROLE ASSIGNMENTS
// =========================================================
return await Role.destroy({
where: { ID: id }
});
}
async assignRoleToUser(authId, roleId) {
const AuthRoles = this.db.get('authenticationRolesModel');
// =========================================================
// 🔗 ROLE ASSIGNMENTS
// =========================================================
return await AuthRoles.create({
Authentication_ObjectGUID: authId,
Role_ID: roleId
});
}
async assignRoleToUser(authId, roleId) {
const AuthRoles = this.db.get('authenticationRolesModel');
async assignRoleToGroup(groupId, roleId) {
const GroupRoles = this.db.get('groupRolesModel');
return await AuthRoles.create({
return await GroupRoles.create({
Group_ObjectGUID: groupId,
Role_ID: roleId
});
}
async removeRoleFromUser(authId, roleId) {
const AuthRoles = this.db.get('authenticationRolesModel');
return await AuthRoles.destroy({
where: {
Authentication_ObjectGUID: authId,
Role_ID: roleId
});
}
}
});
}
async assignRoleToGroup(groupId, roleId) {
const GroupRoles = this.db.get('groupRolesModel');
// =========================================================
// 🔐 PERMISSION CRUD
// =========================================================
return await GroupRoles.create({
Group_ObjectGUID: groupId,
Role_ID: roleId
});
}
async createPermission(data) {
const Permission = this.db.get('permissionModel');
async removeRoleFromUser(authId, roleId) {
const AuthRoles = this.db.get('authenticationRolesModel');
return await Permission.create({
Scope: data.scope,
Resource: data.resource,
Action: data.action
});
}
return await AuthRoles.destroy({
where: {
Authentication_ObjectGUID: authId,
Role_ID: roleId
}
});
}
async updatePermission(id, data) {
const Permission = this.db.get('permissionModel');
// =========================================================
// 🔐 PERMISSION CRUD
// =========================================================
return await Permission.update(data, {
where: { ID: id }
});
}
async createPermission(data) {
const Permission = this.db.get('permissionModel');
async deletePermission(id) {
const Permission = this.db.get('permissionModel');
return await Permission.create({
Scope: data.scope,
Resource: data.resource,
Action: data.action
});
}
return await Permission.destroy({
where: { ID: id }
});
}
async updatePermission(id, data) {
const Permission = this.db.get('permissionModel');
// =========================================================
// 🔗 ROLE ↔ PERMISSION
// =========================================================
return await Permission.update(data, {
where: { ID: id }
});
}
async addPermissionToRole(roleId, permissionId) {
const RolePerms = this.db.get('rolePermissionsModel');
async deletePermission(id) {
const Permission = this.db.get('permissionModel');
return await RolePerms.create({
Role_ID: roleId,
Permission_ID: permissionId
});
}
return await Permission.destroy({
where: { ID: id }
});
}
async removePermissionFromRole(roleId, permissionId) {
const RolePerms = this.db.get('rolePermissionsModel');
// =========================================================
// 🔗 ROLE ↔ PERMISSION
// =========================================================
async addPermissionToRole(roleId, permissionId) {
const RolePerms = this.db.get('rolePermissionsModel');
return await RolePerms.create({
return await RolePerms.destroy({
where: {
Role_ID: roleId,
Permission_ID: permissionId
});
}
async removePermissionFromRole(roleId, permissionId) {
const RolePerms = this.db.get('rolePermissionsModel');
return await RolePerms.destroy({
where: {
Role_ID: roleId,
Permission_ID: permissionId
}
});
}
//#endregio
}
});
}
//#endregion
}
module.exports = RBACManager;