コード例 #1
0
ファイル: handlers.py プロジェクト: DopeChicCity/newebe
    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"}
        '''
        common = CommonManager.get_common(key)
        idInfos = self.request.body

        ids = json_decode(idInfos)

        if common 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:
                info = "Attemp to resend a common to contact: {}."
                logger.info(info.format(contact.name))
                self.forward_to_contact(common, contact, activity)
        else:
            self.return_failure("Common not found", 404)
コード例 #2
0
ファイル: handlers.py プロジェクト: HeartbliT/IReVeAI
    def put(self):
        '''
        Delete common of which data are given inside request.
        Common 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:
                common = CommonManager.get_contact_common(
                    contact.key, data.get("date", ""))

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

                self.return_success("Deletion succeeds")

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

        else:
            self.return_failure("No data sent.", 405)
コード例 #3
0
ファイル: handlers.py プロジェクト: HeartbliT/IReVeAI
    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"}
        '''
        common = CommonManager.get_common(key)
        idInfos = self.request.body

        ids = json_decode(idInfos)

        if common 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:
                info = "Attemp to resend a common to contact: {}."
                logger.info(info.format(contact.name))
                self.forward_to_contact(common, contact, activity)
        else:
            self.return_failure("Common not found", 404)
コード例 #4
0
ファイル: handlers.py プロジェクト: DopeChicCity/newebe
    def put(self):
        '''
        Delete common of which data are given inside request.
        Common 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:
                common = CommonManager.get_contact_common(
                        contact.key, data.get("date", ""))

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

                self.return_success("Deletion succeeds")

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

        else:
            self.return_failure("No data sent.", 405)
コード例 #5
0
ファイル: steps.py プロジェクト: DopeChicCity/newebe
def ensure_that_common_date_is_ok_with_time_zone(step):
    world.date_common = world.commons[0]

    common_db = CommonManager.get_common(world.date_common["_id"])
    date = date_util.convert_utc_date_to_timezone(common_db.date)
    date = date_util.get_db_date_from_date(date)

    assert world.date_common["date"] == date
コード例 #6
0
ファイル: steps.py プロジェクト: HeartbliT/IReVeAI
def ensure_that_common_date_is_ok_with_time_zone(step):
    world.date_common = world.commons[0]

    common_db = CommonManager.get_common(world.date_common["_id"])
    date = date_util.convert_utc_date_to_timezone(common_db.date)
    date = date_util.get_db_date_from_date(date)

    assert world.date_common["date"] == date
コード例 #7
0
ファイル: handlers.py プロジェクト: HeartbliT/IReVeAI
 def get(self, id):
     '''
     Retrieves common corresponding to id. Returns a 404 response if
     common is not found.
     '''
     common = CommonManager.get_common(id)
     if common:
         self.on_common_found(common, id)
     else:
         self.return_failure("Common not found.", 404)
コード例 #8
0
ファイル: handlers.py プロジェクト: DopeChicCity/newebe
 def get(self, id):
     '''
     Retrieves common corresponding to id. Returns a 404 response if
     common is not found.
     '''
     common = CommonManager.get_common(id)
     if common:
         self.on_common_found(common, id)
     else:
         self.return_failure("Common not found.", 404)
コード例 #9
0
ファイル: steps.py プロジェクト: DopeChicCity/newebe
def and_one_activity_for_first_common_with_one_error_for_my_contact(step):
    author = world.browser.user
    world.contact = world.browser2.user.asContact()
    world.common = CommonManager.get_last_commons().first()

    world.activity = Activity(
        author=author.name,
        verb="posts",
        docType="common",
        docId=world.common._id,
    )
    world.activity.add_error(world.contact)
    world.activity.save()
