admin: add button to disable inactive teams

This commit is contained in:
nemunaire 2019-01-21 02:54:27 +01:00
parent 48fcfec0d0
commit 088c2402cd
4 changed files with 61 additions and 1 deletions

View File

@ -237,6 +237,14 @@ func updateCertificateAssociation(cert fic.Certificate, body []byte) (interface{
if err := os.Symlink(srcLinkPath, dstLinkPath); err != nil {
return nil, err
}
// Mark team as active to ensure it'll be generated
if ut, err := fic.GetTeam(*uc.Team); err != nil {
return nil, err
} else if !ut.Active {
ut.Active = true
ut.Update()
}
} else {
os.Remove(dstLinkPath)
}

View File

@ -6,6 +6,7 @@ import (
"strings"
"time"
"srs.epita.fr/fic-server/admin/pki"
"srs.epita.fr/fic-server/libfic"
"github.com/julienschmidt/httprouter"
@ -24,6 +25,8 @@ func init() {
func(httprouter.Params, []byte) (interface{}, error) {
return nginxGenTeams()
}))
router.POST("/api/disableinactiveteams", apiHandler(disableInactiveTeams))
router.POST("/api/enableallteams", apiHandler(enableAllTeams))
router.GET("/api/teams-members-nginx", apiHandler(
func(httprouter.Params, []byte) (interface{}, error) {
return nginxGenMember()
@ -166,6 +169,47 @@ func updateTeam(team fic.Team, body []byte) (interface{}, error) {
return ut, nil
}
func disableInactiveTeams(_ httprouter.Params, _ []byte) (interface{}, error) {
if teams, err := fic.GetTeams(); err != nil {
return nil, err
} else {
for _, team := range teams {
var serials []uint64
serials, err = pki.GetTeamSerials(TeamsDir, team.Id)
if err != nil {
return nil, err
}
if len(serials) == 0 {
if team.Active {
team.Active = false
team.Update()
}
} else if !team.Active {
team.Active = true
team.Update()
}
}
return true, nil
}
}
func enableAllTeams(_ httprouter.Params, _ []byte) (interface{}, error) {
if teams, err := fic.GetTeams(); err != nil {
return nil, err
} else {
for _, team := range teams {
if !team.Active {
team.Active = true
team.Update()
}
}
return true, nil
}
}
func addTeamMember(team fic.Team, body []byte) (interface{}, error) {
var members []fic.Member
if err := json.Unmarshal(body, &members); err != nil {

View File

@ -1427,10 +1427,17 @@ angular.module("FICApp")
}
})
.controller("TeamsListController", function($scope, Team, $location) {
.controller("TeamsListController", function($scope, $rootScope, Team, $location, $http) {
$scope.teams = Team.query();
$scope.fields = ["id", "name"];
$scope.desactiveTeams = function() {
$http.post("/api/disableinactiveteams").then(function() {
$scope.teams = Team.query();
}, function(response) {
$rootScope.newBox('danger', 'An error occurs when disabling inactive teams:', response.data.errmsg);
});
}
$scope.show = function(id) {
$location.url("/teams/" + id);
};

View File

@ -3,6 +3,7 @@
<button type="button" ng-click="show('new')" class="float-right btn btn-sm btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Ajouter une équipe</button>
<button type="button" ng-click="show('print')" class="float-right btn btn-sm btn-secondary mr-2"><span class="glyphicon glyphicon-print" aria-hidden="true"></span> Imprimer les équipes</button>
<button type="button" ng-click="show('export')" class="float-right btn btn-sm btn-secondary mr-2"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Statistiques générales</button>
<button type="button" ng-click="desactiveTeams()" class="float-right btn btn-sm btn-danger mr-2" title="Cliquer pour marquer les équipes sans certificat comme inactives (et ainsi éviter que ses fichiers ne soient générés)"><span class="glyphicon glyphicon-leaf" aria-hidden="true"></span> Désactiver les équipes inactives</button>
</h2>
<p><input type="search" class="form-control" placeholder="Search" ng-model="query" autofocus></p>