Ejemplo n.º 1
0
def index():
    Role.insert_roles()
    role = Role.query.filter_by(name='User').first()
    user = User.query.filter_by(role=role).all()
    for user1 in user:
        print user1.username
    return render_template('main/index.html')
Ejemplo n.º 2
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
     Role.insert_roles()
     self.client = self.app.test_client()
Ejemplo n.º 3
0
 def test_anonymous_user(self):
     Role.insert_roles()
     u = AnonymousUser()
     self.assertFalse(u.can(Permission.COMMENT))
     self.assertFalse(u.can(Permission.WRITE))
     self.assertFalse(u.can(Permission.FOLLOW))
     self.assertFalse(u.can(Permission.ADMIN))
     self.assertFalse(u.can(Permission.MODERATE))
Ejemplo n.º 4
0
 def test_user_role(self):
     Role.insert_roles()
     u = User(name='ose', password='******', email='*****@*****.**')
     self.assertTrue(u.can(Permission.COMMENT))
     self.assertTrue(u.can(Permission.WRITE))
     self.assertTrue(u.can(Permission.FOLLOW))
     self.assertFalse(u.can(Permission.ADMIN))
     self.assertFalse(u.can(Permission.MODERATE))
Ejemplo n.º 5
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()
Ejemplo n.º 6
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='您无法删除权限不小于自己的角色')
Ejemplo n.º 7
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='您无法为权限不小于自己的角色更名')
Ejemplo n.º 8
0
 def test_admin(self):
     Role.insert_roles()
     u = User(name='ose',
              password='******',
              email='*****@*****.**',
              id=1)
     self.assertTrue(u.can(Permission.COMMENT))
     self.assertTrue(u.can(Permission.WRITE))
     self.assertTrue(u.can(Permission.FOLLOW))
     self.assertTrue(u.can(Permission.ADMIN))
     self.assertTrue(u.can(Permission.MODERATE))
Ejemplo n.º 9
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='您无法为角色分配不小于自身的权限')
Ejemplo n.º 10
0
    def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.drop_all()
        db.create_all()
        db.session.commit()

        Role.insert_roles()
        User.insert_root_admin()

        self.client = self.app.test_client()
Ejemplo n.º 11
0
def initialize_instance():
    Admin.insert_admin(g.data['user'], g.data['password'])
    Domain(name='默认部员域').save()
    Role.new_role('成员', 0, [])
    Role.new_role('部长', 64, [
        'new_user', 'remove_user', 'rename_user', 'alloc_user', 'ls_user',
        'import_from_sheet'
    ])
    Role.new_role('总监', 4096, ['*'])
    with open('isinit.flag', 'w') as f:
        pass
    return trueReturn(msg="初始化完成")
Ejemplo n.º 12
0
def deploy():
    """Run deployment tasks."""
    upgrade()
    Role.insert_roles()
    User.insert_root_admin()
Ejemplo n.º 13
0
def new_role():
    Role.new_role(g.data['name'], g.data['permission'])
    return trueReturn()
Ejemplo n.º 14
0
def remove_role():
    Role.get_by_id(g.data['id']).delete()
    return trueReturn()
Ejemplo n.º 15
0
def new_role():
    if g.user.restrict_permission(g.data['permission']):
        Role.new_role(g.data['name'], g.data['permission'])
        return trueReturn()
    else:
        return falseReturn(msg='您无法新建权限不小于自己的角色')
Ejemplo n.º 16
0
def ls_role():
    return trueReturn({"roles": [i.get_base_info() for i in Role.objects()]})
Ejemplo n.º 17
0
def rename_role():
    Role.get_by_id(g.data['id']).rename(g.data['name'])
    return trueReturn()
Ejemplo n.º 18
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()
Ejemplo n.º 19
0
def deploy():
    """Run deployment tasks and prepare necessary data"""
    upgrade()
    Role.insert_roles()
    User.insert_root_admin()
Ejemplo n.º 20
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()