Skip to content

Commit

Permalink
feat: enhance error message when invalid permission value has set
Browse files Browse the repository at this point in the history
  • Loading branch information
macrat committed Feb 2, 2025
1 parent be2ea60 commit 1696e46
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -886,20 +887,27 @@ func (a *KintoneAppConfig) UnmarshalJSON(data []byte) error {
a.ID = tmp.ID
a.Description = tmp.Description

if v, ok := tmp.Permissions["read"]; ok {
a.Permissions.Read = v.(bool)
} else {
a.Permissions.Read = true // read is default true
getPerm := func(key string, default_ bool) (bool, error) {
if v, ok := tmp.Permissions[key]; ok {
if b, ok := v.(bool); ok {
return b, nil
} else {
return false, errors.New("members of 'permissions' must be boolean")
}
} else {
return default_, nil
}
}
if v, ok := tmp.Permissions["write"]; ok {
a.Permissions.Write = v.(bool)
} else {
a.Permissions.Write = false

var err error
if a.Permissions.Read, err = getPerm("read", true); err != nil {
return err
}
if v, ok := tmp.Permissions["delete"]; ok {
a.Permissions.Delete = v.(bool)
} else {
a.Permissions.Delete = false
if a.Permissions.Write, err = getPerm("write", false); err != nil {
return err
}
if a.Permissions.Delete, err = getPerm("delete", false); err != nil {
return err
}

return nil
Expand Down

0 comments on commit 1696e46

Please sign in to comment.