aboutsummaryrefslogtreecommitdiffstats
path: root/keystone-moon/keystone/contrib
diff options
context:
space:
mode:
authorWuKong <rebirthmonkey@gmail.com>2015-08-10 14:28:27 +0200
committerWuKong <rebirthmonkey@gmail.com>2015-08-10 14:28:27 +0200
commit67c5b73910f5fc437429c356978081b252a59480 (patch)
tree42357eb328f6ad366a42ab3f2af68b545bb153ae /keystone-moon/keystone/contrib
parentb7666a6b98b4f935f0eb95826aa43610521ed6dc (diff)
review code
Change-Id: Ie3be0aa22331803a9e2ef8837f8637bb762ae720 Signed-off-by: WuKong <rebirthmonkey@gmail.com>
Diffstat (limited to 'keystone-moon/keystone/contrib')
-rw-r--r--keystone-moon/keystone/contrib/moon/backends/sql.py26
-rw-r--r--keystone-moon/keystone/contrib/moon/controllers.py49
-rw-r--r--keystone-moon/keystone/contrib/moon/core.py285
3 files changed, 177 insertions, 183 deletions
diff --git a/keystone-moon/keystone/contrib/moon/backends/sql.py b/keystone-moon/keystone/contrib/moon/backends/sql.py
index 5ceb5c5b..7a75af39 100644
--- a/keystone-moon/keystone/contrib/moon/backends/sql.py
+++ b/keystone-moon/keystone/contrib/moon/backends/sql.py
@@ -877,6 +877,13 @@ class IntraExtensionConnector(IntraExtensionDriver):
# Getter and Setter for sub_meta_rule
+ def get_aggregation_algorithm_dict(self, intra_extension_id):
+ with sql.transaction() as session:
+ query = session.query(AggregationAlgorithm)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
+ ref = query.first()
+ return {ref.id: ref.aggregation_algorithm}
+
def set_aggregation_algorithm_dict(self, intra_extension_id, aggregation_algorithm_id, aggregation_algorithm_dict):
with sql.transaction() as session:
query = session.query(AggregationAlgorithm)
@@ -898,19 +905,12 @@ class IntraExtensionConnector(IntraExtensionDriver):
session.flush()
return self.get_aggregation_algorithm_dict(intra_extension_id)
- def get_aggregation_algorithm_dict(self, intra_extension_id):
- with sql.transaction() as session:
- query = session.query(AggregationAlgorithm)
- query = query.filter_by(intra_extension_id=intra_extension_id)
- ref = query.first()
- return {ref.id: ref.aggregation_algorithm}
-
- def del_aggregation_algorithm(self, intra_extension_id, aggregation_algorithm_id):
- with sql.transaction() as session:
- query = session.query(AggregationAlgorithm)
- query = query.filter_by(intra_extension_id=intra_extension_id, id=aggregation_algorithm_id)
- ref = query.first()
- session.delete(ref)
+ # def del_aggregation_algorithm(self, intra_extension_id, aggregation_algorithm_id):
+ # with sql.transaction() as session:
+ # query = session.query(AggregationAlgorithm)
+ # query = query.filter_by(intra_extension_id=intra_extension_id, id=aggregation_algorithm_id)
+ # ref = query.first()
+ # session.delete(ref)
# Getter and Setter for sub_meta_rule
diff --git a/keystone-moon/keystone/contrib/moon/controllers.py b/keystone-moon/keystone/contrib/moon/controllers.py
index 46590892..8a950e7a 100644
--- a/keystone-moon/keystone/contrib/moon/controllers.py
+++ b/keystone-moon/keystone/contrib/moon/controllers.py
@@ -193,7 +193,7 @@ class IntraExtensions(controller.V3Controller):
subject_category_dict = dict()
subject_category_dict['name'] = kw.get('subject_category_name', None)
subject_category_dict['description'] = kw.get('subject_category_description', None)
- return self.admin_api.add_subject_category(user_id, intra_extension_id, subject_category_dict)
+ return self.admin_api.add_subject_category_dict(user_id, intra_extension_id, subject_category_dict)
@controller.protected()
def get_subject_category(self, context, **kw):
@@ -217,7 +217,7 @@ class IntraExtensions(controller.V3Controller):
subject_category_dict = dict()
subject_category_dict['name'] = kw.get('subject_category_name', None)
subject_category_dict['description'] = kw.get('subject_category_description', None)
- return self.admin_api.set_subject_category(user_id, intra_extension_id, subject_category_id, subject_category_dict)
+ return self.admin_api.set_subject_category_dict(user_id, intra_extension_id, subject_category_id, subject_category_dict)
@controller.protected()
def get_object_categories(self, context, **kw):
@@ -232,7 +232,7 @@ class IntraExtensions(controller.V3Controller):
object_category_dict = dict()
object_category_dict['name'] = kw.get('object_category_name', None)
object_category_dict['description'] = kw.get('object_category_description', None)
- return self.admin_api.add_object_category(user_id, intra_extension_id, object_category_dict)
+ return self.admin_api.add_object_category_dict(user_id, intra_extension_id, object_category_dict)
@controller.protected()
def get_object_category(self, context, **kw):
@@ -256,7 +256,7 @@ class IntraExtensions(controller.V3Controller):
object_category_dict = dict()
object_category_dict['name'] = kw.get('object_category_name', None)
object_category_dict['description'] = kw.get('object_category_description', None)
- return self.admin_api.set_object_category(user_id, intra_extension_id, object_category_id, object_category_dict)
+ return self.admin_api.set_object_category_dict(user_id, intra_extension_id, object_category_id, object_category_dict)
@controller.protected()
def get_action_categories(self, context, **kw):
@@ -271,7 +271,7 @@ class IntraExtensions(controller.V3Controller):
action_category_dict = dict()
action_category_dict['name'] = kw.get('action_category_name', None)
action_category_dict['description'] = kw.get('action_category_description', None)
- return self.admin_api.add_action_category(user_id, intra_extension_id, action_category_dict)
+ return self.admin_api.add_action_category_dict(user_id, intra_extension_id, action_category_dict)
@controller.protected()
def get_action_category(self, context, **kw):
@@ -295,7 +295,7 @@ class IntraExtensions(controller.V3Controller):
action_category_dict = dict()
action_category_dict['name'] = kw.get('action_category_name', None)
action_category_dict['description'] = kw.get('action_category_description', None)
- return self.admin_api.set_action_category(user_id, intra_extension_id, action_category_id, action_category_dict)
+ return self.admin_api.set_action_category_dict(user_id, intra_extension_id, action_category_id, action_category_dict)
# Perimeter functions
@controller.protected()
@@ -310,7 +310,7 @@ class IntraExtensions(controller.V3Controller):
intra_extension_id = kw.get('intra_extension_id', None)
subject_dict = dict()
subject_dict['name'] = kw.get('subject_name', None)
- subject_dict['description'] = kw.get('description', None)
+ subject_dict['description'] = kw.get('subject_description', None)
return self.admin_api.add_subject_dict(user_id, intra_extension_id, subject_dict)
@controller.protected()
@@ -357,7 +357,7 @@ class IntraExtensions(controller.V3Controller):
user_id = self._get_user_id_from_token(context.get('token_id'))
intra_extension_id = kw.get('intra_extension_id', None)
object_id = kw.get('object_id', None)
- return self.admin_api.get_objects_dict(user_id, intra_extension_id, object_id)
+ return self.admin_api.get_object_dict(user_id, intra_extension_id, object_id)
@controller.protected()
def del_object(self, context, **kw):
@@ -396,7 +396,7 @@ class IntraExtensions(controller.V3Controller):
user_id = self._get_user_id_from_token(context.get('token_id'))
intra_extension_id = kw.get('intra_extension_id', None)
action_id = kw.get('action_id', None)
- return self.admin_api.get_actions_dict(user_id, intra_extension_id, action_id)
+ return self.admin_api.get_action_dict(user_id, intra_extension_id, action_id)
@controller.protected()
def del_action(self, context, **kw):
@@ -483,7 +483,7 @@ class IntraExtensions(controller.V3Controller):
intra_extension_id = kw.get('intra_extension_id', None)
object_category_id = kw.get('object_category_id', None)
object_scope_id = kw.get('object_scope_id', None)
- return self.admin_api.get_object_scopes_dict(user_id, intra_extension_id, object_category_id, object_scope_id)
+ return self.admin_api.get_object_scope_dict(user_id, intra_extension_id, object_category_id, object_scope_id)
@controller.protected()
def del_object_scope(self, context, **kw):
@@ -527,7 +527,7 @@ class IntraExtensions(controller.V3Controller):
intra_extension_id = kw.get('intra_extension_id', None)
action_category_id = kw.get('action_category_id', None)
action_scope_id = kw.get('action_scope_id', None)
- return self.admin_api.get_action_scopes_dict(user_id, intra_extension_id, action_category_id, action_scope_id)
+ return self.admin_api.get_action_scope_dict(user_id, intra_extension_id, action_category_id, action_scope_id)
@controller.protected()
def del_action_scope(self, context, **kw):
@@ -583,7 +583,7 @@ class IntraExtensions(controller.V3Controller):
object_id = kw.get('object_id', None)
object_category_id = kw.get('object_category_id', None)
object_scope_id = kw.get('object_scope_id', None)
- return self.admin_api.add_objecty_assignment_list(user_id, intra_extension_id, object_id, object_category_id, object_scope_id)
+ return self.admin_api.add_object_assignment_list(user_id, intra_extension_id, object_id, object_category_id, object_scope_id)
@controller.protected()
def get_object_assignment(self, context, **kw):
@@ -629,19 +629,22 @@ class IntraExtensions(controller.V3Controller):
self.admin_api.del_action_assignment(user_id, intra_extension_id, action_id, action_category_id, action_scope_id)
# Metarule functions
+
@controller.protected()
- def set_aggregation_algorithm(self, context, **kw):
+ def get_aggregation_algorithm(self, context, **kw):
user_id = self._get_user_id_from_token(context.get('token_id'))
intra_extension_id = kw.get('intra_extension_id', None)
- aggregation_algorithm_id = kw.get('aggregation_algorithm_id', None)
- aggregation_algorithm_dict = kw.get('aggregation_algorithm_dict', None)
- return self.admin_api.set_aggregation_algorithm_dict(user_id, intra_extension_id, aggregation_algorithm_id, aggregation_algorithm_dict)
+ return self.admin_api.get_aggregation_algorithm_dict(user_id, intra_extension_id)
@controller.protected()
- def get_aggregation_algorithm(self, context, **kw):
+ def set_aggregation_algorithm(self, context, **kw):
user_id = self._get_user_id_from_token(context.get('token_id'))
intra_extension_id = kw.get('intra_extension_id', None)
- return self.admin_api.get_aggregation_algorithms_dict(user_id, intra_extension_id)
+ aggregation_algorithm_id = kw.get('aggregation_algorithm_id', None)
+ aggregation_algorithm_dict = dict()
+ aggregation_algorithm_dict['name'] = kw.get('aggregation_algorithm_name', None)
+ aggregation_algorithm_dict['description'] = kw.get('aggregation_algorithm_description', None)
+ return self.admin_api.set_aggregation_algorithm_dict(user_id, intra_extension_id, aggregation_algorithm_id, aggregation_algorithm_dict)
@controller.protected()
def get_sub_meta_rules(self, context, **kw):
@@ -666,12 +669,12 @@ class IntraExtensions(controller.V3Controller):
user_id = self._get_user_id_from_token(context.get('token_id'))
intra_extension_id = kw.get('intra_extension_id', None)
sub_meta_rule_id = kw.get('sub_meta_rule_id', None)
- return self.admin_api.get_sub_meta_rules_dict(user_id, intra_extension_id, sub_meta_rule_id)
+ return self.admin_api.get_sub_meta_rule_dict(user_id, intra_extension_id, sub_meta_rule_id)
@controller.protected()
def del_sub_meta_rule(self, context, **kw):
user_id = self._get_user_id_from_token(context.get('token_id'))
- intra_extension_id = kw.get('intra_extension_id')
+ intra_extension_id = kw.get('intra_extension_id', None)
sub_meta_rule_id = kw.get('sub_meta_rule_id', None)
self.admin_api.del_sub_meta_rule(user_id, intra_extension_id, sub_meta_rule_id)
@@ -706,7 +709,7 @@ class IntraExtensions(controller.V3Controller):
object_category_list = kw.get('object_categories', [])
action_category_list = kw.get('action_categories', [])
rule_list = subject_category_list + action_category_list + object_category_list
- return self.admin_api.add_rule_list(user_id, intra_extension_id, sub_meta_rule_id, rule_list)
+ return self.admin_api.add_rule_dict(user_id, intra_extension_id, sub_meta_rule_id, rule_list)
@controller.protected()
def get_rule(self, context, **kw):
@@ -714,7 +717,7 @@ class IntraExtensions(controller.V3Controller):
intra_extension_id = kw.get('intra_extension_id', None)
sub_meta_rule_id = kw.get('sub_meta_rule_id', None)
rule_id = kw.get('rule_id', None)
- return self.admin_api.get_rules_dict(user_id, intra_extension_id, sub_meta_rule_id, rule_id)
+ return self.admin_api.get_rule_dict(user_id, intra_extension_id, sub_meta_rule_id, rule_id)
@controller.protected()
def del_rule(self, context, **kw):
@@ -735,7 +738,7 @@ class IntraExtensions(controller.V3Controller):
object_category_list = kw.get('object_categories', [])
action_category_list = kw.get('action_categories', [])
rule_list = subject_category_list + action_category_list + object_category_list
- return self.admin_api.set_rule_list(user_id, intra_extension_id, sub_meta_rule_id, rule_id, rule_list)
+ return self.admin_api.set_rule_dict(user_id, intra_extension_id, sub_meta_rule_id, rule_id, rule_list)
@dependency.requires('authz_api')
diff --git a/keystone-moon/keystone/contrib/moon/core.py b/keystone-moon/keystone/contrib/moon/core.py
index 33f80b59..d82c9fcc 100644
--- a/keystone-moon/keystone/contrib/moon/core.py
+++ b/keystone-moon/keystone/contrib/moon/core.py
@@ -908,7 +908,7 @@ class IntraExtensionManager(manager.Manager):
@filter_input
@enforce(("read", "write"), "subject_categories")
- def add_subject_category(self, user_id, intra_extension_id, subject_category_dict):
+ def add_subject_category_dict(self, user_id, intra_extension_id, subject_category_dict):
subject_categories_dict = self.driver.get_subject_categories_dict(intra_extension_id)
for subject_category_id in subject_categories_dict:
if subject_categories_dict[subject_category_id]['name'] == subject_category_dict['name']:
@@ -917,11 +917,11 @@ class IntraExtensionManager(manager.Manager):
@filter_input
@enforce("read", "subject_categories")
- def get_subject_category(self, user_id, intra_extension_id, subject_category_id):
- subject_category_dict = self.driver.get_subject_categories_dict(intra_extension_id)
- if subject_category_id not in subject_category_dict:
+ def get_subject_category_dict(self, user_id, intra_extension_id, subject_category_id):
+ subject_categories_dict = self.driver.get_subject_categories_dict(intra_extension_id)
+ if subject_category_id not in subject_categories_dict:
raise SubjectCategoryUnknown()
- return subject_category_dict[subject_category_id]
+ return subject_categories_dict[subject_category_id]
@filter_input
@enforce(("read", "write"), "subject_categories")
@@ -941,25 +941,20 @@ class IntraExtensionManager(manager.Manager):
@filter_input
@enforce(("read", "write"), "subject_categories")
- def set_subject_category(self, user_id, intra_extension_id, subject_category_id, subject_category_dict):
+ def set_subject_category_dict(self, user_id, intra_extension_id, subject_category_id, subject_category_dict):
if subject_category_id not in self.driver.get_subject_categories_dict(intra_extension_id):
raise SubjectCategoryUnknown()
return self.driver.set_subject_category_dict(intra_extension_id, subject_category_id, subject_category_dict)
@filter_input
@enforce("read", "object_categories")
- def get_object_category_dict(self, user_id, intra_extension_id):
- """
- :param user_id:
- :param intra_extension_id:
- :return:
- """
+ def get_object_categories_dict(self, user_id, intra_extension_id):
return self.driver.get_object_categories_dict(intra_extension_id)
@filter_input
@enforce(("read", "write"), "object_categories")
@enforce(("read", "write"), "object_scopes")
- def add_object_category(self, user_id, intra_extension_id, object_category_dict):
+ def add_object_category_dict(self, user_id, intra_extension_id, object_category_dict):
object_categories_dict = self.driver.get_object_categories_dict(intra_extension_id)
for object_category_id in object_categories_dict:
if object_categories_dict[object_category_id]["name"] == object_category_dict['name']:
@@ -968,11 +963,11 @@ class IntraExtensionManager(manager.Manager):
@filter_input
@enforce("read", "object_categories")
- def get_object_category(self, user_id, intra_extension_id, object_category_id):
- object_category_dict = self.driver.get_object_categories_dict(intra_extension_id)
- if object_category_id not in object_category_dict:
+ def get_object_category_dict(self, user_id, intra_extension_id, object_category_id):
+ object_categories_dict = self.driver.get_object_categories_dict(intra_extension_id)
+ if object_category_id not in object_categories_dict:
raise ObjectCategoryUnknown()
- return object_category_dict[object_category_id]
+ return object_categories_dict[object_category_id]
@filter_input
@enforce(("read", "write"), "object_categories")
@@ -991,19 +986,21 @@ class IntraExtensionManager(manager.Manager):
self.driver.del_object_category(intra_extension_id, object_category_id)
@filter_input
+ @enforce(("read", "write"), "object_categories")
+ def set_object_category_dict(self, user_id, intra_extension_id, object_category_id, object_category_dict):
+ if object_category_id not in self.driver.get_object_categories_dict(intra_extension_id):
+ raise ObjectCategoryUnknown()
+ return self.driver.set_object_category_dict(intra_extension_id, object_category_id, object_category_dict)
+
+ @filter_input
@enforce("read", "action_categories")
- def get_action_category_dict(self, user_id, intra_extension_id):
- """
- :param user_id:
- :param intra_extension_id:
- :return:
- """
+ def get_action_categories_dict(self, user_id, intra_extension_id):
return self.driver.get_action_categories_dict(intra_extension_id)
@filter_input
@enforce(("read", "write"), "action_categories")
@enforce(("read", "write"), "action_scopes")
- def add_action_category(self, user_id, intra_extension_id, action_category_dict):
+ def add_action_category_dict(self, user_id, intra_extension_id, action_category_dict):
action_categories_dict = self.driver.get_action_categories_dict(intra_extension_id)
for action_category_id in action_categories_dict:
if action_categories_dict[action_category_id]['name'] == action_category_dict['name']:
@@ -1012,11 +1009,11 @@ class IntraExtensionManager(manager.Manager):
@filter_input
@enforce("read", "action_categories")
- def get_action_category(self, user_id, intra_extension_id, action_category_id):
- action_category_dict = self.driver.get_action_categories_dict(intra_extension_id)
- if action_category_id not in action_category_dict:
+ def get_action_category_dict(self, user_id, intra_extension_id, action_category_id):
+ action_categories_dict = self.driver.get_action_categories_dict(intra_extension_id)
+ if action_category_id not in action_categories_dict:
raise ActionCategoryUnknown()
- return self.driver.get_action_categories_dict(intra_extension_id)[action_category_id]
+ return action_categories_dict[action_category_id]
@filter_input
@enforce(("read", "write"), "action_categories")
@@ -1033,6 +1030,13 @@ class IntraExtensionManager(manager.Manager):
self.driver.del_action_assignment(intra_extension_id, action_id, action_category_id, assignment_id)
self.driver.del_action_category(intra_extension_id, action_category_id)
+ @filter_input
+ @enforce(("read", "write"), "action_categories")
+ def set_action_category_dict(self, user_id, intra_extension_id, action_category_id, action_category_dict):
+ if action_category_id not in self.driver.get_action_categories_dict(intra_extension_id):
+ raise ActionCategoryUnknown()
+ return self.driver.set_action_category_dict(intra_extension_id, action_category_id, action_category_dict)
+
# Perimeter functions
@filter_input
@@ -1056,10 +1060,10 @@ class IntraExtensionManager(manager.Manager):
@filter_input
@enforce("read", "subjects")
def get_subject_dict(self, user_id, intra_extension_id, subject_id):
- subject_dict = self.driver.get_subjects_dict(intra_extension_id)
- if subject_id in subject_dict:
+ subjects_dict = self.driver.get_subjects_dict(intra_extension_id)
+ if subject_id not in subjects_dict:
raise SubjectUnknown()
- return subject_dict[subject_id]
+ return subjects_dict[subject_id]
@filter_input
@enforce(("read", "write"), "subjects")
@@ -1093,34 +1097,25 @@ class IntraExtensionManager(manager.Manager):
@filter_input
@enforce(("read", "write"), "objects")
- def add_object_dict(self, user_id, intra_extension_id, object_name):
- object_dict = self.driver.get_objects_dict(intra_extension_id)
- for object_id in object_dict:
- if object_dict[object_id]["name"] == object_name:
- raise ObjectNameExisting()
- return self.driver.set_object_dict(intra_extension_id, uuid4().hex, object_name)
-
- @filter_input
- @enforce(("read", "write"), "objects")
- def set_object_dict(self, user_id, intra_extension_id, object_id, object_dict):
+ def add_object_dict(self, user_id, intra_extension_id, object_dict):
objects_dict = self.driver.get_objects_dict(intra_extension_id)
for object_id in objects_dict:
if objects_dict[object_id]["name"] == object_dict['name']:
raise ObjectNameExisting()
- return self.driver.set_object_dict(intra_extension_id, object_id, object_dict)
+ return self.driver.set_object_dict(intra_extension_id, uuid4().hex, object_dict)
@filter_input
@enforce("read", "objects")
def get_object_dict(self, user_id, intra_extension_id, object_id):
- object_dict = self.driver.get_objects_dict(intra_extension_id)
- if object_id in object_dict:
+ objects_dict = self.driver.get_objects_dict(intra_extension_id)
+ if object_id not in objects_dict:
raise ObjectUnknown()
- return object_dict[object_id]
+ return objects_dict[object_id]
@filter_input
@enforce(("read", "write"), "objects")
def del_object(self, user_id, intra_extension_id, object_id):
- if object_id in self.driver.get_objects_dict(intra_extension_id):
+ if object_id not in self.driver.get_objects_dict(intra_extension_id):
raise ObjectUnknown()
# Destroy assignments related to this category
for object_category_id in self.driver.get_object_categories_dict(intra_extension_id):
@@ -1130,40 +1125,40 @@ class IntraExtensionManager(manager.Manager):
self.driver.del_object(intra_extension_id, object_id)
@filter_input
+ @enforce(("read", "write"), "objects")
+ def set_object_dict(self, user_id, intra_extension_id, object_id, object_dict):
+ objects_dict = self.driver.get_objects_dict(intra_extension_id)
+ for object_id in objects_dict:
+ if objects_dict[object_id]["name"] == object_dict['name']:
+ raise ObjectNameExisting()
+ return self.driver.set_object_dict(intra_extension_id, object_id, object_dict)
+
+ @filter_input
@enforce("read", "actions")
def get_actions_dict(self, user_id, intra_extension_id):
return self.driver.get_actions_dict(intra_extension_id)
@filter_input
@enforce(("read", "write"), "actions")
- def add_action_dict(self, user_id, intra_extension_id, action_name):
- action_dict = self.driver.get_actions_dict(intra_extension_id)
- for action_id in action_dict:
- if action_dict[action_id]["name"] == action_name:
- raise ActionNameExisting()
- return self.driver.set_action_dict(intra_extension_id, uuid4().hex, action_name)
-
- @filter_input
- @enforce(("read", "write"), "actions")
- def set_action_dict(self, user_id, intra_extension_id, action_id, action_dict):
+ def add_action_dict(self, user_id, intra_extension_id, action_dict):
actions_dict = self.driver.get_actions_dict(intra_extension_id)
for action_id in actions_dict:
if actions_dict[action_id]["name"] == action_dict['name']:
raise ActionNameExisting()
- return self.driver.set_action_dict(intra_extension_id, action_id, action_dict)
+ return self.driver.set_action_dict(intra_extension_id, uuid4().hex, action_dict)
@filter_input
@enforce("read", "actions")
def get_action_dict(self, user_id, intra_extension_id, action_id):
- action_dict = self.driver.get_actions_dict(intra_extension_id)
- if action_id in action_dict:
+ actions_dict = self.driver.get_actions_dict(intra_extension_id)
+ if action_id not in actions_dict:
raise ActionUnknown()
- return action_dict[action_id]
+ return actions_dict[action_id]
@filter_input
@enforce(("read", "write"), "actions")
def del_action(self, user_id, intra_extension_id, action_id):
- if action_id in self.driver.get_actions_dict(intra_extension_id):
+ if action_id not in self.driver.get_actions_dict(intra_extension_id):
raise ActionUnknown()
# Destroy assignments related to this category
for action_category_id in self.driver.get_action_categories_dict(intra_extension_id):
@@ -1172,6 +1167,15 @@ class IntraExtensionManager(manager.Manager):
self.driver.del_action_assignment(intra_extension_id, _action_id, action_category_id, assignment_id)
return self.driver.del_action(intra_extension_id, action_id)
+ @filter_input
+ @enforce(("read", "write"), "actions")
+ def set_action_dict(self, user_id, intra_extension_id, action_id, action_dict):
+ actions_dict = self.driver.get_actions_dict(intra_extension_id)
+ for action_id in actions_dict:
+ if actions_dict[action_id]["name"] == action_dict['name']:
+ raise ActionNameExisting()
+ return self.driver.set_action_dict(intra_extension_id, action_id, action_dict)
+
# Scope functions
@filter_input
@@ -1205,8 +1209,7 @@ class IntraExtensionManager(manager.Manager):
for _subject_scope_id in subject_scopes_dict:
if subject_scope_dict['name'] == subject_scopes_dict[_subject_scope_id]['name']:
raise SubjectScopeNameExisting()
- subject_scope_id = uuid4().hex
- return self.driver.set_subject_scope_dict(intra_extension_id, subject_category_id, subject_scope_id, subject_scope_dict)
+ return self.driver.set_subject_scope_dict(intra_extension_id, subject_category_id, uuid4().hex, subject_scope_dict)
@filter_input
@enforce("read", "subject_scopes")
@@ -1237,17 +1240,17 @@ class IntraExtensionManager(manager.Manager):
for rule_id in rules_dict:
if subject_scope_id in rules_dict[rule_id]:
self.driver.del_rule(intra_extension_id, sub_meta_rule_id, rule_id)
- return self.driver.del_subject_scope(intra_extension_id, subject_category_id, subject_scope_id)
+ self.driver.del_subject_scope(intra_extension_id, subject_category_id, subject_scope_id)
@filter_input
@enforce(("read", "write"), "subject_scopes")
@enforce("read", "subject_categories")
- def set_subject_scope_dict(self, user_id, intra_extension_id, subject_category_id, subject_scope_id, subject_scope_name):
+ def set_subject_scope_dict(self, user_id, intra_extension_id, subject_category_id, subject_scope_id, subject_scope_dict):
if subject_category_id not in self.driver.get_subject_categories_dict(intra_extension_id):
raise SubjectCategoryUnknown()
- subject_scope_dict = self.driver.get_subject_scopes_dict(intra_extension_id, subject_category_id)
- for _subject_scope_id in subject_scope_dict:
- if subject_scope_name == subject_scope_dict[_subject_scope_id]['name']:
+ subject_scopes_dict = self.driver.get_subject_scopes_dict(intra_extension_id, subject_category_id)
+ for _subject_scope_id in subject_scopes_dict:
+ if subject_scopes_dict[_subject_scope_id]['name'] == subject_scope_dict['name']:
raise SubjectScopeNameExisting()
return self.driver.set_subject_scope_dict(intra_extension_id, subject_category_id, subject_scope_id, subject_scope_dict)
@@ -1262,19 +1265,14 @@ class IntraExtensionManager(manager.Manager):
@filter_input
@enforce(("read", "write"), "object_scopes")
@enforce("read", "object_categories")
- def add_object_scope_dict(self, user_id, intra_extension_id, object_category_id, object_scope_name):
+ def add_object_scope_dict(self, user_id, intra_extension_id, object_category_id, object_scope_dict):
if object_category_id not in self.driver.get_object_categories_dict(intra_extension_id):
raise ObjectCategoryUnknown()
- object_scope_dict = self.driver.get_object_scopes_dict(intra_extension_id, object_category_id)
- for _object_scope_id in object_scope_dict:
- if object_scope_name == object_scope_dict[_object_scope_id]['name']:
+ object_scopes_dict = self.driver.get_object_scopes_dict(intra_extension_id, object_category_id)
+ for _object_scope_id in object_scopes_dict:
+ if object_scopes_dict[_object_scope_id]['name'] == object_scope_dict['name']:
raise ObjectScopeNameExisting()
- object_scope_id = uuid4().hex
- return self.driver.set_object_scope_dict(
- intra_extension_id,
- object_category_id,
- object_scope_id,
- object_scope_name)
+ return self.driver.set_object_scope_dict(intra_extension_id, object_category_id, uuid4().hex, object_scope_dict)
@filter_input
@enforce("read", "object_scopes")
@@ -1282,10 +1280,10 @@ class IntraExtensionManager(manager.Manager):
def get_object_scope_dict(self, user_id, intra_extension_id, object_category_id, object_scope_id):
if object_category_id not in self.driver.get_object_categories_dict(intra_extension_id):
raise ObjectCategoryUnknown()
- object_scopte_dict = self.driver.get_object_scopes_dict(intra_extension_id, object_category_id)
- if object_scope_id not in object_scopte_dict:
+ object_scopes_dict = self.driver.get_object_scopes_dict(intra_extension_id, object_category_id)
+ if object_scope_id not in object_scopes_dict:
raise ObjectScopeUnknown()
- return object_scopte_dict[object_scope_id]
+ return object_scopes_dict[object_scope_id]
@filter_input
@enforce(("read", "write"), "object_scopes")
@@ -1305,17 +1303,17 @@ class IntraExtensionManager(manager.Manager):
for rule_id in rules_dict:
if object_scope_id in rules_dict[rule_id]:
self.driver.del_rule(intra_extension_id, sub_meta_rule_id, rule_id)
- return self.driver.del_object_scope(intra_extension_id, object_category_id, object_scope_id)
+ self.driver.del_object_scope(intra_extension_id, object_category_id, object_scope_id)
@filter_input
@enforce(("read", "write"), "object_scopes")
@enforce("read", "object_categories")
- def set_object_scope_dict(self, user_id, intra_extension_id, object_category_id, object_scope_id, object_scope_name):
+ def set_object_scope_dict(self, user_id, intra_extension_id, object_category_id, object_scope_id, object_scope_dict):
if object_category_id not in self.driver.get_object_categories_dict(intra_extension_id):
raise ObjectCategoryUnknown()
- object_scope_dict = self.driver.get_object_scopes_dict(intra_extension_id, object_category_id)
- for _object_scope_id in object_scope_dict:
- if object_scope_name == object_scope_dict[_object_scope_id]['name']:
+ object_scopes_dict = self.driver.get_object_scopes_dict(intra_extension_id, object_category_id)
+ for _object_scope_id in object_scopes_dict:
+ if object_scopes_dict[_object_scope_id]['name'] == object_scope_dict['name']:
raise ObjectScopeNameExisting()
return self.driver.set_object_scope_dict(intra_extension_id, object_category_id, object_scope_id, object_scope_dict)
@@ -1330,19 +1328,14 @@ class IntraExtensionManager(manager.Manager):
@filter_input
@enforce(("read", "write"), "action_scopes")
@enforce("read", "action_categories")
- def add_action_scope_dict(self, user_id, intra_extension_id, action_category_id, action_scope_name):
+ def add_action_scope_dict(self, user_id, intra_extension_id, action_category_id, action_scope_dict):
if action_category_id not in self.driver.get_action_categories_dict(intra_extension_id):
raise ActionCategoryUnknown()
- action_scope_dict = self.driver.get_action_scopes_dict(intra_extension_id, action_category_id)
- for _action_scope_id in action_scope_dict:
- if action_scope_name == action_scope_dict[_action_scope_id]['name']:
+ action_scopes_dict = self.driver.get_action_scopes_dict(intra_extension_id, action_category_id)
+ for _action_scope_id in action_scopes_dict:
+ if action_scopes_dict[_action_scope_id]['name'] == action_scope_dict['name']:
raise ActionScopeNameExisting()
- action_scope_id = uuid4().hex
- return self.driver.set_action_scope_dict(
- intra_extension_id,
- action_category_id,
- action_scope_id,
- action_scope_name)
+ return self.driver.set_action_scope_dict(intra_extension_id, action_category_id, uuid4().hex, action_scope_dict)
@filter_input
@enforce("read", "action_scopes")
@@ -1350,10 +1343,10 @@ class IntraExtensionManager(manager.Manager):
def get_action_scope_dict(self, user_id, intra_extension_id, action_category_id, action_scope_id):
if action_category_id not in self.driver.get_action_categories_dict(intra_extension_id):
raise ActionCategoryUnknown()
- action_scopte_dict = self.driver.get_action_scopes_dict(intra_extension_id, action_category_id)
- if action_scope_id not in action_scopte_dict:
+ action_scopes_dict = self.driver.get_action_scopes_dict(intra_extension_id, action_category_id)
+ if action_scope_id not in action_scopes_dict:
raise ActionScopeUnknown()
- return action_scopte_dict[action_scope_id]
+ return action_scopes_dict[action_scope_id]
@filter_input
@enforce(("read", "write"), "action_scopes")
@@ -1373,23 +1366,19 @@ class IntraExtensionManager(manager.Manager):
for rule_id in rules_dict:
if action_scope_id in rules_dict[rule_id]:
self.driver.del_rule(intra_extension_id, sub_meta_rule_id, rule_id)
- return self.driver.del_action_scope(intra_extension_id, action_category_id, action_scope_id)
+ self.driver.del_action_scope(intra_extension_id, action_category_id, action_scope_id)
@filter_input
@enforce(("read", "write"), "action_scopes")
@enforce("read", "action_categories")
- def set_action_scope_dict(self, user_id, intra_extension_id, action_category_id, action_scope_id, action_scope_name):
+ def set_action_scope_dict(self, user_id, intra_extension_id, action_category_id, action_scope_id, action_scope_dict):
if action_category_id not in self.driver.get_action_categories_dict(intra_extension_id):
raise ActionCategoryUnknown()
- action_scope_dict = self.driver.get_action_scopes_dict(intra_extension_id, action_category_id)
- for _action_scope_id in action_scope_dict:
- if action_scope_name == action_scope_dict[_action_scope_id]['name']:
+ action_scopes_dict = self.driver.get_action_scopes_dict(intra_extension_id, action_category_id)
+ for _action_scope_id in action_scopes_dict:
+ if action_scopes_dict[_action_scope_id]['name'] == action_scope_dict['name']:
raise ActionScopeNameExisting()
- return self.driver.set_action_scope_dict(
- intra_extension_id,
- action_category_id,
- action_scope_id,
- action_scope_name)
+ return self.driver.set_action_scope_dict(intra_extension_id, action_category_id, action_scope_id, action_scope_dict)
# Assignment functions
@@ -1398,9 +1387,18 @@ class IntraExtensionManager(manager.Manager):
@enforce("read", "subjects")
@enforce("read", "subject_categories")
def get_subject_assignment_list(self, user_id, intra_extension_id, subject_id, subject_category_id):
+ """
+ :param user_id:
+ :param intra_extension_id:
+ :param subject_id:
+ :param subject_category_id:
+ :return: [
+ subject_scope_id1, ..., subject_scope_idn
+ ]
+ """
if subject_id not in self.driver.get_subjects_dict(intra_extension_id):
raise SubjectUnknown()
- elif subject_category_id not in self.driver.get_subject_categories_dict(intra_extension_id):
+ if subject_category_id not in self.driver.get_subject_categories_dict(intra_extension_id):
raise SubjectCategoryUnknown()
return self.driver.get_subject_assignment_list(intra_extension_id, subject_id, subject_category_id)
@@ -1410,14 +1408,13 @@ class IntraExtensionManager(manager.Manager):
@enforce("read", "subject_categories")
@enforce("read", "subject_scopes")
def add_subject_assignment_list(self, user_id, intra_extension_id, subject_id, subject_category_id, subject_scope_id):
- print(subject_id, self.driver.get_subjects_dict(intra_extension_id))
if subject_id not in self.driver.get_subjects_dict(intra_extension_id):
raise SubjectUnknown()
if subject_category_id not in self.driver.get_subject_categories_dict(intra_extension_id):
raise SubjectCategoryUnknown()
if subject_scope_id not in self.driver.get_subject_scopes_dict(intra_extension_id, subject_category_id):
raise SubjectScopeUnknown()
- if subject_scope_id in self.driver.get_subject_assignment_list(intra_extension_id, subject_id, subject_category_id):
+ elif subject_scope_id in self.driver.get_subject_assignment_list(intra_extension_id, subject_id, subject_category_id):
raise SubjectAssignmentExisting()
return self.driver.add_subject_assignment_list(intra_extension_id, subject_id, subject_category_id, subject_scope_id)
@@ -1429,9 +1426,9 @@ class IntraExtensionManager(manager.Manager):
def del_subject_assignment(self, user_id, intra_extension_id, subject_id, subject_category_id, subject_scope_id):
if subject_id not in self.driver.get_subjects_dict(intra_extension_id):
raise SubjectUnknown()
- elif subject_category_id not in self.driver.get_subject_categories_dict(intra_extension_id):
+ if subject_category_id not in self.driver.get_subject_categories_dict(intra_extension_id):
raise SubjectCategoryUnknown()
- elif subject_scope_id not in self.driver.get_subject_scopes_dict(intra_extension_id, subject_category_id):
+ if subject_scope_id not in self.driver.get_subject_scopes_dict(intra_extension_id, subject_category_id):
raise SubjectScopeUnknown()
elif subject_scope_id not in self.driver.get_subject_assignment_list(intra_extension_id, subject_id, subject_category_id):
raise SubjectAssignmentUnknown()
@@ -1444,7 +1441,7 @@ class IntraExtensionManager(manager.Manager):
def get_object_assignment_list(self, user_id, intra_extension_id, object_id, object_category_id):
if object_id not in self.driver.get_objects_dict(intra_extension_id):
raise ObjectUnknown()
- elif object_category_id not in self.driver.get_object_categories_dict(intra_extension_id):
+ if object_category_id not in self.driver.get_object_categories_dict(intra_extension_id):
raise ObjectCategoryUnknown()
return self.driver.get_object_assignment_list(intra_extension_id, object_id, object_category_id)
@@ -1455,9 +1452,9 @@ class IntraExtensionManager(manager.Manager):
def add_object_assignment_list(self, user_id, intra_extension_id, object_id, object_category_id, object_scope_id):
if object_id not in self.driver.get_objects_dict(intra_extension_id):
raise ObjectUnknown()
- elif object_category_id not in self.driver.get_object_categories_dict(intra_extension_id):
+ if object_category_id not in self.driver.get_object_categories_dict(intra_extension_id):
raise ObjectCategoryUnknown()
- elif object_scope_id not in self.driver.get_object_scopes_dict(intra_extension_id, object_category_id):
+ if object_scope_id not in self.driver.get_object_scopes_dict(intra_extension_id, object_category_id):
raise ObjectScopeUnknown()
elif object_scope_id in self.driver.get_object_assignment_list(intra_extension_id, object_id, object_category_id):
raise ObjectAssignmentExisting()
@@ -1471,9 +1468,9 @@ class IntraExtensionManager(manager.Manager):
def del_object_assignment(self, user_id, intra_extension_id, object_id, object_category_id, object_scope_id):
if object_id not in self.driver.get_objects_dict(intra_extension_id):
raise ObjectUnknown()
- elif object_category_id not in self.driver.get_object_categories_dict(intra_extension_id):
+ if object_category_id not in self.driver.get_object_categories_dict(intra_extension_id):
raise ObjectCategoryUnknown()
- elif object_scope_id not in self.driver.get_object_scopes_dict(intra_extension_id, object_category_id):
+ if object_scope_id not in self.driver.get_object_scopes_dict(intra_extension_id, object_category_id):
raise ObjectScopeUnknown()
elif object_scope_id not in self.driver.get_object_assignment_list(intra_extension_id, object_id, object_category_id):
raise ObjectAssignmentUnknown()
@@ -1486,7 +1483,7 @@ class IntraExtensionManager(manager.Manager):
def get_action_assignment_list(self, user_id, intra_extension_id, action_id, action_category_id):
if action_id not in self.driver.get_actions_dict(intra_extension_id):
raise ActionUnknown()
- elif action_category_id not in self.driver.get_action_categories_dict(intra_extension_id):
+ if action_category_id not in self.driver.get_action_categories_dict(intra_extension_id):
raise ActionCategoryUnknown()
return self.driver.get_action_assignment_list(intra_extension_id, action_id, action_category_id)
@@ -1497,9 +1494,9 @@ class IntraExtensionManager(manager.Manager):
def add_action_assignment_list(self, user_id, intra_extension_id, action_id, action_category_id, action_scope_id):
if action_id not in self.driver.get_actions_dict(intra_extension_id):
raise ActionUnknown()
- elif action_category_id not in self.driver.get_action_categories_dict(intra_extension_id):
+ if action_category_id not in self.driver.get_action_categories_dict(intra_extension_id):
raise ActionCategoryUnknown()
- elif action_scope_id not in self.driver.get_action_scopes_dict(intra_extension_id, action_category_id):
+ if action_scope_id not in self.driver.get_action_scopes_dict(intra_extension_id, action_category_id):
raise ActionScopeUnknown()
elif action_scope_id in self.driver.get_action_assignment_list(intra_extension_id, action_id, action_category_id):
raise ObjectAssignmentExisting()
@@ -1513,27 +1510,17 @@ class IntraExtensionManager(manager.Manager):
def del_action_assignment(self, user_id, intra_extension_id, action_id, action_category_id, action_scope_id):
if action_id not in self.driver.get_actions_dict(intra_extension_id):
raise ActionUnknown()
- elif action_category_id not in self.driver.get_action_categories_dict(intra_extension_id):
+ if action_category_id not in self.driver.get_action_categories_dict(intra_extension_id):
raise ActionCategoryUnknown()
- elif action_scope_id not in self.driver.get_action_scopes_dict(intra_extension_id, action_category_id):
+ if action_scope_id not in self.driver.get_action_scopes_dict(intra_extension_id, action_category_id):
raise ActionScopeUnknown()
elif action_scope_id not in self.driver.get_action_assignment_list(intra_extension_id, action_id, action_category_id):
raise ActionAssignmentUnknown()
- return self.driver.del_action_assignment(intra_extension_id, action_id, action_category_id, action_scope_id)
+ self.driver.del_action_assignment(intra_extension_id, action_id, action_category_id, action_scope_id)
# Metarule functions
@filter_input
- @enforce(("read", "write"), "aggregation_algorithm")
- def set_aggregation_algorithm_dict(self, user_id, intra_extension_id, aggregation_algorithm_id, aggregation_algorithm_dict):
- if aggregation_algorithm_id:
- if aggregation_algorithm_id not in self.configuration_api.get_aggregation_algorithms_dict(ADMIN_ID):
- raise AggregationAlgorithmUnknown()
- else:
- aggregation_algorithm_id = uuid4().hex
- return self.driver.set_aggregation_algorithm_dict(intra_extension_id, aggregation_algorithm_id, aggregation_algorithm_dict)
-
- @filter_input
@enforce("read", "aggregation_algorithm")
def get_aggregation_algorithm_dict(self, user_id, intra_extension_id):
"""
@@ -1549,6 +1536,16 @@ class IntraExtensionManager(manager.Manager):
return aggregation_algorithm_dict
@filter_input
+ @enforce(("read", "write"), "aggregation_algorithm")
+ def set_aggregation_algorithm_dict(self, user_id, intra_extension_id, aggregation_algorithm_id, aggregation_algorithm_dict):
+ if aggregation_algorithm_id:
+ if aggregation_algorithm_id not in self.configuration_api.get_aggregation_algorithms_dict(ADMIN_ID):
+ raise AggregationAlgorithmUnknown()
+ else:
+ aggregation_algorithm_id = uuid4().hex
+ return self.driver.set_aggregation_algorithm_dict(intra_extension_id, aggregation_algorithm_id, aggregation_algorithm_dict)
+
+ @filter_input
@enforce("read", "sub_meta_rules")
def get_sub_meta_rules_dict(self, user_id, intra_extension_id):
"""
@@ -1575,16 +1572,15 @@ class IntraExtensionManager(manager.Manager):
for _sub_meta_rule_id in sub_meta_rules_dict:
if sub_meta_rule_dict['name'] == sub_meta_rules_dict[_sub_meta_rule_id]["name"]:
raise SubMetaRuleNameExisting()
- elif sub_meta_rule_dict['subject_categories'] == sub_meta_rules_dict[_sub_meta_rule_id]["subject_categories"] and \
+ if sub_meta_rule_dict['subject_categories'] == sub_meta_rules_dict[_sub_meta_rule_id]["subject_categories"] and \
sub_meta_rule_dict['object_categories'] == sub_meta_rules_dict[_sub_meta_rule_id]["object_categories"] and \
sub_meta_rule_dict['action_categories'] == sub_meta_rules_dict[_sub_meta_rule_id]["action_categories"] and \
sub_meta_rule_dict['algorithm'] == sub_meta_rules_dict[_sub_meta_rule_id]["algorithm"]:
raise SubMetaRuleExisting()
- algorithms = self.configuration_api.get_sub_meta_rule_algorithms_dict(user_id)
- if sub_meta_rule_dict['algorithm'] not in algorithms.keys():
+ if sub_meta_rule_dict['algorithm'] not in self.configuration_api.get_sub_meta_rule_algorithms_dict(user_id):
raise SubMetaRuleAlgorithmNotExisting()
sub_meta_rule_id = uuid4().hex
- # TODO (dthom): add new sub-meta-rule to rule
+ # TODO (dthom): add new sub-meta-rule to rule dict
# self.driver.add_rule(intra_extension_id, sub_meta_rule_id, [])
return self.driver.set_sub_meta_rule_dict(intra_extension_id, sub_meta_rule_id, sub_meta_rule_dict)
@@ -1612,8 +1608,6 @@ class IntraExtensionManager(manager.Manager):
def set_sub_meta_rule_dict(self, user_id, intra_extension_id, sub_meta_rule_id, sub_meta_rule_dict):
if sub_meta_rule_id not in self.driver.get_sub_meta_rules_dict(intra_extension_id):
raise SubMetaRuleUnknown()
- # TODO (dthom): add new sub-meta-rule to rule
- # self.driver.add_rule(intra_extension_id, sub_meta_rule_id, [])
return self.driver.set_sub_meta_rule_dict(intra_extension_id, sub_meta_rule_id, sub_meta_rule_dict)
# Rule functions
@@ -1639,8 +1633,7 @@ class IntraExtensionManager(manager.Manager):
raise SubMetaRuleUnknown()
if rule_list in self.driver.get_rules_dict(intra_extension_id, sub_meta_rule_id).values():
raise RuleExisting()
- rule_id = uuid4().hex
- return self.driver.set_rule_dict(intra_extension_id, sub_meta_rule_id, rule_id, rule_list)
+ return self.driver.set_rule_dict(intra_extension_id, sub_meta_rule_id, uuid4().hex, rule_list)
@filter_input
@enforce("read", "sub_meta_rules")
@@ -1659,8 +1652,7 @@ class IntraExtensionManager(manager.Manager):
def del_rule(self, user_id, intra_extension_id, sub_meta_rule_id, rule_id):
if sub_meta_rule_id not in self.driver.get_sub_meta_rules_dict(intra_extension_id):
raise SubMetaRuleUnknown()
- rules_dict = self.driver.get_rules_dict(intra_extension_id, sub_meta_rule_id)
- if rule_id not in rules_dict:
+ if rule_id not in self.driver.get_rules_dict(intra_extension_id, sub_meta_rule_id):
raise RuleUnknown()
self.driver.del_rule(intra_extension_id, sub_meta_rule_id, rule_id)
@@ -1670,8 +1662,7 @@ class IntraExtensionManager(manager.Manager):
def set_rule_dict(self, user_id, intra_extension_id, sub_meta_rule_id, rule_id, rule_list):
if sub_meta_rule_id not in self.driver.get_sub_meta_rules_dict(intra_extension_id):
raise SubMetaRuleUnknown()
- rules_dict = self.driver.get_rules_dict(intra_extension_id, sub_meta_rule_id)
- if rule_id not in rules_dict:
+ if rule_id not in self.driver.get_rules_dict(intra_extension_id, sub_meta_rule_id):
raise RuleUnknown()
return self.driver.set_rule_dict(intra_extension_id, sub_meta_rule_id, rule_id, rule_list)