summaryrefslogtreecommitdiffstats
path: root/testapi/opnfv_testapi/common/check.py
diff options
context:
space:
mode:
Diffstat (limited to 'testapi/opnfv_testapi/common/check.py')
-rw-r--r--testapi/opnfv_testapi/common/check.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/testapi/opnfv_testapi/common/check.py b/testapi/opnfv_testapi/common/check.py
index 7f866dd..77b48f5 100644
--- a/testapi/opnfv_testapi/common/check.py
+++ b/testapi/opnfv_testapi/common/check.py
@@ -35,7 +35,7 @@ def is_authorized(method):
if type(query) is not dict:
query_data = query()
else:
- if self.json_args is None:
+ if self.json_args is None or 'name' not in self.json_args:
query_data = query
else:
query_data = self.json_args
@@ -47,13 +47,22 @@ def is_authorized(method):
return wrapper
-def is_allowed(method):
+def is_reource_tied(method):
@functools.wraps(method)
def wrapper(self, *args, **kwargs):
- if self.table == 'projects':
- query_data = {}
- query_data['project_name'] = kwargs.get('query')['name']
- data = yield dbapi.db_find_one('testcases', query_data)
+ query_data = {}
+ tied_map_tables = {
+ 'projects': ('testcases', 'project_name'),
+ 'pods': ('results', 'pod_name'),
+ 'testcases': ('results', 'case_name')
+ }
+ if self.table in tied_map_tables:
+ if method.__name__ == '_update':
+ if 'name' not in self.json_args:
+ ret = yield gen.coroutine(method)(self, *args, **kwargs)
+ raise gen.Return(ret)
+ query_data[tied_map_tables[self.table][1]] = kwargs.get('query')['name']
+ data = yield dbapi.db_find_one(tied_map_tables[self.table][0], query_data)
if data:
raises.Unauthorized(message.tied_with_resource())
ret = yield gen.coroutine(method)(self, *args, **kwargs)