Esempio n. 1
0
 def validate_name(self, field):
     """
     如果名称已经有了,就不让重新加组
     :param field:
     :return:
     """
     if PermissionGroup.by_name(field.data) is not None:
         raise ValidationError("以存在同名权限组,不必重复添加")
Esempio n. 2
0
def edit_group(self, data):
    group = PermissionGroup.by_id(data.get("id"))
    group.name = data.get("name")
    group.description = data.get("description")
    try:
        self.db.add(group)
        self.db.commit()
        return msg(True, "保存成功")
    except exc.IntegrityError as e:
        return msg(False, str(e))
Esempio n. 3
0
def add_group(self, data):
    group = PermissionGroup(
        name=data.get("name"),
        description=data.get("description")
    )
    try:
        self.db.add(group)
        self.db.commit()
        return msg(True, '新增成功')
    except exc.IntegrityError as e:
        return msg(False, str(e))
Esempio n. 4
0
 def get(self, role_id):
     data, count = PermissionGroup.all()
     print(data)
     role = RoleModel.by_id(role_id)
     permissions = role.permission
     plist = list()
     for i in permissions:
         plist.append(i.id)
     self.render("passport/role/set_permission.html",
                 permissions=data,
                 role=role,
                 plist=plist)
Esempio n. 5
0
def add_permission(self, data):
    group = PermissionGroup.by_id(data.get('group_id'))
    permission = Permission(
        name=data.get('name'),
        handler=data.get('handler'),
        description=data.get("description")
    )
    group.permissions.append(permission)
    try:
        self.db.add(group)
        self.db.commit()
        return msg(True, "保存成功")
    except exc.IntegrityError as e:
        return msg(False, str(e))
Esempio n. 6
0
 async def get(self, group_id):
     form = EditPermissionGroupForm()
     data = PermissionGroupModel.by_id(group_id)
     self.render("passport/permission/edit_group.html",
                 form=form,
                 data=data)
Esempio n. 7
0
    async def get(self, *args, **kwargs):
        data, count = PermissionGroupModel.all()

        self.render("passport/permission/group_list.html",
                    data=data,
                    count=count)
Esempio n. 8
0
 def get_group(group_id):
     group = PermissionGroupModel.by_id(group_id)
     return group.name