domain_delete: delete moderator data
This commit is contained in:
parent
79f39f8094
commit
13eca3c78a
@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import ()
|
import (
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
func domainDelete(domain string) error {
|
func domainDelete(domain string) error {
|
||||||
if domain == "" {
|
if domain == "" {
|
||||||
@ -38,6 +40,16 @@ func domainDelete(domain string) error {
|
|||||||
return errorInternal
|
return errorInternal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
statement = `
|
||||||
|
DELETE FROM moderators
|
||||||
|
WHERE moderators.domain = $1;
|
||||||
|
`
|
||||||
|
_, err = db.Exec(statement, domain)
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorf("cannot delete domain moderators: %v", err)
|
||||||
|
return errorInternal
|
||||||
|
}
|
||||||
|
|
||||||
statement = `
|
statement = `
|
||||||
DELETE FROM comments
|
DELETE FROM comments
|
||||||
WHERE comments.domain = $1;
|
WHERE comments.domain = $1;
|
||||||
@ -50,3 +62,41 @@ func domainDelete(domain string) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func domainDeleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
type request struct {
|
||||||
|
Session *string `json:"session"`
|
||||||
|
Domain *string `json:"domain"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var x request
|
||||||
|
if err := unmarshalBody(r, &x); err != nil {
|
||||||
|
writeBody(w, response{"success": false, "message": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
o, err := ownerGetBySession(*x.Session)
|
||||||
|
if err != nil {
|
||||||
|
writeBody(w, response{"success": false, "message": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
domain := stripDomain(*x.Domain)
|
||||||
|
isOwner, err := domainOwnershipVerify(o.OwnerHex, domain)
|
||||||
|
if err != nil {
|
||||||
|
writeBody(w, response{"success": false, "message": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !isOwner {
|
||||||
|
writeBody(w, response{"success": false, "message": errorNotAuthorised.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = domainDelete(*x.Domain); err != nil {
|
||||||
|
writeBody(w, response{"success": false, "message": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
writeBody(w, response{"success": true})
|
||||||
|
}
|
||||||
|
@ -13,6 +13,7 @@ func initAPIRouter(router *mux.Router) error {
|
|||||||
router.HandleFunc("/api/owner/self", ownerSelfHandler).Methods("POST")
|
router.HandleFunc("/api/owner/self", ownerSelfHandler).Methods("POST")
|
||||||
|
|
||||||
router.HandleFunc("/api/domain/new", domainNewHandler).Methods("POST")
|
router.HandleFunc("/api/domain/new", domainNewHandler).Methods("POST")
|
||||||
|
router.HandleFunc("/api/domain/delete", domainDeleteHandler).Methods("POST")
|
||||||
router.HandleFunc("/api/domain/list", domainListHandler).Methods("POST")
|
router.HandleFunc("/api/domain/list", domainListHandler).Methods("POST")
|
||||||
router.HandleFunc("/api/domain/update", domainUpdateHandler).Methods("POST")
|
router.HandleFunc("/api/domain/update", domainUpdateHandler).Methods("POST")
|
||||||
router.HandleFunc("/api/domain/moderator/new", domainModeratorNewHandler).Methods("POST")
|
router.HandleFunc("/api/domain/moderator/new", domainModeratorNewHandler).Methods("POST")
|
||||||
|
Loading…
Reference in New Issue
Block a user