diff options
author | Simon Ser <contact@emersion.fr> | 2020-05-13 17:59:04 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2020-05-13 17:59:04 +0200 |
commit | 37be46c047f03cadb5c8a53ff803d46c62fdd2f4 (patch) | |
tree | ff71ae4bc1a7c873fd40aaabe8a992be868d1158 /plugins/carddav | |
parent | 297798dca260ae3cd8ca937d4ad6b17e120c54fa (diff) | |
download | alps-37be46c047f03cadb5c8a53ff803d46c62fdd2f4.tar.gz alps-37be46c047f03cadb5c8a53ff803d46c62fdd2f4.zip |
plugins/carddav: add route to delete a contact
Diffstat (limited to 'plugins/carddav')
-rw-r--r-- | plugins/carddav/public/address-object.html | 3 | ||||
-rw-r--r-- | plugins/carddav/routes.go | 18 |
2 files changed, 21 insertions, 0 deletions
diff --git a/plugins/carddav/public/address-object.html b/plugins/carddav/public/address-object.html index 5423d9f..2b37768 100644 --- a/plugins/carddav/public/address-object.html +++ b/plugins/carddav/public/address-object.html @@ -14,6 +14,9 @@ <a href="{{.AddressObject.URL}}/edit"> Edit </a> + <form action="{{.AddressObject.URL}}/delete" method="post"> + <input type="submit" value="Delete"> + </form> </p> <ul> diff --git a/plugins/carddav/routes.go b/plugins/carddav/routes.go index 78fe1eb..7660dbc 100644 --- a/plugins/carddav/routes.go +++ b/plugins/carddav/routes.go @@ -211,4 +211,22 @@ func registerRoutes(p *plugin) { p.GET("/contacts/:path/edit", updateContact) p.POST("/contacts/:path/edit", updateContact) + + p.POST("/contacts/:path/delete", func(ctx *alps.Context) error { + path, err := parseObjectPath(ctx.Param("path")) + if err != nil { + return err + } + + c, err := p.client(ctx.Session) + if err != nil { + return err + } + + if err := c.RemoveAll(path); err != nil { + return fmt.Errorf("failed to delete address object: %v", err) + } + + return ctx.Redirect(http.StatusFound, "/contacts") + }) } |