diff --git a/api/courses.go b/api/courses.go index 366a9b6c7..f5e577e46 100644 --- a/api/courses.go +++ b/api/courses.go @@ -80,6 +80,7 @@ func configGinCourseRouter(router *gin.Engine, daoWrapper dao.DaoWrapper) { { stream.Use(tools.InitStream(daoWrapper)) stream.GET("/transcodingProgress", routes.getTranscodingProgress) + stream.POST("/copy", routes.copyStream) } stats := courses.Group("/stats") @@ -1516,6 +1517,62 @@ type copyCourseRequest struct { YearW string } +func (r coursesRoutes) copyStream(c *gin.Context) { + type req struct { + TargetCourse uint `json:"targetCourse"` + Move bool `json:"move"` + } + var request req + err := c.BindJSON(&request) + if err != nil { + _ = c.Error(tools.RequestError{Status: http.StatusBadRequest, CustomMessage: "Bad request", Err: err}) + return + } + tlctx := c.MustGet("TUMLiveContext").(tools.TUMLiveContext) + + isAdmin := tlctx.User.Role == model.AdminType + + if !isAdmin { + targetCourseAdmins, err := r.DaoWrapper.CoursesDao.GetCourseAdmins(request.TargetCourse) + if err != nil { + log.WithError(err).Error("Error getting course admins") + _ = c.Error(tools.RequestError{ + Status: http.StatusInternalServerError, + CustomMessage: "can't determine admins of target course", + Err: err, + }) + } + for _, admin := range targetCourseAdmins { + if admin.ID == tlctx.User.ID { + isAdmin = true + break + } + } + } + if !isAdmin { + _ = c.Error(tools.RequestError{ + Status: http.StatusForbidden, + CustomMessage: "you are not admin of the target course", + }) + return + } + + stream := tlctx.Stream + stream.Model = gorm.Model{} + stream.CourseID = request.TargetCourse + err = r.StreamsDao.CreateStream(stream) + if err != nil { + _ = c.Error(tools.RequestError{ + Status: http.StatusInternalServerError, + CustomMessage: "Can't save stream", + Err: err, + }) + } + if request.Move { + r.StreamsDao.DeleteStream(strconv.Itoa(int(tlctx.Stream.ID))) + } +} + func (r coursesRoutes) copyCourse(c *gin.Context) { var request copyCourseRequest err := c.BindJSON(&request) diff --git a/model/stream.go b/model/stream.go index 855c13990..27dec2161 100755 --- a/model/stream.go +++ b/model/stream.go @@ -345,6 +345,7 @@ func (s Stream) getJson(lhs []LectureHall, course Course) gin.H { "courseSlug": course.Slug, "private": s.Private, "downloadableVods": s.GetVodFiles(), + "isCopying": false, } } diff --git a/web/admin.go b/web/admin.go index 7e99b9064..b62dadef4 100755 --- a/web/admin.go +++ b/web/admin.go @@ -241,7 +241,7 @@ func (r mainRoutes) EditCoursePage(c *gin.Context) { Semesters: semesters, CurY: tumLiveContext.Course.Year, CurT: tumLiveContext.Course.TeachingTerm, - EditCourseData: EditCourseData{IndexData: indexData, IngestBase: tools.Cfg.IngestBase, LectureHalls: lectureHalls}, + EditCourseData: EditCourseData{Courses: courses, IndexData: indexData, IngestBase: tools.Cfg.IngestBase, LectureHalls: lectureHalls}, }) if err != nil { log.Printf("%v\n", err) @@ -331,6 +331,7 @@ type EditCourseData struct { IndexData IndexData IngestBase string LectureHalls []model.LectureHall + Courses []model.Course // administered courses of user } type LectureUnitsPageData struct { diff --git a/web/template/partial/course/manage/lecture-management-card.gohtml b/web/template/partial/course/manage/lecture-management-card.gohtml index 8681f9931..8b03a9bd2 100644 --- a/web/template/partial/course/manage/lecture-management-card.gohtml +++ b/web/template/partial/course/manage/lecture-management-card.gohtml @@ -2,6 +2,7 @@ {{- /*gotype: github.com/joschahenningsen/TUM-Live/web.AdminPageData*/ -}} {{$course := .IndexData.TUMLiveContext.Course}} + {{$courses := .Courses}} {{$user := .IndexData.TUMLiveContext.User}} {{$ingestBase := .IngestBase}} {{$lectureHalls := .LectureHalls}} @@ -199,6 +200,10 @@ :class="lecture.private?'text-gray-400 dark:hover:text-gray-500 hover:text-gray-300':'text-red-400 dark:hover:text-red-500 hover:text-red-300'"> Make private +