Example #1
0
    def post(self, key):
        '''
        Resend post with *key* as key to the contact given in the posted
        JSON. Corresponding activity ID is given inside the posted json.
        Here is the format : {"contactId":"data","activityId":"data"}
        '''

        picture = PictureManager.get_picture(key)
        idInfos = self.request.body

        ids = json_decode(idInfos)

        if picture and idInfos:

            contactId = ids["contactId"]
            activityId = ids["activityId"]

            contact = ContactManager.getTrustedContact(contactId)
            activity = ActivityManager.get_activity(activityId)

            if not contact:
                self.return_failure("Contact not found", 404)
            elif not activity:
                self.return_failure("Activity not found", 404)
            else:           
                logger.info("Attemp to resend a picture to contact: {}.".format(
                    contact.name))
                self.forward_to_contact(picture, contact, activity)
        else:
            self.return_failure("Picture not found", 404)
Example #2
0
    def put(self):
        '''
        Delete picture of which data are given inside request.
        Picture is found with contact key and creation date.

        If author is not inside trusted contacts, the request is rejected.
        '''

        data = self.get_body_as_dict()

        if data:
            contact = ContactManager.getTrustedContact(
                    data.get("authorKey", ""))
            
            if contact:
                picture = PictureManager.get_contact_picture(
                        contact.key, data.get("date", ""))

                if picture:
                    self.create_deletion_activity(contact, 
                            picture, "deletes", "picture")
                    picture.delete()

                self.return_success("Deletion succeeds")

            else:
                self.return_failure("Author is not trusted.", 400)      


        else:
            self.return_failure("No data sent.", 405)
Example #3
0
def ensure_that_picture_date_is_ok_with_time_zone(step):
    world.date_picture = world.pictures[0]

    picture_db = PictureManager.get_picture(world.date_picture["_id"])
    date = date_util.convert_utc_date_to_timezone(picture_db.date)
    date = date_util.get_db_date_from_date(date)

    assert world.date_picture["date"] == date
Example #4
0
    def get(self, id):
        '''
        Retrieves picture corresponding to id. Returns a 404 response if
        picture is not found.
        '''

        picture = PictureManager.get_picture(id)
        if picture:
            self.on_picture_found(picture, id)
        else:
            self.return_failure("Picture not found.", 404)
Example #5
0
def and_one_activity_for_first_picture_with_one_error_for_my_contact(step):
    author = world.browser.user
    world.contact = world.browser2.user.asContact()
    world.picture = PictureManager.get_last_pictures().first()
    
    world.activity = Activity(
        author = author.name,
        verb = "posts",
        docType = "picture",
        docId = world.picture._id,
    )
    world.activity.add_error(world.contact)
    world.activity.save()
Example #6
0
    def post(self):
        '''
        Extract picture and file linked to the picture from request, then 
        creates a picture in database for the contact who sends it. An 
        activity is created too.

        If author is not inside trusted contacts, the request is rejected.
        '''

        file = self.request.files['picture'][0]
        data = json_decode(self.get_argument("json"))

        if file and data:
            contact = ContactManager.getTrustedContact(
                    data.get("authorKey", ""))
            
            if contact:
                date = date_util.get_date_from_db_date(data.get("date", ""))

                picture = PictureManager.get_contact_picture(
                            contact.key, data.get("date", ""))

                if not picture:
                    picture = Picture(
                        title = data.get("title", ""),
                        path = data.get("path", ""),
                        contentType = data.get("contentType", ""),
                        authorKey = data.get("authorKey", ""),
                        author = data.get("author", ""),
                        tags = contact.tags,
                        date = date,
                        isMine = False,
                        isFile = False
                    )
                    picture.save()
                    picture.put_attachment(content=file["body"], 
                                           name="th_" + file['filename'])
                    picture.save()

                    self.create_creation_activity(contact,
                            picture, "publishes", "picture")

                logger.info("New picture from %s" % contact.name)
                self.return_success("Creation succeeds", 201)

            else:
                self.return_failure("Author is not trusted.", 400)                
        else:
            self.return_failure("No data sent.", 405)
