feat: enhance error handling and permissions in Admin and Report services
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user