def saveNote(payload, req): uid = UR.getUserId(req) if not auth.canAnnotate(uid, payload["id_ensemble"]): return UR.prepare_response({}, 1, "NOT ALLOWED") payload["id_author"] = uid retval = {} a = annotations.addNote(payload) if len(a) == 0: return UR.prepare_response({}, 2, "DUPLICATE") tms = {} for mark in payload["marks"]: tm = M.ThreadMark() m_types = [c[0] for c in tm.TYPES if c[1]==mark] if len(m_types): #old clients may return types we don't have in DB so ignore them tm.type = m_types[0] tm.user_id = uid tm.comment=a[0] tm.location_id=tm.comment.location_id tm.save() tms[tm.id] = UR.model2dict(tm) retval["locations"], html5 = annotations.getLocation(a[0].location_id) if (html5 is not None): retval["html5locations"]=html5 retval["comments"] = {} retval["tags"] = {} for annotation in a: retval["comments"].update(annotations.getComment(annotation.id, uid)) retval["tags"].update(annotations.getTagsByComment(annotation.id)) retval["threadmarks"] = tms return UR.prepare_response(retval)
def saveNote(payload, req): uid = UR.getUserId(req) if not auth.canAnnotate(uid, payload["id_ensemble"]): return UR.prepare_response({}, 1, "NOT ALLOWED") payload["id_author"] = uid retval = {} a = annotations.addNote(payload) if len(a) == 0: return UR.prepare_response({}, 2, "DUPLICATE") tms = {} for mark in payload["marks"]: tm = M.ThreadMark() m_types = [c[0] for c in tm.TYPES if c[1] == mark] if len( m_types ): #old clients may return types we don't have in DB so ignore them tm.type = m_types[0] tm.user_id = uid tm.comment = a[0] tm.location_id = tm.comment.location_id tm.save() tms[tm.id] = UR.model2dict(tm) retval["locations"], html5 = annotations.getLocation(a[0].location_id) if (html5 is not None): retval["html5locations"] = html5 retval["comments"] = {} retval["tags"] = {} for annotation in a: retval["comments"].update(annotations.getComment(annotation.id, uid)) retval["tags"].update(annotations.getTagsByComment(annotation.id)) retval["threadmarks"] = tms return UR.prepare_response(retval)
def editNote(payload, req): uid = UR.getUserId(req) if not auth.canEdit(uid, payload["id_comment"]): return UR.prepare_response({}, 1, "NOT ALLOWED") else: annotations.editNote(payload) #no need to worry about threadmarks: they can't be changed from an "edit-mode" editor return UR.prepare_response({"comments": annotations.getComment(payload["id_comment"], uid)})
def approveNote(payload, req): uid = UR.getUserId(req) id_comment = payload["id_comment"] if not auth.canApprove(uid,id_comment ): return UR.prepare_response({}, 1, "NOT ALLOWED") else: annotations.approveNote(uid, payload); p = {"comments":annotations.getComment(id_comment,uid) } return UR.prepare_response(p) annotations.addApproveHistory(uid, payload)
def markNote(payload, req): uid = UR.getUserId(req) id_comment = payload["id_comment"] if not auth.canMark(uid,id_comment ): return UR.prepare_response({}, 1, "NOT ALLOWED") else: annotations.markNote(uid, payload); comments = annotations.getComment(id_comment,uid) p = {"locations":annotations.getLocation(comments[int(id_comment)]["ID_location"]), "marks": annotations.getMark(uid, payload), "comments": comments} return UR.prepare_response(p)
def editNote(payload, req): uid = UR.getUserId(req) if not auth.canEdit(uid, payload["id_comment"]): return UR.prepare_response({}, 1, "NOT ALLOWED") else: annotations.editNote(payload) #for mark in payload["marks"]: # annotations.markNote(uid, {"action": payload["marks"][mark], "id_comment": payload["id_comment"]}) return UR.prepare_response({"comments": annotations.getComment(payload["id_comment"], uid), "marks": annotations.getMark(uid,{"id_comment": payload["id_comment"]}) })
def editNote(payload, req): uid = UR.getUserId(req) if not auth.canEdit(uid, payload["id_comment"]): return UR.prepare_response({}, 1, "NOT ALLOWED") else: edited_loc = annotations.editNote(payload) tags = {} tags.update(annotations.getTagsByComment(payload["id_comment"])) #no need to worry about threadmarks: they can't be changed from an "edit-mode" editor retval = {"comments": [annotations.getComment(payload["id_comment"], uid)], "tags": tags, "cid": payload["id_comment"]} if not edited_loc == None: retval["edit_location"] = edited_loc return UR.prepare_response(retval)
def get_comment_info(payload, req): id = int(payload["id"]) uid = UR.getUserId(req); #SACHA TODO: check I'm allowed to know this retval={} comments = annotations.getComment(id, uid) id_location = comments[id]["ID_location"] retval["comments"] = {id: {"ID": id, "ID_location": id_location}} #share only what's needed #print retval["comments"] retval["locations"] , retval["html5locations"] = annotations.getLocation( id_location) if "org" in payload: annotations.logDirectURL(uid, id, payload["org"]) return UR.prepare_response(retval)
def editNote(payload, req): uid = UR.getUserId(req) if not auth.canEdit(uid, payload["id_comment"]): return UR.prepare_response({}, 1, "NOT ALLOWED") else: annotations.editNote(payload) #for mark in payload["marks"]: # annotations.markNote(uid, {"action": payload["marks"][mark], "id_comment": payload["id_comment"]}) return UR.prepare_response({ "comments": annotations.getComment(payload["id_comment"], uid), "marks": annotations.getMark(uid, {"id_comment": payload["id_comment"]}) })
def saveNote(payload, req): uid = UR.getUserId(req) if not auth.canAnnotate(uid, payload["id_ensemble"]): return UR.prepare_response({}, 1, "NOT ALLOWED") payload["id_author"] = uid retval = {} a = annotations.addNote(payload) #for mark in payload["marks"]: # annotations.markNote(uid, {"action": payload["marks"][mark], "id_comment": a["id_comment"]}) if "id_location" in a: retval["locations"] = annotations.getLocation(a["id_location"]) retval["comments"] = annotations.getComment(a["id_comment"], uid) retval["marks"] = annotations.getMark(uid, {"id_comment": a["id_comment"]}) return UR.prepare_response(retval)
def saveNote(payload, req): uid = UR.getUserId(req) if not auth.canAnnotate(uid, payload["id_ensemble"]): return UR.prepare_response({}, 1, "NOT ALLOWED") payload["id_author"] = uid retval = {} a = annotations.addNote(payload) #for mark in payload["marks"]: # annotations.markNote(uid, {"action": payload["marks"][mark], "id_comment": a["id_comment"]}) if "id_location" in a: retval["locations"] = annotations.getLocation(a["id_location"]) retval["comments"] = annotations.getComment(a["id_comment"], uid) retval["marks"] = annotations.getMark(uid,{"id_comment": a["id_comment"]}) return UR.prepare_response(retval)
def editNote(payload, req): uid = UR.getUserId(req) if not auth.canEdit(uid, payload["id_comment"]): return UR.prepare_response({}, 1, "NOT ALLOWED") else: edited_loc = annotations.editNote(payload) tags = {} tags.update(annotations.getTagsByComment(payload["id_comment"])) #no need to worry about threadmarks: they can't be changed from an "edit-mode" editor retval = { "comments": [annotations.getComment(payload["id_comment"], uid)], "tags": tags, "cid": payload["id_comment"] } if not edited_loc == None: retval["edit_location"] = edited_loc return UR.prepare_response(retval)
def promote_location_by_copy(P, req): uid = UR.getUserId(req) if not auth.canAdministrateLocation(uid, P["id_location"]): return UR.prepare_response({}, 1, "NOT ALLOWED") location_ids, comment_ids = annotations.promoteLocationByCopy(P["id_location"]) retval = {} retval["comments"] = {} for cid in comment_ids: retval["comments"].update(annotations.getComment(cid, uid)) retval["locations"] = {} retval["html5locations"] = {} for lid in location_ids: locations, html5locations = annotations.getLocation(lid) retval["locations"].update(locations) if not html5locations: retval["html5locations"].update(html5locations) # clear out html5locations if none exist if retval["html5locations"]: del retval["html5locations"] return UR.prepare_response( retval )
def saveNote(payload, req): uid = UR.getUserId(req) if not auth.canAnnotate(uid, payload["id_ensemble"]): return UR.prepare_response({}, 1, "NOT ALLOWED") payload["id_author"] = uid retval = {} a = annotations.addNote(payload) tms = {} for mark in payload["marks"]: tm = M.ThreadMark() m_types = [c[0] for c in tm.TYPES if c[1]==mark] if len(m_types): #old clients may return types we don't have in DB so ignore them tm.type = m_types[0] tm.user_id = uid tm.comment=a tm.location_id=a.location_id tm.save() tms[tm.id] = UR.model2dict(tm) retval["locations"] = annotations.getLocation(a.location_id) retval["comments"] = annotations.getComment(a.id, uid) retval["threadmarks"] = tms return UR.prepare_response(retval)
def promote_location_by_copy(P, req): uid = UR.getUserId(req) if not auth.canAdministrateLocation(uid, P["id_location"]): return UR.prepare_response({}, 1, "NOT ALLOWED") location_ids, comment_ids = annotations.promoteLocationByCopy( P["id_location"]) retval = {} retval["comments"] = {} for cid in comment_ids: retval["comments"].update(annotations.getComment(cid, uid)) retval["locations"] = {} retval["html5locations"] = {} for lid in location_ids: locations, html5locations = annotations.getLocation(lid) retval["locations"].update(locations) if not html5locations: retval["html5locations"].update(html5locations) # clear out html5locations if none exist if retval["html5locations"]: del retval["html5locations"] return UR.prepare_response(retval)