Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
2020
PPL-C
PPTI-Mobile Apps Monitoring Wabah Tuberkolosis
Neza-Backend
Commits
505fa23d
Commit
505fa23d
authored
Apr 19, 2020
by
Jonathan Christopher Jakub
Browse files
[GREEN] Change accounts to have author, adjust logs accordingly
parent
0a57d7ee
Pipeline
#41413
failed with stages
in 10 minutes and 15 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/accounts/migrations/0003_accounthistory_author.py
0 → 100644
View file @
505fa23d
# Generated by Django 3.0.1 on 2020-04-19 11:26
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'accounts'
,
'0002_auto_20200419_0156'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'accounthistory'
,
name
=
'author'
,
field
=
models
.
UUIDField
(
null
=
True
),
),
]
apps/accounts/migrations/0004_account_author.py
0 → 100644
View file @
505fa23d
# Generated by Django 3.0.1 on 2020-04-19 11:29
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'accounts'
,
'0003_accounthistory_author'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'account'
,
name
=
'author'
,
field
=
models
.
ForeignKey
(
blank
=
True
,
null
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
DO_NOTHING
,
related_name
=
'account'
,
to
=
'accounts.Account'
),
),
]
apps/accounts/models.py
View file @
505fa23d
...
...
@@ -15,6 +15,7 @@ class AccountHistory(HistoryModel):
is_admin
=
models
.
BooleanField
(
default
=
False
)
is_verified
=
models
.
BooleanField
(
default
=
False
)
is_active
=
models
.
BooleanField
(
default
=
False
)
author
=
models
.
UUIDField
(
null
=
True
)
objects
=
models
.
Manager
()
...
...
@@ -22,7 +23,7 @@ class AccountHistory(HistoryModel):
db_table
=
"account_history"
verbose_name_plural
=
"account histories"
ordering
=
[
"-recorded_at"
]
def
__str__
(
self
):
return
f
"[History] Rev.
{
self
.
revision_id
}
-
{
self
.
name
}
"
...
...
@@ -38,6 +39,13 @@ class Account(HistoryEnabledModel):
is_verified
=
models
.
BooleanField
(
default
=
False
)
is_active
=
models
.
BooleanField
(
default
=
False
)
created_at
=
models
.
DateTimeField
(
auto_now_add
=
True
)
author
=
models
.
ForeignKey
(
"self"
,
blank
=
True
,
null
=
True
,
on_delete
=
models
.
DO_NOTHING
,
related_name
=
"account"
,
)
history_class
=
AccountHistory
relation_fields
=
[
"user"
]
...
...
apps/accounts/serializers.py
View file @
505fa23d
...
...
@@ -52,3 +52,6 @@ class AccountRegisterSerializer(serializers.ModelSerializer):
serializer
=
AccountSerializer
(
instance
)
return
serializer
.
data
def
save
(
self
):
account
=
self
.
context
.
get
(
'request'
).
user
.
account
super
(
AccountRegisterSerializer
,
self
).
save
(
author
=
account
)
apps/accounts/views.py
View file @
505fa23d
...
...
@@ -58,6 +58,9 @@ class AccountViewSet(viewsets.ModelViewSet):
user
=
User
.
objects
.
create_user
(
username
=
username
,
password
=
password
)
Account
.
objects
.
create
(
user
=
user
,
**
serializer
.
validated_data
)
def
perform_destroy
(
self
,
instance
):
instance
.
delete
(
author
=
self
.
request
.
user
.
account
)
@
action
(
detail
=
False
,
methods
=
[
"get"
],
url_path
=
"me"
)
def
profile
(
self
,
request
):
user
=
request
.
user
...
...
apps/logs/migrations/0003_delete_log.py
View file @
505fa23d
# Generated by Django 3.0.1 on 2020-04-1
8
1
8
:56
# Generated by Django 3.0.1 on 2020-04-1
9
1
0
:56
from
django.db
import
migrations
...
...
apps/logs/serializers.py
View file @
505fa23d
from
rest_framework
import
serializers
from
apps.accounts.serializers
import
AccountSerializer
from
apps.accounts.models
import
AccountHistory
from
apps.accounts.models
import
AccountHistory
,
Account
from
apps.cases.models
import
(
CaseSubjectHistory
,
InvestigationCaseHistory
,
...
...
@@ -44,5 +44,9 @@ class LogSerializer(serializers.Serializer):
return
MODEL_NAME_CASE_SUBJECT
def
get_author
(
self
,
instance
):
if
hasattr
(
instance
,
"author"
):
return
AccountSerializer
(
instance
.
author
).
data
if
isinstance
(
instance
.
author
,
Account
):
author
=
instance
.
author
else
:
author
=
Account
.
objects
.
filter
(
id
=
instance
.
author
).
first
()
return
AccountSerializer
(
author
).
data
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment