permit updat eto update
parent
15e68cadcd
commit
b231bd3940
|
|
@ -16,10 +16,6 @@ import (
|
|||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
var (
|
||||
errModifiedReserved = errors.New("cannot modify reserved field " + entity.Name)
|
||||
)
|
||||
|
||||
type BoltDB struct {
|
||||
db *bolt.DB
|
||||
}
|
||||
|
|
@ -247,9 +243,6 @@ func apply(doc bson.M, operator interface{}) (bson.M, error) {
|
|||
if err := bson.Unmarshal(b, &op); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, ok := op[entity.Name]; ok {
|
||||
return nil, errModifiedReserved
|
||||
}
|
||||
for k, v := range op {
|
||||
operateBM, ok := v.(bson.M)
|
||||
if !ok {
|
||||
|
|
@ -282,7 +275,7 @@ func apply(doc bson.M, operator interface{}) (bson.M, error) {
|
|||
func applyUnset(doc, operator bson.M) (bson.M, error) {
|
||||
for k := range operator {
|
||||
if k == entity.Name {
|
||||
return nil, errModifiedReserved
|
||||
continue
|
||||
}
|
||||
nesting := strings.Split(k, ".")
|
||||
if len(nesting) > 1 {
|
||||
|
|
@ -315,7 +308,7 @@ func applyUnset(doc, operator bson.M) (bson.M, error) {
|
|||
func applySet(doc, operator bson.M) (bson.M, error) {
|
||||
for k, v := range operator {
|
||||
if k == entity.Name {
|
||||
return nil, errModifiedReserved
|
||||
continue
|
||||
}
|
||||
nesting := strings.Split(k, ".")
|
||||
if len(nesting) > 1 {
|
||||
|
|
|
|||
|
|
@ -188,10 +188,6 @@ func TestBoltDBUpdate(t *testing.T) {
|
|||
i++
|
||||
}
|
||||
|
||||
if err := bdb.Update(context.TODO(), testNS, ones[0].Query(), operator.Set{Key: entity.Name, Value: "NEWNAME"}); err == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := bdb.Update(context.TODO(), testNS, ones[0].Query(), operator.Set{Key: entity.Title, Value: "NEWTITLE"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package view
|
||||
|
||||
const (
|
||||
markdownHead = `<div>
|
||||
<style scoped>
|
||||
@charset"UTF-8";button,input,textarea{transition:background-color 0.1s linear, border-color 0.1s linear, color 0.1s linear, box-shadow 0.1s linear, transform 0.1s ease}h1{font-size:2.2em;margin-top:0}h1,h2,h3,h4,h5,h6{margin-bottom:12px}h1,h2,h3,h4,h5,h6,strong{color:#000000}b,h1,h2,h3,h4,h5,h6,strong,th{font-weight:600}blockquote{border-left:4px solid #0096bfab;margin:1.5em 0;padding:0.5em 1em;font-style:italic}blockquote > footer{margin-top:10px;font-style:normal}blockquote cite{font-style:normal}address{font-style:normal}a[href^='mailto']::before{content:'📧 '}a[href^='tel']::before{content:'📞 '}a[href^='sms']::before{content:'💬 '}button,input[type='submit'],input[type='button'],input[type='checkbox']{cursor:pointer}input:not([type='checkbox']):not([type='radio']),select{display:block}button,input,select,textarea{color:#000000;background-color:#efefef;font-family:inherit;font-size:inherit;margin-right:6px;margin-bottom:6px;padding:10px;border:none;border-radius:6px;outline:none}input:not([type='checkbox']):not([type='radio']),select,button,textarea{-webkit-appearance:none}textarea{margin-right:0;width:100%;box-sizing:border-box;resize:vertical}button,input[type='submit'],input[type='button']{padding-right:30px;padding-left:30px}button:hover,input[type='submit']:hover,input[type='button']:hover{background:#dddddd}button:focus,input:focus,select:focus,textarea:focus{box-shadow:0 0 0 2px #0096bfab}input[type='checkbox']:active,input[type='radio']:active,input[type='submit']:active,input[type='button']:active,button:active{transform:translateY(2px)}button:disabled,input:disabled,select:disabled,textarea:disabled{cursor:not-allowed;opacity:0.5}::-webkit-input-placeholder{color:#949494}:-ms-input-placeholder{color:#949494}::-ms-input-placeholder{color:#949494}::placeholder{color:#949494}a{text-decoration:none;color:#0076d1}a:hover{text-decoration:underline}code,kbd{background:#efefef;color:#000000;padding:5px;border-radius:6px}pre > code{padding:10px;display:block;overflow-x:auto}img{max-width:100%}hr{border:none;border-top:1px solid #dbdbdb}table{border-collapse:collapse;margin-bottom:10px;width:100%}td,th{padding:6px;text-align:left}th{border-bottom:1px solid #dbdbdb}tbody tr:nth-child(even){background-color:#efefef}::-webkit-scrollbar{height:10px;width:10px}::-webkit-scrollbar-track{background:#efefef;border-radius:6px}::-webkit-scrollbar-thumb{background:#d5d5d5;border-radius:6px}::-webkit-scrollbar-thumb:hover{background:#c4c4c4}
|
||||
</style>
|
||||
`
|
||||
markdownTail = `</div>`
|
||||
)
|
||||
21
view/who.go
21
view/who.go
|
|
@ -18,7 +18,6 @@ import (
|
|||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/buger/jsonparser"
|
||||
"github.com/gomarkdown/markdown"
|
||||
"github.com/gomarkdown/markdown/html"
|
||||
"github.com/gomarkdown/markdown/parser"
|
||||
|
|
@ -133,7 +132,7 @@ func whoGet(namespace string, g storage.RateLimitedGraph, w http.ResponseWriter,
|
|||
|
||||
renderer := html.NewRenderer(html.RendererOptions{Flags: html.CommonFlags | html.TOC})
|
||||
parser := parser.NewWithExtensions(parser.CommonExtensions | parser.HeadingIDs | parser.AutoHeadingIDs | parser.Titleblock)
|
||||
m["md"] = string(markdown.ToHTML([]byte(one.Text), parser, renderer))
|
||||
m["md"] = markdownHead + string(markdown.ToHTML([]byte(one.Text), parser, renderer)) + markdownTail
|
||||
|
||||
b, err = json.MarshalIndent(m, "", " ")
|
||||
if err != nil {
|
||||
|
|
@ -156,8 +155,10 @@ func whoPut(namespace string, g storage.RateLimitedGraph, w http.ResponseWriter,
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
reader := bytes.NewReader(body)
|
||||
|
||||
operation := entity.One{}
|
||||
if err := json.Unmarshal(body, &operation); err != nil {
|
||||
if err := json.NewDecoder(reader).Decode(&operation); err != nil {
|
||||
return err
|
||||
}
|
||||
if operation.Name != "" && operation.Name != id {
|
||||
|
|
@ -168,19 +169,13 @@ func whoPut(namespace string, g storage.RateLimitedGraph, w http.ResponseWriter,
|
|||
http.Error(w, `{"error":"cannot specify modified in request body"}`, http.StatusBadRequest)
|
||||
return nil
|
||||
}
|
||||
b, err := bson.Marshal(operation)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
body = bytes.ReplaceAll(body, []byte(`"`+entity.JSONName+`"`), []byte(`"`+entity.Name+`"`))
|
||||
op := bson.M{}
|
||||
if err := bson.Unmarshal(b, &op); err != nil {
|
||||
if err := json.Unmarshal(body, &op); err != nil {
|
||||
return err
|
||||
}
|
||||
for k := range op {
|
||||
if _, _, _, err := jsonparser.Get(body, k); err != nil {
|
||||
delete(op, k)
|
||||
}
|
||||
}
|
||||
|
||||
if err := g.Update(r.Context(), namespace, entity.One{Name: id}, operator.SetMany{Value: op}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"local/dndex/config"
|
||||
|
|
@ -150,13 +149,10 @@ func TestWho(t *testing.T) {
|
|||
if fmt.Sprint(o) != fmt.Sprint(iwant) {
|
||||
t.Fatalf("after resolving connections and modified, iwant and got differ: \nwant %+v\n got %+v", iwant, o)
|
||||
}
|
||||
var paragraphContent string
|
||||
if v, err := jsonparser.GetString(w.Body.Bytes(), "md"); err != nil {
|
||||
if md, err := jsonparser.GetString(w.Body.Bytes(), "md"); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if err := xml.Unmarshal([]byte(v), ¶graphContent); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if paragraphContent != iwant.Text {
|
||||
t.Fatal(iwant.Text, paragraphContent, v)
|
||||
} else if !strings.HasPrefix(strings.TrimSpace(md), "<") || !strings.Contains(md, iwant.Text) {
|
||||
t.Fatal(iwant.Text, md)
|
||||
}
|
||||
b, _ := json.MarshalIndent(o, "", " ")
|
||||
t.Logf("POST GET:\n%s", b)
|
||||
|
|
@ -780,7 +776,9 @@ func TestWho(t *testing.T) {
|
|||
}
|
||||
o.Attachments = want.Attachments
|
||||
if fmt.Sprint(o) != fmt.Sprint(want) {
|
||||
t.Fatalf("GET put != expected: want:\n%+v, got \n%+v", want, o)
|
||||
wantjs, _ := json.MarshalIndent(want, "", " ")
|
||||
ojs, _ := json.MarshalIndent(o, "", " ")
|
||||
t.Fatalf("GET put != expected: want:\n%s, got \n%s", wantjs, ojs)
|
||||
}
|
||||
|
||||
forget := want.Peers()[0]
|
||||
|
|
|
|||
Loading…
Reference in New Issue