Skip to content

Commit

Permalink
Merge pull request #156 from mngoe/feature-30649-dev
Browse files Browse the repository at this point in the history
feat: Control the no_location_check parameter via a configuration in be-insuree
  • Loading branch information
delcroip authored Jan 16, 2025
2 parents 397b760 + 02d7c0a commit 014023d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Rights required:
for adults (default: `60`)
* renewal_photo_age_child": age (in months) of a picture due for renewal
for children (default: `12`)
* no_location_check : if implementation is at a national scale without any Location check for all Users (default: False)

## openIMIS Modules Dependencies
* location.models.HealthFacility
2 changes: 2 additions & 0 deletions insuree/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"insuree_fsp_mandatory": False,
"insuree_as_worker": False,
"is_insuree_photo_required": False,
"no_location_check": False,
}


Expand Down Expand Up @@ -77,6 +78,7 @@ class InsureeConfig(AppConfig):
insuree_fsp_mandatory = None
insuree_as_worker = None
is_insuree_photo_required = None
no_location_check = None

def __load_config(self, cfg):
for field in cfg:
Expand Down
4 changes: 2 additions & 2 deletions insuree/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def get_queryset(cls, queryset, user):
queryset = queryset.exclude(
members__chf_id__in=InsureeConfig.excluded_insuree_chfids
)
if settings.ROW_SECURITY and not user.is_imis_admin:
if settings.ROW_SECURITY and not user.is_imis_admin and not InsureeConfig.no_location_check:
from location.schema import LocationManager
return queryset.filter(
LocationManager().build_user_location_filter_query(user._u, prefix='location__parent__parent', loc_types=['D']))
Expand Down Expand Up @@ -314,7 +314,7 @@ def get_queryset(cls, queryset, user):
# The insuree "health facility" is the "First Point of Service"
# (aka the 'preferred/reference' HF for an insuree)
# ... so not to be used as 'strict filtering'
if settings.ROW_SECURITY and not user.is_imis_admin:
if settings.ROW_SECURITY and not user.is_imis_admin and not InsureeConfig.no_location_check:
return queryset.filter(
Q(LocationManager().build_user_location_filter_query(user._u, prefix='current_village__parent__parent', loc_types=['D']) |
LocationManager().build_user_location_filter_query(user._u, prefix='family__location__parent__parent', loc_types=['D']))
Expand Down
4 changes: 2 additions & 2 deletions insuree/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def resolve_insurees(self, info, **kwargs):
filters += [(Q(current_village__isnull=False) & Q(**{current_village: parent_location})) |
(Q(current_village__isnull=True) & Q(**{family_location: parent_location}))]

if not info.context.user._u.is_imis_admin and (kwargs.get('ignore_location') == False or kwargs.get('ignore_location') is None):
if not info.context.user._u.is_imis_admin and (kwargs.get('ignore_location') == False or kwargs.get('ignore_location') is None) and not InsureeConfig.no_location_check:
# Limit the list by the logged in user location mapping
filters += [Q(LocationManager().build_user_location_filter_query(info.context.user._u, prefix='current_village__parent__parent', loc_types=['D']) |
LocationManager().build_user_location_filter_query(info.context.user._u, prefix='family__location__parent__parent', loc_types=['D']))]
Expand Down Expand Up @@ -288,7 +288,7 @@ def resolve_families(self, info, **kwargs):
filters += [Q(**{f: parent_location})]

# Limit the list by the logged in user location mapping
if not info.context.user._u.is_imis_admin:
if not info.context.user._u.is_imis_admin and not InsureeConfig.no_location_check:
filters += [LocationManager().build_user_location_filter_query(info.context.user._u,
prefix='location__parent__parent', loc_types=['D'])]

Expand Down

0 comments on commit 014023d

Please sign in to comment.