From f71e7830cb6fddba06606c7b2738278d8911f92d Mon Sep 17 00:00:00 2001 From: Joscha Henningsen Date: Wed, 12 Jul 2023 10:59:56 +0200 Subject: [PATCH] allow copying videos to other courses --- api/courses.go | 50 +++++++++++++++++ model/stream.go | 1 + .../manage/lecture-management-card.gohtml | 54 ++++++++++++++++++- 3 files changed, 104 insertions(+), 1 deletion(-) diff --git a/api/courses.go b/api/courses.go index 366a9b6c7..94f9cd98a 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,55 @@ type copyCourseRequest struct { YearW string } +func (r coursesRoutes) copyStream(c *gin.Context) { + type req struct { + TargetCourse uint `json:"targetCourse"` + } + 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) + + 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, + }) + } + isAdmin := false + 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, + }) + } +} + 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/template/partial/course/manage/lecture-management-card.gohtml b/web/template/partial/course/manage/lecture-management-card.gohtml index 8681f9931..a4cefac1c 100644 --- a/web/template/partial/course/manage/lecture-management-card.gohtml +++ b/web/template/partial/course/manage/lecture-management-card.gohtml @@ -199,6 +199,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 +