示例#1
0
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"}
示例#2
0
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"}
示例#3
0
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"
示例#4
0
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"