| 1 | package control |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | |
| 6 | "reasonix/internal/attachment" |
| 7 | ) |
| 8 | |
| 9 | func (c *Controller) RebindDraftImage(ctx context.Context, id string) (attachment.DraftCredential, error) { |
| 10 | svc := c.attachmentService() |
| 11 | draft, ok := svc.Drafts().Lookup(c.attachmentScope(), id) |
| 12 | if !ok { |
| 13 | return attachment.DraftCredential{}, attachment.Error{Code: attachment.CodeMissing, Message: "draft credential is not valid", Retry: true} |
| 14 | } |
| 15 | if _, err := svc.PrepareBatch(ctx, []attachment.Source{{Existing: &draft.Ref, DisplayName: draft.DisplayName}}); err != nil { |
| 16 | return attachment.DraftCredential{}, err |
| 17 | } |
| 18 | return svc.Drafts().RebindVerified(c.attachmentScope(), id) |
| 19 | } |
| 20 | |
| 21 | func (c *Controller) rebindPreparedDrafts(req SubmissionRequest, legacy []string) error { |
| 22 | ids := append([]string(nil), legacy...) |
| 23 | for _, item := range req.Attachments { |
| 24 | if item.DraftID != "" { |
| 25 | ids = append(ids, item.DraftID) |
| 26 | } |
| 27 | } |
| 28 | for _, id := range ids { |
| 29 | // Queue edits may carry an already admitted, authorized reference. |
| 30 | if req.frozenSources["draft:"+id] != nil { |
| 31 | continue |
| 32 | } |
| 33 | if _, err := c.attachmentService().Drafts().RebindVerified(c.attachmentScope(), id); err != nil { |
| 34 | return err |
| 35 | } |
| 36 | } |
| 37 | return nil |
| 38 | } |
| 39 |