admin: add message on claim state change and assignee change

This commit is contained in:
nemunaire 2020-01-24 18:23:06 +01:00
parent e45a674937
commit 83b7df7e69
2 changed files with 38 additions and 12 deletions

View file

@ -106,11 +106,8 @@ func showClaim(claim fic.Claim, _ []byte) (interface{}, error) {
} }
type ClaimUploaded struct { type ClaimUploaded struct {
Subject string `json:"subject"` fic.Claim
Team *int64 `json:"id_team"` Whoami *int64 `json:"whoami"`
Exercice *int64 `json:"id_exercice"`
Assignee *int64 `json:"id_assignee"`
Priority string `json:"priority"`
} }
func newClaim(_ httprouter.Params, body []byte) (interface{}, error) { func newClaim(_ httprouter.Params, body []byte) (interface{}, error) {
@ -124,8 +121,8 @@ func newClaim(_ httprouter.Params, body []byte) (interface{}, error) {
} }
var t *fic.Team var t *fic.Team
if uc.Team != nil { if uc.IdTeam != nil {
if team, err := fic.GetTeam(*uc.Team); err != nil { if team, err := fic.GetTeam(*uc.IdTeam); err != nil {
return nil, err return nil, err
} else { } else {
t = &team t = &team
@ -135,8 +132,8 @@ func newClaim(_ httprouter.Params, body []byte) (interface{}, error) {
} }
var e *fic.Exercice var e *fic.Exercice
if uc.Exercice != nil { if uc.IdExercice != nil {
if exercice, err := fic.GetExercice(*uc.Exercice); err != nil { if exercice, err := fic.GetExercice(*uc.IdExercice); err != nil {
return nil, err return nil, err
} else { } else {
e = &exercice e = &exercice
@ -146,8 +143,8 @@ func newClaim(_ httprouter.Params, body []byte) (interface{}, error) {
} }
var a *fic.ClaimAssignee var a *fic.ClaimAssignee
if uc.Assignee != nil { if uc.IdAssignee != nil {
if assignee, err := fic.GetAssignee(*uc.Assignee); err != nil { if assignee, err := fic.GetAssignee(*uc.IdAssignee); err != nil {
return nil, err return nil, err
} else { } else {
a = &assignee a = &assignee
@ -215,7 +212,7 @@ func updateClaimDescription(claim fic.Claim, body []byte) (interface{}, error) {
} }
func updateClaim(claim fic.Claim, body []byte) (interface{}, error) { func updateClaim(claim fic.Claim, body []byte) (interface{}, error) {
var uc fic.Claim var uc ClaimUploaded
if err := json.Unmarshal(body, &uc); err != nil { if err := json.Unmarshal(body, &uc); err != nil {
return nil, err return nil, err
} }
@ -225,6 +222,32 @@ func updateClaim(claim fic.Claim, body []byte) (interface{}, error) {
if _, err := uc.Update(); err != nil { if _, err := uc.Update(); err != nil {
return nil, err return nil, err
} else { } else {
if claim.State != uc.State {
if uc.Whoami != nil {
if assignee, err := fic.GetAssignee(*uc.Whoami); err == nil {
claim.AddDescription(fmt.Sprintf("%s a changé l'état de la tâche vers %q (était %q).", assignee.Name, uc.State, claim.State), assignee, true)
}
}
}
if claim.IdAssignee != uc.IdAssignee {
if uc.Whoami != nil {
if whoami, err := fic.GetAssignee(*uc.Whoami); err == nil {
if uc.IdAssignee != nil {
if assignee, err := fic.GetAssignee(*uc.IdAssignee); err == nil {
if assignee.Id != whoami.Id {
claim.AddDescription(fmt.Sprintf("%s a assigné la tâche à %s.", whoami.Name, assignee.Name), whoami, false)
} else {
claim.AddDescription(fmt.Sprintf("%s s'est assigné la tâche.", assignee.Name), whoami, false)
}
}
} else {
claim.AddDescription(fmt.Sprintf("%s a retiré l'attribution de la tâche.", whoami.Name), whoami, false)
}
}
}
}
if team, _ := claim.GetTeam(); team != nil { if team, _ := claim.GetTeam(); team != nil {
err = generateTeamIssuesFile(*team) err = generateTeamIssuesFile(*team)
} }

View file

@ -1150,6 +1150,8 @@ angular.module("FICApp")
$scope.changeState = function(state) { $scope.changeState = function(state) {
this.claim.state = state; this.claim.state = state;
if ((state == "in-progress" || state == "invalid") && this.claim.id_assignee)
this.claim.id_assignee = $scope.whoami;
if (this.claim.id) if (this.claim.id)
this.saveClaim(state == "invalid" || state == "closed"); this.saveClaim(state == "invalid" || state == "closed");
} }
@ -1184,6 +1186,7 @@ angular.module("FICApp")
}); });
} }
$scope.saveClaim = function(backToList) { $scope.saveClaim = function(backToList) {
this.claim.whoami = $scope.whoami;
if (this.claim.id_team) { if (this.claim.id_team) {
this.claim.id_team = parseInt(this.claim.id_team, 10); this.claim.id_team = parseInt(this.claim.id_team, 10);
} else { } else {