summaryrefslogtreecommitdiffstats
path: root/testapi/opnfv_testapi/common
diff options
context:
space:
mode:
authorthuva4 <tharma.thuva@gmail.com>2018-02-22 09:57:30 +0530
committerthuva4 <tharma.thuva@gmail.com>2018-02-22 09:59:11 +0530
commit269a45a223c0b67972f3fe249fd2bbe2747dd70f (patch)
tree31a4aab84be4589f1eea9852835c90e81d56d066 /testapi/opnfv_testapi/common
parent86f8a2036521e9401d8c9431e4b6412878e6d94f (diff)
prevent the delete/update for projects
Prevent user from deleting or updating projects which are associated with testcases JIRA: RELENG-335 JIRA: RELENG-336 Change-Id: Ic0a8841a4632329f4b58aeb97cb93a91bacc2b06 Signed-off-by: thuva4 <tharma.thuva@gmail.com>
Diffstat (limited to 'testapi/opnfv_testapi/common')
-rw-r--r--testapi/opnfv_testapi/common/check.py14
-rw-r--r--testapi/opnfv_testapi/common/message.py4
2 files changed, 18 insertions, 0 deletions
diff --git a/testapi/opnfv_testapi/common/check.py b/testapi/opnfv_testapi/common/check.py
index 1a66dd7..7f866dd 100644
--- a/testapi/opnfv_testapi/common/check.py
+++ b/testapi/opnfv_testapi/common/check.py
@@ -47,6 +47,20 @@ def is_authorized(method):
return wrapper
+def is_allowed(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)
+ if data:
+ raises.Unauthorized(message.tied_with_resource())
+ ret = yield gen.coroutine(method)(self, *args, **kwargs)
+ raise gen.Return(ret)
+ return wrapper
+
+
def valid_token(method):
@functools.wraps(method)
def wrapper(self, *args, **kwargs):
diff --git a/testapi/opnfv_testapi/common/message.py b/testapi/opnfv_testapi/common/message.py
index b92b7f0..7c62894 100644
--- a/testapi/opnfv_testapi/common/message.py
+++ b/testapi/opnfv_testapi/common/message.py
@@ -64,3 +64,7 @@ def must_int(name):
def no_permission():
return 'You do not have permission to perform this action'
+
+
+def tied_with_resource():
+ return 'Selected resource is associated with other resources'