This repository has been archived by the owner on Nov 2, 2024. It is now read-only.
forked from intelowlproject/IntelOwl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix duplicated ingestor users (intelowlproject#2412)
* fix * removed if condition and added defaults * removed .title() * fixed test due to .title() change * fixed test due to .title() change
- Loading branch information
1 parent
9cd0a3c
commit 1247cd7
Showing
4 changed files
with
63 additions
and
5 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
api_app/ingestors_manager/migrations/0022_ingestor_fix_duplicated_users.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from django.conf import settings | ||
from django.db import migrations | ||
|
||
|
||
def migrate(apps, schema_editor): | ||
User = apps.get_model(*settings.AUTH_USER_MODEL.split(".")) | ||
UserProfile = apps.get_model("authentication", "UserProfile") | ||
IngestorConfig = apps.get_model("ingestors_manager", "IngestorConfig") | ||
PluginConfig = apps.get_model("api_app", "PluginConfig") | ||
|
||
users = User.objects.filter(username__endswith="Ingestor") | ||
for u in users: | ||
username = u.username.removesuffix("Ingestor") | ||
if username != username.title(): | ||
correct_user = User.objects.get_or_create( | ||
username=f"{username.title()}Ingestor" | ||
)[0] | ||
correct_user.profile = UserProfile() | ||
correct_user.profile.task_priority = 7 | ||
correct_user.profile.is_robot = True | ||
correct_user.profile.save() | ||
|
||
related_ingestor = IngestorConfig.objects.get(name__iexact=username) | ||
related_ingestor.user = correct_user | ||
related_ingestor.save() | ||
|
||
for pc in PluginConfig.objects.filter(owner=u): | ||
pc.owner = correct_user | ||
pc.save() | ||
|
||
u.delete() | ||
|
||
|
||
def reverse_migrate(apps, schema_editor): | ||
pass | ||
|
||
|
||
class Migration(migrations.Migration): | ||
atomic = False | ||
dependencies = [ | ||
("api_app", "0062_alter_parameter_python_module"), | ||
("ingestors_manager", "0021_ingestor_fix_malwarebazaar_threatfox"), | ||
] | ||
|
||
operations = [migrations.RunPython(migrate, reverse_migrate)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters