コード例 #1
0
ファイル: Psinques.py プロジェクト: kradecki/psinque
    def acceptrequest(self):

        try:
            psinque = self._getPsinqueByKey()
        except AjaxError:
            self.displayMessage("templates/Message_PsinqueNotFound.html")
            return

        contactIn = self._getContactForIncoming(psinque)
        contactOut = self._getContactForOutgoing(psinque)

        if contactOut is None:
            contactOut = Contact(
                parent=self.userProfile,
                friend=contactIn.parent(),
                friendsContact=contactIn,
                group=self.userProfile.defaultGroup,
                persona=self.userProfile.defaultPersona,
            )
            contactOut.put()
            contactIn.friendsContact = contactOut

        if not contactOut.outgoing is None:
            raise AjaxError("There already is a psinque from this user")

        existingPsinque = contactIn.incoming
        if not existingPsinque is None:
            if existingPsinque.private:
                psinque.delete()
                raise AjaxError("There already is a private psinque from this user")
            else:
                existingPsinque.delete()

        contactIn.incoming = psinque
        contactIn.status = "private"
        contactIn.persona = contactIn.parent().defaultPersona
        contactIn.put()

        contactOut.outgoing = psinque
        contactOut.status = "private"
        contactOut.persona = contactOut.parent().defaultPersona
        contactOut.put()

        psinque.status = "established"
        psinque.persona = psinque.fromUser.defaultPersona
        psinque.put()

        Notifications.notifyAcceptedRequest(psinque)

        if self.request.get("email") == "true":
            self.displayMessage(
                "templates/Message_Accepted.html", templateVariables={"friendsName": contactOut.displayName}
            )
        else:
            self._sendNewContact(contactOut)
コード例 #2
0
ファイル: Personas.py プロジェクト: kradecki/psinque
    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()
コード例 #3
0
ファイル: Psinques.py プロジェクト: kradecki/psinque
    def changegroup(self):

        try:
            contact = Contact.get(self.getRequiredParameter("contact"))
        except datastore_errors.BadKeyError:
            raise AjaxError("Contact does not exist")

        # oldGroup = contact.group

        try:
            persona = Group.get(self.getRequiredParameter("persona"))
        except datastore_errors.BadKeyError:
            raise AjaxError("Group does not exist")

        # First we check if this psinque is not already asigned to that group
        contact.group = group
        contact.put()

        # oldGroupSize = Contact.all(keys_only = True). \
        # filter("group =", oldGroup). \
        # count(1)
        # if oldGroupSize == 0:
        # olfGroup.delete()

        self.sendJsonOK()
コード例 #4
0
ファイル: CardDAV.py プロジェクト: kradecki/psinque
def getVCard(contactID):
    
    # This is 3 Datastore fetches: Contact, Psinque, Persona
    logging.info("Getting vCard for Contact " + contactID)
    contact = Contact.get(contactID)
    persona = contact.incoming.persona
    if persona.vcardNeedsUpdating:
        reallyGenerateVCard(persona)
    return [persona.vcard, persona.vcardMTime, persona.vcardMD5]
コード例 #5
0
ファイル: Psinques.py プロジェクト: kradecki/psinque
    def _getContact(self):

        # Find contact on this end
        contact = Contact.get(self.getRequiredParameter("key"))
        if contact is None:
            raise AjaxError("Contact not found")

        if contact.parent().key() != self.userProfile.key():
            raise AjaxError("You cannot modify contacts that do not belong to you")

        return contact
コード例 #6
0
ファイル: CardDAV.py プロジェクト: kradecki/psinque
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
コード例 #7
0
ファイル: Psinques.py プロジェクト: kradecki/psinque
    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,
                },
            )
コード例 #8
0
ファイル: Psinques.py プロジェクト: kradecki/psinque
    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]
コード例 #9
0
ファイル: DataManipulation.py プロジェクト: kradecki/psinque
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")
コード例 #10
0
ファイル: Psinques.py プロジェクト: kradecki/psinque
    def changepersona(self):

        try:
            contact = Contact.get(self.getRequiredParameter("contact"))
        except datastore_errors.BadKeyError:
            raise AjaxError("Contact does not exist")

        try:
            persona = Persona.get(self.getRequiredParameter("persona"))
        except datastore_errors.BadKeyError:
            raise AjaxError("Persona does not exist")

        if contact.persona == persona:

            self.sendJsonOK()
            return

        contact.persona = persona
        contact.put()

        if persona.public:

            if contact.outgoing:
                contact.outgoing.private = False
                contact.outgoing.put()
                Notifications.notifyDowngradedPsinque(contact.outgoing)

            if contact.friendsContact:
                contact.friendsContact.status = "public"
                contact.friendsContact.put()

        if contact.outgoing:
            contact.outgoing.persona = persona
            contact.outgoing.put()

        self.sendJsonOK()
コード例 #11
0
ファイル: Personas.py プロジェクト: kradecki/psinque
    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!")
コード例 #12
0
ファイル: DataManipulation.py プロジェクト: kradecki/psinque
def contactExists(userProfile, friendsProfile):

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