From 772983d58e28848f3945eccd278adf8cbb01a262 Mon Sep 17 00:00:00 2001 From: Eddie Arrage Date: Thu, 31 May 2018 23:59:31 +0000 Subject: Add improvements to OVP directory and logo upload - Formatting changes to directory on home page based on OPNFV marketing - Updated branding guide link - Added test_id field to mongo applications collection to associate to approved results for directory - Set Test ID from user accounts with administrator role in Applications view - Provide file upload function for administrator to post company logos for OVP directory - Company logos are stored and served through tornado from cvp-cvpapi container rather than cvp-web JIRA: DOVETAIL-663 JIRA: DOVETAIL-664 Change-Id: I1226b42883afa2ea2eb5551e3836211abbb94b20 Signed-off-by: Eddie Arrage --- .../resources/application_handlers.py | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'cvp/opnfv_testapi/resources') diff --git a/cvp/opnfv_testapi/resources/application_handlers.py b/cvp/opnfv_testapi/resources/application_handlers.py index 144b2241..258c1aa2 100644 --- a/cvp/opnfv_testapi/resources/application_handlers.py +++ b/cvp/opnfv_testapi/resources/application_handlers.py @@ -30,6 +30,49 @@ class GenericApplicationHandler(handlers.GenericApiHandler): self.table_cls = application_models.Application +class ApplicationsLogoHandler(GenericApplicationHandler): + @web.asynchronous + @gen.coroutine + def post(self): + role = self.get_secure_cookie(auth_const.ROLE) + if role.find('administrator') == -1: + msg = 'Only administrator is allowed to upload logos' + self.finish_request({'code': '-1', 'msg': msg}) + return + + fileinfo = self.request.files['file'][0] + fname = fileinfo['filename'] + location = '3rd_party/static/testapi-ui/assets/img/' + fh = open(location + fname, 'w') + fh.write(fileinfo['body']) + msg = 'Successfully uploaded logo: ' + fname + resp = {'code': '1', 'msg': msg} + self.finish_request(resp) + + +class ApplicationsGetLogoHandler(GenericApplicationHandler): + def get(self, filename): + location = '3rd_party/static/testapi-ui/assets/img/' + filename + self.set_header('Content-Type', 'application/force-download') + self.set_header('Content-Disposition', + 'attachment; filename=%s' % filename) + try: + with open(location, "rb") as f: + try: + while True: + _buffer = f.read(4096) + if _buffer: + self.write(_buffer) + else: + f.close() + self.finish() + return + except Exception: + raise web.HTTPError(404) + except Exception: + raise web.HTTPError(500) + + class ApplicationsCLHandler(GenericApplicationHandler): @swagger.operation(nickname="queryApplications") @web.asynchronous -- cgit 1.2.3-korg