Skip to content

Commit

Permalink
Merge branch 'fix-migrations-new-install' into fix-attachment-resize
Browse files Browse the repository at this point in the history
  • Loading branch information
noliveleger committed Jun 18, 2024
2 parents a093d65 + f617366 commit d13d49e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
29 changes: 23 additions & 6 deletions hub/admin/password_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.db import transaction
from django.utils.html import format_html

from kpi.deployment_backends.kc_access.shadow_models import KobocatUserProfile
from kobo.apps.openrosa.apps.main.models import UserProfile
from .filters import PasswordValidationAdvancedSearchFilter
from .mixins import AdvancedSearchMixin
from ..models import ExtraUserDetail
Expand Down Expand Up @@ -67,12 +67,17 @@ def get_queryset(self, request):

@admin.display(description='Validated')
def get_validated_password(self, obj):
value = True
value = False
try:
value = obj.extra_details.validated_password
except obj.extra_details.RelatedObjectDoesNotExist:
pass

try:
value = value and obj.profile.validated_password
except obj.profile.RelatedObjectDoesNotExist:
pass

return format_html(
'<img src="/static/admin/img/icon-{}.svg" alt="{}">',
'yes' if value else 'no',
Expand All @@ -88,8 +93,14 @@ def invalidate_passwords(self, request, queryset, **kwargs):
ExtraUserDetail.objects.filter(user_id__in=user_ids).update(
validated_password=False
)
KobocatUserProfile.objects.filter(user_id__in=user_ids).update(
validated_password=False
UserProfile.objects.bulk_create(
[
UserProfile(user_id=user_id, validated_password=False)
for user_id in user_ids
],
update_conflicts=True,
unique_fields=['user_id'],
update_fields=['validated_password'],
)

self.message_user(
Expand All @@ -107,8 +118,14 @@ def validate_passwords(self, request, queryset, **kwargs):
ExtraUserDetail.objects.filter(user_id__in=user_ids).update(
validated_password=True
)
KobocatUserProfile.objects.filter(user_id__in=user_ids).update(
validated_password=True
UserProfile.objects.bulk_create(
[
UserProfile(user_id=user_id, validated_password=True)
for user_id in user_ids
],
update_conflicts=True,
unique_fields=['user_id'],
update_fields=['validated_password'],
)

self.message_user(
Expand Down
3 changes: 3 additions & 0 deletions kpi/management/commands/create_kobo_superuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.db.utils import ProgrammingError

from kobo.apps.kobo_auth.shortcuts import User
from kobo.apps.openrosa.apps.main.models import UserProfile


class Command(BaseCommand):
Expand All @@ -29,6 +30,8 @@ def handle(self, *args, **options):
except Exception as e:
self.stdout.write('Superuser could not be created.\n'
'Error: {}'.format(str(e)))
else:
UserProfile.objects.create(user=user)

if User.objects.filter(username=super_username).count() > 0:
self.stdout.write('Superuser successfully created.')

0 comments on commit d13d49e

Please sign in to comment.