-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added setting to remove admin link on status page #16
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -827,6 +827,7 @@ var cancelAppCtx context.CancelFunc | |||||
var rwDB *sql.DB | ||||||
var metaSetup string | ||||||
var metaName string | ||||||
var metaShowAdminLink bool | ||||||
var metaDomain string | ||||||
var metaUnconfirmedDomain string | ||||||
var metaUnconfirmedDomainProblem string | ||||||
|
@@ -845,6 +846,7 @@ type pageCtx struct { | |||||
HXRequest bool | ||||||
HXBoosted bool | ||||||
AdminArea bool | ||||||
ShowAdminLink bool | ||||||
Nav string | ||||||
UnconfirmedDomainProblem string | ||||||
UnconfirmedDomain string | ||||||
|
@@ -879,6 +881,7 @@ func getPageCtx(r *http.Request) pageCtx { | |||||
HXRequest: r.Header.Get("HX-Request") == "true", | ||||||
HXBoosted: r.Header.Get("HX-Boosted") == "true", | ||||||
AdminArea: adminArea, | ||||||
ShowAdminLink: metaShowAdminLink, | ||||||
Nav: adminURLPrefix, | ||||||
UnconfirmedDomainProblem: metaUnconfirmedDomainProblem, | ||||||
UnconfirmedDomain: metaUnconfirmedDomain, | ||||||
|
@@ -3553,6 +3556,18 @@ func main() { | |||||
} | ||||||
metaName = name | ||||||
|
||||||
showAdminLink, err := getMetaValue(tx, "showAdminLink") | ||||||
if err != nil && !errors.Is(err, sql.ErrNoRows) { | ||||||
log.Fatalf("main.getMetaValueShowAdminLink: %s", err) | ||||||
return | ||||||
} | ||||||
|
||||||
metaShowAdminLink, err = strconv.ParseBool(showAdminLink) | ||||||
if err != nil { | ||||||
log.Fatalf("main.ParseBoolShowAdminLink: %s", err) | ||||||
return | ||||||
} | ||||||
|
||||||
Comment on lines
+3559
to
+3570
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're going to need to handle the absence of Maybe we could do one of the following:
Let me know if I missed anything There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we going to add configuration for |
||||||
domain, err := getMetaValue(tx, "domain") | ||||||
if err != nil && !errors.Is(err, sql.ErrNoRows) { | ||||||
log.Fatalf("main.getMetaValueDomain: %s", err) | ||||||
|
@@ -5603,10 +5618,9 @@ func index(w http.ResponseWriter, r *http.Request) { | |||||
|
||||||
|
||||||
<a class="index-link" href="/history" hx-boost="true">View full history</a> | ||||||
{{if not .Ctx.Auth.ID}} | ||||||
<a class="index-link index-link--secondary" href="/login" hx-boost="true">Manage this page</a> | ||||||
{{if and .Ctx.ShowAdminLink (not .Ctx.Auth.ID)}} | ||||||
<a class="index-link index-link--secondary" href="/login" hx-boost="true">Manage this page</a> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we've got a double indent here
Suggested change
|
||||||
{{end}} | ||||||
|
||||||
<dialog class="email-updates-modal"> | ||||||
<div> | ||||||
<span>Get email updates</span> | ||||||
|
@@ -15409,6 +15423,23 @@ func getSettings(w http.ResponseWriter, r *http.Request) { | |||||
return | ||||||
} | ||||||
|
||||||
showAdminLinkStr, err := getMetaValue(tx, "showAdminLink") | ||||||
if err != nil && !errors.Is(err, sql.ErrNoRows) { | ||||||
log.Printf("getSettings.getMetaValueShowAdminLink: %s", err) | ||||||
w.WriteHeader(http.StatusInternalServerError) | ||||||
return | ||||||
} | ||||||
|
||||||
showAdminLinkEnabled := false | ||||||
if showAdminLinkStr != "" { | ||||||
showAdminLinkEnabled, err = strconv.ParseBool(showAdminLinkStr) | ||||||
if err != nil { | ||||||
log.Printf("getSettings.ParseBoolShowAdminLink: %s", err) | ||||||
w.WriteHeader(http.StatusInternalServerError) | ||||||
return | ||||||
} | ||||||
} | ||||||
Comment on lines
+15426
to
+15441
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we drop all of this and use
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related: #16 (comment) |
||||||
|
||||||
configFileEnabledStr, err := getMetaValue(tx, "configFileEnabled") | ||||||
if err != nil && !errors.Is(err, sql.ErrNoRows) { | ||||||
log.Printf("getSettings.getMetaValueConfigFileEnabled: %s", err) | ||||||
|
@@ -15644,14 +15675,35 @@ func getSettings(w http.ResponseWriter, r *http.Request) { | |||||
<button | ||||||
type="button" | ||||||
class="cancel-button" | ||||||
onclick="document.querySelector('#domain').disabled = true;" | ||||||
> | ||||||
onclick="document.querySelector('#domain').disabled = true;"> | ||||||
Comment on lines
-15647
to
+15678
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like an unintentional diff |
||||||
Cancel | ||||||
</button> | ||||||
</div> | ||||||
{{end}} | ||||||
</form> | ||||||
|
||||||
|
||||||
<form id="showAdminLinkSetting" hx-post="" autocomplete="off" hx-swap="none"> | ||||||
<label for="general"> | ||||||
General | ||||||
</label> | ||||||
<div class="checkbox-group"> | ||||||
<label> | ||||||
<input | ||||||
Comment on lines
+15690
to
+15692
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation is a bit off in this region |
||||||
name="showAdminLink" | ||||||
type="checkbox" | ||||||
{{if .ShowAdminLink}} | ||||||
checked | ||||||
{{end}} | ||||||
hx-trigger="change from:body" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might be missing something, why do we need this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see. Is it to include the input value in request? Maybe you wanted to say:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep things consistent and kebab-case |
||||||
hx-post="/admin/settings" | ||||||
/> | ||||||
Show 'Manage this page'-link on Status Page | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe "Show manage link on status page" would be neater |
||||||
</label> | ||||||
|
||||||
</div> | ||||||
</form> | ||||||
|
||||||
<div class="settings-users-header"> | ||||||
<h3>Users</h3> | ||||||
</div> | ||||||
|
@@ -16029,6 +16081,7 @@ func getSettings(w http.ResponseWriter, r *http.Request) { | |||||
GitHubConfigSHA string | ||||||
GitHubCommitLink string | ||||||
GitHubConfigErrors []string | ||||||
ShowAdminLink bool | ||||||
Ctx pageCtx | ||||||
}{ | ||||||
CurrentVersion: VERSION, | ||||||
|
@@ -16043,6 +16096,7 @@ func getSettings(w http.ResponseWriter, r *http.Request) { | |||||
GitHubCommitLink: githubRepoURL + "/blob/" + githubConfigBranch + "/" + | ||||||
githubConfigPath, | ||||||
GitHubConfigErrors: githubConfigErrors, | ||||||
ShowAdminLink: showAdminLinkEnabled, | ||||||
Ctx: getPageCtx(r), | ||||||
}, | ||||||
) | ||||||
|
@@ -16056,6 +16110,32 @@ func getSettings(w http.ResponseWriter, r *http.Request) { | |||||
func postSettings(w http.ResponseWriter, r *http.Request) { | ||||||
name := r.PostFormValue("name") | ||||||
domain := strings.ToLower(r.PostFormValue("domain")) | ||||||
showAdminLink := r.PostFormValue("showAdminLink") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think all other form params are kebab-case, so I think we should go for On the other hand, |
||||||
|
||||||
isShowAdminLinkEnabled := strings.ToLower(strings.TrimSpace(showAdminLink)) == "on" | ||||||
|
||||||
tx, err := rwDB.Begin() | ||||||
if err != nil { | ||||||
log.Printf("postSettings.BeginShowAdminLink: %s", err) | ||||||
w.WriteHeader(http.StatusInternalServerError) | ||||||
return | ||||||
} | ||||||
defer tx.Rollback() | ||||||
|
||||||
err = updateMetaValue(tx, "showAdminLink", strconv.FormatBool(isShowAdminLinkEnabled)) | ||||||
if err != nil { | ||||||
log.Printf("postSettings.updateMetaValueShowAdminLink: %s", err) | ||||||
w.WriteHeader(http.StatusInternalServerError) | ||||||
return | ||||||
} | ||||||
|
||||||
if err := tx.Commit(); err != nil { | ||||||
log.Printf("postSettings.CommitShowAdminLink: %s", err) | ||||||
w.WriteHeader(http.StatusInternalServerError) | ||||||
return | ||||||
} | ||||||
|
||||||
metaShowAdminLink = isShowAdminLinkEnabled | ||||||
Comment on lines
+16113
to
+16138
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently this end up wiping out Steps to reproduce:
Could we only run these bits when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bug.mp4 |
||||||
|
||||||
if name != "" { | ||||||
if metaConfigFileEnabled { | ||||||
|
@@ -17315,6 +17395,7 @@ func getConfigSettings(w http.ResponseWriter, r *http.Request) { | |||||
GitHubToken string | ||||||
GitHubWebhookSecret string | ||||||
Domain string | ||||||
ShowAdminLink bool | ||||||
Ctx pageCtx | ||||||
}{ | ||||||
ConfigFile: configFile, | ||||||
|
@@ -17325,6 +17406,7 @@ func getConfigSettings(w http.ResponseWriter, r *http.Request) { | |||||
GitHubToken: githubToken, | ||||||
GitHubWebhookSecret: githubWebhookSecret, | ||||||
Domain: metaDomain, | ||||||
ShowAdminLink: metaShowAdminLink, | ||||||
Ctx: getPageCtx(r), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we want this here, this is |
||||||
}) | ||||||
if err != nil { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't need this globally, it's not as ubiquitous as something like
metaName
. I don't really mind right though now as there's not too many of these variables at the moment. I'll let you decide.If you change this you should ignore my other feedback on dropping the reading & parsing in
getSettings
, it will be necessary.