Download this file
| 1 | package caps |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "os" |
| 6 | "path/filepath" |
| 7 | |
| 8 | "github.com/carlosframework/platform/internal/rootparticipation" |
| 9 | ) |
| 10 | |
| 11 | func (o Ops) authorizeMutation() error { |
| 12 | if _, err := os.Lstat(filepath.Join(rootparticipation.Namespace, "census.json")); !errors.Is(err, os.ErrNotExist) { |
| 13 | if err != nil { |
| 14 | return err |
| 15 | } |
| 16 | ledger, required, err := rootparticipation.OpenForUpdate() |
| 17 | if ledger.State != nil { |
| 18 | defer ledger.State.Close() |
| 19 | } |
| 20 | if err != nil { |
| 21 | return err |
| 22 | } |
| 23 | if required { |
| 24 | return os.ErrPermission |
| 25 | } |
| 26 | } |
| 27 | if o.Authorize != nil { |
| 28 | return o.Authorize() |
| 29 | } |
| 30 | return nil |
| 31 | } |
| 32 | |