def check_ifcread(request=None,**kwargs): print kwargs['id'] document = Document_mongo.objects.get(id=kwargs['id']) assignees=[] sub_label = request.session["rwlabel"] # current label of user requesting.. lm = LabelManager() rw = RWFM() doc_label = lm.getLabel(str(kwargs["id"])) # label of the document requested... print 'doc_label'+str(doc_label) check = rw.checkRead(sub_label,doc_label) testread = check["bool"] for user in document.assignee: assignees.append(user["id"]) #print assignees if request is not None and not ((document.is_public) or (request.user.id == str(document.user_id)) or (request.user.id in assignees)) and not testread: #print 'abc' raise ImmediateHttpResponse(response=http.HttpUnauthorized()) print sub_label["readers"] print doc_label["readers"] newsublabel = check["sublabel"] request.session["rwlabel"] = newsublabel # request.session["rwlabel"]["readers"] = list(set(sub_label["readers"]).intersection(set(doc_label["readers"]))) # print request.session["rwlabel"]["readers"] # request.session["rwlabel"]["writers"] = list(set(sub_label["writers"]).union(set(doc_label["writers"]))) print request.session["rwlabel"] return document
def MakeForkLabel(document,session): # databaseName = "dbpatterns" # connection = Connection() lm = LabelManager() rw = RWFM() # db = connection[databaseName] # rwlabel = db["rwlabel"] sublabel = session["rwlabel"] # r2 = session["rwlabel"]["readers"] # w = session["rwlabel"]["writers"] # just after creation of label rw.createObjLabel(sublabel,document["_id"]) # temp2 = { "doc_id" : document["_id"],"owner" : session["rwlabel"]["owner"],"readers": r2,"writers": w } # rwlabel.save(temp2) # connection.disconnect() return {"bool":True}
def MakeForkLabel(document, session): # databaseName = "dbpatterns" # connection = Connection() lm = LabelManager() rw = RWFM() # db = connection[databaseName] # rwlabel = db["rwlabel"] sublabel = session["rwlabel"] # r2 = session["rwlabel"]["readers"] # w = session["rwlabel"]["writers"] # just after creation of label rw.createObjLabel(sublabel, document["_id"]) # temp2 = { "doc_id" : document["_id"],"owner" : session["rwlabel"]["owner"],"readers": r2,"writers": w } # rwlabel.save(temp2) # connection.disconnect() return {"bool": True}
def MakeRWLabel(document, session): lm = LabelManager() rw = RWFM() print "MakeRWLabel" # databaseName = "dbpatterns" # connection = Connection() # db = connection[databaseName] # rwlabel = db["rwlabel"] sublabel = session["rwlabel"] r2 = session["rwlabel"]["readers"] w = session["rwlabel"]["writers"] # just after creation label temp2 = rw.createObjLabel(sublabel, document["_id"]) # temp2 = { "doc_id" : document["_id"],"owner" : session["rwlabel"]["owner"],"readers": r2,"writers": w } print temp2 if document["is_public"]: # readers = * readers = User.objects.all() r3 = [] for x in readers: r3.append(x.id) # label is made to public temp3 = { "doc_id": document["_id"], "owner": session["rwlabel"]["owner"], "readers": r3, "writers": w } if rw.checkDowngrade(sublabel, temp2, temp3): # rwlabel.save(temp3) lm.updatelabel(document["_id"], temp3) # connection.disconnect() return {"bool": True, "type": "public"} else: # rwlabel.save(temp2) # connection.disconnect() return {"bool": False, "type": "public"} else: # if private make readers same as readers of subject.. then check for assignee. #readers = owner #temp3 = {"doc_id" : document["_id"],"owner" : session["rwlabel"]["owner"],"readers": session["rwlabel"]["owner"],"writers": w} # rwlabel.save(temp2) # connection.disconnect() return {"bool": True, "type": "private"}
def MakeRWLabel(document,session): lm = LabelManager() rw = RWFM() print "MakeRWLabel" # databaseName = "dbpatterns" # connection = Connection() # db = connection[databaseName] # rwlabel = db["rwlabel"] sublabel = session["rwlabel"] r2 = session["rwlabel"]["readers"] w = session["rwlabel"]["writers"] # just after creation label print document['_id'].pk temp2 = rw.createObjLabel(sublabel,document["_id"].pk) # temp2 = { "doc_id" : document["_id"],"owner" : session["rwlabel"]["owner"],"readers": r2,"writers": w } print temp2 if document["is_public"]: # readers = * readers = User.objects.all() r3 = [] for x in readers: r3.append(x.id) # label is made to public temp3 = {"doc_id" : document["_id"].pk,"owner" : session["rwlabel"]["owner"],"readers": r3,"writers": w} if rw.checkDowngrade(sublabel,temp2,temp3): # rwlabel.save(temp3) lm.updateLabel(document["_id"].pk,temp3) # connection.disconnect() return {"bool": True, "type":"public"} else: # rwlabel.save(temp2) # connection.disconnect() return {"bool": False, "type":"public"} else: # if private make readers same as readers of subject.. then check for assignee. #readers = owner #temp3 = {"doc_id" : document["_id"],"owner" : session["rwlabel"]["owner"],"readers": session["rwlabel"]["owner"],"writers": w} # rwlabel.save(temp2) # connection.disconnect() return {"bool":True,"type":"private"}
def updatedoc(request,document_id,reader,can_rw): lm = LabelManager() rw = RWFM() print "updatedoc" # is_public = request.POST.get("is_public") # doc_res = request.POST.get("doc_res") # doc_id = (doc_res.split("/api/documents/")[1]).split("/")[0] doc_id = str(document_id) temp2 = lm.getLabel(doc_id) print "temp2" print temp2 #assignees = json.loads(request.POST.get("assignees")) #print assignees sublabel = request.session["rwlabel"] temp3 = {} r3 = [] w3 = temp2["writers"] if (str(can_rw)=="can_view"): r3.append(reader) if (str(can_rw)=="can_edit"): r3.append(reader) w3.append(reader) # # print is_public # # if is_public=="true": # print "public" # readers = User.objects.all() # for x in readers: # r3.append(x.id) # for x in assignees: # if x["permission"]=="can_edit": # w3.append(x["id"]) # temp3 = {"owner":temp2["owner"],"readers":r3,"writers":w3,"doc_id":doc_id} # else: # print "private" # for x in assignees: # if x["permission"]=="can_view": # r3.append(x["id"]) # if x["permission"]=="can_edit": # r3.append(x["id"]) # w3.append(x["id"]) r = [] readers = User.objects.all() for x in readers: r.append(x.id) if temp2["readers"] == r: temp3 = {"owner":temp2["owner"],"readers":list((set(r3).union(set(temp2["owner"])))),"writers":w3,"doc_id":doc_id} else: temp3 = {"owner":temp2["owner"],"readers":list((set(r3).union(set(temp2["readers"])))),"writers":w3,"doc_id":doc_id} print "temp3" print temp3 print temp2["readers"] if len(temp2["readers"]) > len(temp3["readers"]): print "upgrade" if rw.checkUpgrade(sublabel,temp2,temp3): print temp3 if lm.updateLabel(doc_id,temp3): request.session["rwlabel"] = sublabel # return HttpResponseRedirect("/") else: print "error" else: print "cant upgrade" return HttpResponseRedirect("/") elif len(temp2["readers"]) < len(temp3["readers"]): print "downgrade" if rw.checkDowngrade(sublabel,temp2,temp3): if lm.updateLabel(doc_id,temp3): request.session["rwlabel"] = sublabel # return HttpResponseRedirect("/") else: print "error" else: print 'cant downgrade' # return HttpResponseRedirect("/") #return HttpResponseRedirect("/rwlabel/napublic/") else: if lm.updateLabel(doc_id,temp3): print ("temp2['readers']==temp3[readers]") request.session["rwlabel"] = sublabel # return HttpResponseRedirect("/") else: print "error"
def updatedoc(request): lm = LabelManager() rw = RWFM() print "updatedoc" is_public = request.POST.get("is_public") doc_res = request.POST.get("doc_res") doc_id = (doc_res.split("/api/documents/")[1]).split("/")[0] doc_id = str(doc_id) temp2 = lm.getLabel(doc_id) print "temp2" print temp2 assignees = json.loads(request.POST.get("assignees")) print assignees sublabel = request.session["rwlabel"] temp3 = {} r3 = [] w3 = temp2["writers"] print is_public if is_public == "true": print "public" readers = User.objects.all() for x in readers: r3.append(x.id) for x in assignees: if x["permission"] == "can_edit": w3.append(x["id"]) temp3 = { "owner": temp2["owner"], "readers": r3, "writers": w3, "doc_id": doc_id } else: print "private" for x in assignees: if x["permission"] == "can_view": r3.append(x["id"]) if x["permission"] == "can_edit": r3.append(x["id"]) w3.append(x["id"]) r = [] readers = User.objects.all() for x in readers: r.append(x.id) if temp2["readers"] == r: temp3 = { "owner": temp2["owner"], "readers": list((set(r3).union(set(temp2["owner"])))), "writers": w3, "doc_id": doc_id } else: temp3 = { "owner": temp2["owner"], "readers": list((set(r3).union(set(temp2["readers"])))), "writers": w3, "doc_id": doc_id } print "temp3" print temp3 print temp2["readers"] if len(temp2["readers"]) > len(temp3["readers"]): print "upgrade" if rw.checkUpgrade(sublabel, temp2, temp3): print temp3 if lm.updatelabel(doc_id, temp3): request.session["rwlabel"] = sublabel return HttpResponseRedirect("/documents/" + doc_id + "/") else: print "error" else: # cant upgrade return HttpResponseRedirect("/rwlabel/naprivate/") elif len(temp2["readers"]) < len(temp3["readers"]): print "downgrade" if rw.checkDowngrade(sublabel, temp2, temp3): if lm.updatelabel(doc_id, temp3): request.session["rwlabel"] = sublabel return HttpResponseRedirect("/documents/" + doc_id + "/") else: print "error" else: # cant downgrade raise PermissionDenied #return HttpResponseRedirect("/rwlabel/napublic/") else: if lm.updatelabel(doc_id, temp3): request.session["rwlabel"] = sublabel return HttpResponseRedirect("/documents/" + doc_id + "/") else: print "error"