Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delisting unavailable pinned courses #1420

Open
wants to merge 21 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions .idea/dataSources.xml
KemalKrKX marked this conversation as resolved.
Show resolved Hide resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions api/courses.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,15 @@ func (r coursesRoutes) getPinned(c *gin.Context) {
user := tumLiveContext.User
resp := make([]model.CourseDTO, 0, len(pinnedCourses))
for _, course := range pinnedCourses {
// todo: check if user is allowed to see the course
// -> Get full course from database
enrolled, err := r.CoursesDao.IsUserEnrolledInCourse(tumLiveContext.User.ID, course.ID)
if err != nil {
enrolled = false
}
if course.Visibility == "enrolled" && !enrolled {
continue
}
if !course.IsHidden() {
resp = append(resp, course.ToDTO(user))
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/tumlive/tumlive.go
KemalKrKX marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func GinServer() (err error) {
router.Use(gzip.Gzip(gzip.DefaultCompression))
api.ConfigGinRouter(router)
web.ConfigGinRouter(router)
err = router.Run(":8081")
err = router.Run(":8083")
// err = router.RunTLS(":443", tools.Cfg.Saml.Cert, tools.Cfg.Saml.Privkey)
if err != nil {
sentry.CaptureException(err)
Expand Down
11 changes: 11 additions & 0 deletions dao/courses.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type CoursesDao interface {

RemoveAdminFromCourse(userID uint, courseID uint) error
DeleteCourse(course model.Course)

IsUserEnrolledInCourse(userID uint, courseID uint) (bool, error)
}

type coursesDao struct {
Expand Down Expand Up @@ -338,3 +340,12 @@ func (d coursesDao) DeleteCourse(course model.Course) {
logger.Error("Can't delete course", "err", err)
}
}

func (d coursesDao) IsUserEnrolledInCourse(user uint, course uint) (bool, error) {
var nRows int64
err := DB.Table("course_users").Where("user_id = ? AND course_id = ?", user, course).Count(&nRows).Error
if err != nil {
return false, err
}
return nRows == 1, nil
}
4 changes: 4 additions & 0 deletions docker-compose.yml
KemalKrKX marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ services:
db:
container_name: mariadb_container
image: mariadb
ports:
- "3306:3306"
environment:
MYSQL_ROOT_USER: root
MYSQL_ROOT_PASSWORD: example
Expand All @@ -71,6 +73,8 @@ services:
- ./init.sql:/data/application/init.sql
- mariadb-data:/var/lib/mysql
restart: always
ports:
- "3306:3306"
# Omitted for local development due to size. Comment out to use voice-service
# voice-service:
# container_name: tum-live-voice-service
Expand Down
1 change: 1 addition & 0 deletions web/template/home.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

{{if and .VersionTag (eq .VersionTag "development")}}
<script defer src="/static/node_modules/alpinejs/dist/cdn.js"></script>
<script defer src="/static/node_modules/alpinejs/dist/cdn.js"></script>
{{else}}
<script defer src="/static/node_modules/alpinejs/dist/cdn.min.js"></script>
{{end}}
Expand Down
2 changes: 1 addition & 1 deletion web/template/index.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{{if .PinnedCourses}}
<h2 class="text-2xl text-1 mt-2">Pinned Courses</h2>
{{range $course := .PinnedCourses}}
{{if not $course.IsHidden}}
{{if $user.IsEligibleToWatchCourse $course}}
{{template "course-card" (dict "course" $course "user" $user)}}
{{end}}
{{end}}
Expand Down
Loading