admin: new route and interface to manage symlink for team association exclusing certificates
This commit is contained in:
parent
2b95995104
commit
14d31737e0
|
@ -52,6 +52,25 @@ func init() {
|
|||
}
|
||||
})))
|
||||
|
||||
router.GET("/api/teams/:tid/associations", apiHandler(teamHandler(
|
||||
func(team fic.Team, _ []byte) (interface{}, error) {
|
||||
return pki.GetTeamAssociations(TeamsDir, team.Id)
|
||||
})))
|
||||
router.POST("/api/teams/:tid/associations/:assoc", apiHandler(teamAssocHandler(
|
||||
func(team fic.Team, assoc string, _ []byte) (interface{}, error) {
|
||||
if err := os.Symlink(fmt.Sprintf("%d", team.Id), path.Join(TeamsDir, assoc)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return "\"" + assoc + "\"", nil
|
||||
})))
|
||||
router.DELETE("/api/teams/:tid/associations/:assoc", apiHandler(teamAssocHandler(
|
||||
func(team fic.Team, assoc string, _ []byte) (interface{}, error) {
|
||||
if err := os.Remove(path.Join(TeamsDir, assoc)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return "null", nil
|
||||
})))
|
||||
|
||||
router.GET("/api/certs/", apiHandler(getCertificates))
|
||||
router.POST("/api/certs/", apiHandler(generateClientCert))
|
||||
router.DELETE("/api/certs/", apiHandler(func(_ httprouter.Params, _ []byte) (interface{}, error) { return fic.ClearCertificates() }))
|
||||
|
|
|
@ -110,6 +110,19 @@ func teamHandler(f func(fic.Team, []byte) (interface{}, error)) func(httprouter.
|
|||
}
|
||||
}
|
||||
|
||||
func teamAssocHandler(f func(fic.Team, string, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
var team fic.Team
|
||||
|
||||
teamHandler(func (tm fic.Team, _ []byte) (interface{}, error) {
|
||||
team = tm
|
||||
return nil, nil
|
||||
})(ps, body)
|
||||
|
||||
return f(team, string(ps.ByName("assoc")), body)
|
||||
}
|
||||
}
|
||||
|
||||
func themeHandler(f func(fic.Theme, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if thid, err := strconv.ParseInt(string(ps.ByName("thid")), 10, 64); err != nil {
|
||||
|
|
|
@ -180,7 +180,13 @@ func disableInactiveTeams(_ httprouter.Params, _ []byte) (interface{}, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if len(serials) == 0 {
|
||||
var assocs []string
|
||||
assocs, err = pki.GetTeamAssociations(TeamsDir, team.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(serials) == 0 && len(assocs) == 0 {
|
||||
if team.Active {
|
||||
team.Active = false
|
||||
team.Update()
|
||||
|
|
|
@ -47,3 +47,21 @@ func GetTeamSerials(dirname string, id_team int64) (serials []uint64, err error)
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GetTeamAssociations(dirname string, id_team int64) (teamAssocs []string, err error) {
|
||||
// As futher comparaisons will be made with strings, convert it only one time
|
||||
str_tid := fmt.Sprintf("%d", id_team)
|
||||
|
||||
var assocs []string
|
||||
if assocs, err = GetAssociations(dirname); err != nil {
|
||||
return
|
||||
} else {
|
||||
for _, assoc := range assocs {
|
||||
var tid string
|
||||
if tid, err = os.Readlink(path.Join(dirname, assoc)); err == nil && tid == str_tid && !strings.HasPrefix(assoc, SymlinkPrefix) {
|
||||
teamAssocs = append(teamAssocs, assoc)
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -179,6 +179,9 @@ angular.module("FICApp")
|
|||
.factory("TeamCertificate", function($resource) {
|
||||
return $resource("/api/teams/:teamId/certificates", { teamId: '@id' })
|
||||
})
|
||||
.factory("TeamAssociation", function($resource) {
|
||||
return $resource("/api/teams/:teamId/associations/:assoc", { teamId: '@teamId', assoc: '@assoc' })
|
||||
})
|
||||
.factory("TeamMember", function($resource) {
|
||||
return $resource("/api/teams/:teamId/members", { teamId: '@id' }, {
|
||||
'save': {method: 'PUT'},
|
||||
|
@ -1498,29 +1501,12 @@ angular.module("FICApp")
|
|||
}
|
||||
}
|
||||
})
|
||||
.controller("TeamController", function($scope, $rootScope, $location, Team, TeamMember, TeamCertificate, $routeParams, $http) {
|
||||
.controller("TeamController", function($scope, $rootScope, $location, Team, TeamMember, $routeParams) {
|
||||
if ($scope.team && $scope.team.id)
|
||||
$routeParams.teamId = $scope.team.id;
|
||||
$scope.team = Team.get({ teamId: $routeParams.teamId });
|
||||
$scope.fields = ["name", "color"];
|
||||
|
||||
$scope.certificates = TeamCertificate.query({ teamId: $routeParams.teamId });
|
||||
|
||||
$scope.dissociateCertificate = function(certificate) {
|
||||
$http({
|
||||
url: "/api/certs/" + certificate.id,
|
||||
method: "PUT",
|
||||
data: {
|
||||
id_team: null
|
||||
}
|
||||
}).then(function(response) {
|
||||
$scope.certificates = TeamCertificate.query({ teamId: $routeParams.teamId });
|
||||
$rootScope.newBox('success', 'Certificate successfully dissociated!');
|
||||
}, function(response) {
|
||||
$rootScope.newBox('danger', 'An error occurs when dissociating certiticate:', response.data.errmsg);
|
||||
});
|
||||
}
|
||||
|
||||
$scope.saveTeam = function() {
|
||||
if (this.team.id) {
|
||||
this.team.$update();
|
||||
|
@ -1544,6 +1530,50 @@ angular.module("FICApp")
|
|||
$location.url("/teams/" + $scope.team.id + "/score");
|
||||
}
|
||||
})
|
||||
.controller("TeamCertificatesController", function($scope, $rootScope, TeamCertificate, $routeParams, $http) {
|
||||
$scope.certificates = TeamCertificate.query({ teamId: $routeParams.teamId });
|
||||
|
||||
$scope.dissociateCertificate = function(certificate) {
|
||||
$http({
|
||||
url: "/api/certs/" + certificate.id,
|
||||
method: "PUT",
|
||||
data: {
|
||||
id_team: null
|
||||
}
|
||||
}).then(function(response) {
|
||||
$scope.certificates = TeamCertificate.query({ teamId: $routeParams.teamId });
|
||||
$rootScope.newBox('success', 'Certificate successfully dissociated!');
|
||||
}, function(response) {
|
||||
$rootScope.newBox('danger', 'An error occurs when dissociating certiticate:', response.data.errmsg);
|
||||
});
|
||||
}
|
||||
})
|
||||
.controller("TeamAssociationsController", function($scope, $rootScope, TeamAssociation, $routeParams, $http) {
|
||||
$scope.associations = TeamAssociation.query({ teamId: $routeParams.teamId });
|
||||
$scope.form = { "newassoc": "" };
|
||||
|
||||
$scope.addAssociation = function() {
|
||||
if ($scope.form.newassoc) {
|
||||
TeamAssociation.save({ teamId: $scope.team.id, assoc: $scope.form.newassoc }).$promise.then(
|
||||
function() {
|
||||
$scope.form.newassoc = "";
|
||||
$scope.associations = TeamAssociation.query({ teamId: $routeParams.teamId });
|
||||
}, function(response) {
|
||||
if (response.data)
|
||||
$rootScope.newBox('danger', 'An error occurs when creating user association: ', response.data.errmsg);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$scope.dropAssociation = function(assoc) {
|
||||
TeamAssociation.delete({ teamId: $routeParams.teamId, assoc: assoc }).$promise.then(
|
||||
function() {
|
||||
$scope.associations = TeamAssociation.query({ teamId: $routeParams.teamId });
|
||||
}, function(response) {
|
||||
$rootScope.newBox('danger', 'An error occurs when removing user association: ', response.data.errmsg);
|
||||
});
|
||||
}
|
||||
})
|
||||
.controller("TeamHistoryController", function($scope, TeamHistory, $routeParams, $http, $rootScope) {
|
||||
$scope.history = TeamHistory.query({ teamId: $routeParams.teamId });
|
||||
$scope.delHistory = function(row) {
|
||||
|
|
|
@ -70,7 +70,7 @@
|
|||
</div>
|
||||
</form>
|
||||
|
||||
<div class="card">
|
||||
<div class="card" ng-controller="TeamCertificatesController">
|
||||
<div class="card-header bg-primary text-light">
|
||||
<span class="glyphicon glyphicon-certificate" aria-hidden="true"></span>
|
||||
Certificates
|
||||
|
@ -89,7 +89,7 @@
|
|||
</dd>
|
||||
<dt>
|
||||
Date de création
|
||||
<a class="btn btn-sm btn-success float-right" href="../api/certs/{{ cert.id }}">Télécharger</a>
|
||||
<a class="btn btn-sm btn-success float-right" href="api/certs/{{ cert.id }}">Télécharger</a>
|
||||
</dt>
|
||||
<dd>{{ cert.creation }}</dd>
|
||||
<dt>Mot de passe</dt>
|
||||
|
@ -100,6 +100,31 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card" ng-controller="TeamAssociationsController">
|
||||
<div class="card-header bg-warning text-light">
|
||||
<span class="glyphicon glyphicon-sunglasses" aria-hidden="true"></span>
|
||||
Utilisateurs associés
|
||||
</div>
|
||||
<div class="card-body bg-light text-dark">
|
||||
<ul>
|
||||
<li ng-repeat="a in associations">
|
||||
{{ a }}
|
||||
<button class="btn btn-sm btn-danger" type="button" ng-click="dropAssociation(a)">
|
||||
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
|
||||
</button>
|
||||
</li>
|
||||
<li>
|
||||
<form class="input-group" ng-submit="addAssociation()">
|
||||
<input type="text" class="form-control form-control-sm" ng-model="form.newassoc" placeholder="Nouvelle association">
|
||||
<span class="input-group-append">
|
||||
<button class="btn btn-sm btn-success" ng-disabled="!form.newassoc.length"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
|
||||
</span>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue
Block a user