Check for enabled features on local sites when on a global site
Review Request #9705 — Created Feb. 26, 2018 and updated
When browing a non-LocalSite specific page, if any LocalSite the user is
a member of has a feature enabled then it should be enabled for that
user while browsing the non-LocalSite page. Previously, this was not
taken into account and features that a user should otherwise have access
to would be disabled if they were enabled only for their LocalSites.
This has been corrected.
Ran unit tests.
We can simplify this, reducing the code paths for checking a value and returning and code paths with:
if local_site: local_sites = [local_site] elif request is not None and request.user.is_authenticated(): local_sites = request.user.local_site.all() else: local_sites =  for local_site in local_sites: if self._is_enabled_for_local_site(...): return True return False
I don't like this returning
Noneas an optional, and don't like not having an explicit return. This way leads to confusing problems down the road. This can easily return a boolean explicitly using basically what we had before:
if local_site.extra_data: try: return local_site.extra_data[self.EXTRA_DATA_KEY][feature_id] except KeyError: pass return False
No trailing comma.
Addressed Christian's comments.
Revision 2 (+84 -26)
Checks run (1 failed, 1 succeeded)