From e11b49d6debe23c235de1a3f0794d18466654327 Mon Sep 17 00:00:00 2001 From: matthias Date: Sat, 19 Aug 2023 14:15:35 +0200 Subject: [PATCH] Video Section Admin Bugs (#1125) - Resolves deletion of video sections broken #1123 (Allow the deletion of video sections for which no thumbnail exists) - Resolves Input validation for video section timestamps not working on Firefox #1124 (Firefox still allows letters in fields. Manual validation via regex necessary) --- api/stream.go | 30 +++++++++---------- api/stream_test.go | 29 ------------------ web/router.go | 1 - .../course/manage/edit-video-sections.gohtml | 24 ++++++++------- web/ts/video-sections.ts | 14 ++++++++- 5 files changed, 41 insertions(+), 57 deletions(-) diff --git a/api/stream.go b/api/stream.go index cac67f15b..74c2a43f9 100644 --- a/api/stream.go +++ b/api/stream.go @@ -571,35 +571,35 @@ func (r streamRoutes) deleteVideoSection(c *gin.Context) { return } - file, err := r.FileDao.GetFileById(fmt.Sprintf("%d", old.FileID)) + err = r.VideoSectionDao.Delete(uint(id)) if err != nil { - log.WithError(err).Error("can not find file") + log.WithError(err).Error("can not delete video-section") _ = c.Error(tools.RequestError{ - Status: http.StatusNotFound, - CustomMessage: "can not find file", + Status: http.StatusInternalServerError, + CustomMessage: "can not delete video-section", Err: err, }) return } - err = r.VideoSectionDao.Delete(uint(id)) - if err != nil { - log.WithError(err).Error("can not delete video-section") + file, err := r.FileDao.GetFileById(fmt.Sprintf("%d", old.FileID)) + if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { + log.WithError(err).Error("can not get video section thumbnail file") _ = c.Error(tools.RequestError{ Status: http.StatusInternalServerError, - CustomMessage: "can not delete video-section", + CustomMessage: "can not get video section thumbnail file", Err: err, }) return + } else { + go func() { + err := DeleteVideoSectionImage(r.DaoWrapper.WorkerDao, file.Path) + if err != nil { + log.WithError(err).Error("failed to generate video section images") + } + }() } - go func() { - err := DeleteVideoSectionImage(r.DaoWrapper.WorkerDao, file.Path) - if err != nil { - log.WithError(err).Error("failed to generate video section images") - } - }() - c.Status(http.StatusAccepted) } diff --git a/api/stream_test.go b/api/stream_test.go index 3b8420715..db1b59da2 100644 --- a/api/stream_test.go +++ b/api/stream_test.go @@ -539,35 +539,6 @@ func TestStreamVideoSections(t *testing.T) { Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), ExpectedCode: http.StatusBadRequest, }, - "GetFileById returns error": { - Router: func(r *gin.Engine) { - wrapper := dao.DaoWrapper{ - StreamsDao: testutils.GetStreamMock(t), - CoursesDao: testutils.GetCoursesMock(t), - VideoSectionDao: func() dao.VideoSectionDao { - sectionMock := mock_dao.NewMockVideoSectionDao(gomock.NewController(t)) - sectionMock. - EXPECT(). - Get(section.ID). - Return(section, nil). - AnyTimes() - return sectionMock - }(), - FileDao: func() dao.FileDao { - fileMock := mock_dao.NewMockFileDao(gomock.NewController(t)) - fileMock. - EXPECT(). - GetFileById(fmt.Sprintf("%d", section.ID)). - Return(model.File{}, errors.New("")). - AnyTimes() - return fileMock - }(), - } - configGinStreamRestRouter(r, wrapper) - }, - Middlewares: testutils.GetMiddlewares(tools.ErrorHandler, testutils.TUMLiveContext(testutils.TUMLiveContextAdmin)), - ExpectedCode: http.StatusNotFound, - }, "Delete returns error": { Router: func(r *gin.Engine) { wrapper := dao.DaoWrapper{ diff --git a/web/router.go b/web/router.go index ce4bd6c36..455726a51 100755 --- a/web/router.go +++ b/web/router.go @@ -33,7 +33,6 @@ var templatePaths = []string{ "template/partial/*.gohtml", "template/partial/stream/*.gohtml", "template/partial/course/manage/*.gohtml", - "template/partial/stream/chat/*.gohtml", "template/partial/course/manage/*.gohtml", "template/partial/course/manage/create-lecture-form-slides/*.gohtml", } diff --git a/web/template/partial/course/manage/edit-video-sections.gohtml b/web/template/partial/course/manage/edit-video-sections.gohtml index c7992715f..71f1edf2f 100644 --- a/web/template/partial/course/manage/edit-video-sections.gohtml +++ b/web/template/partial/course/manage/edit-video-sections.gohtml @@ -1,8 +1,7 @@ {{define "editvideosections"}} -
+ class="grid gap-y-3">
Video Sections
@@ -36,21 +35,24 @@ Unsaved Changes
-
+
: :
@@ -87,19 +89,19 @@
-
-