Skip to content

Commit

Permalink
fix: comment list and dashboard add admin check
Browse files Browse the repository at this point in the history
  • Loading branch information
lizheming committed Dec 3, 2020
1 parent ec2d3a7 commit 5438a9c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/admin/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const createRouter = function(config) {
const PrivateRoute = Comp => props => {
// 检查用户登录状态
const user = useSelector(state => state.user);
if (!user || !user.email) {
if (!user || !user.email || !user.type !== 'administrator') {
return (location.href = '/ui/login');
}
return React.createElement(Comp, props);
Expand Down
31 changes: 17 additions & 14 deletions packages/server/src/logic/comment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
const Base = require('./base');
module.exports = class extends Base {
async __before() {
await super.__before();

const {type, path} = this.get();
if(this.isGet && (type !== 'list' || path)) {
return;
}

const {userInfo} = this.ctx.state;
if(think.isEmpty(userInfo)) {
return this.ctx.throw(401);
}
if(userInfo.type !== 'administrator') {
return this.ctx.throw(403);
}
}

getAction() {
const {type} = this.get();
switch(type) {
Expand Down Expand Up @@ -56,18 +73,4 @@ module.exports = class extends Base {
break;
}
}

putAction() {
const {userInfo} = this.ctx.state;
if(userInfo.type !== 'administrator') {
return this.fail();
}
}

deleteAction() {
const {userInfo} = this.ctx.state;
if(userInfo.type !== 'administrator') {
return this.fail();
}
}
}

0 comments on commit 5438a9c

Please sign in to comment.