1
mirror of https://gitlab.com/commento/commento.git synced 2025-06-28 22:55:39 -04:00

frontend, api: allow disabling login methods individually

This commit is contained in:
Adhityaa Chandrasekar
2019-04-19 19:03:34 -04:00
parent 0e54739980
commit a455ff54bc
17 changed files with 258 additions and 56 deletions

View File

@ -167,6 +167,12 @@ func commentListHandler(w http.ResponseWriter, r *http.Request) {
"isFrozen": d.State == "frozen",
"isModerator": isModerator,
"attributes": p,
"configuredOauths": configuredOauths,
"configuredOauths": map[string]bool{
"commento": d.CommentoProvider,
"google": googleConfigured && d.GoogleProvider,
"twitter": twitterConfigured && d.TwitterProvider,
"github": githubConfigured && d.GithubProvider,
"gitlab": gitlabConfigured && d.GitlabProvider,
},
})
}

View File

@ -17,4 +17,9 @@ type domain struct {
ModerateAllAnonymous bool `json:"moderateAllAnonymous"`
Moderators []moderator `json:"moderators"`
EmailNotificationPolicy string `json:"emailNotificationPolicy"`
CommentoProvider bool `json:"commentoProvider"`
GoogleProvider bool `json:"googleProvider"`
TwitterProvider bool `json:"twitterProvider"`
GithubProvider bool `json:"githubProvider"`
GitlabProvider bool `json:"gitlabProvider"`
}

View File

@ -8,7 +8,23 @@ func domainGet(dmn string) (domain, error) {
}
statement := `
SELECT domain, ownerHex, name, creationDate, state, importedComments, autoSpamFilter, requireModeration, requireIdentification, moderateAllAnonymous, emailNotificationPolicy
SELECT
domain,
ownerHex,
name,
creationDate,
state,
importedComments,
autoSpamFilter,
requireModeration,
requireIdentification,
moderateAllAnonymous,
emailNotificationPolicy,
commentoProvider,
googleProvider,
twitterProvider,
githubProvider,
gitlabProvider
FROM domains
WHERE domain = $1;
`
@ -16,7 +32,23 @@ func domainGet(dmn string) (domain, error) {
var err error
d := domain{}
if err = row.Scan(&d.Domain, &d.OwnerHex, &d.Name, &d.CreationDate, &d.State, &d.ImportedComments, &d.AutoSpamFilter, &d.RequireModeration, &d.RequireIdentification, &d.ModerateAllAnonymous, &d.EmailNotificationPolicy); err != nil {
if err = row.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,
&d.GitlabProvider); err != nil {
return d, errorNoSuchDomain
}

View File

@ -10,7 +10,23 @@ func domainList(ownerHex string) ([]domain, error) {
}
statement := `
SELECT domain, ownerHex, name, creationDate, state, importedComments, autoSpamFilter, requireModeration, requireIdentification, moderateAllAnonymous, emailNotificationPolicy
SELECT
domain,
ownerHex,
name,
creationDate,
state,
importedComments,
autoSpamFilter,
requireModeration,
requireIdentification,
moderateAllAnonymous,
emailNotificationPolicy,
commentoProvider,
googleProvider,
twitterProvider,
githubProvider,
gitlabProvider
FROM domains
WHERE ownerHex=$1;
`
@ -24,7 +40,23 @@ func domainList(ownerHex string) ([]domain, error) {
domains := []domain{}
for rows.Next() {
d := domain{}
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); err != nil {
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,
&d.GitlabProvider); err != nil {
logger.Errorf("cannot Scan domain: %v", err)
return nil, errorInternal
}
@ -63,5 +95,14 @@ func domainListHandler(w http.ResponseWriter, r *http.Request) {
return
}
bodyMarshal(w, response{"success": true, "domains": domains})
bodyMarshal(w, response{
"success": true,
"domains": domains,
"configuredOauths": map[string]bool{
"google": googleConfigured,
"twitter": twitterConfigured,
"github": githubConfigured,
"gitlab": gitlabConfigured,
},
})
}

View File

@ -7,11 +7,36 @@ import (
func domainUpdate(d domain) error {
statement := `
UPDATE domains
SET name=$2, state=$3, autoSpamFilter=$4, requireModeration=$5, requireIdentification=$6, moderateAllAnonymous=$7, emailNotificationPolicy=$8
SET
name=$2,
state=$3,
autoSpamFilter=$4,
requireModeration=$5,
requireIdentification=$6,
moderateAllAnonymous=$7,
emailNotificationPolicy=$8,
commentoProvider=$9,
googleProvider=$10,
twitterProvider=$11,
githubProvider=$12,
gitlabProvider=$13
WHERE domain=$1;
`
_, err := db.Exec(statement, d.Domain, d.Name, d.State, d.AutoSpamFilter, d.RequireModeration, d.RequireIdentification, d.ModerateAllAnonymous, d.EmailNotificationPolicy)
_, 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,
d.GitlabProvider)
if err != nil {
logger.Errorf("cannot update non-moderators: %v", err)
return errorInternal

View File

@ -2,11 +2,12 @@ package main
import ()
var configuredOauths []string
var googleConfigured bool
var twitterConfigured bool
var githubConfigured bool
var gitlabConfigured bool
func oauthConfigure() error {
configuredOauths = []string{}
if err := googleOauthConfigure(); err != nil {
return err
}

View File

@ -37,7 +37,7 @@ func githubOauthConfigure() error {
Endpoint: github.Endpoint,
}
configuredOauths = append(configuredOauths, "github")
githubConfigured = true
return nil
}

View File

@ -36,7 +36,7 @@ func gitlabOauthConfigure() error {
Endpoint: gitlab.Endpoint,
}
configuredOauths = append(configuredOauths, "gitlab")
gitlabConfigured = true
return nil
}

View File

@ -37,7 +37,7 @@ func googleOauthConfigure() error {
Endpoint: google.Endpoint,
}
configuredOauths = append(configuredOauths, "google")
googleConfigured = true
return nil
}

View File

@ -43,9 +43,9 @@ func twitterOauthConfigure() error {
},
}
configuredOauths = append(configuredOauths, "twitter")
twitterCredMap = make(map[string]twitterOauthState, 1e3)
twitterConfigured = true
return nil
}