Remove team's initial_name, replaced by their ID
This commit is contained in:
parent
ed89252a72
commit
842a769385
@ -81,11 +81,7 @@ func apiHandler(f DispatchFunction) func(http.ResponseWriter, *http.Request, htt
|
|||||||
func teamPublicHandler(f func(*fic.Team,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
|
func teamPublicHandler(f func(*fic.Team,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
|
||||||
return func (ps httprouter.Params, body []byte) (interface{}, error) {
|
return func (ps httprouter.Params, body []byte) (interface{}, error) {
|
||||||
if tid, err := strconv.Atoi(string(ps.ByName("tid"))); err != nil {
|
if tid, err := strconv.Atoi(string(ps.ByName("tid"))); err != nil {
|
||||||
if team, err := fic.GetTeamByInitialName(ps.ByName("tid")); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
|
||||||
return f(&team, body)
|
|
||||||
}
|
|
||||||
} else if tid == 0 {
|
} else if tid == 0 {
|
||||||
return f(nil, body)
|
return f(nil, body)
|
||||||
} else if team, err := fic.GetTeam(tid); err != nil {
|
} else if team, err := fic.GetTeam(tid); err != nil {
|
||||||
@ -99,11 +95,7 @@ func teamPublicHandler(f func(*fic.Team,[]byte) (interface{}, error)) func (http
|
|||||||
func teamHandler(f func(fic.Team,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
|
func teamHandler(f func(fic.Team,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
|
||||||
return func (ps httprouter.Params, body []byte) (interface{}, error) {
|
return func (ps httprouter.Params, body []byte) (interface{}, error) {
|
||||||
if tid, err := strconv.Atoi(string(ps.ByName("tid"))); err != nil {
|
if tid, err := strconv.Atoi(string(ps.ByName("tid"))); err != nil {
|
||||||
if team, err := fic.GetTeamByInitialName(ps.ByName("tid")); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
|
||||||
return f(team, body)
|
|
||||||
}
|
|
||||||
} else if team, err := fic.GetTeam(tid); err != nil {
|
} else if team, err := fic.GetTeam(tid); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
|
@ -19,9 +19,6 @@ func init() {
|
|||||||
router.GET("/api/teams-binding", apiHandler(
|
router.GET("/api/teams-binding", apiHandler(
|
||||||
func(httprouter.Params,[]byte) (interface{}, error) {
|
func(httprouter.Params,[]byte) (interface{}, error) {
|
||||||
return bindingTeams() }))
|
return bindingTeams() }))
|
||||||
router.GET("/api/teams-nginx", apiHandler(
|
|
||||||
func(httprouter.Params,[]byte) (interface{}, error) {
|
|
||||||
return nginxGenTeam() }))
|
|
||||||
router.GET("/api/teams-nginx-members", apiHandler(
|
router.GET("/api/teams-nginx-members", apiHandler(
|
||||||
func(httprouter.Params,[]byte) (interface{}, error) {
|
func(httprouter.Params,[]byte) (interface{}, error) {
|
||||||
return nginxGenMember() }))
|
return nginxGenMember() }))
|
||||||
@ -73,12 +70,8 @@ func init() {
|
|||||||
return team.GetMembers() })))
|
return team.GetMembers() })))
|
||||||
router.POST("/api/teams/:tid/members", apiHandler(teamHandler(addTeamMember)))
|
router.POST("/api/teams/:tid/members", apiHandler(teamHandler(addTeamMember)))
|
||||||
router.PUT("/api/teams/:tid/members", apiHandler(teamHandler(setTeamMember)))
|
router.PUT("/api/teams/:tid/members", apiHandler(teamHandler(setTeamMember)))
|
||||||
router.GET("/api/teams/:tid/name", apiHandler(teamHandler(
|
|
||||||
func(team fic.Team, _ []byte) (interface{}, error) {
|
|
||||||
return team.InitialName, nil })))
|
|
||||||
|
|
||||||
router.GET("/api/members/:mid/team", apiHandler(dispMemberTeam))
|
router.GET("/api/members/:mid/team", apiHandler(dispMemberTeam))
|
||||||
router.GET("/api/members/:mid/team/name", apiHandler(dispMemberTeamName))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func nginxGenMember() (string, error) {
|
func nginxGenMember() (string, error) {
|
||||||
@ -89,7 +82,7 @@ func nginxGenMember() (string, error) {
|
|||||||
for _, team := range teams {
|
for _, team := range teams {
|
||||||
if members, err := team.GetMembers(); err == nil {
|
if members, err := team.GetMembers(); err == nil {
|
||||||
for _, member := range members {
|
for _, member := range members {
|
||||||
ret += fmt.Sprintf(" if ($remote_user = \"%s\") { set $team \"%s\"; }\n", member.Nickname, team.InitialName)
|
ret += fmt.Sprintf(" if ($remote_user = \"%s\") { set $team \"%s\"; }\n", member.Nickname, team.Id)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return "", err
|
return "", err
|
||||||
@ -100,19 +93,6 @@ func nginxGenMember() (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func nginxGenTeam() (string, error) {
|
|
||||||
if teams, err := fic.GetTeams(); err != nil {
|
|
||||||
return "", err
|
|
||||||
} else {
|
|
||||||
ret := ""
|
|
||||||
for _, team := range teams {
|
|
||||||
ret += fmt.Sprintf(" if ($ssl_client_s_dn ~ \"/C=FR/ST=France/O=Epita/OU=SRS/CN=%s\") { set $team \"%s\"; }\n", team.InitialName, team.InitialName)
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func bindingTeams() (string, error) {
|
func bindingTeams() (string, error) {
|
||||||
if teams, err := fic.GetTeams(); err != nil {
|
if teams, err := fic.GetTeams(); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -204,16 +184,6 @@ func dispMemberTeam(ps httprouter.Params, body []byte) (interface{}, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func dispMemberTeamName(ps httprouter.Params, body []byte) (interface{}, error) {
|
|
||||||
if mid, err := strconv.Atoi(string(ps.ByName("mid"))); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else if team, err := fic.GetMember(mid); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else {
|
|
||||||
return team.InitialName, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
type uploadedHistory struct {
|
type uploadedHistory struct {
|
||||||
Kind string
|
Kind string
|
||||||
|
@ -1041,7 +1041,7 @@ angular.module("FICApp")
|
|||||||
|
|
||||||
.controller("TeamsListController", function($scope, Team, $location) {
|
.controller("TeamsListController", function($scope, Team, $location) {
|
||||||
$scope.teams = Team.query();
|
$scope.teams = Team.query();
|
||||||
$scope.fields = ["id", "name", "initialName"];
|
$scope.fields = ["id", "name"];
|
||||||
|
|
||||||
$scope.show = function(id) {
|
$scope.show = function(id) {
|
||||||
$location.url("/teams/" + id);
|
$location.url("/teams/" + id);
|
||||||
|
@ -22,7 +22,7 @@ func isStarted() bool {
|
|||||||
|
|
||||||
// Generate my.json and wait.json for a given team
|
// Generate my.json and wait.json for a given team
|
||||||
func genTeamMyFile(team fic.Team) error {
|
func genTeamMyFile(team fic.Team) error {
|
||||||
dirPath := path.Join(TeamsDir, team.InitialName)
|
dirPath := path.Join(TeamsDir, fmt.Sprintf("%d", team.Id))
|
||||||
|
|
||||||
if s, err := os.Stat(dirPath); os.IsNotExist(err) {
|
if s, err := os.Stat(dirPath); os.IsNotExist(err) {
|
||||||
os.MkdirAll(dirPath, 0777)
|
os.MkdirAll(dirPath, 0777)
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -142,7 +143,9 @@ func treat(raw_path string) {
|
|||||||
if len(spath) == 3 {
|
if len(spath) == 3 {
|
||||||
if spath[1] == "_registration" {
|
if spath[1] == "_registration" {
|
||||||
treatRegistration(raw_path, spath[2])
|
treatRegistration(raw_path, spath[2])
|
||||||
} else if team, err := fic.GetTeamByInitialName(spath[1]); err != nil {
|
} else if teamid, err := strconv.Atoi(spath[1]); err != nil {
|
||||||
|
log.Println("[ERR]", err)
|
||||||
|
} else if team, err := fic.GetTeam(teamid); err != nil {
|
||||||
log.Println("[ERR]", err)
|
log.Println("[ERR]", err)
|
||||||
} else if spath[2] == "name" {
|
} else if spath[2] == "name" {
|
||||||
treatRename(raw_path, team)
|
treatRename(raw_path, team)
|
||||||
|
@ -17,7 +17,7 @@ type uTeamRegistration struct {
|
|||||||
Members []fic.Member
|
Members []fic.Member
|
||||||
}
|
}
|
||||||
|
|
||||||
func treatRegistration(pathname string, initial_name string) {
|
func treatRegistration(pathname string, team_id string) {
|
||||||
var nTeam uTeamRegistration
|
var nTeam uTeamRegistration
|
||||||
|
|
||||||
if cnt_raw, err := ioutil.ReadFile(pathname); err != nil {
|
if cnt_raw, err := ioutil.ReadFile(pathname); err != nil {
|
||||||
@ -25,7 +25,7 @@ func treatRegistration(pathname string, initial_name string) {
|
|||||||
} else if err := json.Unmarshal(cnt_raw, &nTeam); err != nil {
|
} else if err := json.Unmarshal(cnt_raw, &nTeam); err != nil {
|
||||||
log.Println("[ERR]", err)
|
log.Println("[ERR]", err)
|
||||||
} else if validTeamName(nTeam.TeamName) {
|
} else if validTeamName(nTeam.TeamName) {
|
||||||
if team, err := fic.RegisterTeam(initial_name, nTeam.TeamName, uint32(rand.Int31n(16581376))); err != nil {
|
if team, err := fic.CreateTeam(nTeam.TeamName, uint32(rand.Int31n(16581376))); err != nil {
|
||||||
log.Printf("[ERR] Unable to register new team %s: %s\n", nTeam.TeamName, err)
|
log.Printf("[ERR] Unable to register new team %s: %s\n", nTeam.TeamName, err)
|
||||||
} else {
|
} else {
|
||||||
for _, m := range nTeam.Members {
|
for _, m := range nTeam.Members {
|
||||||
@ -43,8 +43,13 @@ func treatRegistration(pathname string, initial_name string) {
|
|||||||
log.Println("[WRN] Unable to create event:", err)
|
log.Println("[WRN] Unable to create event:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
os.MkdirAll(path.Join(SubmissionDir, team.InitialName), 0777)
|
teamDirPath := path.Join(TeamsDir, fmt.Sprintf("%d", team.Id))
|
||||||
os.MkdirAll(path.Join(TeamsDir, team.InitialName), 0777)
|
if err := os.MkdirAll(teamDirPath, 0777); err != nil {
|
||||||
|
log.Println("[ERR]", err)
|
||||||
|
}
|
||||||
|
if err := os.Symlink(teamDirPath, path.Join(TeamsDir, fmt.Sprintf("_AUTH_ID_%s", team_id))); err != nil {
|
||||||
|
log.Println("[ERR]", err)
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if err := genTeamMyFile(team); err != nil {
|
if err := genTeamMyFile(team); err != nil {
|
||||||
|
@ -76,7 +76,6 @@ CREATE TABLE IF NOT EXISTS themes(
|
|||||||
if _, err := db.Exec(`
|
if _, err := db.Exec(`
|
||||||
CREATE TABLE IF NOT EXISTS teams(
|
CREATE TABLE IF NOT EXISTS teams(
|
||||||
id_team INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
id_team INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||||
initial_name VARCHAR(255) NOT NULL UNIQUE,
|
|
||||||
name VARCHAR(255) NOT NULL,
|
name VARCHAR(255) NOT NULL,
|
||||||
color INTEGER NOT NULL
|
color INTEGER NOT NULL
|
||||||
) DEFAULT CHARACTER SET = utf8 COLLATE = utf8_bin;
|
) DEFAULT CHARACTER SET = utf8 COLLATE = utf8_bin;
|
||||||
|
@ -12,7 +12,7 @@ type Member struct {
|
|||||||
|
|
||||||
func GetMember(cnt int) (Team, error) {
|
func GetMember(cnt int) (Team, error) {
|
||||||
var t Team
|
var t Team
|
||||||
if err := DBQueryRow("SELECT T.id_team, T.initial_name, T.name, T.color FROM team_members M RIGHT OUTER JOIN teams T ON T.id_team = M.id_team LIMIT ?, 1", cnt - 1).Scan(&t.Id, &t.InitialName, &t.Name, &t.Color); err != nil {
|
if err := DBQueryRow("SELECT T.id_team, T.name, T.color FROM team_members M RIGHT OUTER JOIN teams T ON T.id_team = M.id_team LIMIT ?, 1", cnt - 1).Scan(&t.Id, &t.Name, &t.Color); err != nil {
|
||||||
return t, err
|
return t, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package fic
|
package fic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -9,7 +8,6 @@ var UnlockedChallenges bool
|
|||||||
|
|
||||||
type Team struct {
|
type Team struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
InitialName string `json:"initialName"`
|
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Color uint32 `json:"color"`
|
Color uint32 `json:"color"`
|
||||||
}
|
}
|
||||||
@ -17,7 +15,7 @@ type Team struct {
|
|||||||
// Access functions
|
// Access functions
|
||||||
|
|
||||||
func GetTeams() ([]Team, error) {
|
func GetTeams() ([]Team, error) {
|
||||||
if rows, err := DBQuery("SELECT id_team, initial_name, name, color FROM teams"); err != nil {
|
if rows, err := DBQuery("SELECT id_team, name, color FROM teams"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
@ -25,7 +23,7 @@ func GetTeams() ([]Team, error) {
|
|||||||
var teams = make([]Team, 0)
|
var teams = make([]Team, 0)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var t Team
|
var t Team
|
||||||
if err := rows.Scan(&t.Id, &t.InitialName, &t.Name, &t.Color); err != nil {
|
if err := rows.Scan(&t.Id, &t.Name, &t.Color); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
teams = append(teams, t)
|
teams = append(teams, t)
|
||||||
@ -40,16 +38,16 @@ func GetTeams() ([]Team, error) {
|
|||||||
|
|
||||||
func GetTeam(id int) (Team, error) {
|
func GetTeam(id int) (Team, error) {
|
||||||
var t Team
|
var t Team
|
||||||
if err := DBQueryRow("SELECT id_team, initial_name, name, color FROM teams WHERE id_team = ?", id).Scan(&t.Id, &t.InitialName, &t.Name, &t.Color); err != nil {
|
if err := DBQueryRow("SELECT id_team, name, color FROM teams WHERE id_team = ?", id).Scan(&t.Id, &t.Name, &t.Color); err != nil {
|
||||||
return t, err
|
return t, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTeamByInitialName(initialName string) (Team, error) {
|
func GetTeamBySerial(serial int64) (Team, error) {
|
||||||
var t Team
|
var t Team
|
||||||
if err := DBQueryRow("SELECT id_team, initial_name, name, color FROM teams WHERE initial_name = ?", initialName).Scan(&t.Id, &t.InitialName, &t.Name, &t.Color); err != nil {
|
if err := DBQueryRow("SELECT T.id_team, T.name, T.color FROM certificates C INNER JOIN teams T ON T.id_team = C.id_team WHERE id_cert = ?", serial).Scan(&t.Id, &t.Name, &t.Color); err != nil {
|
||||||
return t, err
|
return t, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,18 +58,12 @@ func GetTeamByInitialName(initialName string) (Team, error) {
|
|||||||
// CRUD method
|
// CRUD method
|
||||||
|
|
||||||
func CreateTeam(name string, color uint32) (Team, error) {
|
func CreateTeam(name string, color uint32) (Team, error) {
|
||||||
re := regexp.MustCompile("[^a-zA-Z0-9]+")
|
if res, err := DBExec("INSERT INTO teams (name, color) VALUES (?, ?)", name, color); err != nil {
|
||||||
initialName := re.ReplaceAllLiteralString(name, "_")
|
|
||||||
return RegisterTeam(initialName, name, color)
|
|
||||||
}
|
|
||||||
|
|
||||||
func RegisterTeam(initialName string, name string, color uint32) (Team, error) {
|
|
||||||
if res, err := DBExec("INSERT INTO teams (initial_name, name, color) VALUES (?, ?, ?)", initialName, name, color); err != nil {
|
|
||||||
return Team{}, err
|
return Team{}, err
|
||||||
} else if tid, err := res.LastInsertId(); err != nil {
|
} else if tid, err := res.LastInsertId(); err != nil {
|
||||||
return Team{}, err
|
return Team{}, err
|
||||||
} else {
|
} else {
|
||||||
return Team{tid, name, name, color}, nil
|
return Team{tid, name, color}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user