Skip to content

Commit

Permalink
chore: Revert "fix: OPTIC-184: Revert "feat: OPTIC-184: Remove is_del…
Browse files Browse the repository at this point in the history
…eted fi… (#5182)

Revert "fix: OPTIC-184: Revert "feat: OPTIC-184: Remove is_deleted field from User model and manager" (#5168)"

This reverts commit 52afd31.
  • Loading branch information
jombooth committed Dec 12, 2023
1 parent 1ce70cc commit d3e3897
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
4 changes: 0 additions & 4 deletions label_studio/users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ class UserAdminShort(UserAdmin):

add_fieldsets = ((None, {'fields': ('email', 'password1', 'password2')}),)

def get_queryset(self, request):
# Use the with_deleted method to include soft-deleted users in the queryset
return User.with_deleted.all()

def __init__(self, *args, **kwargs):
super(UserAdminShort, self).__init__(*args, **kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

def add_tokens(apps, schema_editor):
User = apps.get_model('users', 'User')
all_users = User.with_deleted.all()
all_users = User.objects.all()

for user_one in all_users:
if not hasattr(user_one, 'auth_token'):
Expand Down Expand Up @@ -67,9 +67,6 @@ class Migration(migrations.Migration):
'verbose_name_plural': 'users',
'db_table': 'htx_user',
},
managers=[
('with_deleted', users.models.UserManagerWithDeleted()),
],
),
migrations.RunPython(add_tokens),
# migrations.RunPython(add_users), # TODO: flag:ent
Expand Down
3 changes: 2 additions & 1 deletion label_studio/users/migrations/0008_alter_user_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class Migration(migrations.Migration):
name='user',
managers=[
('objects', django.db.models.manager.Manager()),
('with_deleted', users.models.UserManagerWithDeleted()),
# Previously, this migration contained an addition of UserManagerWithDeleted, which has since been
# removed in order to avoid referencing a non-existent manager.
],
),
]
24 changes: 24 additions & 0 deletions label_studio/users/migrations/0009_auto_20231201_0001.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.2.23 on 2023-12-01 00:01

from django.db import migrations
import users.models


class Migration(migrations.Migration):

dependencies = [
('users', '0008_alter_user_managers'),
]

operations = [
migrations.AlterModelManagers(
name='user',
managers=[
('objects', users.models.UserManager()),
],
),
migrations.RemoveField(
model_name='user',
name='is_deleted',
),
]
20 changes: 2 additions & 18 deletions label_studio/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
year = models.IntegerField(_('year'), choices=YEAR_CHOICES, default=datetime.datetime.now().year)


class UserManagerWithDeleted(BaseUserManager):
use_in_migrations: bool = True
class UserManager(BaseUserManager):
use_in_migrations = True

def _create_user(self, email, password, **extra_fields):
"""
Expand Down Expand Up @@ -61,15 +61,6 @@ def create_superuser(self, email, password, **extra_fields):
return self._create_user(email, password, **extra_fields)


class UserManager(UserManagerWithDeleted):
use_in_migrations: bool = False

def get_queryset(self):
qs = super().get_queryset()
qs = qs.filter(is_deleted=False)
return qs


class UserLastActivityMixin(models.Model):
last_activity = models.DateTimeField(_('last activity'), default=timezone.now, editable=False)

Expand Down Expand Up @@ -109,12 +100,6 @@ class User(UserMixin, AbstractBaseUser, PermissionsMixin, UserLastActivityMixin)
default=True,
help_text=_('Designates whether to treat this user as active. Unselect this instead of deleting accounts.'),
)
is_deleted = models.BooleanField(
_('deleted'),
default=False,
db_index=True,
help_text=_('Designates whether to treat this user as deleted. Select this instead of deleting accounts.'),
)

date_joined = models.DateTimeField(_('date joined'), default=timezone.now)

Expand All @@ -129,7 +114,6 @@ class User(UserMixin, AbstractBaseUser, PermissionsMixin, UserLastActivityMixin)
)

objects = UserManager()
with_deleted = UserManagerWithDeleted()

EMAIL_FIELD = 'email'
USERNAME_FIELD = 'email'
Expand Down

0 comments on commit d3e3897

Please sign in to comment.