33from django .contrib .auth .decorators import login_required
44from django .utils .decorators import method_decorator
55from django .urls import reverse
6- from django_email_learning .models import Organization
7- from django_email_learning .decorators import is_platform_admin
6+ from django_email_learning .models import Organization , OrganizationUser , Course
7+ from django_email_learning .decorators import (
8+ is_platform_admin ,
9+ is_an_organization_member ,
10+ )
811from typing import Dict , Any
912
1013
@@ -19,10 +22,19 @@ def get_context_data(self, **kwargs) -> Dict[str, Any]: # type: ignore[no-untyp
1922
2023 def get_shared_context (self ) -> Dict [str , Any ]:
2124 """Get shared context for all platform views"""
25+ active_organization_id = self .get_or_set_active_organization ()
26+ if self .request .user .is_superuser :
27+ role = "admin"
28+ else :
29+ role = OrganizationUser .objects .get ( # type: ignore[misc]
30+ user = self .request .user ,
31+ organization_id = active_organization_id ,
32+ ).role
2233 return {
2334 "api_base_url" : reverse ("django_email_learning:api:root" )[:- 1 ],
2435 "platform_base_url" : reverse ("django_email_learning:platform:root" )[:- 1 ],
25- "active_organization_id" : self .get_or_set_active_organization (),
36+ "active_organization_id" : active_organization_id ,
37+ "user_role" : role ,
2638 "is_platform_admin" : (
2739 self .request .user .is_superuser
2840 or (
@@ -62,6 +74,18 @@ def get_context_data(self, **kwargs) -> dict: # type: ignore[no-untyped-def]
6274 return context
6375
6476
77+ @method_decorator (login_required , name = "dispatch" )
78+ @method_decorator (is_an_organization_member (), name = "dispatch" )
79+ class CourseView (BasePlatformView ):
80+ template_name = "platform/course.html"
81+
82+ def get_context_data (self , ** kwargs ) -> dict : # type: ignore[no-untyped-def]
83+ context = super ().get_context_data (** kwargs )
84+ course = Course .objects .get (pk = self .kwargs ["course_id" ])
85+ context ["page_title" ] = course .title
86+ return context
87+
88+
6589@method_decorator (login_required , name = "dispatch" )
6690@method_decorator (is_platform_admin (), name = "dispatch" )
6791class Organizations (BasePlatformView ):
0 commit comments