Download this file
| 1 | package planning |
| 2 | |
| 3 | import ( |
| 4 | "amadan.net/oficina/equipo/internal/taskplan" |
| 5 | "encoding/json" |
| 6 | ) |
| 7 | |
| 8 | // Explicit plan picks must be eligible for the requester in this transaction. |
| 9 | func (s *Store) validateSelections(person string, p taskplan.Plan, started map[string]bool) error { |
| 10 | for _, step := range p.Steps { |
| 11 | if started[step.Key] || step.ConnectionID == "" && step.Model == "" { |
| 12 | continue |
| 13 | } |
| 14 | if step.Specialist == "" { |
| 15 | return s.deps.Invalid |
| 16 | } |
| 17 | _, ids, err := ConnectionChoiceAt(s.tx, person, p.ProjectID) |
| 18 | if err != nil { |
| 19 | return s.deps.Invalid |
| 20 | } |
| 21 | var rows []ConnectionRecord |
| 22 | q := s.tx.Where("person=? AND id IN ?", person, ids) |
| 23 | if step.ConnectionID != "" { |
| 24 | q = q.Where("id=?", step.ConnectionID) |
| 25 | } |
| 26 | if err = q.Find(&rows).Error; err != nil { |
| 27 | return err |
| 28 | } |
| 29 | found := false |
| 30 | for _, c := range rows { |
| 31 | if err = json.Unmarshal([]byte(c.ReportsJSON), &c.Reports); err != nil { |
| 32 | return err |
| 33 | } |
| 34 | for _, report := range c.Reports { |
| 35 | if step.Model != "" && step.Model != report.Model { |
| 36 | continue |
| 37 | } |
| 38 | ok, err := s.deps.EligibleSelection(s.tx, p.ProjectID, step, c, report) |
| 39 | if err != nil { |
| 40 | return err |
| 41 | } |
| 42 | found = found || ok |
| 43 | } |
| 44 | } |
| 45 | if !found { |
| 46 | return s.deps.Invalid |
| 47 | } |
| 48 | } |
| 49 | return nil |
| 50 | } |
| 51 | |