Skip to content

Commit

Permalink
♻️(backend) rename simple_jwt attributes
Browse files Browse the repository at this point in the history
As we now have only playlist tokens, the simple_jwt attributes must
be renamed for reflecting it.
  • Loading branch information
kernicPanel committed Aug 22, 2023
1 parent b47d6e7 commit bec1040
Show file tree
Hide file tree
Showing 130 changed files with 682 additions and 673 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class {{cookiecutter.model}}ViewSet(
queryset = {{cookiecutter.model}}.objects.all()
serializer_class = serializers.{{cookiecutter.model}}Serializer
permission_classes = [
core_permissions.IsTokenResourceRouteObject
core_permissions.IsTokenPlaylistRouteObject
& (core_permissions.IsTokenInstructor | core_permissions.IsTokenAdmin)
]

Expand All @@ -44,7 +44,7 @@ def get_permissions(self):
& (core_permissions.IsTokenInstructor | core_permissions.IsTokenAdmin)
]
elif self.action in ["retrieve"]:
permission_classes = [core_permissions.IsTokenResourceRouteObject]
permission_classes = [core_permissions.IsTokenPlaylistRouteObject]
else:
permission_classes = self.permission_classes
return [permission() for permission in permission_classes]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_api_{{cookiecutter.model_lower}}_fetch_list_student(self):
{{cookiecutter.model_lower}} = {{cookiecutter.model}}Factory()

jwt_token = StudentLtiTokenFactory(
resource={{cookiecutter.model_lower}},
playlist={{cookiecutter.model_lower}}.playlist,
permissions__can_update=True,
)

Expand All @@ -55,7 +55,7 @@ def test_api_{{cookiecutter.model_lower}}_fetch_list_instructor(self):
"""An instructor should not be able to fetch a {{cookiecutter.model_lower}} list."""
{{cookiecutter.model_lower}} = {{cookiecutter.model}}Factory()

jwt_token = InstructorOrAdminLtiTokenFactory(resource={{cookiecutter.model_lower}})
jwt_token = InstructorOrAdminLtiTokenFactory(playlist={{cookiecutter.model_lower}}.playlist)

