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 23 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
2 changes: 1 addition & 1 deletion api/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/TUM-Dev/gocast/tools"
"github.com/TUM-Dev/gocast/tools/testutils"
"github.com/gin-gonic/gin"
"github.com/golang/mock/gomock"
"github.com/matthiasreumann/gomino"
"go.uber.org/mock/gomock"
)

func TestGetAudits(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion api/bookmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/TUM-Dev/gocast/tools"
"github.com/TUM-Dev/gocast/tools/testutils"
"github.com/gin-gonic/gin"
"github.com/golang/mock/gomock"
"github.com/matthiasreumann/gomino"
"go.uber.org/mock/gomock"
"gorm.io/gorm"
)

Expand Down
2 changes: 1 addition & 1 deletion api/chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/TUM-Dev/gocast/tools"
"github.com/TUM-Dev/gocast/tools/testutils"
"github.com/gin-gonic/gin"
"github.com/golang/mock/gomock"
"github.com/matthiasreumann/gomino"
"go.uber.org/mock/gomock"
"gorm.io/gorm"
)

Expand Down
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
2 changes: 1 addition & 1 deletion api/courses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
"github.com/TUM-Dev/gocast/tools/testutils"
"github.com/dgraph-io/ristretto"
"github.com/gin-gonic/gin"
"github.com/golang/mock/gomock"
"github.com/matthiasreumann/gomino"
"github.com/u2takey/go-utils/uuid"
"go.uber.org/mock/gomock"
"gorm.io/gorm"
)

Expand Down
2 changes: 1 addition & 1 deletion api/download_ics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/TUM-Dev/gocast/tools"
"github.com/TUM-Dev/gocast/tools/testutils"
"github.com/gin-gonic/gin"
"github.com/golang/mock/gomock"
"github.com/matthiasreumann/gomino"
"go.uber.org/mock/gomock"
)

func TestDownloadICS(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion api/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/TUM-Dev/gocast/tools"
"github.com/TUM-Dev/gocast/tools/testutils"
"github.com/gin-gonic/gin"
"github.com/golang/mock/gomock"
"github.com/matthiasreumann/gomino"
"go.uber.org/mock/gomock"
)

func DownloadRouterWrapper(r *gin.Engine) {
Expand Down
2 changes: 1 addition & 1 deletion api/info-pages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/TUM-Dev/gocast/tools"
"github.com/TUM-Dev/gocast/tools/testutils"
"github.com/gin-gonic/gin"
"github.com/golang/mock/gomock"
"github.com/matthiasreumann/gomino"
"go.uber.org/mock/gomock"
)

func InfoPagesRouterWrapper(r *gin.Engine) {
Expand Down
2 changes: 1 addition & 1 deletion api/lecture_halls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"github.com/TUM-Dev/gocast/tools"
"github.com/TUM-Dev/gocast/tools/testutils"
"github.com/gin-gonic/gin"
"github.com/golang/mock/gomock"
"github.com/matthiasreumann/gomino"
"go.uber.org/mock/gomock"
)

func LectureHallRouterWrapper(t *testing.T) func(r *gin.Engine) {
Expand Down
2 changes: 1 addition & 1 deletion api/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/TUM-Dev/gocast/tools"
"github.com/TUM-Dev/gocast/tools/testutils"
"github.com/gin-gonic/gin"
"github.com/golang/mock/gomock"
"github.com/matthiasreumann/gomino"
"go.uber.org/mock/gomock"
)

func NotificationsRouterWrapper(r *gin.Engine) {
Expand Down
2 changes: 1 addition & 1 deletion api/progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/TUM-Dev/gocast/tools"
"github.com/TUM-Dev/gocast/tools/testutils"
"github.com/gin-gonic/gin"
"github.com/golang/mock/gomock"
"github.com/matthiasreumann/gomino"
"go.uber.org/mock/gomock"
"gorm.io/gorm"
)

