Пример #1
0
def alloc_user():
    for i in g.data['roles']:
        if not g.user.restrict_permission(Role.get_by_id(i).permission):
            return falseReturn(msg='您无法赋予他人权限不小于自己的角色')
        if not g.user.restrict_functions(Role.get_by_id(i).allow_functions):
            return falseReturn(msg='您无法赋予他人权能不在自己范围内的角色')
    u = User.get_by_id(g.data['id'])
    u.change_role(g.data['roles'])
    return trueReturn()
Пример #2
0
def rename_role():
    if g.user.restrict_permission(Role.get_by_id(g.data['id']).permission):
        if g.user.restrict_functions(
                Role.get_by_id(g.data['id']).allow_functions):
            Role.get_by_id(g.data['id']).rename(g.data['name'])
            return trueReturn()
        else:
            return falseReturn(msg='您无法为权能比自己多的角色更名')
    else:
        return falseReturn(msg='您无法为权限不小于自己的角色更名')
Пример #3
0
def remove_role():
    if g.user.restrict_permission(Role.get_by_id(g.data['id']).permission):
        if g.user.restrict_functions(
                Role.get_by_id(g.data['id']).allow_functions):
            Role.get_by_id(g.data['id']).delete()
            return trueReturn()
        else:
            return falseReturn(msg='您无法删除权能比自己多的角色')
    else:
        return falseReturn(msg='您无法删除权限不小于自己的角色')
Пример #4
0
def edit_role():
    if g.user.restrict_permission(g.data['permission']):
        if g.user.restrict_functions(g.data['functions']):
            Role.get_by_id(g.data['id']).modify_permission(
                g.data['permission'])
            Role.get_by_id(g.data['id']).modify_functions(g.data['functions'])
            return trueReturn()
        else:
            return falseReturn(msg='您无法为角色分配自己没有的权能')
    else:
        return falseReturn(msg='您无法为角色分配不小于自身的权限')
Пример #5
0
 def change_role(self, roles):
     for p, i in enumerate(roles):
         if not isinstance(i, Role):
             roles[p] = Role.get_by_id(i)
     self.roles = roles
     return self.save()
Пример #6
0
def edit_role():
    Role.get_by_id(g.data['id']).modify_permission(g.data['permission'])
    Role.get_by_id(g.data['id']).modify_functions(g.data['functions'])
    return trueReturn()
Пример #7
0
def rename_role():
    Role.get_by_id(g.data['id']).rename(g.data['name'])
    return trueReturn()
Пример #8
0
def remove_role():
    Role.get_by_id(g.data['id']).delete()
    return trueReturn()