mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-28 17:01:53 +03:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -91,11 +91,15 @@ const WRITE_METHODS = new Set([
|
||||
]);
|
||||
|
||||
function authorizeGatewayMethod(method: string, client: GatewayRequestOptions["client"]) {
|
||||
if (!client?.connect) return null;
|
||||
if (!client?.connect) {
|
||||
return null;
|
||||
}
|
||||
const role = client.connect.role ?? "operator";
|
||||
const scopes = client.connect.scopes ?? [];
|
||||
if (NODE_ROLE_METHODS.has(method)) {
|
||||
if (role === "node") return null;
|
||||
if (role === "node") {
|
||||
return null;
|
||||
}
|
||||
return errorShape(ErrorCodes.INVALID_REQUEST, `unauthorized role: ${role}`);
|
||||
}
|
||||
if (role === "node") {
|
||||
@@ -104,7 +108,9 @@ function authorizeGatewayMethod(method: string, client: GatewayRequestOptions["c
|
||||
if (role !== "operator") {
|
||||
return errorShape(ErrorCodes.INVALID_REQUEST, `unauthorized role: ${role}`);
|
||||
}
|
||||
if (scopes.includes(ADMIN_SCOPE)) return null;
|
||||
if (scopes.includes(ADMIN_SCOPE)) {
|
||||
return null;
|
||||
}
|
||||
if (APPROVAL_METHODS.has(method) && !scopes.includes(APPROVALS_SCOPE)) {
|
||||
return errorShape(ErrorCodes.INVALID_REQUEST, "missing scope: operator.approvals");
|
||||
}
|
||||
@@ -117,10 +123,18 @@ function authorizeGatewayMethod(method: string, client: GatewayRequestOptions["c
|
||||
if (WRITE_METHODS.has(method) && !scopes.includes(WRITE_SCOPE)) {
|
||||
return errorShape(ErrorCodes.INVALID_REQUEST, "missing scope: operator.write");
|
||||
}
|
||||
if (APPROVAL_METHODS.has(method)) return null;
|
||||
if (PAIRING_METHODS.has(method)) return null;
|
||||
if (READ_METHODS.has(method)) return null;
|
||||
if (WRITE_METHODS.has(method)) return null;
|
||||
if (APPROVAL_METHODS.has(method)) {
|
||||
return null;
|
||||
}
|
||||
if (PAIRING_METHODS.has(method)) {
|
||||
return null;
|
||||
}
|
||||
if (READ_METHODS.has(method)) {
|
||||
return null;
|
||||
}
|
||||
if (WRITE_METHODS.has(method)) {
|
||||
return null;
|
||||
}
|
||||
if (ADMIN_METHOD_PREFIXES.some((prefix) => method.startsWith(prefix))) {
|
||||
return errorShape(ErrorCodes.INVALID_REQUEST, "missing scope: operator.admin");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user