Add make-admin command to uncloud_auth

This commit is contained in:
fnux 2020-05-07 12:45:06 +02:00
parent 268e08c4db
commit 718abab9d2
3 changed files with 23 additions and 3 deletions

View file

@ -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`

View file

@ -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))

View file

@ -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)