Ejemplo n.º 1
0
    def removepersona(self):
        
        try:
            persona = Persona.get(self.getRequiredParameter('key'))

        except datastore_errors.BadKeyError:
            raise AjaxError("Persona not found")
            
        # Check for errors
        if persona.name == "Public":  # cannot remove the public persona
            raise AjaxError("Cannot remove the public persona")
        if persona.name == "Default":  # cannot remove the default persona
            raise AjaxError("Cannot remove the default private persona")

        # Get all contacts that use this persona and assign them the default persona
        contacts = Contact.all(). \
                           ancestor(self.userProfile). \
                           filter("persona =", persona)
        defaultPersona = self._getPersonaByName("Default")
        for contact in contacts:
            contact.persona = defaultPersona
            contact.put()

        # Remove all children individual permits
        individualPermits = IndividualPermit.all().ancestor(persona)
        for individualPermit in individualPermits:
            individualPermit.delete()
        persona.delete()  # and the persona itself

        self.sendJsonOK()
Ejemplo n.º 2
0
def friendList(userProfile, groupName):
    
    friendList = []

    group = Group.all(). \
                  ancestor(userProfile). \
                  filter("name =", groupName). \
                  get()
    
    contacts = Contact.all(). \
                       ancestor(userProfile). \
                       filter("group =", group)
    
    for contact in contacts:
        friendList.append(str(contact.key()) + ".vcf")
        
    return friendList
Ejemplo n.º 3
0
    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,
                },
            )
Ejemplo n.º 4
0
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")
Ejemplo n.º 5
0
    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]
Ejemplo n.º 6
0
def contactExists(userProfile, friendsProfile):

    return Contact.all(). \
                   ancestor(userProfile). \
                   filter("friend =", friendsProfile). \
                   get()