Fakultas Ilmu Komputer UI

Commit 20842e86 authored by Jonathan Christopher Jakub's avatar Jonathan Christopher Jakub
Browse files

Merge branch 'bugfix/PBI-9-case-subject-author' into 'staging'

Fix: set author on case_subject to reduce chaining the author value from case

See merge request !33
parents 1c7f17d2 d1b04e92
Pipeline #40487 passed with stages
in 4 minutes and 33 seconds
# Generated by Django 3.0.1 on 2020-04-15 11:36
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('accounts', '0001_initial'),
('cases', '0003_auto_20200414_1453'),
]
operations = [
migrations.AddField(
model_name='casesubject',
name='author',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='case_subject', to='accounts.Account'),
),
]
......@@ -21,6 +21,13 @@ class CaseSubject(models.Model):
deleted_at = models.DateTimeField(blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
is_active = models.BooleanField(default=True, db_index=True)
author = models.ForeignKey(
Account,
blank=True,
null=True,
on_delete=models.DO_NOTHING,
related_name="case_subject",
)
objects = SoftObjectManager()
......
......@@ -63,18 +63,25 @@ class CaseSubjectViewSet(viewsets.ViewSet):
def create(self, request):
serializer = self.serializer_class(data=request.data)
serializer.is_valid(raise_exception=True)
serializer.save()
serializer_data = serializer.data
instance = CaseSubject.objects.create(
**serializer_data, author=request.user.account
)
# Add case subject creation log
Log.objects.create(
model_name=MODEL_NAME_CASE_SUBJECT,
object_id=serializer.data["subject_id"],
revision_id=serializer.data["revision_id"],
object_id=instance.subject_id,
revision_id=instance.revision_id,
action_type=ACTIVITY_TYPE_CREATE,
author=request.user.account,
)
return Response(serializer.data, status=status.HTTP_201_CREATED,)
return Response(
self.serializer_class(instance).data,
status=status.HTTP_201_CREATED,
)
def update(self, request, pk=None):
previous_instance = get_object_or_404(self.queryset, pk=pk)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment