feat: enhance error handling and permissions in Admin and Report services

This commit is contained in:
gabdevele
2026-06-14 21:37:12 +02:00 Unverified
parent 002f89bd73
commit ca09e7b6c8
5 changed files with 93 additions and 14 deletions
+11 -5
View File
@@ -364,7 +364,8 @@ Json::Value AdminService::updateUserRoles(const auth::UserContext &user,
return failure("user_not_found");
}
db->execSqlSync("DELETE FROM user_roles WHERE user_id = ?", targetUserId);
std::vector<long long> roleIds;
roleIds.reserve(body["roles"].size());
for (const auto &role : body["roles"])
{
if (!role.isString())
@@ -378,10 +379,15 @@ Json::Value AdminService::updateUserRoles(const auth::UserContext &user,
{
return failure("role_not_found");
}
db->execSqlSync(
"INSERT INTO user_roles (user_id, role_id) VALUES (?, ?)",
targetUserId,
roleRows[0]["id"].as<long long>());
roleIds.push_back(roleRows[0]["id"].as<long long>());
}
db->execSqlSync("DELETE FROM user_roles WHERE user_id = ?", targetUserId);
for (const auto roleId : roleIds)
{
db->execSqlSync("INSERT INTO user_roles (user_id, role_id) VALUES (?, ?)",
targetUserId,
roleId);
}
return success();
}