admin: When deleting team, also delete associations
This commit is contained in:
parent
2ca2018485
commit
02bd5f316a
3 changed files with 28 additions and 10 deletions
|
|
@ -96,10 +96,7 @@ func init() {
|
||||||
})))
|
})))
|
||||||
router.DELETE("/api/teams/:tid/associations/:assoc", apiHandler(teamAssocHandler(
|
router.DELETE("/api/teams/:tid/associations/:assoc", apiHandler(teamAssocHandler(
|
||||||
func(team *fic.Team, assoc string, _ []byte) (interface{}, error) {
|
func(team *fic.Team, assoc string, _ []byte) (interface{}, error) {
|
||||||
if err := os.Remove(path.Join(TeamsDir, assoc)); err != nil {
|
return "null", pki.DeleteTeamAssociation(TeamsDir, assoc)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return "null", nil
|
|
||||||
})))
|
})))
|
||||||
|
|
||||||
router.GET("/api/certs/", apiHandler(getCertificates))
|
router.GET("/api/certs/", apiHandler(getCertificates))
|
||||||
|
|
|
||||||
|
|
@ -53,10 +53,7 @@ func init() {
|
||||||
})))
|
})))
|
||||||
router.PUT("/api/teams/:tid/", apiHandler(teamHandler(updateTeam)))
|
router.PUT("/api/teams/:tid/", apiHandler(teamHandler(updateTeam)))
|
||||||
router.POST("/api/teams/:tid/", apiHandler(teamHandler(addTeamMember)))
|
router.POST("/api/teams/:tid/", apiHandler(teamHandler(addTeamMember)))
|
||||||
router.DELETE("/api/teams/:tid/", apiHandler(teamHandler(
|
router.DELETE("/api/teams/:tid/", apiHandler(teamHandler(deleteTeam)))
|
||||||
func(team *fic.Team, _ []byte) (interface{}, error) {
|
|
||||||
return team.Delete()
|
|
||||||
})))
|
|
||||||
router.GET("/api/teams/:tid/score-grid.json", apiHandler(teamHandler(
|
router.GET("/api/teams/:tid/score-grid.json", apiHandler(teamHandler(
|
||||||
func(team *fic.Team, _ []byte) (interface{}, error) {
|
func(team *fic.Team, _ []byte) (interface{}, error) {
|
||||||
return team.ScoreGrid()
|
return team.ScoreGrid()
|
||||||
|
|
@ -229,6 +226,23 @@ func enableAllTeams(_ httprouter.Params, _ []byte) (interface{}, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func deleteTeam(team *fic.Team, _ []byte) (interface{}, error) {
|
||||||
|
assocs, err := pki.GetTeamAssociations(TeamsDir, team.Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, assoc := range assocs {
|
||||||
|
err = pki.DeleteTeamAssociation(TeamsDir, assoc)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return team.Delete()
|
||||||
|
}
|
||||||
|
|
||||||
func addTeamMember(team *fic.Team, body []byte) (interface{}, error) {
|
func addTeamMember(team *fic.Team, body []byte) (interface{}, error) {
|
||||||
var members []fic.Member
|
var members []fic.Member
|
||||||
if err := json.Unmarshal(body, &members); err != nil {
|
if err := json.Unmarshal(body, &members); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -70,3 +70,10 @@ func GetTeamAssociations(dirname string, id_team int64) (teamAssocs []string, er
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DeleteTeamAssociation(dirname string, assoc string) error {
|
||||||
|
if err := os.Remove(path.Join(dirname, assoc)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
||||||
Reference in a new issue