@@ -105,12 +105,8 @@ type StreamRequest interface {
105
105
func (a * API ) authorizeUserForStreamCourse (ctx context.Context , req StreamRequest ) (* model.User , model.Stream , model.Course , error ) {
106
106
stream := model.Stream {}
107
107
course := model.Course {}
108
- user , err := a .getCurrent (ctx )
109
- if err != nil {
110
- return nil , stream , course , e .WithStatus (http .StatusUnauthorized , err )
111
- }
112
108
113
- stream , err = a .dao .GetStreamByID (ctx , strconv .FormatUint (uint64 (req .GetStreamId ()), 10 ))
109
+ stream , err : = a .dao .GetStreamByID (ctx , strconv .FormatUint (uint64 (req .GetStreamId ()), 10 ))
114
110
if err != nil {
115
111
if errors .Is (err , gorm .ErrRecordNotFound ) {
116
112
return nil , stream , course , e .WithStatus (http .StatusNotFound , err )
@@ -123,9 +119,14 @@ func (a *API) authorizeUserForStreamCourse(ctx context.Context, req StreamReques
123
119
return nil , stream , course , e .WithStatus (http .StatusInternalServerError , err )
124
120
}
125
121
122
+ user , _ := a .getCurrent (ctx )
126
123
if ! user .IsEligibleToWatchCourse (course ) {
127
124
return nil , stream , course , e .WithStatus (http .StatusForbidden , errors .New ("User is not eligible to access course content" ))
128
125
}
129
126
127
+ if stream .Private && (user == nil || ! user .IsAdminOfCourse (course )) {
128
+ return nil , stream , course , e .WithStatus (http .StatusForbidden , errors .New ("User is not allowed to access private stream" ))
129
+ }
130
+
130
131
return user , stream , course , nil
131
132
}
0 commit comments