2018-05-27 22:40:42 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
func domainUpdate(d domain) error {
|
2019-04-21 08:34:25 +08:00
|
|
|
if d.SsoProvider && d.SsoUrl == "" {
|
|
|
|
return errorMissingField
|
|
|
|
}
|
|
|
|
|
2018-05-27 22:40:42 +08:00
|
|
|
statement := `
|
|
|
|
UPDATE domains
|
2019-04-20 07:03:34 +08:00
|
|
|
SET
|
|
|
|
name=$2,
|
|
|
|
state=$3,
|
|
|
|
autoSpamFilter=$4,
|
|
|
|
requireModeration=$5,
|
|
|
|
requireIdentification=$6,
|
|
|
|
moderateAllAnonymous=$7,
|
|
|
|
emailNotificationPolicy=$8,
|
|
|
|
commentoProvider=$9,
|
|
|
|
googleProvider=$10,
|
|
|
|
twitterProvider=$11,
|
|
|
|
githubProvider=$12,
|
2019-04-21 08:34:25 +08:00
|
|
|
gitlabProvider=$13,
|
|
|
|
ssoProvider=$14,
|
2019-12-05 10:50:50 +08:00
|
|
|
ssoUrl=$15,
|
2022-10-11 00:01:30 +08:00
|
|
|
defaultSortPolicy=$16,
|
|
|
|
authentikProvider=$17
|
2018-05-27 22:40:42 +08:00
|
|
|
WHERE domain=$1;
|
|
|
|
`
|
|
|
|
|
2019-04-20 07:03:34 +08:00
|
|
|
_, err := db.Exec(statement,
|
|
|
|
d.Domain,
|
|
|
|
d.Name,
|
|
|
|
d.State,
|
|
|
|
d.AutoSpamFilter,
|
|
|
|
d.RequireModeration,
|
|
|
|
d.RequireIdentification,
|
|
|
|
d.ModerateAllAnonymous,
|
|
|
|
d.EmailNotificationPolicy,
|
|
|
|
d.CommentoProvider,
|
|
|
|
d.GoogleProvider,
|
|
|
|
d.TwitterProvider,
|
|
|
|
d.GithubProvider,
|
2019-04-21 08:34:25 +08:00
|
|
|
d.GitlabProvider,
|
|
|
|
d.SsoProvider,
|
2019-12-05 10:50:50 +08:00
|
|
|
d.SsoUrl,
|
2022-10-11 00:01:30 +08:00
|
|
|
d.DefaultSortPolicy,
|
|
|
|
d.AuthentikProvider,
|
|
|
|
)
|
2018-05-27 22:40:42 +08:00
|
|
|
if err != nil {
|
2022-10-11 00:01:30 +08:00
|
|
|
logger.Errorf("cannot update non-moderators: %s", d.AuthentikProvider)
|
2018-05-27 22:40:42 +08:00
|
|
|
return errorInternal
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func domainUpdateHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
type request struct {
|
2018-06-20 11:29:55 +08:00
|
|
|
OwnerToken *string `json:"ownerToken"`
|
2018-06-20 11:50:11 +08:00
|
|
|
D *domain `json:"domain"`
|
2018-05-27 22:40:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var x request
|
2018-07-24 14:58:43 +08:00
|
|
|
if err := bodyUnmarshal(r, &x); err != nil {
|
|
|
|
bodyMarshal(w, response{"success": false, "message": err.Error()})
|
2018-05-27 22:40:42 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-06-20 11:29:55 +08:00
|
|
|
o, err := ownerGetByOwnerToken(*x.OwnerToken)
|
2018-05-27 22:40:42 +08:00
|
|
|
if err != nil {
|
2018-07-24 14:58:43 +08:00
|
|
|
bodyMarshal(w, response{"success": false, "message": err.Error()})
|
2018-05-27 22:40:42 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-24 15:00:45 +08:00
|
|
|
domain := domainStrip((*x.D).Domain)
|
2018-05-27 22:40:42 +08:00
|
|
|
isOwner, err := domainOwnershipVerify(o.OwnerHex, domain)
|
|
|
|
if err != nil {
|
2018-07-24 14:58:43 +08:00
|
|
|
bodyMarshal(w, response{"success": false, "message": err.Error()})
|
2018-05-27 22:40:42 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !isOwner {
|
2018-07-24 14:58:43 +08:00
|
|
|
bodyMarshal(w, response{"success": false, "message": errorNotAuthorised.Error()})
|
2018-05-27 22:40:42 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = domainUpdate(*x.D); err != nil {
|
2018-07-24 14:58:43 +08:00
|
|
|
bodyMarshal(w, response{"success": false, "message": err.Error()})
|
2018-05-27 22:40:42 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-24 14:58:43 +08:00
|
|
|
bodyMarshal(w, response{"success": true})
|
2018-05-27 22:40:42 +08:00
|
|
|
}
|