Commit 1376dd38 authored by Aymeric Barantal's avatar Aymeric Barantal

filter campaign admin models for user related organizations if not super user

parent ff1fb676
......@@ -10,7 +10,34 @@ class InlineContact(admin.TabularInline):
class CampaignAdmin(admin.ModelAdmin):
inlines = [InlineContact]
def get_queryset(self, request):
qs = super(CampaignAdmin, self).get_queryset(request)
if request.user.is_superuser:
return qs
user_orgs = [x.id for x in request.user.organizations.all()]
return qs.filter(organization__in=user_orgs)
class CampaignContactAdmin(admin.ModelAdmin):
def get_queryset(self, request):
qs = super(CampaignContactAdmin, self).get_queryset(request)
if request.user.is_superuser:
return qs
user_orgs = [x.id for x in request.user.organizations.all()]
return qs.filter(campaign__organization__in=user_orgs)
class ArgumentaryAdmin(admin.ModelAdmin):
def get_queryset(self, request):
qs = super(ArgumentaryAdmin, self).get_queryset(request)
if request.user.is_superuser:
return qs
user_orgs = [x.id for x in request.user.organizations.all()]
return qs.filter(campaign__organization__in=user_orgs)
admin.site.register(Campaign, CampaignAdmin)
admin.site.register(CampaignContact)
admin.site.register(Argumentary)
admin.site.register(CampaignContact, CampaignContactAdmin)
admin.site.register(Argumentary, ArgumentaryAdmin)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment