def get_company_organisations__companyorganisationuser_queryset(cls, request, queryset): """ queryset filtering for CO users changelist link: "/mo_admin/company_organisations_companyorganisationuser/" """ allowed_organizations = get_allowed_mo_for_mo_admin(request.user, is_admin=True) queryset = queryset.filter(organization__member_organisation__in=allowed_organizations) return queryset
def get_member_organisations__m2mtoken_queryset(cls, request, queryset): if request.user.is_superuser: return queryset elif request.user.groups.filter(name='MO Admins').exists(): allowed_organizations = get_allowed_mo_for_mo_admin(request.user, is_admin=False) queryset = queryset.filter( token__user__member_organisations_memberorganisation__in=allowed_organizations ) return queryset
def get_company_organisations__companyorganisation_queryset(cls, request, queryset): """ queryset filtering for CO owners edit/add: CO FK link: "/mo_admin/company_organisations_companyorganisationowner/<number>/<change/add>" """ allowed_organizations = get_allowed_mo_for_mo_admin(request.user) queryset = queryset.filter(member_organisation__in=allowed_organizations) return queryset
def get_company_organisations__companyorganisation_queryset(cls, request, queryset): """ name convention: "get_{model._meta.app_label}__{model._meta.model_name}_queryset".lower() if a method doesn't exist you'll recieve the exception with a required method and class names """ allowed_organizations = get_allowed_mo_for_mo_admin(request.user) queryset = queryset.filter(member_organisation__in=allowed_organizations) return queryset
def get_auth__user_queryset(cls, request, queryset): if request.user.is_superuser: return queryset elif request.user.groups.filter(name='MO Admins').exists(): allowed_organizations = get_allowed_mo_for_mo_admin(request.user, is_admin=True) queryset = ( queryset.filter( member_organisations_memberorganisation__in=allowed_organizations ) .exclude(groups__name="GO Admins") .exclude(is_superuser=True) .exclude(is_staff=True) ) return queryset
def get_company_organisations__companyorganisationowner_queryset(cls, request, queryset): """ queryset filtering for CO owners changelist link: "/mo_admin/company_organisations_companyorganisationowner/" """ # filter by organization, company organization should belong to request.user MO allowed_organizations = get_allowed_mo_for_mo_admin(request.user, is_admin=True) queryset = queryset.filter(organization__member_organisation__in=allowed_organizations) # filter by user, organization user should belong to CO, which belong to request.user MO queryset = queryset.filter( organization_user__organization__member_organisation__in=allowed_organizations ) return queryset
def get_bcm__country_queryset(cls, request, queryset): allowed_organizations = get_allowed_mo_for_mo_admin(request.user) queryset = queryset.filter(member_organisation__in=allowed_organizations) return queryset
def get_member_organisations__memberorganisation_queryset(cls, request, queryset): allowed_organizations = get_allowed_mo_for_mo_admin(request.user) queryset = queryset.filter(pk__in=allowed_organizations) return queryset
def get_products__subproduct_queryset(cls, request, queryset): allowed_organizations = get_allowed_mo_for_mo_admin(request.user) queryset = queryset.filter() return queryset
def has_actions_permission(self, request, original_method): if request.user.is_superuser: return True elif get_allowed_mo_for_mo_admin(request.user, is_admin=True): return original_method(request) return False