Example #7
0
def and_i_add_one_deletion_activity_for_first_picture_with_one_error(step):
    author = world.browser.user
    world.contact = world.browser2.user.asContact()
    world.picture = PictureManager.get_last_pictures().first()
    
    world.activity = Activity(
        author = author.name,
        verb = "deletes",
        docType = "picture",
        docId = world.picture._id,
        method = "PUT"
    )
    date = date_util.get_db_date_from_date(world.picture.date)
    world.activity.add_error(world.contact, extra=date)
    world.activity.save()
Example #8
0
    def send_pictures_to_contact(self, client, contact, now, date):
        '''
        Send pictures from last month to given contact.
        '''

        pictures = PictureManager.get_owner_last_pictures(
                startKey=date_util.get_db_date_from_date(now), 
                endKey=date_util.get_db_date_from_date(date))

        for picture in pictures:
            client.post_files(contact, PICTURE_PATH, 
                    { "json": str(picture.toJson(localized=False)) },
                    [("picture", str(picture.path), 
                            picture.fetch_attachment("th_" + picture.path))]
                    , self.onContactResponse)
Example #9
0
    def delete(self, id):
        '''
        Deletes picture corresponding to id.
        '''

        picture = PictureManager.get_picture(id)
        if picture:
            user = UserManager.getUser()
            
            if picture.authorKey == user.key:
                self.create_owner_deletion_activity(
                        picture, "deletes", "picture")
                self.send_deletion_to_contacts("pictures/contact/", picture)
          
            picture.delete()
            self.return_success("Picture deleted.")
        else:
            self.return_failure("Picture not found.", 404)
Example #10
0
    def convert(self, data):
        '''
        Expect to have an attachments field in given dict. When dict has some
        attachments, it retrieves corresponding docs and convert them in
        attachment dict (same as usual dict with less fields).
        Then attach docs are returned inside an array.
        '''

        docs = []
        self.fileDocs = []
        for doc in data.get("attachments", []):
            if doc["type"] == "Note":
                note = NoteManager.get_note(doc["id"])
                docs.append(note.toDictForAttachment())
            elif doc["type"] == "Picture":
                picture = PictureManager.get_picture(doc["id"])
                docs.append(picture.toDictForAttachment())
                self.fileDocs.append(picture)

        return docs
Example #11
0
    def post(self):
        '''
        When a post request is sent, the newebe downloads full size version of 
        picture specified in the request from the contact also specified in 
        the request. 
        '''

        data = self.get_body_as_dict()

        contact = ContactManager.getTrustedContact(data["contact"]["key"])

        if contact:
            date = data["picture"]["date"]
     
            picture = PictureManager.get_owner_last_pictures(date).first()

            if picture:
                self.on_picture_found(picture, id)
            else:
                logger.info("Picture no more available.")
                self.return_failure("Picture not found.", 404)
        else:
            logger.info("Contact unknown")
            self.return_failure("Picture not found", 404)
Example #12
0
def when_i_get_owner_pictures_until_november_1(step):
    world.pictures = PictureManager.get_owner_last_pictures(
            "2011-11-01T23:59:00Z").all()
Example #13
0
def when_i_get_my_last_pictures(step):    
    world.pictures = PictureManager.get_owner_last_pictures().all()
Example #14
0
def when_i_get_first_from_its_date_and_author(step):
    picture = world.pictures[0]    
    world.picture = PictureManager.get_contact_picture(picture.authorKey, 
                                date_util.get_db_date_from_date(picture.date))
Example #15
0
def when_i_get_first_from_its_id(step):
    world.picture = PictureManager.get_picture(world.pictures[0]._id)
Example #16
0
def clear_all_pictures(step):
    pictures = PictureManager.get_last_pictures()
    while pictures:
        for picture in pictures:
            picture.delete()
        pictures = PictureManager.get_last_pictures()