From ea88326d13f56317e83c9d77d076e8b130454d9d Mon Sep 17 00:00:00 2001 From: Davis Raymond Muro Date: Thu, 8 Apr 2021 21:37:18 +0300 Subject: [PATCH] Set project shared status to xform shared status if not the same --- onadata/apps/logger/models/xform.py | 6 ++++-- onadata/libs/utils/project_utils.py | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/onadata/apps/logger/models/xform.py b/onadata/apps/logger/models/xform.py index e90e1adde5..365d31c626 100644 --- a/onadata/apps/logger/models/xform.py +++ b/onadata/apps/logger/models/xform.py @@ -1054,7 +1054,9 @@ def clear_project_cache(project_id): def set_object_permissions(sender, instance=None, created=False, **kwargs): # clear cache - clear_project_cache(instance.project.pk) + project = instance.project + project.refresh_from_db() + clear_project_cache(project.pk) safe_delete('{}{}'.format(IS_ORG, instance.pk)) if created: @@ -1065,7 +1067,7 @@ def set_object_permissions(sender, instance=None, created=False, **kwargs): OwnerRole.add(instance.created_by, instance) from onadata.libs.utils.project_utils import set_project_perms_to_xform - set_project_perms_to_xform(instance, instance.project) + set_project_perms_to_xform(instance, project) post_save.connect( diff --git a/onadata/libs/utils/project_utils.py b/onadata/libs/utils/project_utils.py index 3248c05c58..1681134721 100644 --- a/onadata/libs/utils/project_utils.py +++ b/onadata/libs/utils/project_utils.py @@ -22,8 +22,7 @@ def set_project_perms_to_xform(xform, project): """ # allows us to still use xform.shared and xform.shared_data as before # only switch if xform.shared is False - xform_is_shared = xform.shared or xform.shared_data - if not xform_is_shared and project.shared != xform.shared: + if project.shared != xform.shared: xform.shared = project.shared xform.shared_data = project.shared xform.save()