Skip to content

Commit

Permalink
feat: use enforceEx in remoteEnforcer to show response reason (#182)
Browse files Browse the repository at this point in the history
* feat: modify the parameter enforce to enforceEx to display Reason

* fix: synchronous display mode
  • Loading branch information
liewstar authored Dec 23, 2024
1 parent 3f74ea3 commit 7353505
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions app/components/editor/hooks/useRemoteEnforcer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function remoteEnforcer(props: RemoteEnforcerProps) {
try {
const baseUrl = 'https://door.casdoor.com/api/run-casbin-command';
const args = [
'enforce',
'enforceEx',
'-m',
props.model,
'-p',
Expand Down Expand Up @@ -60,24 +60,12 @@ export async function remoteEnforcer(props: RemoteEnforcerProps) {
try {
enforceResult = JSON.parse(data);
} catch {
if (data.toLowerCase() === 'allowed') {
enforceResult = {
allow: true,
explain: 'Allowed by policy',
};
} else if (data.toLowerCase() === 'denied') {
enforceResult = {
allow: false,
explain: 'Denied by policy',
};
} else {
throw new Error(`Unexpected response format: ${data}`);
}
throw new Error(`Unexpected response format: ${data}`);
}

return {
allowed: enforceResult.allow,
reason: enforceResult.explain ? [enforceResult.explain] : [],
reason: enforceResult.explain ? enforceResult.explain : [],
error: null,
};
} catch (error) {
Expand Down

0 comments on commit 7353505

Please sign in to comment.