admin: New option to drop all solutions from the database

This commit is contained in:
nemunaire 2024-03-14 18:43:07 +01:00
parent 79afaa8fb2
commit daae6f4f07
3 changed files with 54 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"log" "log"
"net/http" "net/http"
"net/url" "net/url"
"os"
"path" "path"
"strings" "strings"
@ -136,6 +137,45 @@ func declareSyncRoutes(router *gin.RouterGroup) {
c.JSON(http.StatusOK, true) c.JSON(http.StatusOK, true)
}) })
// Remove soluces from the database.
apiSyncRoutes.POST("/drop_soluces", func(c *gin.Context) {
exercices, err := fic.GetExercices()
if err != nil {
log.Println("Unable to GetExercices:", err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Unable to retrieve exercices list."})
return
}
var errs error
for _, e := range exercices {
// Remove any published video
if len(e.VideoURI) > 0 && strings.HasPrefix(e.VideoURI, "$FILES$") {
vpath := path.Join(fic.FilesDir, strings.TrimPrefix(e.VideoURI, "$FILES$/"))
err = os.Remove(vpath)
if err != nil {
errs = multierr.Append(errs, fmt.Errorf("unable to delete published video (%q): %w", e.VideoURI, err))
}
}
// Clean the database
if len(e.VideoURI) > 0 || len(e.Resolution) > 0 {
e.VideoURI = ""
e.Resolution = ""
_, err = e.Update()
if err != nil {
errs = multierr.Append(errs, fmt.Errorf("unable to update exercice (%d: %s): %w", e.Id, e.Title, err))
}
}
}
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"errmsg": flatifySyncErrors(err)})
} else {
c.JSON(http.StatusOK, true)
}
})
} }
func declareSyncExercicesRoutes(router *gin.RouterGroup) { func declareSyncExercicesRoutes(router *gin.RouterGroup) {

View File

@ -859,6 +859,19 @@ angular.module("FICApp")
}); });
}); });
}; };
$scope.dropSoluces = function() {
$scope.addToast('warning', 'Effacer les solutions', 'Ceci va retirer les textes de résolution de la base de données ainsi que les liens vers les vidéos.',
function() {
$scope.deepSyncInProgress = true;
$http.post("api/sync/drop_soluces").then(function() {
$scope.deepSyncInProgress = false;
$scope.addToast('success', 'Effacement des solutions terminé.');
}, function(response) {
$scope.deepSyncInProgress = false;
$scope.addToast('danger', 'Effacement des solutions terminé avec des erreurs.', response.data.errmsg);
});
});
};
}) })
.controller("PKIController", function($scope, $rootScope, Certificate, CACertificate, Team, $location, $http) { .controller("PKIController", function($scope, $rootScope, Certificate, CACertificate, Team, $location, $http) {

View File

@ -54,6 +54,7 @@
</div> </div>
<button type="button" class="btn btn-secondary" ng-click="speedyDeepSync()" ng-disabled="deepSyncInProgress"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Synchronisation sans fichiers</button> <button type="button" class="btn btn-secondary" ng-click="speedyDeepSync()" ng-disabled="deepSyncInProgress"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Synchronisation sans fichiers</button>
<button type="button" class="btn btn-info" ng-if="settings.wip" ng-click="syncVideos()" ng-disabled="deepSyncInProgress"><span class="glyphicon glyphicon-facetime-video" aria-hidden="true"></span> Mettre à disposition les vidéos</button> <button type="button" class="btn btn-info" ng-if="settings.wip" ng-click="syncVideos()" ng-disabled="deepSyncInProgress"><span class="glyphicon glyphicon-facetime-video" aria-hidden="true"></span> Mettre à disposition les vidéos</button>
<button type="button" class="btn btn-danger" ng-click="dropSoluces()" ng-disabled="deepSyncInProgress" title="Par solutions, on entend les résolutions écrites dans la base de données, les liens vers les fichiers vidéos">Effacer les solutions</button>
</div> </div>
</div> </div>
</div> </div>