コード例 #10
0
ファイル: steps.py プロジェクト: HeartbliT/IReVeAI
def and_i_add_one_deletion_activity_for_first_common_with_one_error(step):
    author = world.browser.user
    world.contact = world.browser2.user.asContact()
    world.common = CommonManager.get_last_commons().first()

    world.activity = Activity(author=author.name,
                              verb="deletes",
                              docType="common",
                              docId=world.common._id,
                              method="PUT")
    date = date_util.get_db_date_from_date(world.common.date)
    world.activity.add_error(world.contact, extra=date)
    world.activity.save()
コード例 #11
0
ファイル: steps.py プロジェクト: HeartbliT/IReVeAI
def and_one_activity_for_first_common_with_one_error_for_my_contact(step):
    author = world.browser.user
    world.contact = world.browser2.user.asContact()
    world.common = CommonManager.get_last_commons().first()

    world.activity = Activity(
        author=author.name,
        verb="posts",
        docType="common",
        docId=world.common._id,
    )
    world.activity.add_error(world.contact)
    world.activity.save()
コード例 #12
0
    def send_commons_to_contact(self, client, contact, now, date):
        '''
        Send pictures from last month to given contact.
        '''
        commons = CommonManager.get_owner_last_commons(
                startKey=date_util.get_db_date_from_date(now),
                endKey=date_util.get_db_date_from_date(date))

        for common in commons:
            if tags_match(common, contact):
                body = common.toJson(localized=False)

                client.post(contact, COMMON_PATH, body, self.onContactResponse)
コード例 #13
0
ファイル: steps.py プロジェクト: DopeChicCity/newebe
def and_i_add_one_deletion_activity_for_first_common_with_one_error(step):
    author = world.browser.user
    world.contact = world.browser2.user.asContact()
    world.common = CommonManager.get_last_commons().first()

    world.activity = Activity(
        author=author.name,
        verb="deletes",
        docType="common",
        docId=world.common._id,
        method="PUT"
    )
    date = date_util.get_db_date_from_date(world.common.date)
    world.activity.add_error(world.contact, extra=date)
    world.activity.save()
