From 04fb04340a08ce3444ac04f4ff01b90e0632d311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Barrag=C3=A1n=20Merino?= Date: Fri, 29 Jul 2016 12:40:54 +0200 Subject: [PATCH] Prevent the creation of a duplicate gogs user if you have the gogs plugin enabled --- taiga/hooks/gogs/migrations/0001_initial.py | 26 +++++++++++---------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/taiga/hooks/gogs/migrations/0001_initial.py b/taiga/hooks/gogs/migrations/0001_initial.py index 09ba6709..5c35b081 100644 --- a/taiga/hooks/gogs/migrations/0001_initial.py +++ b/taiga/hooks/gogs/migrations/0001_initial.py @@ -15,18 +15,20 @@ def create_gogs_system_user(apps, schema_editor): # if we directly import it, it'll be the wrong version User = apps.get_model("users", "User") db_alias = schema_editor.connection.alias - random_hash = uuid.uuid4().hex - user = User.objects.using(db_alias).create( - username="gogs-{}".format(random_hash), - email="gogs-{}@taiga.io".format(random_hash), - full_name="Gogs", - is_active=False, - is_system=True, - bio="", - ) - f = open("{}/logo.png".format(CUR_DIR), "rb") - user.photo.save("logo.png", File(f)) - user.save() + + if not User.objects.using(db_alias).filter(is_system=True, username__startswith="gogs-").exists(): + random_hash = uuid.uuid4().hex + user = User.objects.using(db_alias).create( + username="gogs-{}".format(random_hash), + email="gogs-{}@taiga.io".format(random_hash), + full_name="Gogs", + is_active=False, + is_system=True, + bio="", + ) + f = open("{}/logo.png".format(CUR_DIR), "rb") + user.photo.save("logo.png", File(f)) + user.save() class Migration(migrations.Migration):