Skip to content

Commit

Permalink
更换权限的检查方式, 在compoentDidMount时候检查权限
Browse files Browse the repository at this point in the history
  • Loading branch information
boxcc committed Apr 2, 2018
1 parent eae49ba commit 9a91abf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/pages/profile/advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import styles from './advanced.less';
const { Step } = Steps;
const { Description } = DescriptionList;
const ButtonGroup = Button.Group;
const { Secured } = Authorized;

const getWindowWidth = () => (window.innerWidth || document.documentElement.clientWidth);

const menu = (
Expand Down Expand Up @@ -141,7 +139,6 @@ const columns = [{
key: 'memo',
}];

@Secured('admin')
@connect(({ profile, loading }) => ({
profile,
loading: loading.effects['profile/fetchAdvanced'],
Expand All @@ -153,6 +150,8 @@ export default class AdvancedProfile extends Component {
}

componentDidMount() {
Authorized.grant(['admin']);

const { dispatch } = this.props;
dispatch({
type: 'profile/fetchAdvanced',
Expand Down
7 changes: 7 additions & 0 deletions src/utils/Authorized.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import RenderAuthorized from 'components/Authorized';
import { getAuthority } from './authority';
import router from 'umi/router';

let Authorized = RenderAuthorized(getAuthority()); // eslint-disable-line

Expand All @@ -8,5 +9,11 @@ const reloadAuthorized = () => {
Authorized = RenderAuthorized(getAuthority());
};

Authorized.grant = (authority) => {
if (!Authorized.check(authority, true, false) ) {
router.push('/403');
}
}

export { reloadAuthorized };
export default Authorized;

0 comments on commit 9a91abf

Please sign in to comment.