def changeOwnershipOfOwnable(self, currentuser, owner, fqon, newowner): "this is used for things like itentypes and tagtypes, not for g/a/l. Also for tags?" otype = gettype(fqon) oq = otype.objects(basic__fqin=fqon) try: ownable = oq.get() except: doabort("BAD_REQ", "No such ownable %s %s" % (otype.__name__, fqon)) authorize_ownable_owner(False, self, currentuser, owner, ownable) # try: # newowner=self.getUserForFqin(currentuser, newownerfqin) # except: # #make sure target exists. # doabort('BAD_REQ', "No such newowner %s" % newownerfqin) newownerfqin = newowner.basic.fqin permit( self.isMemberOfMembable(currentuser, newowner, ownable), " Possible new owner %s must be member of ownable %s %s" % (newownerfqin, ptype.__name__, fqpn), ) try: oldownerfqpn = ownable.owner # memb=MembableEmbedded(mtype=User.classname, fqmn=newowner.basic.fqin, readwrite=True, pname = newowner.presentable_name()) memb = is_me_in_pble(newowner, ownable.members) # oq.filter(members__fqmn=newowner.basic.fqin).update_one(safe_update=True, set__owner = newowner.basic.fqin, set__members_S=memb) ownable.update(safe_update=True, set__owner=newowner.basic.fqin) except: doabort( "BAD_REQ", "Failed changing owner from %s to %s for ownable %s %s" % (oldownerfqpn, newowner.basic.fqin, otype.__name__, fqon), ) newowner.reload() ownable.reload() return newowner, ownable
def removePostable(self, currentuser, fqpn): "currentuser removes a postable" rempostable = self.getPostable(currentuser, fqpn) authorize_ownable_owner(False, self, currentuser, None, rempostable) # BUG: group deletion is very fraught. Once someone else is in there # the semantics go crazy. Will have to work on refcounting here. And # then get refcounting to come in rempostable.delete(safe=True) return OK
def removeMemberableFromMembable(self, currentuser, fqpn, memberablefqin): "remove a u/g/a from a g/a/l" ptype = gettype(fqpn) mtype = gettype(memberablefqin) membableq = ptype.objects(basic__fqin=fqpn) memberableq = mtype.objects(basic__fqin=memberablefqin) try: membable = membableq.get() except: doabort("BAD_REQ", "No such membable %s" % fqpn) # Bug: this is currentuser for now authorize_ownable_owner(False, self, currentuser, None, membable) try: membableq.update(safe_update=True, pull__members__fqmn=memberablefqin) except: doabort( "BAD_REQ", "Failed removing memberable %s %s from postable %s %s" % (mtype.__name__, memberablefqin, ptype.__name__, fqpn), ) return OK
def removeMemberableFromPostable(self, currentuser, fqpn, memberablefqin): "remove a u/g/a from a g/a/l" ptype = gettype(fqpn) mtype = gettype(memberablefqin) postableq = ptype.objects(basic__fqin=fqpn) memberableq = mtype.objects(basic__fqin=memberablefqin) try: postable = postableq.get() except: doabort("BAD_REQ", "No such group %s" % fqpn) # Bug shouldnt this have memberable? authorize_ownable_owner(False, self, currentuser, None, postable) try: memberableq.update(safe_update=True, pull__postablesin__fqpn=postable.basic.fqin) # buf not sure how removing embedded doc works, if at all postableq.update(safe_update=True, pull__members__fqmn=memberablefqin) except: doabort( "BAD_REQ", "Failed removing memberable %s %s from postable %s %s" % (mtype.__name__, memberablefqin, ptype.__name__, fqpn), ) return OK