Skip to content

Commit 437af46

Browse files
committed
feat!: Drop the archived_by user.
We don't need that for this model, it's not that important.
1 parent d20336f commit 437af46

File tree

5 files changed

+7
-26
lines changed

5 files changed

+7
-26
lines changed

backend/sample_plugin/models.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ class CourseArchiveStatus(models.Model):
1010
"""
1111
Model to track the archive status of a course.
1212
13-
Stores information about whether a course has been archived, when it was archived,
14-
and who archived it.
13+
Stores information about whether a course has been archived and when it was archived.
14+
15+
.. no_pii: This model does not store PII directly, only references to users via foreign keys.
1516
"""
1617

1718
course_id = CourseKeyField(
@@ -39,15 +40,6 @@ class CourseArchiveStatus(models.Model):
3940
help_text="The date and time when the course was archived."
4041
)
4142

42-
archived_by = models.ForeignKey(
43-
get_user_model(),
44-
null=True,
45-
blank=True,
46-
on_delete=models.SET_NULL,
47-
related_name="archived_courses",
48-
help_text="The user who archived the course."
49-
)
50-
5143
created_at = models.DateTimeField(auto_now_add=True)
5244
updated_at = models.DateTimeField(auto_now=True)
5345

backend/sample_plugin/serializers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ class Meta:
2222
'user',
2323
'is_archived',
2424
'archive_date',
25-
'archived_by',
2625
'created_at',
2726
'updated_at',
2827
]
29-
read_only_fields = ['id', 'created_at', 'updated_at', 'archive_date', 'archived_by']
28+
read_only_fields = ['id', 'created_at', 'updated_at', 'archive_date']

backend/sample_plugin/views.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def get_queryset(self):
9090
self._validate_query_params()
9191

9292
# Always use select_related to avoid N+1 queries
93-
base_queryset = CourseArchiveStatus.objects.select_related('user', 'archived_by')
93+
base_queryset = CourseArchiveStatus.objects.select_related('user')
9494

9595
if user.is_staff or user.is_superuser:
9696
return base_queryset
@@ -147,10 +147,9 @@ def perform_create(self, serializer):
147147
)
148148
raise PermissionDenied("You do not have permission to create records for other users.")
149149

150-
# Set archive_date and archived_by if is_archived is True
150+
# Set archive_date if is_archived is True
151151
if data.get('is_archived', False):
152152
data['archive_date'] = timezone.now()
153-
data['archived_by'] = self.request.user
154153

155154
# Create the record
156155
instance = serializer.save(**data)
@@ -174,16 +173,14 @@ def perform_update(self, serializer):
174173
instance = serializer.instance
175174
data = serializer.validated_data.copy()
176175

177-
# Handle archive_date and archived_by if is_archived changes
176+
# Handle archive_date if is_archived changes
178177
if 'is_archived' in data:
179178
# If changing from not archived to archived
180179
if data['is_archived'] and not instance.is_archived:
181180
data['archive_date'] = timezone.now()
182-
data['archived_by'] = self.request.user
183181
# If changing from archived to not archived
184182
elif not data['is_archived'] and instance.is_archived:
185183
data['archive_date'] = None
186-
data['archived_by'] = None
187184

188185
# Update the record
189186
updated_instance = serializer.save(**data)

backend/tests/test_api.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,11 @@ def test_create_course_archive_status(api_client, user, course_key):
152152
assert response.data['user'] == user.id
153153
assert response.data['is_archived'] is True
154154
assert response.data['archive_date'] is not None
155-
assert response.data['archived_by'] == user.id
156155

157156
# Verify in database
158157
course_archive_status = CourseArchiveStatus.objects.get(course_id=course_key, user=user)
159158
assert course_archive_status.is_archived is True
160159
assert course_archive_status.archive_date is not None
161-
assert course_archive_status.archived_by == user
162160

163161

164162
@pytest.mark.django_db
@@ -197,7 +195,6 @@ def test_staff_create_course_archive_status_for_another_user(api_client, staff_u
197195
assert response.data['user'] == user.id
198196
assert response.data['is_archived'] is True
199197
assert response.data['archive_date'] is not None
200-
assert response.data['archived_by'] == staff_user.id
201198

202199

203200
@pytest.mark.django_db
@@ -215,13 +212,11 @@ def test_update_course_archive_status(api_client, user, course_archive_status):
215212
assert response.status_code == status.HTTP_200_OK
216213
assert response.data['is_archived'] is True
217214
assert response.data['archive_date'] is not None
218-
assert response.data['archived_by'] == user.id
219215

220216
# Verify in database
221217
course_archive_status.refresh_from_db()
222218
assert course_archive_status.is_archived is True
223219
assert course_archive_status.archive_date is not None
224-
assert course_archive_status.archived_by == user
225220

226221

227222
@pytest.mark.django_db
@@ -266,4 +261,3 @@ def test_staff_can_update_other_user_course_archive_status(api_client, staff_use
266261

267262
assert response.status_code == status.HTTP_200_OK
268263
assert response.data['is_archived'] is True
269-
assert response.data['archived_by'] == staff_user.id

backend/tests/test_models.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ def test_course_archive_status_creation(user, course_key):
6464
assert course_archive_status.user == user
6565
assert course_archive_status.is_archived is False
6666
assert course_archive_status.archive_date is None
67-
assert course_archive_status.archived_by is None
6867
assert course_archive_status.created_at is not None
6968
assert course_archive_status.updated_at is not None
7069

0 commit comments

Comments
 (0)