summaryrefslogtreecommitdiffstats
path: root/cvp/opnfv_testapi/resources
diff options
context:
space:
mode:
authorEddie Arrage <eddie.arrage@huawei.com>2018-05-31 23:59:31 +0000
committerGeorg Kunz <georg.kunz@ericsson.com>2018-06-07 09:25:12 +0000
commit772983d58e28848f3945eccd278adf8cbb01a262 (patch)
treea07102184166227ae71c1e9272e331ee27c36acd /cvp/opnfv_testapi/resources
parentb37fe7b72a6b6b2ba63eb4f8761c91975344a14e (diff)
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 <eddie.arrage@huawei.com>
Diffstat (limited to 'cvp/opnfv_testapi/resources')
-rw-r--r--cvp/opnfv_testapi/resources/application_handlers.py43
1 files changed, 43 insertions, 0 deletions
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