def post(self): ''' Creates a common and corresponding activity. Then common is propagated to all trusted contacts. Errors are stored inside activity. ''' file = self.request.files['common'][0] if file: filebody = file["body"] filename = file['filename'] common = Common(title="New Common", path=filename, contentType=file["content_type"], authorKey=UserManager.getUser().key, author=UserManager.getUser().name, isFile=True) common.save() common.put_attachment(filebody, filename) common.save() self.create_owner_creation_activity(common, "publishes", "common") self.send_creation_to_contacts(CONTACT_PATH, common) logger.info("Common %s successfuly posted." % filename) self.return_json(common.toJson(), 201) else: self.return_failure("No common posted.", 400)
def add_three_commons_to_the_database_with_different_dates(step): file = open(TEST_COMMON) for i in range(1, 4): common = Common( title="Common 0%d" % i, author=world.browser.user.name, authorKey=world.browser.user.key, date=datetime.datetime(2011, 11, i), path="vimqrc.pdf", isMine=i != 3 ) common.save() common.put_attachment(file.read(), "vimqrc.pdf")
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)
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)
def and_5_commons(step, nbcommons, tag): file = open("./apps/commons/tests/vimqrc.pdf") for i in range(1, int(nbcommons) + 1): common = Common(title="Common 0%d" % i, author=world.user.name, authorKey=world.user.key, date=datetime.datetime(2011, 11, i), path="test.jpg", contentType="image/jpeg", isMine=True, tags=[tag]) common.save() common.put_attachment(file.read(), "vimqrc.pdf") common.save()
def post(self): ''' Creates a common and corresponding activity. Then common is propagated to all trusted contacts. Errors are stored inside activity. ''' filebody = self.request.body filename = self.get_argument("qqfile") try: tag = self.get_argument("tag") except: tag = "all" filetype = mimetypes.guess_type(filename)[0] or \ 'application/octet-stream' if filebody: common = Common(title="New Common", path=filename, contentType=filetype, authorKey=UserManager.getUser().key, author=UserManager.getUser().name, isMine=True, isFile=True, tags=[tag]) common.save() common.put_attachment(content=filebody, name=filename) common.save() self.create_owner_creation_activity(common, "publishes", "common") self.send_creation_to_contacts(CONTACT_PATH, common) logger.info("Common %s successfuly posted." % filename) self.return_json(common.toJson(), 201) else: self.return_failure("No common posted.", 400)
def post(self): ''' Creates a common and corresponding activity. Then common is propagated to all trusted contacts. Errors are stored inside activity. ''' filebody = self.request.body filename = self.get_argument("qqfile") try: tag = self.get_argument("tag") except: tag = "all" filetype = mimetypes.guess_type(filename)[0] or \ 'application/octet-stream' if filebody: common = Common( title="New Common", path=filename, contentType=filetype, authorKey=UserManager.getUser().key, author=UserManager.getUser().name, isMine=True, isFile=True, tags=[tag] ) common.save() common.put_attachment(content=filebody, name=filename) common.save() self.create_owner_creation_activity( common, "publishes", "common") self.send_creation_to_contacts(CONTACT_PATH, common) logger.info("Common %s successfuly posted." % filename) self.return_json(common.toJson(), 201) else: self.return_failure("No common posted.", 400)
def add_three_commons_to_the_database_with_different_dates(step): file = open(TEST_COMMON) for i in range(1, 4): common = Common(title="Common 0%d" % i, author=world.browser.user.name, authorKey=world.browser.user.key, date=datetime.datetime(2011, 11, i), path="vimqrc.pdf", isMine=i != 3) common.save() common.put_attachment(file.read(), "vimqrc.pdf")
def and_5_commons(step, nbcommons, tag): file = open("./apps/commons/tests/vimqrc.pdf") for i in range(1, int(nbcommons) + 1): common = Common( title = "Common 0%d" % i, author = world.user.name, authorKey = world.user.key, date = datetime.datetime(2011, 11, i), path = "test.jpg", contentType = "image/jpeg", isMine = True, tags = [tag] ) common.save() common.put_attachment(file.read(), "vimqrc.pdf") common.save()
def put(self, key): ''' Resend deletion of micropost 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"} ''' data = self.get_body_as_dict( expectedFields=["contactId", "activityId", "extra"]) if data: contactId = data["contactId"] activityId = data["activityId"] date = data["extra"] 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: user = UserManager.getUser() common = Common(authorKey=user.key, date=date_util.get_date_from_db_date(date)) info = "Attemp to resend a common deletion to contact: {}." logger.info(info.format(contact.name)) self.forward_to_contact(common, contact, activity, method="PUT") else: self.return_failure("Micropost not found", 404)
def post(self): ''' Creates a common and corresponding activity. Then common is propagated to all trusted contacts. Errors are stored inside activity. ''' file = self.request.files['common'][0] if file: filebody = file["body"] filename = file['filename'] common = Common( title="New Common", path=filename, contentType=file["content_type"], authorKey=UserManager.getUser().key, author=UserManager.getUser().name, isFile=True ) common.save() common.put_attachment(filebody, filename) common.save() self.create_owner_creation_activity( common, "publishes", "common") self.send_creation_to_contacts(CONTACT_PATH, common) logger.info("Common %s successfuly posted." % filename) self.return_json(common.toJson(), 201) else: self.return_failure("No common posted.", 400)