diff --git a/src/components/Authorized/CheckPermissions.test.js b/src/components/Authorized/CheckPermissions.test.js index ee686b326b29923e47549aec023479646bbd555c..eda08a7fa5a0684f96159b959fae7a8ef4fd93c6 100644 --- a/src/components/Authorized/CheckPermissions.test.js +++ b/src/components/Authorized/CheckPermissions.test.js @@ -13,6 +13,9 @@ describe('test CheckPermissions', () => { it('authority is undefined , return ok', () => { expect(checkPermissions(null, 'NULL', target, error)).toEqual('ok'); }); + it('currentAuthority is undefined , return error', () => { + expect(checkPermissions('admin', null, target, error)).toEqual('error'); + }); it('Wrong string permission authentication', () => { expect(checkPermissions('admin', 'user', target, error)).toEqual('error'); }); diff --git a/src/components/Authorized/index.d.ts b/src/components/Authorized/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..6b073a6567a57ca92e4f71cbf601e56bf1fc2973 --- /dev/null +++ b/src/components/Authorized/index.d.ts @@ -0,0 +1,47 @@ +import * as React from "react"; +import * as H from "history"; +import { RouteProps } from "react-router"; + +type authorityFN = () => string; + +type authority = string | Array | authorityFN | Promise; + +interface Secured { + (authority: authority, error?: React.ReactNode): ( + target: React.ReactNode + ) => React.ReactNode; +} + +export interface AuthorizedRouteProps extends RouteProps { + authority: authority; +} +export class AuthorizedRoute extends React.Component< + AuthorizedRouteProps, + any +> { + constructor(props: AuthorizedRouteProps); +} + +interface check { + ( + authority: authority, + target: React.ReactNode, + Exception: React.ReactNode + ): React.ReactNode; +} + +interface AuthorizedProps { + authority: authority; + noMatch?: React.ReactNode; +} + +export class Authorized extends React.Component { + static Secured: Secured; + static AuthorizedRoute: typeof AuthorizedRoute; + static check: check; + constructor(props: AuthorizedProps); +} + +declare function renderAuthorize(currentAuthority: string): typeof Authorized; + +export default renderAuthorize;