Skip to content

Commit 125534e

Browse files
fix: public stream access in apiv2 (#1597)
1 parent aed00a0 commit 125534e

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

apiv2/server/authorization.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,8 @@ type StreamRequest interface {
105105
func (a *API) authorizeUserForStreamCourse(ctx context.Context, req StreamRequest) (*model.User, model.Stream, model.Course, error) {
106106
stream := model.Stream{}
107107
course := model.Course{}
108-
user, err := a.getCurrent(ctx)
109-
if err != nil {
110-
return nil, stream, course, e.WithStatus(http.StatusUnauthorized, err)
111-
}
112108

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))
114110
if err != nil {
115111
if errors.Is(err, gorm.ErrRecordNotFound) {
116112
return nil, stream, course, e.WithStatus(http.StatusNotFound, err)
@@ -123,9 +119,14 @@ func (a *API) authorizeUserForStreamCourse(ctx context.Context, req StreamReques
123119
return nil, stream, course, e.WithStatus(http.StatusInternalServerError, err)
124120
}
125121

122+
user, _ := a.getCurrent(ctx)
126123
if !user.IsEligibleToWatchCourse(course) {
127124
return nil, stream, course, e.WithStatus(http.StatusForbidden, errors.New("User is not eligible to access course content"))
128125
}
129126

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+
130131
return user, stream, course, nil
131132
}

0 commit comments

Comments
 (0)