Commit 24a19271 authored by Alexander Færøy's avatar Alexander Færøy 🍍
Browse files

Create models for Gitlab signup/approval.

parent 9dc04c66
import gitlab
from django.contrib import admin
# Register your models here.
from .models import GitlabAccountRequest
from lobby.settings import GITLAB_URL, GITLAB_SECRET_TOKEN
def approve(modeladmin, request, queryset):
for item in queryset:
client = gitlab.Gitlab(GITLAB_URL, private_token=GITLAB_SECRET_TOKEN)
try:
client.users.create({
"name": item.username,
"username": item.username,
"email": item.email,
"reset_password": True,
"projects_limit": 5,
"can_create_group": False,
"skip_confirmation": True, # The password reset mail is enough.
})
except Exception as e:
print("Error: {}".format(e))
continue
item.delete()
approve.short_description = "Approve account requests"
@admin.register(GitlabAccountRequest)
class GitlabAccountRequestAdmin(admin.ModelAdmin):
fields = ('username', 'email', 'approved')
list_display = ('username', 'email')
actions = [approve]
def has_delete_permission(self, request, obj=None):
return False
from django.db import models
from django import forms
# Create your models here.
class GitlabAccountRequest(models.Model):
username = models.CharField(max_length=64)
email = models.EmailField()
approved = models.BooleanField(default=False)
class GitlabAccountRequestForm(forms.ModelForm):
class Meta:
model = GitlabAccountRequest
fields = ["username", "email"]
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