Пример #1
0
def getHTML5Info(payload, req):
    if "url" not in payload:
        return UR.prepare_response({}, 1, "missing url !")
    url = payload["url"].partition("#")[0].rstrip(
        "/"
    )  # remove hash part of the URL by default, as well as trailing slash.
    #TODO: use optional argument id_ensemble to disambiguate if provided.
    sources_info = M.HTML5Info.objects.filter(url=url)
    ownerships = M.Ownership.objects.select_related(
        "source", "ensemble",
        "folder").filter(source__html5info__in=sources_info, deleted=False)
    if not ownerships.exists():
        return UR.prepare_response({}, 1, "this URL is not recognized: ")

    output = {
        "files":
        UR.qs2dict(ownerships, annotations.__NAMES["files2"], "ID"),
        "ensembles":
        UR.qs2dict(ownerships, annotations.__NAMES["ensembles2"], "ID"),
        "folders":
        UR.qs2dict(ownerships, annotations.__NAMES["folders2"], "ID"),
    }
    for i in output["ensembles"]:
        if not (output["ensembles"][i]["allow_guest"]
                or auth.isMember(UR.getUserId(req), i)):
            return UR.prepare_response(
                {}, 1,
                "not allowed: guest access isn't allowed for this file.")
    return UR.prepare_response(output)
Пример #2
0
def getCommentLabels(payload, req): 
    uid = UR.getUserId(req)
    if "file" in payload: #access by file
        id_source = payload["file"]
        o = M.Membership.objects.filter(ensemble__in=M.Ensemble.objects.filter(ownership__in=M.Ownership.objects.filter(source__id=id_source))).filter(user__id=uid, deleted=False)
        if len(o)>0 and o[0].admin: #for now, simply restrict to admin level            
            output = {}
            lc =  M.LabelCategory.objects.filter(ensemble = o[0].ensemble) 
            output["labelcategories"] =  UR.qs2dict(lc)
            comments = M.Comment.objects.filter(location__source__id=id_source, deleted=False, moderated=False)
            output["commentlabels"] = UR.qs2dict(M.CommentLabel.objects.filter(category__in=lc, comment__in=comments, grader__id=uid))
            return UR.prepare_response(output)     
    return UR.prepare_response({}, 1, "NOT ALLOWED")
Пример #3
0
def getCommentLabels(payload, req): 
    uid = UR.getUserId(req)
    if "file" in payload: #access by file
        id_source = payload["file"]
        o = M.Membership.objects.filter(ensemble__in=M.Ensemble.objects.filter(ownership__in=M.Ownership.objects.filter(source__id=id_source))).filter(user__id=uid, deleted=False)
        if len(o)>0 and o[0].admin: #for now, simply restrict to admin level            
            output = {}
            lc =  M.LabelCategory.objects.filter(ensemble = o[0].ensemble) 
            output["labelcategories"] =  UR.qs2dict(lc)
            comments = M.Comment.objects.filter(location__source__id=id_source, deleted=False, moderated=False)
            output["commentlabels"] = UR.qs2dict(M.CommentLabel.objects.filter(category__in=lc, comment__in=comments, grader__id=uid))
            output["labelcategorycaptions"] = UR.qs2dict(M.LabelCategoryCaption.objects.filter(category__in=lc))
            return UR.prepare_response(output)     
    return UR.prepare_response({}, 1, "NOT ALLOWED")
Пример #4
0
def getHTML5Info(payload, req):
    if "url" not in payload: 
        return UR.prepare_response({}, 1, "missing url !")
    url = payload["url"].partition("#")[0] #remove hash part of the URL by default. 
    #TODO: use optional argument id_ensemble to disambiguate if provided. 
    sources_info = M.HTML5Info.objects.filter(url=url)
    ownerships =  M.Ownership.objects.select_related("source", "ensemble", "folder").filter(source__html5info__in=sources_info, deleted=False)
    output = {
         "files": UR.qs2dict(ownerships, annotations.__NAMES["files2"] , "ID"),
         "ensembles": UR.qs2dict(ownerships, annotations.__NAMES["ensembles2"] , "ID") ,
         "folders": UR.qs2dict(ownerships, annotations.__NAMES["folders2"] , "ID") ,
         }    
    for i in output["ensembles"]: 
        if  not (output["ensembles"][i]["allow_guest"] or  auth.isMember(UR.getUserId(req), i)): 
            return  UR.prepare_response({}, 1, "not allowed: guest access isn't allowed for this file.")
    return UR.prepare_response(output)
Пример #5
0
def generate_latest(*t_args): 
    from django.db.models import Max
    latestCtime = M.Comment.objects.all().aggregate(Max("ctime"))["ctime__max"]
    latestNotif = M.Notification.objects.get(type="richpdf")
    sources = UR.qs2dict(M.Comment.objects.select_related("location").filter(type=3, ctime__gt=latestNotif.atime),{"ID": "location.source_id"} ,"ID" )
    for s in sources:
        process_file(s)
    latestNotif.atime = latestCtime
    latestNotif.save()
Пример #6
0
def getSectionsInfo(payload, req): 
    uid = UR.getUserId(req)
    if "id_ensemble" not in payload: 
        return UR.prepare_response({}, 1, "MISSING id_ensemble")
    id_ensemble = payload["id_ensemble"]
    if auth.canGetSectionsInfo(uid, id_ensemble):  
        m = M.Membership.objects.filter(user__id=uid, ensemble__id=id_ensemble, deleted=False)
        output={"sections": UR.qs2dict(m[0].ensemble.section_set.all())};
        return UR.prepare_response(output)
    return UR.prepare_response({}, 1, "NOT ALLOWED")