Skip to content

Commit

Permalink
feat: fix bug that unable to find matchers in model (casbin#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
HashCookie authored Jul 16, 2024
1 parent 53b9769 commit 0d26e5e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
9 changes: 4 additions & 5 deletions app/components/editor/hooks/useIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export default function useIndex() {
setEcho(<div>Loading Shared Content...</div>);
fetch(`https://dpaste.com/${hash}.txt`)
.then((resp) => {
if (!resp.ok) {
throw new Error(`HTTP error! status: ${resp.status}`);
}
return resp.text();
})
.then((content) => {
Expand All @@ -49,11 +52,7 @@ export default function useIndex() {
setModelTextPersistent(sharedContent.model);
setCustomConfigPersistent(sharedContent.customConfig);
setRequestPersistent(sharedContent.request);
setRequestPersistent(sharedContent.request);
if (sharedContent.enforceContext) {
setEnforceContextDataPersistent(new Map(Object.entries(sharedContent.enforceContext)));
}
setRequestResult('');
setModelKind(sharedContent.modelKind);
window.location.hash = ''; // prevent duplicate load
setEcho(<div>Shared Content Loaded.</div>);
})
Expand Down
6 changes: 4 additions & 2 deletions app/components/editor/hooks/useShareInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ interface ShareProps extends ShareFormat {
}

export interface ShareFormat {
modelKind: string;
model: string;
policy: string;
customConfig: string;
request: string;
enforceContext: object;
requestResult: object;
}

async function dpaste(content: string) {
Expand All @@ -43,11 +44,12 @@ export default function useShareInfo() {
setSharing(true);
props.onResponse(<div>Sharing...</div>);
const shareContent: ShareFormat = {
modelKind: props.modelKind,
model: props.model,
policy: props.policy,
customConfig: props.customConfig,
request: props.request,
enforceContext: props.enforceContext,
requestResult: props.requestResult,
};
dpaste(JSON.stringify(shareContent)).then((url: string) => {
setSharing(false);
Expand Down
3 changes: 2 additions & 1 deletion app/components/editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,12 @@ export const EditorScreen = () => {
onResponse: (v) => {
return handleShare(v);
},
modelKind,
model: modelText,
policy,
customConfig,
request,
enforceContext: Object.entries(enforceContextData),
requestResult: Array.from(enforceContextData.entries()),
});
}}
>
Expand Down
1 change: 1 addition & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import GenerateCasbinVersionPlugin from './generateCasbinVersionPlugin.js';
/** @type {import('next').NextConfig} */
const nextConfig = {
// reactStrictMode: false,
/**
* Enable static exports for the App Router.
*
Expand Down

0 comments on commit 0d26e5e

Please sign in to comment.