Scope reseller access to assigned hosting accounts
Allow operators to assign accounts to resellers and give each reseller read-only access to their own accounts and Apache previews.
This commit is contained in:
1 parent
bb95b86173
commit
39243a8ab3
13 files changed
+325
-33
No files matched your search
@@ -0,0 +1,31 @@
|
||||
def reseller_for_user(user):
|
||||
if not user.is_authenticated or user.is_superuser:
|
||||
return None
|
||||
return getattr(user, "hosting_reseller", None)
|
||||
|
||||
|
||||
def panel_access(request):
|
||||
return {"is_reseller": reseller_for_user(request.user) is not None}
|
||||
|
||||
|
||||
class OperatorOnlyMixin:
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if reseller_for_user(request.user) is not None:
|
||||
return self.handle_no_permission()
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
class ResellerScopeMixin:
|
||||
reseller_relation = "reseller"
|
||||
|
||||
def has_permission(self):
|
||||
return (
|
||||
reseller_for_user(self.request.user) is not None or super().has_permission()
|
||||
)
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = super().get_queryset()
|
||||
reseller = reseller_for_user(self.request.user)
|
||||
if reseller is not None:
|
||||
return queryset.filter(**{f"{self.reseller_relation}_id": reseller.pk})
|
||||
return queryset
|
||||
Reference in new issue
Block a user