Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: OPTIC-184: Remove is_deleted field from User model and manager #5125

Merged
merged 5 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading