Esempio n. 1
0
def generate_tabs_and_tree(role_id=None, tenant_uid=None):
    permission_resources = auth.permission_resources(role_id, tenant_uid)
    root_resources = Resource.query \
        .filter(Resource.level == 1, Resource.enable == 1) \
        .order_by(Resource.order).all()

    permission_codes = get_permission_codes(
        permission_resources=permission_resources)
    menus_tree = get_menus_tree(root_resources=root_resources,
                                permission_codes=permission_codes)
    menus_tree = [menus for menus in menus_tree if menus.get('children')]
    permissions = get_permissions(permission_resources=permission_resources)
    tabs = get_tabs(permission_codes)
    return menus_tree, tabs, permissions
Esempio n. 2
0
def get_role(role_id):
    query = Role.query.filter(Role.id == role_id, Role.id != g.role_id)
    query_role = check_request(query).first_or_404()
    role = query_role.to_dict()
    if g.role_id != 1 and g.tenant_uid:
        permission_resources = auth.permission_resources(role_id, g.tenant_uid)
        ids = [resource.id for resource in permission_resources]
    else:
        permission_resources = db.session.query(Permission.resourceIntID) \
            .filter(Permission.roleIntID == role_id) \
            .all()
        ids = [resource[0] for resource in permission_resources]
    role['permissions'] = ids
    return jsonify(role)
Esempio n. 3
0
def validate_permissions(request_permissions):
    """
    Compare request permissions and default permissions
    :raise PermissionDenied if request permission not in default permissions
    """

    permission_resources = auth.permission_resources(g.role_id, g.tenant_uid)
    permission_ids = get_permission_code_or_id(permission_resources,
                                               return_type='id')
    no_permissions = [
        per_id for per_id in request_permissions
        if per_id not in permission_ids
    ]
    if no_permissions:
        raise PermissionDenied()
Esempio n. 4
0
def list_all_permissions():
    query = Resource.query
    if request.path.find('app') >= 0:
        # App permission
        query = query.filter(
            Resource.code.in_(
                ['device_manage', 'alert_manage', 'business_rules']))
        role_id = db.session.query(Role.id) \
            .filter(Role.roleName == u'超级应用', Role.roleType == 2,
                    Role.isShare == 1, Role.tenantID.is_(None)) \
            .first()
        role_id = role_id
    else:
        role_id = g.role_id
        query = query.filter_by(level=1)
    root_resources = query.order_by(Resource.order).all()

    permission_resources = auth.permission_resources(role_id, g.tenant_uid)
    permission_codes = get_permission_code_or_id(permission_resources,
                                                 return_type='code')
    permission_tree = get_permission_tree(root_resources=root_resources,
                                          permission_codes=permission_codes)
    return jsonify(permission_tree)