def _getPsinqueByKey(self): psinqueKey = self.getRequiredParameter("key") psinque = Psinque.get(psinqueKey) if psinque is None: raise AjaxError("Psinque not found.") return psinque
def requestprivate(self): contact = self._getContact() existingPsinque = Psinque.all(keys_only=True).ancestor(contact).filter("private =", True).get() if not existingPsinque is None: raise AjaxError("Request has already been sent.") self._addRequestToUpgrade(contact, contact.friend) self.sendJsonOK()
def sendContent(self, templateName, activeEntry = "", templateVariables = None): if self.user: try: getattr(self, "userProfile") except AttributeError: if not self.getUserProfile(): return if not self.userProfile.active: email = self.userProfile.emails.get().itemValue invitation = Invitation.all().filter("email =", email).get() if not invitation is None: invitation.status = "used" invitation.put() self.userProfile.active = True self.userProfile.put() else: self.restrictedAccess() return notificationCount = Psinque.all(keys_only = True). \ filter("fromUser ="******"status =", "pending"). \ count() menuentries = [ MenuEntry("profile/view", "Profile"), MenuEntry("personas/view", "Personas"), MenuEntry("psinques/view", "Psinques"), MenuEntry("settings/view", "Settings"), ] if activeEntry != "": for entry in menuentries: if entry.title == activeEntry: entry.entryclass = "active" # mark menu item as active if templateVariables: allTemplateVariables = dict(templateVariables.items() + self.getUserVariables().items() + { 'menuentries': menuentries, 'notificationCount': notificationCount }.items()) else: allTemplateVariables = dict(self.getUserVariables().items() + {'menuentries': menuentries}.items()) else: allTemplateVariables = templateVariables template = jinja_environment.get_template(templateName) self.response.out.write(template.render(allTemplateVariables))
def _addRequestToUpgrade(self, contact, friendsProfile): if contact.incoming.private: raise AjaxError("You already have access to private data") # We need to share our own private data first if contact.persona.public: contact.persona = self.userProfile.defaultPersona contact.status = "pending" contact.put() newPsinque = Psinque( parent=contact, fromUser=friendsProfile, private=True, persona=friendsProfile.defaultPersona, status="pending", ) newPsinque.put() Notifications.notifyPendingPsinque(newPsinque)
def addincoming(self): contact = self._getContact() if contact.incoming: raise AjaxError("Incoming psinque already exists.") friendsProfle = contact.friendsContact.parent() newPsinque = Psinque( parent=contact, fromUser=friendsProfle, private=True, persona=friendsProfle.defaultPersona, status="established", ) newPsinque.put() contact.incoming = newPsinque contact.put() contact.friendsContact.outgoing = newPsinque contact.friendsContact.put() self._sendNewContact(contact)
def _addPublicPsinque(self, friendsProfile): contact = contactExists(self.userProfile, friendsProfile) if contact is None: contactExisted = False contact = Contact( parent=self.userProfile, friend=friendsProfile, group=self.userProfile.defaultGroup, persona=self.userProfile.publicPersona, ) contact.put() friendsContact = Contact.all().ancestor(friendsProfile).filter("friend =", self.userProfile).get() if not friendsContact is None: persona = friendsContact.persona if not persona.public: contact.status = "private" else: persona = friendsProfile.publicPersona newPsinque = Psinque( parent=contact, fromUser=friendsProfile, private=False, persona=persona, status="established" ) newPsinque.put() if not friendsContact is None: if friendsContact.incoming: contact.outgoing = friendsContact.incoming friendsContact.outgoing = newPsinque friendsContact.put() contact.incoming = newPsinque contact.put() return [contactExisted, contact, newPsinque]
def view(self): if self.getUserProfile(): offset = self.request.get("offset") if not offset: offset = 0 else: offset = int(offset) currentCursor = self.request.get("cursor") # Pending decisions pendingPsinques = Psinque.all().filter("fromUser ="******"status =", "pending") pendingList = [{"name": x.parent().persona.displayName, "key": str(x.key())} for x in pendingPsinques] # List of contacts contactQuery = Contact.all().ancestor(self.userProfile).order("creationTime") count = contactQuery.count(1000) if currentCursor: contactQuery.with_cursor(currentCursor) # start from the previous position contacts = contactQuery.fetch(limit=10) if len(contacts) == 10: isThereMore = offset + 10 < count else: isThereMore = False personaList = {persona.key(): persona.name for persona in self.userProfile.personas.fetch(100)} groupList = {group.key(): group.name for group in self.userProfile.groups.fetch(100)} self.sendContent( "templates/Psinques.html", activeEntry="Psinques", templateVariables={ "offset": offset, "isThereMore": (offset + len(contacts) < count), "count": count, "nextCursor": contactQuery.cursor(), "contacts": contacts, "pendings": pendingList, "groups": groupList, "personas": personaList, }, )
def deleteProfile(userProfileKey): userProfile = UserProfile.get(userProfileKey) for e in CardDAVLogin.all().ancestor(userProfile): e.delete() for e in IndividualPermit.all().ancestor(userProfile): e.delete() for e in Persona.all().ancestor(userProfile): e.delete() for e in Psinque.all().ancestor(userProfile): e.delete() for e in Contact.all().ancestor(userProfile): e.delete() for e in Group.all().ancestor(userProfile): e.delete() for e in UserAddress.all().ancestor(userProfile): e.delete() for e in UserEmail.all().ancestor(userProfile): e.delete() for e in UserIM.all().ancestor(userProfile): e.delete() for e in UserPhoneNumber.all().ancestor(userProfile): e.delete() for e in UserPhoto.all().ancestor(userProfile): e.image.delete() e.delete() for e in UserNickname.all().ancestor(userProfile): e.delete() for e in UserCompany.all().ancestor(userProfile): e.delete() for e in UserWebpage.all().ancestor(userProfile): e.delete() if not userProfile.userSettings is None: userProfile.userSettings.delete() userProfile.delete() logging.info("User profile deleted")
def get(self, personaKey): self.user = users.get_current_user() if not self.getUserProfile(): self.sendJsonError("User profile not found") try: persona = Persona.get(personaKey) friendsProfile = persona.parent() if not contactExists(self.userProfile, friendsProfile) is None: self.sendJsonError("Person already in contacts.") return existingPsinque = Psinque.all(keys_only = True).ancestor(self.userProfile).filter("fromUser ="******"An incoming psinque from this person already exists") return newPsinque = Psinque(parent = self.userProfile, fromUser = friendsProfile, status = "established", private = not persona.public, persona = persona) newPsinque.put() # Contact on user's side if persona.public: status = "public" else: status = "private" contact = Contact(parent = self.userProfile, incoming = newPsinque, friend = friendsProfile, group = self.userProfile.defaultGroup, status = status, persona = self.userProfile.publicPersona) contact.put() # Contact on user's friend's side friendsContact = Contact(parent = friendsProfile, outgoing = newPsinque, friend = self.userProfile, friendsContact = contact, group = friendsProfile.defaultGroup, status = status, persona = persona) friendsContact.put() contact.friendsContact = friendsContact contact.put() self.displayMessage("templates/Message_Success.html", templateVariables = { 'message': 'You have successfully added a new contact to your contact list', }) except datastore_errors.BadKeyError: self.sendJsonError("Persona not found!")
def _getPsinqueFrom(self, userProfile): return Psinque.all(keys_only=True).ancestor(self.userProfile).filter("fromUser =", userProfile).get()