diff --git a/api/comment_list.go b/api/comment_list.go index dfc9047..663b75a 100644 --- a/api/comment_list.go +++ b/api/comment_list.go @@ -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, + }, }) } diff --git a/api/domain.go b/api/domain.go index c5f7a51..1316ca3 100644 --- a/api/domain.go +++ b/api/domain.go @@ -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"` } diff --git a/api/domain_get.go b/api/domain_get.go index b0c036f..4f38b90 100644 --- a/api/domain_get.go +++ b/api/domain_get.go @@ -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 } diff --git a/api/domain_list.go b/api/domain_list.go index f1eca8c..8a48d4c 100644 --- a/api/domain_list.go +++ b/api/domain_list.go @@ -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, + }, + }) } diff --git a/api/domain_update.go b/api/domain_update.go index c1a87ff..a60fcca 100644 --- a/api/domain_update.go +++ b/api/domain_update.go @@ -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 diff --git a/api/oauth.go b/api/oauth.go index 5e324a0..c221326 100644 --- a/api/oauth.go +++ b/api/oauth.go @@ -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 } diff --git a/api/oauth_github.go b/api/oauth_github.go index d92a017..b3b565c 100644 --- a/api/oauth_github.go +++ b/api/oauth_github.go @@ -37,7 +37,7 @@ func githubOauthConfigure() error { Endpoint: github.Endpoint, } - configuredOauths = append(configuredOauths, "github") + githubConfigured = true return nil } diff --git a/api/oauth_gitlab.go b/api/oauth_gitlab.go index ba882c2..495ba58 100644 --- a/api/oauth_gitlab.go +++ b/api/oauth_gitlab.go @@ -36,7 +36,7 @@ func gitlabOauthConfigure() error { Endpoint: gitlab.Endpoint, } - configuredOauths = append(configuredOauths, "gitlab") + gitlabConfigured = true return nil } diff --git a/api/oauth_google.go b/api/oauth_google.go index 6eb53e8..d50dc08 100644 --- a/api/oauth_google.go +++ b/api/oauth_google.go @@ -37,7 +37,7 @@ func googleOauthConfigure() error { Endpoint: google.Endpoint, } - configuredOauths = append(configuredOauths, "google") + googleConfigured = true return nil } diff --git a/api/oauth_twitter.go b/api/oauth_twitter.go index 753df2a..a600917 100644 --- a/api/oauth_twitter.go +++ b/api/oauth_twitter.go @@ -43,9 +43,9 @@ func twitterOauthConfigure() error { }, } - configuredOauths = append(configuredOauths, "twitter") - twitterCredMap = make(map[string]twitterOauthState, 1e3) + twitterConfigured = true + return nil } diff --git a/db/20190418210855-configurable-auth.sql b/db/20190418210855-configurable-auth.sql new file mode 100644 index 0000000..9dab0f5 --- /dev/null +++ b/db/20190418210855-configurable-auth.sql @@ -0,0 +1,16 @@ +-- Make all login providers optional (but enabled by default) + +ALTER TABLE domains + ADD commentoProvider BOOLEAN NOT NULL DEFAULT true; + +ALTER TABLE domains + ADD googleProvider BOOLEAN NOT NULL DEFAULT true; + +ALTER TABLE domains + ADD twitterProvider BOOLEAN NOT NULL DEFAULT true; + +ALTER TABLE domains + ADD githubProvider BOOLEAN NOT NULL DEFAULT true; + +ALTER TABLE domains + ADD gitlabProvider BOOLEAN NOT NULL DEFAULT true; diff --git a/frontend/dashboard.html b/frontend/dashboard.html index 2277697..893cb94 100644 --- a/frontend/dashboard.html +++ b/frontend/dashboard.html @@ -181,14 +181,6 @@