Add make-admin command to uncloud_auth
This commit is contained in:
		
					parent
					
						
							
								268e08c4db
							
						
					
				
			
			
				commit
				
					
						718abab9d2
					
				
			
		
					 3 changed files with 23 additions and 3 deletions
				
			
		| 
						 | 
					@ -6,6 +6,11 @@ Cloud management platform, the ungleich way.
 | 
				
			||||||
[](https://code.ungleich.ch/uncloud/uncloud/commits/master)
 | 
					[](https://code.ungleich.ch/uncloud/uncloud/commits/master)
 | 
				
			||||||
[](https://code.ungleich.ch/uncloud/uncloud/commits/master)
 | 
					[](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
 | 
					## Development setup
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Install system dependencies:
 | 
					Install system dependencies:
 | 
				
			||||||
| 
						 | 
					@ -55,4 +60,3 @@ If you want to use Postgres:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* Install on configure PGSQL on your base system.
 | 
					* 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`
 | 
					* OR use a container! `podman run --rm -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust -it postgres:latest`
 | 
				
			||||||
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										16
									
								
								uncloud_auth/management/commands/make-admin.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								uncloud_auth/management/commands/make-admin.py
									
										
									
									
									
										Normal 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))
 | 
				
			||||||
| 
						 | 
					@ -243,7 +243,7 @@ class BillingAddressViewSet(mixins.CreateModelMixin,
 | 
				
			||||||
        return Response(serializer.data)
 | 
					        return Response(serializer.data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
###
 | 
					###
 | 
				
			||||||
# Old admin stuff.
 | 
					# Admin stuff.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class AdminPaymentViewSet(viewsets.ModelViewSet):
 | 
					class AdminPaymentViewSet(viewsets.ModelViewSet):
 | 
				
			||||||
    serializer_class = PaymentSerializer
 | 
					    serializer_class = PaymentSerializer
 | 
				
			||||||
| 
						 | 
					@ -279,7 +279,7 @@ class AdminBillViewSet(viewsets.ModelViewSet):
 | 
				
			||||||
        return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
 | 
					        return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class AdminOrderViewSet(viewsets.ModelViewSet):
 | 
					class AdminOrderViewSet(viewsets.ModelViewSet):
 | 
				
			||||||
    permission_classes = [permissions.IsAuthenticated]
 | 
					    permission_classes = [permissions.IsAdminUser]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_serializer(self, *args, **kwargs):
 | 
					    def get_serializer(self, *args, **kwargs):
 | 
				
			||||||
        return OrderSerializer(*args, **kwargs, admin=True)
 | 
					        return OrderSerializer(*args, **kwargs, admin=True)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue