admin: Insert $team assignee in db automatically

This commit is contained in:
nemunaire 2021-09-03 12:18:02 +02:00
parent f5941dcece
commit abf0715dbf
4 changed files with 37 additions and 32 deletions

View File

@ -171,11 +171,11 @@ func clearClaims(_ httprouter.Params, _ []byte) (interface{}, error) {
func generateTeamIssuesFile(team fic.Team) error {
if my, err := team.MyIssueFile(); err != nil {
return err
return fmt.Errorf("Unable to generate issue FILE (tid=%d): %w", team.Id, err)
} else if j, err := json.Marshal(my); err != nil {
return err
return fmt.Errorf("Unable to encode issues' file JSON: %w", err)
} else if err = ioutil.WriteFile(path.Join(TeamsDir, fmt.Sprintf("%d", team.Id), "issues.json"), j, 0644); err != nil {
return err
return fmt.Errorf("Unable to write issues' file: %w", err)
}
return nil
}

View File

@ -283,9 +283,9 @@ func eventHandler(f func(fic.Event, []byte) (interface{}, error)) func(httproute
func claimHandler(f func(fic.Claim, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
if cid, err := strconv.ParseInt(string(ps.ByName("cid")), 10, 64); err != nil {
return nil, err
return nil, fmt.Errorf("Invalid claim id: %w", err)
} else if claim, err := fic.GetClaim(cid); err != nil {
return nil, err
return nil, fmt.Errorf("Unable to find requested claim (id=%d): %w", cid, err)
} else {
return f(claim, body)
}

View File

@ -400,6 +400,8 @@ CREATE TABLE IF NOT EXISTS claim_assignees(
`); err != nil {
return err
}
db.Exec(`INSERT INTO claim_assignees VALUES (0, "$team");`)
db.Exec(`UPDATE claim_assignees SET id_assignee = 0 WHERE name = "$team";`)
if _, err := db.Exec(`
CREATE TABLE IF NOT EXISTS claims(
id_claim INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,

View File

@ -2,20 +2,21 @@ package fic
import (
"database/sql"
"fmt"
"path"
"time"
)
// Claim represents an issue, a bug or a ToDo item.
type Claim struct {
Id int64 `json:"id"`
Subject string `json:"subject"`
IdTeam *int64 `json:"id_team"`
IdExercice *int64 `json:"id_exercice"`
IdAssignee *int64 `json:"id_assignee"`
Creation time.Time `json:"creation"`
State string `json:"state"`
Priority string `json:"priority"`
Id int64 `json:"id"`
Subject string `json:"subject"`
IdTeam *int64 `json:"id_team"`
IdExercice *int64 `json:"id_exercice"`
IdAssignee *int64 `json:"id_assignee"`
Creation time.Time `json:"creation"`
State string `json:"state"`
Priority string `json:"priority"`
}
// GetClaim retrieves the claim with the given identifier.
@ -25,7 +26,7 @@ func GetClaim(id int64) (c Claim, err error) {
}
// GetClaims returns a list of all Claim registered in the database.
func GetClaims() (res []Claim, err error) {
func GetClaims() (res []Claim, err error) {
var rows *sql.Rows
if rows, err = DBQuery("SELECT id_claim, subject, id_team, id_exercice, id_assignee, creation, state, priority FROM claims"); err != nil {
return
@ -51,7 +52,7 @@ func (t Team) GetClaim(id int64) (c Claim, err error) {
}
// GetClaims returns a list of all Claim registered for the Team.
func (t Team) GetClaims() (res []Claim, err error) {
func (t Team) GetClaims() (res []Claim, err error) {
var rows *sql.Rows
if rows, err = DBQuery("SELECT id_claim, subject, id_team, id_exercice, id_assignee, creation, state, priority FROM claims WHERE id_team = ?", t.Id); err != nil {
return nil, err
@ -71,7 +72,7 @@ func (t Team) GetClaims() (res []Claim, err error) {
}
// GetExercices returns a list of all Claim registered for the Exercice.
func (e Exercice) GetClaims() (res []Claim, err error) {
func (e Exercice) GetClaims() (res []Claim, err error) {
var rows *sql.Rows
if rows, err = DBQuery("SELECT id_claim, subject, id_team, id_exercice, id_assignee, creation, state, priority FROM claims WHERE id_exercice = ?", e.Id); err != nil {
return nil, err
@ -189,15 +190,15 @@ func ClearClaims() (int64, error) {
// ClaimDescription represents some text describing an issue.
type ClaimDescription struct {
Id int64 `json:"id"`
Id int64 `json:"id"`
// IdAssignee stores the user who handle the claim (or 0 if nobody handles it).
IdAssignee int64 `json:"id_assignee"`
IdAssignee int64 `json:"id_assignee"`
// Content is the raw description.
Content string `json:"content"`
Content string `json:"content"`
// Date is the timestamp when the description was written.
Date time.Time `json:"date"`
Date time.Time `json:"date"`
// Publish indicates wether it is shown back to the team.
Publish bool `json:"publish"`
Publish bool `json:"publish"`
}
// GetLastUpdate returns the date of the latest message written for the given Claim.
@ -394,28 +395,28 @@ func (t Team) MyIssueFile() (ret []teamIssueFile, err error) {
}
if descriptions, err := claim.GetDescriptions(); err != nil {
return nil, err
return nil, fmt.Errorf("Error occurs during description retrieval (cid=%d): %w", claim.Id, err)
} else {
tif := teamIssueFile{
Id: claim.Id,
Subject: claim.Subject,
Exercice: exercice,
Id: claim.Id,
Subject: claim.Subject,
Exercice: exercice,
ExerciceURL: url,
Assignee: assignee,
State: claim.State,
Priority: claim.Priority,
Texts: []teamIssueText{},
Assignee: assignee,
State: claim.State,
Priority: claim.Priority,
Texts: []teamIssueText{},
}
for _, description := range descriptions {
if description.Publish {
if people, err := description.GetAssignee(); err != nil {
return nil, err
return nil, fmt.Errorf("Error ocurs during assignee retrieval (aid=%d): %w", description.IdAssignee, err)
} else {
tif.Texts = append(tif.Texts, teamIssueText{
Content: description.Content,
Content: description.Content,
Assignee: people.Name,
Date: description.Date,
Date: description.Date,
})
}
}
@ -424,6 +425,8 @@ func (t Team) MyIssueFile() (ret []teamIssueFile, err error) {
ret = append(ret, tif)
}
}
} else {
err = fmt.Errorf("Error occurs during claim retrieval: %w", err)
}
return