checkPermission rejects a permission that cannot upload. It is an allowlist, so an unlisted value is rejected rather than sent.
(viewerPermission string)
| 92 | // checkPermission rejects a permission that cannot upload. It is an allowlist, |
| 93 | // so an unlisted value is rejected rather than sent. |
| 94 | func checkPermission(viewerPermission string) error { |
| 95 | // A caller that never requested the field hands over an empty string. That |
| 96 | // is a different fault from a permission that is too low. |
| 97 | if viewerPermission == "" { |
| 98 | return errors.New("could not determine your permission on the repository to attach files") |
| 99 | } |
| 100 | |
| 101 | if slices.Contains(uploadPermissions, viewerPermission) { |
| 102 | return nil |
| 103 | } |
| 104 | return errors.New("attaching files requires write access to the repository") |
| 105 | } |
| 106 | |
| 107 | // upload sends the file's bytes and returns the asset URL to reference |
| 108 | // from the markdown. |