Merge "Add qtip job to pod zte-virtual6"
[releng.git] / utils / test / testapi / opnfv_testapi / handlers / user_handlers.py
1 from opnfv_testapi.common import constants
2 from opnfv_testapi.common import raises
3 from opnfv_testapi.common.config import CONF
4 from opnfv_testapi.handlers import base_handlers
5 from opnfv_testapi.models.user_models import User
6
7
8 class UserHandler(base_handlers.GenericApiHandler):
9     def __init__(self, application, request, **kwargs):
10         super(UserHandler, self).__init__(application, request, **kwargs)
11         self.table = 'users'
12         self.table_cls = User
13
14     def get(self):
15         if CONF.api_authenticate:
16             username = self.get_secure_cookie(constants.TESTAPI_ID)
17             if username:
18                 self._get_one(query={'user': username})
19             else:
20                 raises.Unauthorized('Unauthorized')
21         else:
22             self.finish_request(User('anonymous',
23                                      'anonymous@linuxfoundation.com',
24                                      'anonymous lf',
25                                      constants.TESTAPI_USERS).format())