-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Created model, serializer and view for user-bio * Created user bio model and made migrations * Created user bio serializer + viewsets + added new endpoint * Tested create method + added bio serializer to user serializer * Format * Created update method and started testing * Debugging test failures in user retrieve * fixed model error * Created user_bio_factory + started testing put method * Created fixture for UserBio * Created custom excpetion for duplicate user bio * Added permissions and inherited from BaseModel * Modularized serializer for bio * Use correct serializers in viewset + added destroy method * Finished testing bio viewset integration + format * Changed environent file to .env to avoid pushing up keys * Fix: Flipped assertion statement in test, since user bio should not be deleted * skiped buggy test from kontres * added mark to pytest.skip * Moved keys to .env file and reverted docker variables * Skip buggy kontres test * format * Added str method to user_bio * Removed unused imports * format * Changed user relation to a OneToOne-field (same affect as ForeignKey(unique=True) + removed check for duplicate bio in serializer * Migrations + changed assertion status code in duplicate bio test (could try catch in serializer to produce 400 status code) * format * format * Changed limit for description 50 -> 500 + migrations * Migrate * added id to serializer * merged leaf nodes in migrations * format --------- Co-authored-by: Ester2109 <[email protected]> Co-authored-by: Mads Nylund <[email protected]> Co-authored-by: Mads Nylund <[email protected]> Co-authored-by: Tam Le <[email protected]>
- Loading branch information
1 parent
95ef58c
commit bfa2299
Showing
20 changed files
with
457 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import factory | ||
from factory.django import DjangoModelFactory | ||
|
||
from app.content.factories.user_factory import UserFactory | ||
from app.content.models.user_bio import UserBio | ||
|
||
|
||
class UserBioFactory(DjangoModelFactory): | ||
class Meta: | ||
model = UserBio | ||
|
||
user = factory.SubFactory(UserFactory) |
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,43 @@ | ||
# Generated by Django 4.2.5 on 2024-01-29 17:51 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("content", "0058_merge_20231217_2155"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="UserBio", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("description", models.CharField(max_length=50)), | ||
("gitHub_link", models.URLField(blank=True, max_length=300, null=True)), | ||
( | ||
"linkedIn_link", | ||
models.URLField(blank=True, max_length=300, null=True), | ||
), | ||
( | ||
"user", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="bio", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
), | ||
] |
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,18 @@ | ||
# Generated by Django 4.2.5 on 2024-02-01 10:27 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("content", "0059_userbio"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="userbio", | ||
name="description", | ||
field=models.CharField(blank=True, max_length=50, null=True), | ||
), | ||
] |
27 changes: 27 additions & 0 deletions
27
app/content/migrations/0061_userbio_created_at_userbio_updated_at.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,27 @@ | ||
# Generated by Django 4.2.5 on 2024-02-19 16:09 | ||
|
||
from django.db import migrations, models | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("content", "0060_alter_userbio_description"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="userbio", | ||
name="created_at", | ||
field=models.DateTimeField( | ||
auto_now_add=True, default=django.utils.timezone.now | ||
), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name="userbio", | ||
name="updated_at", | ||
field=models.DateTimeField(auto_now=True), | ||
), | ||
] |
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,25 @@ | ||
# Generated by Django 4.2.5 on 2024-02-21 13:35 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("content", "0061_userbio_created_at_userbio_updated_at"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="userbio", | ||
name="user", | ||
field=models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="bio", | ||
to=settings.AUTH_USER_MODEL, | ||
unique=True, | ||
), | ||
), | ||
] |
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,24 @@ | ||
# Generated by Django 4.2.5 on 2024-02-21 13:39 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("content", "0062_alter_userbio_user"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="userbio", | ||
name="user", | ||
field=models.OneToOneField( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="bio", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
] |
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,18 @@ | ||
# Generated by Django 4.2.5 on 2024-02-26 15:27 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("content", "0063_alter_userbio_user"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="userbio", | ||
name="description", | ||
field=models.CharField(blank=True, max_length=500, null=True), | ||
), | ||
] |
13 changes: 13 additions & 0 deletions
13
app/content/migrations/0065_merge_0060_minute_tag_0064_alter_userbio_description.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,13 @@ | ||
# Generated by Django 4.2.5 on 2024-04-16 06:58 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("content", "0060_minute_tag"), | ||
("content", "0064_alter_userbio_description"), | ||
] | ||
|
||
operations = [] |
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.db import models | ||
|
||
from app.common.enums import Groups | ||
from app.common.permissions import BasePermissionModel, check_has_access | ||
from app.content.models.user import User | ||
from app.util.models import BaseModel | ||
|
||
|
||
class UserBio(BaseModel, BasePermissionModel): | ||
read_access = (Groups.TIHLDE,) | ||
write_access = (Groups.TIHLDE,) | ||
|
||
description = models.CharField(max_length=500, blank=True, null=True) | ||
|
||
gitHub_link = models.URLField(max_length=300, blank=True, null=True) | ||
|
||
linkedIn_link = models.URLField(max_length=300, blank=True, null=True) | ||
|
||
user = models.OneToOneField( | ||
User, on_delete=models.CASCADE, unique=True, related_name="bio" | ||
) | ||
|
||
def __str__(self): | ||
bio_str = f"{self.user}" | ||
if self.description: | ||
bio_str += f" - {self.description}" | ||
if self.gitHub_link: | ||
bio_str += f" - {self.gitHub_link}" | ||
if self.linkedIn_link: | ||
bio_str += f" - {self.linkedIn_link}" | ||
return bio_str | ||
|
||
@classmethod | ||
def has_update_permission(cls, request): | ||
return check_has_access(cls.write_access, request) | ||
|
||
@classmethod | ||
def has_destroy_permission(cls, request): | ||
return check_has_access(cls.write_access, request) | ||
|
||
def has_object_update_permission(self, request): | ||
return self.user == request.user | ||
|
||
def has_object_destroy_permission(self, request): | ||
return self.user == request.user |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from app.common.serializers import BaseModelSerializer | ||
from app.content.models.user_bio import UserBio | ||
|
||
|
||
class UserBioSerializer(BaseModelSerializer): | ||
class Meta: | ||
model = UserBio | ||
fields = ["id", "description", "gitHub_link", "linkedIn_link"] | ||
|
||
|
||
class UserBioCreateSerializer(BaseModelSerializer): | ||
class Meta: | ||
model = UserBio | ||
fields = ["description", "gitHub_link", "linkedIn_link"] | ||
|
||
def create(self, validated_data): | ||
return super().create(validated_data) | ||
|
||
|
||
class UserBioUpdateSerializer(BaseModelSerializer): | ||
class Meta: | ||
model = UserBio | ||
fields = ["description", "gitHub_link", "linkedIn_link"] |
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
Oops, something went wrong.