aboutsummaryrefslogtreecommitdiffstats
path: root/keystone-moon/keystone/contrib
diff options
context:
space:
mode:
authorRuan HE <ruan.he@orange.com>2015-09-11 09:09:51 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2015-09-11 09:09:51 +0000
commitad2869493fc54f8c3f7f91c4d4f44e24b9048238 (patch)
tree45c0dd48f4df67dbcfcdd709b297929dd5de2b93 /keystone-moon/keystone/contrib
parent3d20cf2c0e76b76e0fe602968f599a74f5616f6b (diff)
parent509d6acbecd9d776c4c85d39946bb75e7e01c3f6 (diff)
Merge "Change the deletion behaviour of scope and assignment when deleting an intra-extension because of foreign key contraints."
Diffstat (limited to 'keystone-moon/keystone/contrib')
-rw-r--r--keystone-moon/keystone/contrib/moon/backends/sql.py78
-rw-r--r--keystone-moon/keystone/contrib/moon/core.py31
2 files changed, 78 insertions, 31 deletions
diff --git a/keystone-moon/keystone/contrib/moon/backends/sql.py b/keystone-moon/keystone/contrib/moon/backends/sql.py
index f08038a2..9f4beb6b 100644
--- a/keystone-moon/keystone/contrib/moon/backends/sql.py
+++ b/keystone-moon/keystone/contrib/moon/backends/sql.py
@@ -667,9 +667,14 @@ class IntraExtensionConnector(IntraExtensionDriver):
def del_subject_scope(self, intra_extension_id, subject_category_id, subject_scope_id):
with sql.transaction() as session:
query = session.query(SubjectScope)
- query = query.filter_by(intra_extension_id=intra_extension_id, subject_category_id=subject_category_id, id=subject_scope_id)
- ref = query.first()
- session.delete(ref)
+ if not subject_category_id or not subject_scope_id:
+ query = query.filter_by(intra_extension_id=intra_extension_id)
+ for ref in query.all():
+ session.delete(ref)
+ else:
+ query = query.filter_by(intra_extension_id=intra_extension_id, subject_category_id=subject_category_id, id=subject_scope_id)
+ ref = query.first()
+ session.delete(ref)
# Getter and Setter for object_category_scope
@@ -706,9 +711,14 @@ class IntraExtensionConnector(IntraExtensionDriver):
def del_object_scope(self, intra_extension_id, object_category_id, object_scope_id):
with sql.transaction() as session:
query = session.query(ObjectScope)
- query = query.filter_by(intra_extension_id=intra_extension_id, object_category_id=object_category_id, id=object_scope_id)
- ref = query.first()
- session.delete(ref)
+ if not object_category_id or not object_scope_id:
+ query = query.filter_by(intra_extension_id=intra_extension_id)
+ for ref in query.all():
+ session.delete(ref)
+ else:
+ query = query.filter_by(intra_extension_id=intra_extension_id, object_category_id=object_category_id, id=object_scope_id)
+ ref = query.first()
+ session.delete(ref)
# Getter and Setter for action_scope
@@ -745,17 +755,27 @@ class IntraExtensionConnector(IntraExtensionDriver):
def del_action_scope(self, intra_extension_id, action_category_id, action_scope_id):
with sql.transaction() as session:
query = session.query(ActionScope)
- query = query.filter_by(intra_extension_id=intra_extension_id, action_category_id=action_category_id, id=action_scope_id)
- ref = query.first()
- session.delete(ref)
+ if not action_category_id or not action_scope_id:
+ query = query.filter_by(intra_extension_id=intra_extension_id)
+ for ref in query.all():
+ session.delete(ref)
+ else:
+ query = query.filter_by(intra_extension_id=intra_extension_id, action_category_id=action_category_id, id=action_scope_id)
+ ref = query.first()
+ session.delete(ref)
# Getter and Setter for subject_category_assignment
def get_subject_assignment_list(self, intra_extension_id, subject_id, subject_category_id):
with sql.transaction() as session:
query = session.query(SubjectAssignment)
- query = query.filter_by(intra_extension_id=intra_extension_id, subject_id=subject_id, subject_category_id=subject_category_id)
- ref = query.first()
+ if not subject_id or not subject_category_id or not subject_category_id:
+ query = query.filter_by(intra_extension_id=intra_extension_id)
+ ref = query.all()
+ return ref
+ else:
+ query = query.filter_by(intra_extension_id=intra_extension_id, subject_id=subject_id, subject_category_id=subject_category_id)
+ ref = query.first()
if not ref:
return list()
return list(ref.subject_assignment)
@@ -791,6 +811,11 @@ class IntraExtensionConnector(IntraExtensionDriver):
return self.set_subject_assignment_list(intra_extension_id, subject_id, subject_category_id, new_subject_assignment_list)
def del_subject_assignment(self, intra_extension_id, subject_id, subject_category_id, subject_scope_id):
+ if not subject_id or not subject_category_id or not subject_category_id:
+ with sql.transaction() as session:
+ for ref in self.get_subject_assignment_list(intra_extension_id, None, None):
+ session.delete(ref)
+ return
new_subject_assignment_list = self.get_subject_assignment_list(intra_extension_id, subject_id, subject_category_id)
new_subject_assignment_list.remove(subject_scope_id)
return self.set_subject_assignment_list(intra_extension_id, subject_id, subject_category_id, new_subject_assignment_list)
@@ -800,8 +825,13 @@ class IntraExtensionConnector(IntraExtensionDriver):
def get_object_assignment_list(self, intra_extension_id, object_id, object_category_id):
with sql.transaction() as session:
query = session.query(ObjectAssignment)
- query = query.filter_by(intra_extension_id=intra_extension_id, object_id=object_id, object_category_id=object_category_id)
- ref = query.first()
+ if not object_id or not object_category_id or not object_category_id:
+ query = query.filter_by(intra_extension_id=intra_extension_id)
+ ref = query.all()
+ return ref
+ else:
+ query = query.filter_by(intra_extension_id=intra_extension_id, object_id=object_id, object_category_id=object_category_id)
+ ref = query.first()
if not ref:
return list()
return list(ref.object_assignment)
@@ -836,6 +866,11 @@ class IntraExtensionConnector(IntraExtensionDriver):
return self.set_object_assignment_list(intra_extension_id, object_id, object_category_id, new_object_assignment_list)
def del_object_assignment(self, intra_extension_id, object_id, object_category_id, object_scope_id):
+ if not object_id or not object_category_id or not object_category_id:
+ with sql.transaction() as session:
+ for ref in self.get_object_assignment_list(intra_extension_id, None, None):
+ session.delete(ref)
+ return
new_object_assignment_list = self.get_object_assignment_list(intra_extension_id, object_id, object_category_id)
new_object_assignment_list.remove(object_scope_id)
return self.set_object_assignment_list(intra_extension_id, object_id, object_category_id, new_object_assignment_list)
@@ -845,8 +880,13 @@ class IntraExtensionConnector(IntraExtensionDriver):
def get_action_assignment_list(self, intra_extension_id, action_id, action_category_id):
with sql.transaction() as session:
query = session.query(ActionAssignment)
- query = query.filter_by(intra_extension_id=intra_extension_id, action_id=action_id, action_category_id=action_category_id)
- ref = query.first()
+ if not action_id or not action_category_id or not action_category_id:
+ query = query.filter_by(intra_extension_id=intra_extension_id)
+ ref = query.all()
+ return ref
+ else:
+ query = query.filter_by(intra_extension_id=intra_extension_id, action_id=action_id, action_category_id=action_category_id)
+ ref = query.first()
if not ref:
return list()
return list(ref.action_assignment)
@@ -881,6 +921,11 @@ class IntraExtensionConnector(IntraExtensionDriver):
return self.set_action_assignment_list(intra_extension_id, action_id, action_category_id, new_action_assignment_list)
def del_action_assignment(self, intra_extension_id, action_id, action_category_id, action_scope_id):
+ if not action_id or not action_category_id or not action_category_id:
+ with sql.transaction() as session:
+ for ref in self.get_action_assignment_list(intra_extension_id, None, None):
+ session.delete(ref)
+ return
new_action_assignment_list = self.get_action_assignment_list(intra_extension_id, action_id, action_category_id)
new_action_assignment_list.remove(action_scope_id)
return self.set_action_assignment_list(intra_extension_id, action_id, action_category_id, new_action_assignment_list)
@@ -983,12 +1028,13 @@ class IntraExtensionConnector(IntraExtensionDriver):
)
if not ref:
session.add(new_ref)
+ ref = new_ref
else:
for attr in Rule.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
session.flush()
- return {rule_id: self.get_rules_dict(intra_extension_id, sub_meta_rule_id)[rule_id]}
+ return {rule_id: ref.rule}
def del_rule(self, intra_extension_id, sub_meta_rule_id, rule_id):
with sql.transaction() as session:
diff --git a/keystone-moon/keystone/contrib/moon/core.py b/keystone-moon/keystone/contrib/moon/core.py
index 8916e2bd..86aadc8b 100644
--- a/keystone-moon/keystone/contrib/moon/core.py
+++ b/keystone-moon/keystone/contrib/moon/core.py
@@ -850,6 +850,7 @@ class IntraExtensionManager(manager.Manager):
@enforce(("read", "write"), "intra_extensions")
def load_intra_extension_dict(self, user_id, intra_extension_dict):
ie_dict = dict()
+ LOG.debug("load_intra_extension_dict {}".format(intra_extension_dict))
ie_dict['id'] = uuid4().hex
ie_dict["name"] = filter_input(intra_extension_dict["name"])
ie_dict["model"] = filter_input(intra_extension_dict["model"])
@@ -927,26 +928,26 @@ class IntraExtensionManager(manager.Manager):
for aggregation_algorithm_id in self.driver.get_aggregation_algorithm_dict(intra_extension_id):
self.driver.del_aggregation_algorithm(intra_extension_id, aggregation_algorithm_id)
for subject_id in self.driver.get_subjects_dict(intra_extension_id):
+ for subject_category_id in self.driver.get_subject_categories_dict(intra_extension_id):
+ self.driver.del_subject_scope(intra_extension_id, None, None)
+ self.driver.del_subject_assignment(intra_extension_id, None, None, None)
+ self.driver.del_subject_category(intra_extension_id, subject_category_id)
+ for object_id in self.driver.get_objects_dict(intra_extension_id):
+ for object_category_id in self.driver.get_object_categories_dict(intra_extension_id):
+ self.driver.del_object_scope(intra_extension_id, None, None)
+ self.driver.del_object_assignment(intra_extension_id, None, None, None)
+ self.driver.del_object_category(intra_extension_id, object_category_id)
+ for action_id in self.driver.get_actions_dict(intra_extension_id):
+ for action_category_id in self.driver.get_action_categories_dict(intra_extension_id):
+ self.driver.del_action_scope(intra_extension_id, None, None)
+ self.driver.del_action_assignment(intra_extension_id, None, None, None)
+ self.driver.del_action_category(intra_extension_id, action_category_id)
+ for subject_id in self.driver.get_subjects_dict(intra_extension_id):
self.driver.del_subject(intra_extension_id, subject_id)
for object_id in self.driver.get_objects_dict(intra_extension_id):
self.driver.del_object(intra_extension_id, object_id)
for action_id in self.driver.get_actions_dict(intra_extension_id):
self.driver.del_action(intra_extension_id, action_id)
- for subject_category_id in self.driver.get_subject_categories_dict(intra_extension_id):
- for subject_scope_id in self.driver.get_subject_assignment_list(intra_extension_id, subject_id, subject_category_id):
- self.driver.del_subject_assignment(intra_extension_id, subject_id, subject_category_id, subject_scope_id)
- self.driver.del_subject_scope(intra_extension_id, subject_category_id, subject_scope_id)
- self.driver.del_subject_category(intra_extension_id, subject_category_id)
- for object_category_id in self.driver.get_object_categories_dict(intra_extension_id):
- for object_scope_id in self.driver.get_object_assignment_list(intra_extension_id, object_id, object_category_id):
- self.driver.del_object_assignment(intra_extension_id, object_id, object_category_id, object_scope_id)
- self.driver.del_object_scope(intra_extension_id, object_category_id, object_scope_id)
- self.driver.del_object_category(intra_extension_id, object_category_id)
- for action_category_id in self.driver.get_action_categories_dict(intra_extension_id):
- for action_scope_id in self.driver.get_action_assignment_list(intra_extension_id, action_id, action_category_id):
- self.driver.del_action_assignment(intra_extension_id, action_id, action_category_id, action_scope_id)
- self.driver.del_action_scope(intra_extension_id, action_category_id, action_scope_id)
- self.driver.del_action_category(intra_extension_id, action_category_id)
return self.driver.del_intra_extension(intra_extension_id)
@enforce(("read", "write"), "intra_extensions")