mirror of
https://github.com/stefanpejcic/openpanel
synced 2025-06-26 18:28:26 +00:00
cleaner
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
import { BaseKey, IResourceItem, ITreeMenu } from "../../interfaces";
|
||||
|
||||
export type CanParams = {
|
||||
/**
|
||||
* Resource name for API data interactions
|
||||
*/
|
||||
resource?: string;
|
||||
/**
|
||||
* Intended action on resource
|
||||
*/
|
||||
action: string;
|
||||
/**
|
||||
* Parameters associated with the resource
|
||||
* @type { resource?: [IResourceItem](https://refine.dev/docs/api-reference/core/interfaceReferences/#canparams), id?: [BaseKey](https://refine.dev/docs/api-reference/core/interfaceReferences/#basekey), [key: string]: any }
|
||||
*/
|
||||
params?: {
|
||||
resource?: IResourceItem & { children?: ITreeMenu[] };
|
||||
id?: BaseKey;
|
||||
[key: string]: any;
|
||||
};
|
||||
};
|
||||
|
||||
export type CanReturnType = {
|
||||
can: boolean;
|
||||
reason?: string;
|
||||
};
|
||||
|
||||
export interface IAccessControlContext {
|
||||
can?: ({ resource, action, params }: CanParams) => Promise<CanReturnType>;
|
||||
options?: {
|
||||
buttons?: {
|
||||
enableAccessControl?: boolean;
|
||||
hideIfUnauthorized?: boolean;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export interface IAccessControlContextReturnType {
|
||||
can?: ({ resource, action, params }: CanParams) => Promise<CanReturnType>;
|
||||
options: {
|
||||
buttons: {
|
||||
enableAccessControl?: boolean;
|
||||
hideIfUnauthorized?: boolean;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export type AccessControlProvider = Partial<IAccessControlContext> &
|
||||
Required<Pick<IAccessControlContext, "can">>;
|
||||
@@ -1,49 +0,0 @@
|
||||
import React from "react";
|
||||
|
||||
import {
|
||||
IAccessControlContext,
|
||||
IAccessControlContextReturnType,
|
||||
} from "./IAccessControlContext";
|
||||
|
||||
/** @deprecated default value for access control context has no use and is an empty object. */
|
||||
export const defaultAccessControlContext: IAccessControlContext = {};
|
||||
|
||||
export const AccessControlContext =
|
||||
React.createContext<IAccessControlContextReturnType>({
|
||||
options: {
|
||||
buttons: { enableAccessControl: true, hideIfUnauthorized: false },
|
||||
},
|
||||
});
|
||||
|
||||
export { IAccessControlContext };
|
||||
|
||||
export const AccessControlContextProvider: React.FC<
|
||||
IAccessControlContext & {
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
> = ({ can, children, options }) => {
|
||||
return (
|
||||
<AccessControlContext.Provider
|
||||
value={{
|
||||
can,
|
||||
options: options
|
||||
? {
|
||||
...options,
|
||||
buttons: {
|
||||
enableAccessControl: true,
|
||||
hideIfUnauthorized: false,
|
||||
...options.buttons,
|
||||
},
|
||||
}
|
||||
: {
|
||||
buttons: {
|
||||
enableAccessControl: true,
|
||||
hideIfUnauthorized: false,
|
||||
},
|
||||
},
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</AccessControlContext.Provider>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user