Änderung: Erweiterung der Benutzer- und Rechteverwaltung im Admin-Bereich
Änderungen: - Neue Funktionen zur Benutzerverwaltung hinzugefügt: Benutzer suchen, Benutzer abrufen und Benutzer aktualisieren. - Implementierung von Funktionen zur Verwaltung von Benutzerrechten: Rechtearten auflisten, Benutzerrechte auflisten, Recht hinzufügen und Recht entfernen. - Routen für die neuen Funktionen im Admin-Router definiert. - Übersetzungen für Benutzer- und Rechteverwaltung in den Sprachdateien aktualisiert. Diese Anpassungen verbessern die Verwaltung von Benutzern und deren Rechten im Admin-Bereich und erweitern die Funktionalität der Anwendung.
This commit is contained in:
@@ -23,6 +23,17 @@ class AdminController {
|
||||
this.getRooms = this.getRooms.bind(this);
|
||||
this.createRoom = this.createRoom.bind(this);
|
||||
this.deleteRoom = this.deleteRoom.bind(this);
|
||||
|
||||
// User administration
|
||||
this.searchUsers = this.searchUsers.bind(this);
|
||||
this.getUser = this.getUser.bind(this);
|
||||
this.updateUser = this.updateUser.bind(this);
|
||||
|
||||
// Rights
|
||||
this.listRightTypes = this.listRightTypes.bind(this);
|
||||
this.listUserRights = this.listUserRights.bind(this);
|
||||
this.addUserRight = this.addUserRight.bind(this);
|
||||
this.removeUserRight = this.removeUserRight.bind(this);
|
||||
}
|
||||
|
||||
async getOpenInterests(req, res) {
|
||||
@@ -35,6 +46,93 @@ class AdminController {
|
||||
}
|
||||
}
|
||||
|
||||
// --- User Administration ---
|
||||
async searchUsers(req, res) {
|
||||
try {
|
||||
const { userid: requester } = req.headers;
|
||||
const { q } = req.query;
|
||||
const result = await AdminService.searchUsers(requester, q || '');
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
const status = error.message === 'noaccess' ? 403 : 500;
|
||||
res.status(status).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
async getUser(req, res) {
|
||||
try {
|
||||
const { userid: requester } = req.headers;
|
||||
const { id } = req.params;
|
||||
const result = await AdminService.getUserByHashedId(requester, id);
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
const status = error.message === 'noaccess' ? 403 : (error.message === 'notfound' ? 404 : 500);
|
||||
res.status(status).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
async updateUser(req, res) {
|
||||
try {
|
||||
const { userid: requester } = req.headers;
|
||||
const { id } = req.params;
|
||||
const result = await AdminService.updateUser(requester, id, req.body || {});
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
const status = error.message === 'noaccess' ? 403 : (error.message === 'notfound' ? 404 : 500);
|
||||
res.status(status).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
// --- Rights ---
|
||||
async listRightTypes(req, res) {
|
||||
try {
|
||||
const { userid: requester } = req.headers;
|
||||
const types = await AdminService.listUserRightTypes(requester);
|
||||
res.status(200).json(types);
|
||||
} catch (error) {
|
||||
const status = error.message === 'noaccess' ? 403 : 500;
|
||||
res.status(status).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
async listUserRights(req, res) {
|
||||
try {
|
||||
const { userid: requester } = req.headers;
|
||||
const { id } = req.params;
|
||||
const rights = await AdminService.listUserRightsForUser(requester, id);
|
||||
res.status(200).json(rights);
|
||||
} catch (error) {
|
||||
const status = error.message === 'noaccess' ? 403 : (error.message === 'notfound' ? 404 : 500);
|
||||
res.status(status).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
async addUserRight(req, res) {
|
||||
try {
|
||||
const { userid: requester } = req.headers;
|
||||
const { id } = req.params;
|
||||
const { rightTypeId } = req.body || {};
|
||||
const result = await AdminService.addUserRight(requester, id, rightTypeId);
|
||||
res.status(201).json({ status: 'ok' });
|
||||
} catch (error) {
|
||||
const status = error.message === 'noaccess' ? 403 : (error.message === 'notfound' || error.message === 'wrongtype' ? 404 : 500);
|
||||
res.status(status).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
async removeUserRight(req, res) {
|
||||
try {
|
||||
const { userid: requester } = req.headers;
|
||||
const { id } = req.params;
|
||||
const { rightTypeId } = req.body || {};
|
||||
await AdminService.removeUserRight(requester, id, rightTypeId);
|
||||
res.status(204).send();
|
||||
} catch (error) {
|
||||
const status = error.message === 'noaccess' ? 403 : (error.message === 'notfound' ? 404 : 500);
|
||||
res.status(status).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
async changeInterest(req, res) {
|
||||
try {
|
||||
const { userid: userId } = req.headers;
|
||||
|
||||
Reference in New Issue
Block a user