response = self.client.get(
"/api/{{cookiecutter.model_url_part}}/", HTTP_AUTHORIZATION=f"Bearer {jwt_token}"
Expand All @@ -66,7 +66,7 @@ def test_api_{{cookiecutter.model_lower}}_fetch_student(self):
"""A student should be allowed to fetch a {{cookiecutter.model_lower}}."""
{{cookiecutter.model_lower}} = {{cookiecutter.model}}Factory()

jwt_token = StudentLtiTokenFactory(resource={{cookiecutter.model_lower}})
jwt_token = StudentLtiTokenFactory(playlist={{cookiecutter.model_lower}}.playlist)

response = self.client.get(
f"/api/{{cookiecutter.model_url_part}}/{ {{cookiecutter.model_lower}}.id!s}/",
Expand Down Expand Up @@ -95,7 +95,7 @@ def test_api_{{cookiecutter.model_lower}}_fetch_from_other_{{cookiecutter.model_
other_{{cookiecutter.model_lower}} = {{cookiecutter.model}}Factory()


jwt_token = StudentLtiTokenFactory(resource=other_{{cookiecutter.model_lower}})
jwt_token = StudentLtiTokenFactory(playlist=other_{{cookiecutter.model_lower}}.playlist)

response = self.client.get(
f"/api/{{cookiecutter.model_url_part}}/{ {{cookiecutter.model_lower}}.id!s}/",
Expand All @@ -107,7 +107,7 @@ def test_api_{{cookiecutter.model_lower}}_fetch_instructor(self):
"""An instructor should be able to fetch a {{cookiecutter.model_lower}}."""
{{cookiecutter.model_lower}} = {{cookiecutter.model}}Factory()

jwt_token = InstructorOrAdminLtiTokenFactory(resource={{cookiecutter.model_lower}})
jwt_token = InstructorOrAdminLtiTokenFactory(playlist={{cookiecutter.model_lower}}.playlist)

response = self.client.get(
f"/api/{{cookiecutter.model_url_part}}/{ {{cookiecutter.model_lower}}.id!s}/",
Expand Down Expand Up @@ -140,7 +140,7 @@ def test_api_{{cookiecutter.model_lower}}_create_student(self):
{{cookiecutter.model_lower}} = {{cookiecutter.model}}Factory()

jwt_token = StudentLtiTokenFactory(
resource={{cookiecutter.model_lower}},
playlist={{cookiecutter.model_lower}}.playlist,
permissions__can_update=True,
)

Expand All @@ -163,7 +163,7 @@ def test_api_{{cookiecutter.model_lower}}_create_instructor(self):
"""An instructor without playlist token should not be able to create a {{cookiecutter.model_lower}}."""
{{cookiecutter.model_lower}} = {{cookiecutter.model}}Factory()

jwt_token = InstructorOrAdminLtiTokenFactory(resource={{cookiecutter.model_lower}})
jwt_token = InstructorOrAdminLtiTokenFactory(playlist={{cookiecutter.model_lower}}.playlist)

response = self.client.post(
"/api/{{cookiecutter.model_url_part}}/", HTTP_AUTHORIZATION=f"Bearer {jwt_token}"
Expand Down Expand Up @@ -230,7 +230,7 @@ def test_api_{{cookiecutter.model_lower}}_update_student(self):
"""A student user should not be able to update a {{cookiecutter.model_lower}}."""
{{cookiecutter.model_lower}} = {{cookiecutter.model}}Factory()

jwt_token = StudentLtiTokenFactory(resource={{cookiecutter.model_lower}})
jwt_token = StudentLtiTokenFactory(playlist={{cookiecutter.model_lower}}.playlist)
data = {"title": "new title"}

response = self.client.patch(
Expand All @@ -246,7 +246,7 @@ def test_api_{{cookiecutter.model_lower}}_update_instructor_read_only(self):
{{cookiecutter.model_lower}} = {{cookiecutter.model}}Factory()

jwt_token = InstructorOrAdminLtiTokenFactory(
resource={{cookiecutter.model_lower}},
playlist={{cookiecutter.model_lower}}.playlist,
permissions__can_update=False,
)
data = {"title": "new title"}
Expand All @@ -263,7 +263,7 @@ def test_api_{{cookiecutter.model_lower}}_update_instructor(self):
"""An instructor should be able to update a {{cookiecutter.model_lower}}."""
{{cookiecutter.model_lower}} = {{cookiecutter.model}}Factory()

jwt_token = InstructorOrAdminLtiTokenFactory(resource={{cookiecutter.model_lower}})
jwt_token = InstructorOrAdminLtiTokenFactory(playlist={{cookiecutter.model_lower}}.playlist)
data = {"title": "new title", "description": "Hello"}

response = self.client.patch(
Expand Down
12 changes: 6 additions & 6 deletions src/backend/marsha/account/tests/api/test_token_refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ def test_success_user_access(self):
# ... and new refresh token is not
new_refresh_token.verify()

def test_success_resource_access(self):
def test_success_playlist_access(self):
"""
A request with a correct resource refresh token should return a 200 with a new token pair.
A request with a correct playlist refresh token should return a 200 with a new token pair.
"""
session_id = str(uuid.uuid4())
resource_id = str(uuid.uuid4())
refresh_token = PlaylistRefreshToken.for_resource_id(resource_id, session_id)
playlist_id = str(uuid.uuid4())
refresh_token = PlaylistRefreshToken.for_playlist_id(playlist_id, session_id)

response = self.client.post(
"/account/api/token/refresh/",
Expand All @@ -113,9 +113,9 @@ def test_success_resource_access(self):
new_token = PlaylistAccessToken(response_data["access"])
new_refresh_token = PlaylistRefreshToken(response_data["refresh"])

self.assertEqual(new_token.payload["token_type"], "resource_access")
self.assertEqual(new_token.payload["token_type"], "playlist_access")
self.assertEqual(
new_refresh_token.payload["access_token_type"], "resource_access"
new_refresh_token.payload["access_token_type"], "playlist_access"
)

# Assert old refresh token is blacklisted ...
Expand Down
6 changes: 3 additions & 3 deletions src/backend/marsha/bbb/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def get_permissions(self):
elif self.action in ["retrieve", "service_join"]:
permission_classes = [
core_permissions.IsPlaylistTokenMatchingRouteObject
| core_permissions.IsTokenResourceRouteObject # needed for invite links
| core_permissions.IsTokenPlaylistRouteObject # needed for invite links
| (
core_permissions.UserIsAuthenticated # asserts request.resource is None
& (
Expand Down Expand Up @@ -188,7 +188,7 @@ def get_serializer_context(self):
)
# For LTI
| (
core_permissions.ResourceIsAuthenticated
core_permissions.PlaylistIsAuthenticated
& core_permissions.IsPlaylistTokenMatchingRouteObject
& (
core_permissions.IsTokenInstructor
Expand Down Expand Up @@ -539,7 +539,7 @@ def get_permissions(self):
)
]
elif self.action in ["metadata"]:
permission_classes = [core_permissions.UserOrResourceIsAuthenticated]
permission_classes = [core_permissions.UserOrPlaylistIsAuthenticated]
else:
permission_classes = self.permission_classes
return [permission() for permission in permission_classes]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_api_classroom_recording_create_anonymous_unknown_recording(self):
def test_api_classroom_recording_create_vod_student(self):
"""Students should not be able to convert a recording to a VOD."""
recording = ClassroomRecordingFactory()
jwt_token = StudentLtiTokenFactory(resource=recording.classroom.playlist)
jwt_token = StudentLtiTokenFactory(playlist=recording.classroom.playlist)

with mock.patch("marsha.bbb.api.invoke_lambda_convert"):
response = self.client.post(
Expand All @@ -100,7 +100,7 @@ def test_api_classroom_recording_create_vod_instructor_or_admin(self):
started_at="2019-08-21T15:00:02Z",
)
jwt_token = InstructorOrAdminLtiTokenFactory(
resource=recording.classroom.playlist
playlist=recording.classroom.playlist
)

self.assertEqual(Video.objects.count(), 0)
Expand Down Expand Up @@ -155,7 +155,7 @@ def test_api_classroom_recording_create_vod_instructor_or_admin_unknown_recordin
started_at="2019-08-21T15:00:02Z",
)
jwt_token = InstructorOrAdminLtiTokenFactory(
resource=recording.classroom.playlist
playlist=recording.classroom.playlist
)

self.assertEqual(Video.objects.count(), 0)
Expand Down Expand Up @@ -372,7 +372,7 @@ def test_api_classroom_recording_create_vod_instructor_or_admin_inactive_convers
classroom__playlist__consumer_site__inactive_features=["vod_convert"],
)
jwt_token = InstructorOrAdminLtiTokenFactory(
resource=recording.classroom.playlist
playlist=recording.classroom.playlist
)

self.assertEqual(Video.objects.count(), 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_api_delete_classroom_recording_anonymous(self, delete_recording_mock):
def test_api_delete_classroom_recording_student(self, delete_recording_mock):
"""Students should not be able to delete a recording."""
recording = ClassroomRecordingFactory()
jwt_token = StudentLtiTokenFactory(resource=recording.classroom.playlist)
jwt_token = StudentLtiTokenFactory(playlist=recording.classroom.playlist)
self.assertEqual(ClassroomRecording.objects.count(), 1)

response = self.client.delete(
Expand All @@ -94,7 +94,7 @@ def test_api_delete_classroom_recording_instructor_or_admin(
started_at="2019-08-21T15:00:02Z",
)
jwt_token = InstructorOrAdminLtiTokenFactory(
resource=recording.classroom.playlist
playlist=recording.classroom.playlist
)
self.assertEqual(ClassroomRecording.objects.count(), 1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_api_classroom_bulk_delete_student(self):
classroom2 = ClassroomFactory()

jwt_token = StudentLtiTokenFactory(
resource=classroom1.playlist,
playlist=classroom1.playlist,
permissions__can_update=True,
)

Expand All @@ -71,7 +71,7 @@ def test_api_classroom_bulk_delete_instructor(self):
"""LTI Token can't delete a list of classroom."""
classroom = ClassroomFactory()

jwt_token = InstructorOrAdminLtiTokenFactory(resource=classroom.playlist)
jwt_token = InstructorOrAdminLtiTokenFactory(playlist=classroom.playlist)

response = self.client.delete(
self._api_url(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_api_list_classroom_documents_student(self):
"""A student should not be able to fetch a list of classroom documents."""
classroom = ClassroomFactory()
ClassroomDocumentFactory.create_batch(3, classroom=classroom)
jwt_token = StudentLtiTokenFactory(resource=classroom.playlist)
jwt_token = StudentLtiTokenFactory(playlist=classroom.playlist)

response = self.client.get(
f"/api/classrooms/{classroom.id}/classroomdocuments/",
Expand All @@ -63,7 +63,7 @@ def test_api_list_classroom_documents_instructor(self):
classroom_documents = ClassroomDocumentFactory.create_batch(
3, classroom=classroom
)
jwt_token = InstructorOrAdminLtiTokenFactory(resource=classroom.playlist)
jwt_token = InstructorOrAdminLtiTokenFactory(playlist=classroom.playlist)

response = self.client.get(
f"/api/classrooms/{classroom.id}/classroomdocuments/?limit=2",
Expand Down Expand Up @@ -118,7 +118,7 @@ def test_api_list_classroom_documents_instructor_urls(self):
uploaded_on=now,
)
)
jwt_token = InstructorOrAdminLtiTokenFactory(resource=classroom.playlist)
jwt_token = InstructorOrAdminLtiTokenFactory(playlist=classroom.playlist)

response = self.client.get(
f"/api/classrooms/{classroom.id}/classroomdocuments/",
Expand Down
4 changes: 2 additions & 2 deletions src/backend/marsha/bbb/tests/api/classroom/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_api_classroom_create_student(self):
classroom = ClassroomFactory()

jwt_token = StudentLtiTokenFactory(
resource=classroom.playlist,
playlist=classroom.playlist,
permissions__can_update=True,
)

Expand All @@ -69,7 +69,7 @@ def test_api_classroom_create_instructor(self, mock_get_meeting_infos):
"running": "true",
}

jwt_token = InstructorOrAdminLtiTokenFactory(resource=playlist)
jwt_token = InstructorOrAdminLtiTokenFactory(playlist=playlist)

self.assertEqual(Classroom.objects.count(), 0)

Expand Down
4 changes: 2 additions & 2 deletions src/backend/marsha/bbb/tests/api/classroom/test_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_api_classroom_delete_student(self):
classroom = ClassroomFactory()

jwt_token = StudentLtiTokenFactory(
resource=classroom.playlist,
playlist=classroom.playlist,
permissions__can_update=True,
)

Expand All @@ -58,7 +58,7 @@ def test_api_classroom_delete_instructor(self):
"""An instructor without playlist token should not be able to delete a classroom."""
classroom = ClassroomFactory()

jwt_token = InstructorOrAdminLtiTokenFactory(resource=classroom.playlist)
jwt_token = InstructorOrAdminLtiTokenFactory(playlist=classroom.playlist)

response = self.client.delete(
f"/api/classrooms/{classroom.id}/", HTTP_AUTHORIZATION=f"Bearer {jwt_token}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def test_invite_public_token(self):
public_token = response.json().get("access_token")

decoded_public_token = PlaylistAccessToken(public_token)
self.assertEqual(decoded_public_token.payload["resource_id"], str(classroom.id))
self.assertEqual(
decoded_public_token.payload["playlist_id"], str(classroom.playlist_id)
)
self.assertEqual(decoded_public_token.payload["roles"], [NONE])
self.assertEqual(
decoded_public_token.payload["permissions"],
Expand All @@ -73,7 +75,7 @@ def test_invite_instructor_token(self):

decoded_instructor_token = PlaylistAccessToken(instructor_token)
self.assertEqual(
decoded_instructor_token.payload["resource_id"], str(classroom.id)
decoded_instructor_token.payload["playlist_id"], str(classroom.playlist_id)
)
self.assertEqual(decoded_instructor_token.payload["roles"], [INSTRUCTOR])
self.assertEqual(
Expand Down
4 changes: 2 additions & 2 deletions src/backend/marsha/bbb/tests/api/classroom/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_api_classroom_fetch_list_student(self):
classroom = ClassroomFactory()

jwt_token = StudentLtiTokenFactory(
resource=classroom.playlist,
playlist=classroom.playlist,
permissions__can_update=True,
)

Expand All @@ -59,7 +59,7 @@ def test_api_fetch_list_instructor(self):
"""An instructor should not be able to fetch a classroom list."""
classroom = ClassroomFactory()

jwt_token = InstructorOrAdminLtiTokenFactory(resource=classroom.playlist)
jwt_token = InstructorOrAdminLtiTokenFactory(playlist=classroom.playlist)

response = self.client.get(
"/api/classrooms/", HTTP_AUTHORIZATION=f"Bearer {jwt_token}"
Expand Down
6 changes: 3 additions & 3 deletions src/backend/marsha/bbb/tests/api/classroom/test_lti_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_api_select_instructor_no_bbb_server(self):
"""An instructor should be able to fetch a classroom lti select."""
playlist = core_factories.PlaylistFactory()

jwt_token = InstructorOrAdminLtiTokenFactory(resource=playlist)
jwt_token = InstructorOrAdminLtiTokenFactory(playlist=playlist)

response = self.client.get(
"/api/classrooms/lti-select/",
Expand All @@ -50,7 +50,7 @@ def test_api_select_instructor_no_classrooms(self):
"""An instructor should be able to fetch a classroom lti select."""
playlist = core_factories.PlaylistFactory()

jwt_token = InstructorOrAdminLtiTokenFactory(resource=playlist)
jwt_token = InstructorOrAdminLtiTokenFactory(playlist=playlist)

response = self.client.get(
"/api/classrooms/lti-select/",
Expand All @@ -69,7 +69,7 @@ def test_api_select_instructor(self):
"""An instructor should be able to fetch a classroom lti select."""
classroom = ClassroomFactory()

jwt_token = InstructorOrAdminLtiTokenFactory(resource=classroom.playlist)
jwt_token = InstructorOrAdminLtiTokenFactory(playlist=classroom.playlist)

response = self.client.get(
"/api/classrooms/lti-select/",
Expand Down
Loading

0 comments on commit bec1040

Please sign in to comment.