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 all 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: 13 additions & 0 deletions api/courses.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,19 @@ func (r coursesRoutes) getPinned(c *gin.Context) {
user := tumLiveContext.User
resp := make([]model.CourseDTO, 0, len(pinnedCourses))
for _, course := range pinnedCourses {
enrolled := false
var err error
// todo: check if user is allowed to see the course
// -> Get full course from database
if user != nil {
enrolled, err = r.CoursesDao.IsUserEnrolledInCourse(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
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
}
15 changes: 15 additions & 0 deletions mock_dao/courses.go

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

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