Pārlūkot izejas kodu

Merge branch 'unstable' of blezz-tech/sharix-open-webapp-base into unstable

5 mainītis faili ar 22 papildinājumiem un 101 dzēšanām
  1. 13 5
      README.md
  2. 3 0
      bin/install.cfg.example
  3. 5 1
      bin/install.sh
  4. 0 3
      core/_settings_vars.py
  5. 1 92
      sharix_admin/signals.py

+ 13 - 5
README.md

@@ -11,13 +11,21 @@ The base Django project of a service web application to which other modules are
 
 ### Test Users
 
-During the installation/upgrade, you can pass the envvar: `TEST_USERS=true` or set
-`GENERATE_TEST_USERS = True` in core/settings_vars.py to automatically create test
-users. These users will be assigned to the **TEST** group. Additionally, if the `DEBUG`
-setting is enabled (`DEBUG=True` in *core/settings_vars.py*), these test
-users will be marked as active and can log in. If `DEBUG` is disabled
+During the installation/upgrade, you can pass the `GENERATE_TEST_USERS=1`
+is set in the `install.cfg` file to automatically create test users.
+These users will be assigned to the **TEST** group. Additionally, if the
+`DEBUG` setting is enabled (`DEBUG=True` in *core/settings_vars.py*), these
+test users will be marked as active and can log in. If `DEBUG` is disabled
 (`DEBUG=False`), the users will be inactive and unable to log in.
 
+#### Alternative gen test user
+
+Use command:
+
+```bash
+python manage.py init_test_users
+```
+
 #### Properties
 
 - **Username:** `test-<group_name>-<ordinal_number_in_group>`.

+ 3 - 0
bin/install.cfg.example

@@ -28,3 +28,6 @@ WEBSERVICE_RUNNING_BRANCH="unstable"
 DESIGN_TEMPLATE_BRANCH="unstable"
 
 LANDING_BRANCH="module-figma"
+
+#Create test users
+GENERATE_TEST_USERS=1

+ 5 - 1
bin/install.sh

@@ -94,4 +94,8 @@ python manage.py collectstatic -l --no-input
 # Seeding data
 python manage.py init_default_data
 
-#cp conf/sharix_open.service /etc/systemd/system/
+if (($GENERATE_TEST_USERS)); then
+    python manage.py init_test_users
+fi
+
+#cp conf/sharix_open.service /etc/systemd/system/

+ 0 - 3
core/_settings_vars.py

@@ -61,6 +61,3 @@ EJ_HOST = "ej.sharix-app.org"
 # Service name that is used in generating ejabber rooms
 METASERVICE_NAME = "open"
 METASERVICE_ID = 1
-
-#Create test users
-GENERATE_TEST_USERS = True

+ 1 - 92
sharix_admin/signals.py

@@ -1,103 +1,12 @@
-import os
 from django.conf import settings
 from django.contrib.auth import get_user_model
-from django.contrib.auth.hashers import make_password
 from django.contrib.auth.models import Group
-from django.db.models.signals import post_migrate
-from django.dispatch import receiver
-from tickets.models import Ticket, TicketList
-from datetime import datetime
-
-from core.settings_vars import GENERATE_TEST_USERS
-
-User = get_user_model()
-
-
-@receiver(post_migrate)
-def create_test_users(sender, **kwargs):
-    """
-    Создает тестовых пользователей, если:
-    
-    - В файле settings_vers.py переменная GENERATE_TEST_USERS = True
-    - Или была задана переменная окружения TEST_USERS=true
-    """
-    if os.getenv('TEST_USERS') == 'true' or GENERATE_TEST_USERS:
-
-        # Создание админа
-        if not get_user_model().objects.filter(phone_number="11111111111").exists():
-            admin = get_user_model().objects.create_superuser(
-                'admin',
-                'admin@admin.com',
-                'Sharix!',
-                phone_number="11111111111"
-            )
-
-        password = make_password("sharix-open-test")
-        test_group = Group.objects.get(pk=99)
-
-        # Группа, в которой надо создать пользователя и их количество
-        test_users = [
-            ('METASERVICE-ADMIN', 1),
-            ('METASERVICE-SUPERVISOR', 3),
-            ('METASERVICE-SUPPORT', 3),
-            ('METASERVICE-TECHSUPPORT', 3),
-
-            ('PARTNER-ADMIN', 1),
-            ('PARTNER-SUPERVISOR', 3),
-            ('PARTNER-SUPPORT', 3),
-            ('PARTNER-TECHSUPPORT', 3),
-
-            ('PROVIDER', 3),
-            ('CLIENT', 3),
-            ('GUEST', 3)
-        ]
-
-        for test_user in test_users:
-            group_name = test_user[0]
-            group = Group.objects.get(name=group_name)
-
-            for i in range(1, test_user[1] + 1):
-                user, created = User.objects.get_or_create(
-                    phone_number=f"{group.pk}0{i}",
-                    defaults={
-                        'last_name': i,
-                        'first_name': group_name,
-                        'email': f"test-{group_name.lower()}-{i}@domain.org",
-                        'username': f"test-{group_name.lower()}-{i}",
-                        'middle_name': "Test",
-                        'password': password
-                    }
-                )
-
-                if created:
-                    user.groups.add(
-                        test_group,
-                        group
-                    )
-
-        # Создание тикета о создании пользователей
-        if Ticket.objects.all().exists():
-            # test-metaservice-admin-1
-            user = get_user_model().objects.filter(phone_number=2101).get()
-            ticket_list = TicketList.objects.get(pk=2103)
-
-            Ticket.objects.create(
-                title=f"Создание тестовых пользователей",
-                ticket_list=ticket_list,
-                ticket_type=1,  # ST_REQUEST
-                due_date=datetime.now().date(),
-                created_by=user,
-                note=f"""
-                    Успешное создание тестовых пользователей
-                """
-            )
-
 
 # Откючаем тестовых пользователей (если такие есть), если DEBUG=False и наоброт
 try:
     if Group.objects.filter(name="TEST").exists():
         test_group = Group.objects.get(name="TEST")
-        users_in_test_group = User.objects.filter(groups=test_group)
+        users_in_test_group = get_user_model().objects.filter(groups=test_group)
 
         if users_in_test_group:
             users_in_test_group.update(is_active=settings.DEBUG)