2018-05-27 22:40:42 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
func domainList(ownerHex string) ([]domain, error) {
|
|
|
|
if ownerHex == "" {
|
|
|
|
return []domain{}, errorMissingField
|
|
|
|
}
|
|
|
|
|
|
|
|
statement := `
|
2019-04-20 07:03:34 +08:00
|
|
|
SELECT
|
|
|
|
domain,
|
|
|
|
ownerHex,
|
|
|
|
name,
|
|
|
|
creationDate,
|
|
|
|
state,
|
|
|
|
importedComments,
|
|
|
|
autoSpamFilter,
|
|
|
|
requireModeration,
|
|
|
|
requireIdentification,
|
|
|
|
moderateAllAnonymous,
|
|
|
|
emailNotificationPolicy,
|
|
|
|
commentoProvider,
|
|
|
|
googleProvider,
|
|
|
|
twitterProvider,
|
|
|
|
githubProvider,
|
2019-04-21 08:34:25 +08:00
|
|
|
gitlabProvider,
|
|
|
|
ssoProvider,
|
|
|
|
ssoSecret,
|
2019-12-05 10:50:50 +08:00
|
|
|
ssoUrl,
|
|
|
|
defaultSortPolicy
|
2018-05-27 22:40:42 +08:00
|
|
|
FROM domains
|
|
|
|
WHERE ownerHex=$1;
|
|
|
|
`
|
|
|
|
rows, err := db.Query(statement, ownerHex)
|
|
|
|
if err != nil {
|
|
|
|
logger.Errorf("cannot query domains: %v", err)
|
|
|
|
return nil, errorInternal
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
|
|
|
|
domains := []domain{}
|
|
|
|
for rows.Next() {
|
|
|
|
d := domain{}
|
2019-04-20 07:03:34 +08:00
|
|
|
if err = rows.Scan(
|
|
|
|
&d.Domain,
|
|
|
|
&d.OwnerHex,
|
|
|
|
&d.Name,
|
|
|
|
&d.CreationDate,
|
|
|
|
&d.State,
|
|
|
|
&d.ImportedComments,
|
|
|
|
&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,
|
|
|
|
&d.SsoSecret,
|
2019-12-05 10:50:50 +08:00
|
|
|
&d.SsoUrl,
|
|
|
|
&d.DefaultSortPolicy); err != nil {
|
2018-05-27 22:40:42 +08:00
|
|
|
logger.Errorf("cannot Scan domain: %v", err)
|
|
|
|
return nil, errorInternal
|
|
|
|
}
|
|
|
|
|
|
|
|
d.Moderators, err = domainModeratorList(d.Domain)
|
|
|
|
if err != nil {
|
|
|
|
return []domain{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
domains = append(domains, d)
|
|
|
|
}
|
|
|
|
|
|
|
|
return domains, rows.Err()
|
|
|
|
}
|
|
|
|
|
|
|
|
func domainListHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
type request struct {
|
2018-06-20 11:29:55 +08:00
|
|
|
OwnerToken *string `json:"ownerToken"`
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
domains, err := domainList(o.OwnerHex)
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-04-20 07:03:34 +08:00
|
|
|
bodyMarshal(w, response{
|
|
|
|
"success": true,
|
|
|
|
"domains": domains,
|
|
|
|
"configuredOauths": map[string]bool{
|
|
|
|
"google": googleConfigured,
|
|
|
|
"twitter": twitterConfigured,
|
|
|
|
"github": githubConfigured,
|
|
|
|
"gitlab": gitlabConfigured,
|
|
|
|
},
|
|
|
|
})
|
2018-05-27 22:40:42 +08:00
|
|
|
}
|