| 1 | package equipo |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "encoding/json" |
| 6 | "net/http" |
| 7 | "net/url" |
| 8 | "strconv" |
| 9 | |
| 10 | "amadan.net/oficina/equipo/internal/copydesk" |
| 11 | "amadan.net/oficina/equipo/internal/equipo/chat" |
| 12 | ) |
| 13 | |
| 14 | func (a *application) saveCopySetting(w http.ResponseWriter, r *http.Request) { |
| 15 | a.chatActionTo(w, r, "/conversation/settings/copy", func(ctx context.Context, person string) error { |
| 16 | revision, err := strconv.ParseInt(r.FormValue("revision"), 10, 64) |
| 17 | if err != nil { |
| 18 | return chat.ErrInvalid |
| 19 | } |
| 20 | return a.store.Chat().SetCopyDelegation(ctx, person, r.FormValue("project"), r.FormValue("copy_enabled") == "on", revision) |
| 21 | }) |
| 22 | } |
| 23 | func (a *application) importCopyReview(w http.ResponseWriter, r *http.Request) { |
| 24 | a.chatActionTo(w, r, "/conversation/settings/copy", func(ctx context.Context, person string) error { |
| 25 | var in chat.CopyImport |
| 26 | raw := r.FormValue("result") |
| 27 | if len(raw) > 32<<10 { |
| 28 | return chat.ErrInvalid |
| 29 | } |
| 30 | d := json.Unmarshal([]byte(raw), &in) |
| 31 | if d != nil { |
| 32 | return chat.ErrInvalid |
| 33 | } |
| 34 | return a.store.Chat().ImportCopyReview(ctx, person, r.FormValue("project"), in) |
| 35 | }) |
| 36 | } |
| 37 | |
| 38 | func (a *application) recoverCopy(w http.ResponseWriter, r *http.Request) { |
| 39 | a.chatActionTo(w, r, "/conversation/settings/copy", func(ctx context.Context, person string) error { |
| 40 | var refs []copydesk.Reference |
| 41 | raw := r.FormValue("references") |
| 42 | if len(raw) > 4000 { |
| 43 | return chat.ErrInvalid |
| 44 | } |
| 45 | if raw != "" { |
| 46 | if err := json.Unmarshal([]byte(raw), &refs); err != nil { |
| 47 | return chat.ErrInvalid |
| 48 | } |
| 49 | } |
| 50 | return a.store.Chat().RecoverCopyReferences(ctx, person, r.FormValue("task"), r.FormValue("candidate"), r.FormValue("tooling"), refs) |
| 51 | }) |
| 52 | } |
| 53 | |
| 54 | func (a *application) editCopyWording(w http.ResponseWriter, r *http.Request) { |
| 55 | a.chatActionTo(w, r, "/tasks/"+url.PathEscape(r.FormValue("task")), func(ctx context.Context, person string) error { |
| 56 | return a.store.Chat().EditCopyWording(ctx, person, r.FormValue("record"), r.FormValue("text"), r.FormValue("reason")) |
| 57 | }) |
| 58 | } |
| 59 | |