diff --git a/api/courses.go b/api/courses.go index 4b2c6c4a9..73ac8a61e 100644 --- a/api/courses.go +++ b/api/courses.go @@ -81,6 +81,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") @@ -1557,6 +1558,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 { + logger.Error("Error getting course admins", "err", err) + _ = 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 4231a17af..ab44a7a6c 100755 --- a/model/stream.go +++ b/model/stream.go @@ -359,6 +359,7 @@ func (s Stream) GetJson(lhs []LectureHall, course Course) gin.H { "courseSlug": course.Slug, "private": s.Private, "downloadableVods": s.GetVodFiles(), + "isCopying": false, "videoSections": videoSections, } } diff --git a/web/admin.go b/web/admin.go index e963fd659..a645ec620 100644 --- a/web/admin.go +++ b/web/admin.go @@ -276,6 +276,7 @@ func (r mainRoutes) EditCoursePage(c *gin.Context) { CurT: tumLiveContext.Course.TeachingTerm, EditCourseData: EditCourseData{ IndexData: indexData, + Courses: courses, IngestBase: tools.Cfg.IngestBase, LectureHalls: lectureHalls, }, @@ -368,6 +369,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 626dcd344..2b66b8865 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/TUM-Dev/gocast/web.AdminPageData*/ -}} {{$course := .IndexData.TUMLiveContext.Course}} + {{$courses := .Courses}} {{$user := .IndexData.TUMLiveContext.User}} {{$ingestBase := .IngestBase}} {{$lectureHalls := .LectureHalls}} @@ -200,6 +201,10 @@ :class="lectureData.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 + + Move/Copy to other course + @@ -218,8 +223,8 @@ - Edit Lecture @@ -383,5 +388,53 @@ + + + {success=r.ok})"> + + + + Copy + + + Move + + + Select target course: + + {{range $c := $courses}} + {{if ne $c.ID $course.ID}} + + + + {{$c.Name}} + {{$c.Year}} | {{$c.TeachingTerm}} + + + {{end}} + {{end}} + + + Cancel + + + + Done + + + + Lecture copied successfully. + + + Lecture could not be copied! + + + {{end}} \ No newline at end of file diff --git a/worker/worker/silence.go b/worker/worker/silence.go index 845db604a..9415e8886 100644 --- a/worker/worker/silence.go +++ b/worker/worker/silence.go @@ -55,7 +55,7 @@ func (s *SilenceDetect) ParseSilence() error { return nil } -//postprocess merges short duration of silence into units of silence +// postprocess merges short duration of silence into units of silence func (s *SilenceDetect) postprocess() { oldSilences := *s.Silences if len(oldSilences) < 2 { diff --git a/worker/worker/waveform.go b/worker/worker/waveform.go index 6d3d6e819..70f19fbc2 100644 --- a/worker/worker/waveform.go +++ b/worker/worker/waveform.go @@ -2,8 +2,8 @@ package worker import ( "fmt" - uuid "github.com/iris-contrib/go.uuid" "github.com/TUM-Dev/gocast/worker/pb" + uuid "github.com/iris-contrib/go.uuid" log "github.com/sirupsen/logrus" "io" "os"