From 718abab9d2ac842f19a08bd4f0f6acf53f2a355c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Thu, 7 May 2020 12:45:06 +0200 Subject: [PATCH] Add make-admin command to uncloud_auth --- README.md | 6 +++++- uncloud_auth/management/commands/make-admin.py | 16 ++++++++++++++++ uncloud_pay/views.py | 4 ++-- 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 uncloud_auth/management/commands/make-admin.py diff --git a/README.md b/README.md index 6da7cdb..8c53654 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,11 @@ Cloud management platform, the ungleich way. [![pipeline status](https://code.ungleich.ch/uncloud/uncloud/badges/master/pipeline.svg)](https://code.ungleich.ch/uncloud/uncloud/commits/master) [![coverage report](https://code.ungleich.ch/uncloud/uncloud/badges/master/coverage.svg)](https://code.ungleich.ch/uncloud/uncloud/commits/master) +## Useful commands + +* `./manage.py import-vat-rates path/to/csv` +* `./manage.py make-admin username` + ## Development setup Install system dependencies: @@ -55,4 +60,3 @@ If you want to use Postgres: * Install on configure PGSQL on your base system. * OR use a container! `podman run --rm -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust -it postgres:latest` - diff --git a/uncloud_auth/management/commands/make-admin.py b/uncloud_auth/management/commands/make-admin.py new file mode 100644 index 0000000..b750bc3 --- /dev/null +++ b/uncloud_auth/management/commands/make-admin.py @@ -0,0 +1,16 @@ +from django.core.management.base import BaseCommand +from django.contrib.auth import get_user_model +import sys + +class Command(BaseCommand): + help = 'Give Admin rights to existing user' + + def add_arguments(self, parser): + parser.add_argument('username', type=str) + + def handle(self, *args, **options): + user = get_user_model().objects.get(username=options['username']) + user.is_staff = True + user.save() + + print("{} is now admin.".format(user.username)) diff --git a/uncloud_pay/views.py b/uncloud_pay/views.py index 54ff2f0..8bb2280 100644 --- a/uncloud_pay/views.py +++ b/uncloud_pay/views.py @@ -243,7 +243,7 @@ class BillingAddressViewSet(mixins.CreateModelMixin, return Response(serializer.data) ### -# Old admin stuff. +# Admin stuff. class AdminPaymentViewSet(viewsets.ModelViewSet): serializer_class = PaymentSerializer @@ -279,7 +279,7 @@ class AdminBillViewSet(viewsets.ModelViewSet): return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers) class AdminOrderViewSet(viewsets.ModelViewSet): - permission_classes = [permissions.IsAuthenticated] + permission_classes = [permissions.IsAdminUser] def get_serializer(self, *args, **kwargs): return OrderSerializer(*args, **kwargs, admin=True)