Skip to content

Commit

Permalink
29038 remove user profile
Browse files Browse the repository at this point in the history
  • Loading branch information
domdinicola committed May 6, 2022
1 parent fe5f4cf commit 46cf827
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 49 deletions.
3 changes: 1 addition & 2 deletions django_api/etools_prp/apps/account/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib.auth.admin import UserAdmin

from etools_prp.apps.account.forms import CustomUserCreationForm, UserAdminForm
from etools_prp.apps.account.models import User, UserProfile
from etools_prp.apps.account.models import User


class CustomUserAdmin(UserAdmin):
Expand Down Expand Up @@ -56,4 +56,3 @@ class CustomUserAdmin(UserAdmin):


admin.site.register(User, CustomUserAdmin)
admin.site.register(UserProfile)
28 changes: 0 additions & 28 deletions django_api/etools_prp/apps/account/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from django.db.models.signals import post_save
from django.utils.functional import cached_property

from model_utils.models import TimeStampedModel

from etools_prp.apps.core.common import PRP_ROLE_TYPES, USER_TYPES
from etools_prp.apps.utils.emails import send_email_from_template

Expand Down Expand Up @@ -112,30 +110,4 @@ def save(self, *args, **kwargs):
super().save(*args, **kwargs)


class UserProfile(TimeStampedModel):
"""
User Profile model related with user as profile.
related models:
account.User (OneToOne): "user"
"""
user = models.OneToOneField(
User,
related_name="profile",
on_delete=models.CASCADE,
)

def __str__(self):
return "{} - Profile".format(self.user.get_fullname())

@classmethod
def create_user_profile(cls, sender, instance, created, **kwargs):
"""
Signal handler to create user profiles automatically
"""
if created:
cls.objects.create(user=instance)


post_save.connect(UserProfile.create_user_profile, sender=User)
post_save.connect(User.lock_password_if_new, sender=User)
8 changes: 2 additions & 6 deletions django_api/etools_prp/apps/account/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,9 @@ def get_access(self, obj):
class Meta:
model = User
fields = (
'id', 'email', 'first_name',
'last_name', 'profile',
'partner', 'organization',
'access', 'prp_roles',
'position'
'id', 'email', 'first_name', 'last_name', 'partner', 'organization', 'access', 'prp_roles', 'position'
)
read_only_fields = ('id', 'profile', 'partner', 'organization', 'access', 'prp_roles')
read_only_fields = ('id', 'partner', 'organization', 'access', 'prp_roles')
depth = 1


Expand Down
2 changes: 1 addition & 1 deletion django_api/etools_prp/apps/account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ def get_queryset(self):

users_queryset = self.custom_ordering(users_queryset)

return users_queryset.select_related('profile', 'partner').prefetch_related(prp_roles_prefetch)
return users_queryset.select_related('partner', ).prefetch_related(prp_roles_prefetch)
15 changes: 3 additions & 12 deletions django_api/etools_prp/apps/core/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from faker import Faker
from unicef_locations.models import CartoDBTable

from etools_prp.apps.account.models import User, UserProfile
from etools_prp.apps.account.models import User
from etools_prp.apps.cluster.models import Cluster, ClusterActivity, ClusterObjective
from etools_prp.apps.core.common import (
CLUSTER_TYPES,
Expand Down Expand Up @@ -158,22 +158,13 @@ class AbstractUserFactory(factory.django.DjangoModelFactory):
position = factory.LazyFunction(faker.job)
username = factory.LazyFunction(faker.user_name)
password = factory.PostGenerationMethodCall('set_password', 'test')
profile = factory.RelatedFactory('etools_prp.apps.core.tests.factories.UserProfileFactory', 'user')

class Meta:
model = User
django_get_or_create = ('email', 'username')
abstract = True


@factory.django.mute_signals(signals.post_save)
class UserProfileFactory(factory.django.DjangoModelFactory):
class Meta:
model = UserProfile

user = factory.SubFactory('etools_prp.apps.core.tests.factories.AbstractUserFactory', profile=None)


@factory.django.mute_signals(signals.post_save)
class PartnerUserFactory(AbstractUserFactory):
"""
Expand Down Expand Up @@ -1225,8 +1216,8 @@ class ProgressReportFactory(factory.django.DjangoModelFactory):
review_date = due_date
submission_date = due_date
programme_document = factory.SubFactory('etools_prp.apps.core.tests.factories.ProgrammeDocument', progress_report=None)
submitted_by = factory.SubFactory('etools_prp.apps.core.tests.factories.PartnerUserFactory', profile=None)
submitting_user = factory.SubFactory('etools_prp.apps.core.tests.factories.PartnerUserFactory', profile=None)
submitted_by = factory.SubFactory('etools_prp.apps.core.tests.factories.PartnerUserFactory')
submitting_user = factory.SubFactory('etools_prp.apps.core.tests.factories.PartnerUserFactory')
reviewed_by_email = factory.LazyFunction(faker.ascii_safe_email)
reviewed_by_name = factory.LazyFunction(faker.name)
sent_back_feedback = factory.LazyFunction(faker.text)
Expand Down

0 comments on commit 46cf827

Please sign in to comment.