Expand Down
2 changes: 1 addition & 1 deletion api/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (
"github.com/TUM-Dev/gocast/tools"
"github.com/TUM-Dev/gocast/tools/testutils"
"github.com/gin-gonic/gin"
"github.com/golang/mock/gomock"
"github.com/matthiasreumann/gomino"
"github.com/meilisearch/meilisearch-go"
"go.uber.org/mock/gomock"
)

func SearchRouterWrapper(r *gin.Engine) {
Expand Down
2 changes: 1 addition & 1 deletion api/seek_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/TUM-Dev/gocast/model"
"github.com/TUM-Dev/gocast/tools/testutils"
"github.com/gin-gonic/gin"
"github.com/golang/mock/gomock"
"github.com/matthiasreumann/gomino"
"go.uber.org/mock/gomock"
)

func ReportSeekRouterWrapper(r *gin.Engine) {
Expand Down
2 changes: 1 addition & 1 deletion api/statistics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/TUM-Dev/gocast/tools"
"github.com/TUM-Dev/gocast/tools/testutils"
"github.com/gin-gonic/gin"
"github.com/golang/mock/gomock"
"github.com/matthiasreumann/gomino"
"go.uber.org/mock/gomock"
"gorm.io/gorm"
)

Expand Down
2 changes: 1 addition & 1 deletion api/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/TUM-Dev/gocast/tools"
"github.com/TUM-Dev/gocast/tools/testutils"
"github.com/gin-gonic/gin"
"github.com/golang/mock/gomock"
"github.com/matthiasreumann/gomino"
"go.uber.org/mock/gomock"
"gorm.io/gorm"
)

Expand Down
2 changes: 1 addition & 1 deletion api/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/TUM-Dev/gocast/tools"
"github.com/TUM-Dev/gocast/tools/testutils"
"github.com/gin-gonic/gin"
"github.com/golang/mock/gomock"
"github.com/matthiasreumann/gomino"
"go.uber.org/mock/gomock"
)

func TokenRouterWrapper(r *gin.Engine) {
Expand Down
2 changes: 1 addition & 1 deletion api/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/TUM-Dev/gocast/tools"
"github.com/TUM-Dev/gocast/tools/testutils"
"github.com/gin-gonic/gin"
"github.com/golang/mock/gomock"
"github.com/matthiasreumann/gomino"
"go.uber.org/mock/gomock"
"gorm.io/gorm"
)

Expand Down
2 changes: 1 addition & 1 deletion api/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/TUM-Dev/gocast/tools"
"github.com/TUM-Dev/gocast/tools/testutils"
"github.com/gin-gonic/gin"
"github.com/golang/mock/gomock"
"github.com/matthiasreumann/gomino"
"go.uber.org/mock/gomock"
)

func TestWorker(t *testing.T) {
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
}
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module github.com/TUM-Dev/gocast

go 1.21
toolchain go1.22.5
go 1.22

toolchain go1.23.2

require (
github.com/RBG-TUM/CAMPUSOnline v0.0.0-20230412070523-8db58ed5c0b4
Expand Down Expand Up @@ -41,7 +42,7 @@ require (
github.com/crewjam/saml v0.4.14
github.com/golang/mock v1.6.0
github.com/icholy/digest v0.1.22
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
github.com/u2takey/go-utils v0.3.1
)

Expand All @@ -52,6 +53,7 @@ require (
github.com/matthiasreumann/gomino v0.0.2
github.com/meilisearch/meilisearch-go v0.26.0
github.com/orandin/slog-gorm v1.1.0
go.uber.org/mock v0.5.0
)

require (
Expand Down
5 changes: 4 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,9 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
Expand All @@ -317,6 +318,8 @@ github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdI
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU=
go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
Expand Down
4 changes: 3 additions & 1 deletion go.work
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
go 1.21
go 1.22

toolchain go1.23.2

use (
.
Expand Down
Loading