Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
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))
Exemplo n.º 6
0
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))