Commit 0b9dcc34 authored by Alexander Færøy's avatar Alexander Færøy 🍍
Browse files

Refactor user approval into its own function in gitlab.py.

parent 02b41f64
import gitlab
from django.contrib import admin
from .models import GitlabAccountRequest
from lobby.settings import GITLAB_URL, GITLAB_SECRET_TOKEN
from .gitlab import approve_user
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.approved = True
item.save()
approve_user(item)
approve.short_description = "Approve account requests"
......
import gitlab
from lobby.settings import GITLAB_URL, GITLAB_SECRET_TOKEN
def approve_user(model):
client = gitlab.Gitlab(GITLAB_URL, private_token=GITLAB_SECRET_TOKEN)
try:
client.users.create({
"name": model.username,
"username": model.username,
"email": model.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))
return
model.approved = True
model.save()
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