mirror of https://github.com/jlelse/GoBlog
Allow to update post-status using Micropub update
This commit is contained in:
parent
10616e24a5
commit
24cd6dbdac
|
@ -465,7 +465,6 @@ func (s *micropubImplementation) updatePostPropertiesFromMf(p *post, properties
|
||||||
|
|
||||||
// Ignore the following properties
|
// Ignore the following properties
|
||||||
delete(properties, "url")
|
delete(properties, "url")
|
||||||
delete(properties, "post-status")
|
|
||||||
delete(properties, "photo")
|
delete(properties, "photo")
|
||||||
delete(properties, "photo-alt")
|
delete(properties, "photo-alt")
|
||||||
|
|
||||||
|
@ -492,6 +491,12 @@ func (s *micropubImplementation) updatePostPropertiesFromMf(p *post, properties
|
||||||
delete(properties, "mp-channel")
|
delete(properties, "mp-channel")
|
||||||
p.Visibility = postVisibility(defaultIfEmpty(getFirstStringFromArray(properties["visibility"]), string(p.Visibility)))
|
p.Visibility = postVisibility(defaultIfEmpty(getFirstStringFromArray(properties["visibility"]), string(p.Visibility)))
|
||||||
delete(properties, "visibility")
|
delete(properties, "visibility")
|
||||||
|
if newStatusString := getFirstStringFromArray(properties["post-status"]); newStatusString != "" {
|
||||||
|
if newStatus := postStatus(newStatusString); newStatus == statusPublished || newStatus == statusDraft {
|
||||||
|
p.Status = newStatus
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete(properties, "post-status")
|
||||||
|
|
||||||
for key, value := range properties {
|
for key, value := range properties {
|
||||||
p.Parameters[s.mapToParameterName(key)] = cast.ToStringSlice(value)
|
p.Parameters[s.mapToParameterName(key)] = cast.ToStringSlice(value)
|
||||||
|
|
|
@ -279,7 +279,7 @@ func Test_micropubUpdate(t *testing.T) {
|
||||||
"category": {"test"},
|
"category": {"test"},
|
||||||
"random": {"def"},
|
"random": {"def"},
|
||||||
"content": {"New test"},
|
"content": {"New test"},
|
||||||
"post-status": {"published-deleted"},
|
"post-status": {"draft"},
|
||||||
"visibility": {"unlisted"},
|
"visibility": {"unlisted"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -292,11 +292,40 @@ func Test_micropubUpdate(t *testing.T) {
|
||||||
assert.Equal(t, []string{"test"}, p.Parameters["tags"])
|
assert.Equal(t, []string{"test"}, p.Parameters["tags"])
|
||||||
assert.Equal(t, []string{"def"}, p.Parameters["random"])
|
assert.Equal(t, []string{"def"}, p.Parameters["random"])
|
||||||
assert.Equal(t, "New test", p.Content)
|
assert.Equal(t, "New test", p.Content)
|
||||||
assert.Equal(t, statusPublished, p.Status)
|
assert.Equal(t, statusDraft, p.Status)
|
||||||
assert.Nil(t, p.Parameters["post-status"])
|
assert.Nil(t, p.Parameters["post-status"])
|
||||||
assert.Equal(t, visibilityUnlisted, p.Visibility)
|
assert.Equal(t, visibilityUnlisted, p.Visibility)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("Replace wrong status", func(t *testing.T) {
|
||||||
|
postPath := "/replace2"
|
||||||
|
|
||||||
|
err := app.createPost(&post{
|
||||||
|
Path: postPath,
|
||||||
|
Content: "",
|
||||||
|
Status: statusPublished,
|
||||||
|
Visibility: visibilityPublic,
|
||||||
|
Parameters: map[string][]string{},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
_, err = app.getMicropubImplementation().Update(µpub.Request{
|
||||||
|
URL: app.cfg.Server.PublicAddress + postPath,
|
||||||
|
Updates: micropub.RequestUpdate{
|
||||||
|
Replace: map[string][]any{
|
||||||
|
"post-status": {"published-deleted"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
p, err := app.getPost(postPath)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
assert.Equal(t, statusPublished, p.Status)
|
||||||
|
assert.Nil(t, p.Parameters["post-status"])
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("Add", func(t *testing.T) {
|
t.Run("Add", func(t *testing.T) {
|
||||||
postPath := "/add1"
|
postPath := "/add1"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue