server/comments: fix privileges

This commit is contained in:
rr- 2016-06-11 17:35:41 +02:00
parent 5090e3f6c9
commit b5aa3e75c4
3 changed files with 4 additions and 4 deletions

View file

@ -39,7 +39,7 @@ class CommentDetailApi(BaseApi):
def put(self, ctx, comment_id): def put(self, ctx, comment_id):
comment = comments.get_comment_by_id(comment_id) comment = comments.get_comment_by_id(comment_id)
infix = 'self' if ctx.user.user_id == comment.user_id else 'any' infix = 'own' if ctx.user.user_id == comment.user_id else 'any'
text = ctx.get_param_as_string('text', required=True) text = ctx.get_param_as_string('text', required=True)
auth.verify_privilege(ctx.user, 'comments:edit:%s' % infix) auth.verify_privilege(ctx.user, 'comments:edit:%s' % infix)
comment.last_edit_time = datetime.datetime.now() comment.last_edit_time = datetime.datetime.now()
@ -49,7 +49,7 @@ class CommentDetailApi(BaseApi):
def delete(self, ctx, comment_id): def delete(self, ctx, comment_id):
comment = comments.get_comment_by_id(comment_id) comment = comments.get_comment_by_id(comment_id)
infix = 'self' if ctx.user.user_id == comment.user_id else 'any' infix = 'own' if ctx.user.user_id == comment.user_id else 'any'
auth.verify_privilege(ctx.user, 'comments:delete:%s' % infix) auth.verify_privilege(ctx.user, 'comments:delete:%s' % infix)
ctx.session.delete(comment) ctx.session.delete(comment)
ctx.session.commit() ctx.session.commit()

View file

@ -7,7 +7,7 @@ from szurubooru.func import util, comments
def test_ctx(config_injector, context_factory, user_factory, comment_factory): def test_ctx(config_injector, context_factory, user_factory, comment_factory):
config_injector({ config_injector({
'privileges': { 'privileges': {
'comments:delete:self': db.User.RANK_REGULAR, 'comments:delete:own': db.User.RANK_REGULAR,
'comments:delete:any': db.User.RANK_MODERATOR, 'comments:delete:any': db.User.RANK_MODERATOR,
}, },
}) })

View file

@ -10,7 +10,7 @@ def test_ctx(
'data_dir': str(tmpdir), 'data_dir': str(tmpdir),
'data_url': 'http://example.com', 'data_url': 'http://example.com',
'privileges': { 'privileges': {
'comments:edit:self': db.User.RANK_REGULAR, 'comments:edit:own': db.User.RANK_REGULAR,
'comments:edit:any': db.User.RANK_MODERATOR, 'comments:edit:any': db.User.RANK_MODERATOR,
'users:edit:any:email': db.User.RANK_MODERATOR, 'users:edit:any:email': db.User.RANK_MODERATOR,
}, },