コード例 #14
0
ファイル: handlers.py プロジェクト: DopeChicCity/newebe
    def post(self):
        '''
        Extract common and file linked to the common from request, then
        creates a common in database for the contact who sends it. An
        activity is created too.

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

        data = self.get_body_as_dict(
            expectedFields=["title", "path", "contentType", "authorKey",
                             "author", "date"])

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

            if contact:
                date = date_util.get_date_from_db_date(data.get("date", ""))

                common = CommonManager.get_contact_common(
                            contact.key, data.get("date", ""))

                if not common:
                    common = Common(
                        _id=data.get("_id", ""),
                        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
                    )
                    common.save()

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

                logger.info("New common 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)
コード例 #15
0
ファイル: handlers.py プロジェクト: DopeChicCity/newebe
    def delete(self, id):
        '''
        Deletes common corresponding to id.
        '''
        common = CommonManager.get_common(id)
        if common:
            user = UserManager.getUser()

            if common.authorKey == user.key:
                self.create_owner_deletion_activity(
                        common, "deletes", "common")
                self.send_deletion_to_contacts("commons/contact/", common)

            common.delete()
            self.return_success("Common deleted.")
        else:
            self.return_failure("Common not found.", 404)
コード例 #16
0
ファイル: handlers.py プロジェクト: HeartbliT/IReVeAI
    def delete(self, id):
        '''
        Deletes common corresponding to id.
        '''
        common = CommonManager.get_common(id)
        if common:
            user = UserManager.getUser()

            if common.authorKey == user.key:
                self.create_owner_deletion_activity(common, "deletes",
                                                    "common")
                self.send_deletion_to_contacts("commons/contact/", common)

            common.delete()
            self.return_success("Common deleted.")
        else:
            self.return_failure("Common not found.", 404)
コード例 #17
0
ファイル: handlers.py プロジェクト: HeartbliT/IReVeAI
    def post(self):
        '''
        Extract common and file linked to the common from request, then
        creates a common in database for the contact who sends it. An
        activity is created too.

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

        data = self.get_body_as_dict(expectedFields=[
            "title", "path", "contentType", "authorKey", "author", "date"
        ])

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

            if contact:
                date = date_util.get_date_from_db_date(data.get("date", ""))

                common = CommonManager.get_contact_common(
                    contact.key, data.get("date", ""))

                if not common:
                    common = Common(_id=data.get("_id", ""),
                                    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)
                    common.save()

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

                logger.info("New common 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)
コード例 #18
0
ファイル: handlers.py プロジェクト: HeartbliT/IReVeAI
    def post(self):
        '''
        When a post request is sent, the newebe downloads full size version of
        common 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["common"]["date"]

            common = CommonManager.get_owner_last_commons(date).first()

            if common:
                self.on_common_found(common, id)
            else:
                logger.info("Common no more available.")
                self.return_failure("Common not found.", 404)
        else:
            logger.info("Contact unknown")
            self.return_failure("Common not found", 404)
コード例 #19
0
ファイル: handlers.py プロジェクト: DopeChicCity/newebe
    def post(self):
        '''
        When a post request is sent, the newebe downloads full size version of
        common 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["common"]["date"]

            common = CommonManager.get_owner_last_commons(date).first()

            if common:
                self.on_common_found(common, id)
            else:
                logger.info("Common no more available.")
                self.return_failure("Common not found.", 404)
        else:
            logger.info("Contact unknown")
            self.return_failure("Common not found", 404)
コード例 #20
0
ファイル: steps.py プロジェクト: DopeChicCity/newebe
def when_i_get_owner_commons_until_november_1(step):
    world.commons = CommonManager.get_owner_last_commons(
            "2011-11-01T23:59:00Z").all()
コード例 #21
0
ファイル: steps.py プロジェクト: HeartbliT/IReVeAI
def when_i_get_owner_commons_until_november_1(step):
    world.commons = CommonManager.get_owner_last_commons(
        "2011-11-01T23:59:00Z").all()
コード例 #22
0
ファイル: steps.py プロジェクト: DopeChicCity/newebe
def when_i_get_my_last_commons(step):
    world.commons = CommonManager.get_owner_last_commons().all()
コード例 #23
0
ファイル: steps.py プロジェクト: DopeChicCity/newebe
def when_i_get_first_from_its_id(step):
    world.common = CommonManager.get_common(world.commons[0]._id)
コード例 #24
0
ファイル: steps.py プロジェクト: DopeChicCity/newebe
def when_i_get_first_from_its_date_and_author(step):
    common = world.commons[0]
    world.common = CommonManager.get_contact_common(common.authorKey,
                                date_util.get_db_date_from_date(common.date))
コード例 #25
0
ファイル: steps.py プロジェクト: HeartbliT/IReVeAI
def clear_all_commons(step):
    commons = CommonManager.get_last_commons()
    while commons:
        for common in commons:
            common.delete()
        commons = CommonManager.get_last_commons()
コード例 #26
0
ファイル: steps.py プロジェクト: HeartbliT/IReVeAI
def when_i_get_first_from_its_id(step):
    world.common = CommonManager.get_common(world.commons[0]._id)
コード例 #27
0
ファイル: steps.py プロジェクト: HeartbliT/IReVeAI
def when_i_get_first_from_its_date_and_author(step):
    common = world.commons[0]
    world.common = CommonManager.get_contact_common(
        common.authorKey, date_util.get_db_date_from_date(common.date))
コード例 #28
0
ファイル: steps.py プロジェクト: DopeChicCity/newebe
def clear_all_commons(step):
    commons = CommonManager.get_last_commons()
    while commons:
        for common in commons:
            common.delete()
        commons = CommonManager.get_last_commons()
コード例 #29
0
ファイル: steps.py プロジェクト: HeartbliT/IReVeAI
def when_i_get_my_last_commons(step):
    world.commons = CommonManager.get_owner_last_commons().all()