Пример #1
0
 def build_json_user_resource_tree(usr):
     json_res = {}
     perm_type = PermissionType.INHERITED if inherit_groups_perms else PermissionType.DIRECT
     services = ResourceService.all(models.Service, db_session=db)
     # add service-types so they are ordered and listed if no service of that type was defined
     for svc_type in sorted(SERVICE_TYPE_DICT):
         json_res[svc_type] = {}
     for svc in services:
         svc_perms = uu.get_user_service_permissions(
             user=usr,
             service=svc,
             request=request,
             inherit_groups_permissions=inherit_groups_perms,
             resolve_groups_permissions=resolve_groups_perms)
         res_perms_dict = uu.get_user_service_resources_permissions_dict(
             user=usr,
             service=svc,
             request=request,
             inherit_groups_permissions=inherit_groups_perms,
             resolve_groups_permissions=resolve_groups_perms)
         # always allow admin to view full resource tree, unless explicitly requested to be filtered
         # otherwise (non-admin), only add details if there is at least one resource permission (any level)
         if (is_admin and not filtered_perms) or (svc_perms
                                                  or res_perms_dict):
             json_res[svc.type][
                 svc.resource_name] = format_service_resources(
                     svc,
                     db_session=db,
                     service_perms=svc_perms,
                     resources_perms_dict=res_perms_dict,
                     permission_type=perm_type,
                     show_all_children=False,
                     show_private_url=False,
                 )
     return json_res
Пример #2
0
def get_group_resources(group, db_session):
    # type: (models.Group, Session) -> JSON
    """
    Get formatted JSON body describing all service resources the ``group`` as permissions on.
    """
    json_response = {}
    for svc in list(ResourceService.all(models.Service,
                                        db_session=db_session)):
        svc_perms = get_group_service_permissions(group=group,
                                                  service=svc,
                                                  db_session=db_session)
        svc_name = str(svc.resource_name)
        svc_type = str(svc.type)
        if svc_type not in json_response:
            json_response[svc_type] = {}
        res_perm_dict = get_group_service_resources_permissions_dict(
            group=group, service=svc, db_session=db_session)
        json_response[svc_type][svc_name] = format_service_resources(
            svc,
            db_session=db_session,
            service_perms=svc_perms,
            resources_perms_dict=res_perm_dict,
            permission_type=PermissionType.APPLIED,
            show_all_children=False,
            show_private_url=False,
        )
    return json_response