Commit c859fde8 authored by 陈帅's avatar 陈帅 Committed by 偏右

Authorized typescript (#573)

* add Authorized typescript support

* add currentAuthority is undefine test
parent 5ade2230
...@@ -13,6 +13,9 @@ describe('test CheckPermissions', () => { ...@@ -13,6 +13,9 @@ describe('test CheckPermissions', () => {
it('authority is undefined , return ok', () => { it('authority is undefined , return ok', () => {
expect(checkPermissions(null, 'NULL', target, error)).toEqual('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', () => { it('Wrong string permission authentication', () => {
expect(checkPermissions('admin', 'user', target, error)).toEqual('error'); expect(checkPermissions('admin', 'user', target, error)).toEqual('error');
}); });
......
import * as React from "react";
import * as H from "history";
import { RouteProps } from "react-router";
type authorityFN = () => string;
type authority = string | Array<string> | authorityFN | Promise<any>;
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<AuthorizedProps, any> {
static Secured: Secured;
static AuthorizedRoute: typeof AuthorizedRoute;
static check: check;
constructor(props: AuthorizedProps);
}
declare function renderAuthorize(currentAuthority: string): typeof Authorized;
export default renderAuthorize;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment