admin: new route to export nginx translation file from team name to team_id
authorPierre-Olivier Mercier <nemunaire@nemunai.re>
Mon, 10 Dec 2018 01:17:11 +0000 (02:17 +0100)
committerPierre-Olivier Mercier <nemunaire@nemunai.re>
Mon, 10 Dec 2018 01:17:11 +0000 (02:17 +0100)
admin/api/team.go

index bb4ca9f..92d0fae 100644 (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