예제 #1
0
    def post(self):
        '''
        Updates contact from sent data (contact object at JSON format).
        Sets its status to Trusted.
        '''
        data = self.get_body_as_dict(expectedFields=["url", "key", "name"])

        if data:
            url = data["url"]
            slug = slugify(url)

            contact = ContactManager.getContact(slug)

            if contact:
                contact.state = STATE_TRUSTED
                contact.key = data["key"]
                contact.name = data["name"]
                contact.save()
                self.return_success("Contact trusted.")
            
            else:
                self.return_failure("No contact for this slug.", 400)
             
        else:
            self.return_failure("Sent data are incorrects.", 400)
예제 #2
0
    def post(self, slug):
        '''
        When post request is received, contact of which slug is equal to
        slug is retrieved. If its state is Pending or Error, the contact
        request is send again.
        '''

        logger = logging.getLogger("newebe.contact")

        self.contact = ContactManager.getContact(slug)
        owner = UserManager.getUser()

        if self.contact and self.contact.url != owner.url:
            try:
                data = owner.asContact().toJson()

                client = ContactClient()
                client.post(self.contact, "contacts/request/", data, 
                            self.on_contact_response)

            except Exception:
                import traceback
                logger.error("Error on adding contact:\n %s" % 
                        traceback.format_exc())

                self.contact.state = STATE_ERROR
                self.contact.save()

            self.return_one_document(self.contact)
        else:
            self.return_failure("Contact does not exist", 404)
예제 #3
0
    def get(self, slug):
        '''
        Retrieves contact corresponding to slug at JSON format.
        '''

        contact = ContactManager.getContact(slug)

        self.return_one_document_or_404(contact, "Contact does not exist.")
예제 #4
0
    def delete(self, slug):
        '''
        Deletes contact corresponding to slug.
        '''

        contact = ContactManager.getContact(slug)
        if contact:
            contact.delete()
            return self.return_success("Contact has been deleted.")
        else:
            self.return_failure("Contact does not exist.")
예제 #5
0
    def put(self, slug):
        '''
        Grab tags sent inside request to set is on contact matching slug.
        '''

        contact = ContactManager.getContact(slug)    
        data = self.get_body_as_dict(["tags"])
        
        if contact:
            if data:
                contact.tags = data["tags"]
                contact.save()
            else:
                self.return_failure("No tags were sent")
        else:
            self.return_failure("Contact to modify does not exist.", 404)
예제 #6
0
    def post(self):
        '''
        Create a new contact from sent data (contact object at JSON format).
        Sets its status to Wait For Approval
        '''
        data = self.get_body_as_dict(expectedFields=["url"])

        if data:
            url = data["url"]
            owner = UserManager.getUser()

            if owner.url != url:
                slug = slugify(url)

                contact = ContactManager.getContact(slug)
                owner = UserManager.getUser()

                if contact is None:
                    contact = Contact(
                        name = data["name"], 
                        url = url,
                        slug = slug,
                        key = data["key"],
                        state = STATE_WAIT_APPROVAL,
                        requestDate = datetime.datetime.utcnow(),
                        description = data["description"]
                    )
                    contact.save()

                contact.state = STATE_WAIT_APPROVAL
                contact.save()

                self.return_success("Request received.")

            else:
                self.return_failure("Contact and owner have same url.")

        else:
            self.return_failure("Sent data are incorrects.")
예제 #7
0
    def put(self, slug):
        '''
        Confirm contact request.
        '''

        self.contact = ContactManager.getContact(slug)
        if self.contact:
            self.contact.state = STATE_TRUSTED
            self.contact.save()

            user = UserManager.getUser()
            data = user.asContact().toJson(localized=False)

            try:
                 client = ContactClient()
                 client.post(self.contact, "contacts/confirm/", data, 
                             self.on_contact_response)
            except:
                self.contact.state = STATE_ERROR
                self.contact.save()
                self.return_failure("Error occurs while confirming contact.")
        else:
            self.return_failure("Contact to confirm does not exist.")
예제 #8
0
def checks_that_default_contact_data_are_updated(step):
    contact = ContactManager.getContact(slugify(u"http://default:8000/"))
    assert "http://default:8010/" == contact.url
    assert "default contact 2" == contact.name
    assert "desc 2" == contact.description
예제 #9
0
def change_default_contact_data_through_handlers(step):
    contact = ContactManager.getContact(slugify(u"http://default:8000/"))
    contact.description = "desc 2"
    contact.url = u"http://default:8010/"
    contact.name = "default contact 2"
    world.browser.put("contacts/update-profile/", contact.toJson())
예제 #10
0
def get_contact_with_slug(step, slug):
    world.contact = ContactManager.getContact(slug)