admin: new route to export nginx translation file from team name to team_id

This commit is contained in:
nemunaire 2018-12-10 02:17:11 +01:00
parent 20df137eeb
commit 93f36faafe

View File

@ -20,7 +20,11 @@ func init() {
func(httprouter.Params, []byte) (interface{}, error) {
return bindingTeams()
}))
router.GET("/api/teams-nginx-members", apiHandler(
router.GET("/api/teams-nginx", apiHandler(
func(httprouter.Params, []byte) (interface{}, error) {
return nginxGenTeams()
}))
router.GET("/api/teams-members-nginx", apiHandler(
func(httprouter.Params, []byte) (interface{}, error) {
return nginxGenMember()
}))
@ -86,6 +90,19 @@ func init() {
router.PUT("/api/teams/:tid/members", apiHandler(teamHandler(setTeamMember)))
}
func nginxGenTeams() (string, error) {
if teams, err := fic.GetTeams(); err != nil {
return "", err
} else {
ret := ""
for _, team := range teams {
ret += fmt.Sprintf(" if ($remote_user = \"%s\") { set $team \"%d\"; }\n", strings.ToLower(team.Name), team.Id)
}
return ret, nil
}
}
func nginxGenMember() (string, error) {
if teams, err := fic.GetTeams(); err != nil {
return "", err