Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

addvanced
Copy link

No description provided.

@addvanced addvanced force-pushed the feature/optional-login-link branch from b6aad4b to f599c87 Compare June 25, 2024 18:39
Copy link
Owner

@goksan goksan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

I've left some comments, let me know if you have any questions about any of the feedback, and whether you're up for making the changes.

Comment on lines +16113 to +16138
showAdminLink := r.PostFormValue("showAdminLink")

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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently this end up wiping out showAdminLink if you do any other action that hits postSettings.

Steps to reproduce:

  • Check the manage this page option
  • Rename your Statusnook instance
  • Refresh the page, you'll see the box is unchecked

Could we only run these bits when showAdminLink is present to solve this?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug.mp4

@@ -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")
Copy link
Owner

Choose a reason for hiding this comment

The 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 show-admin-link.

On the other hand, meta.name values in the DB are camelCase 🙃

Comment on lines +3559 to +3570
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
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're going to need to handle the absence of showAdminLink in the DB, currently this would fail on ParseBool. I'm assuming you may have tested with a value manually entered into the DB, but let me know if I missed something.

Maybe we could do one of the following:

  • Create a migration to add showAdminLink
  • I think my preferred option would be - fallback to a default value when we see sql.ErrNoRows (my vote would be true)

Let me know if I missed anything

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to add configuration for showAdminLink via the text-based config?

Comment on lines +15426 to +15441
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
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we drop all of this and use metaShowAdminLink, we're assigning it in main?

metaShowAdminLink onlys change in postSetttings and you're updating it after a successful transaction so it should always be consistent with the DB.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related: #16 (comment)

{{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>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we've got a double indent here

Suggested change
<a class="index-link index-link--secondary" href="/login" hx-boost="true">Manage this page</a>
<a class="index-link index-link--secondary" href="/login" hx-boost="true">Manage this page</a>

@@ -827,6 +827,7 @@ var cancelAppCtx context.CancelFunc
var rwDB *sql.DB
var metaSetup string
var metaName string
var metaShowAdminLink bool
Copy link
Owner

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.

{{if .ShowAdminLink}}
checked
{{end}}
hx-trigger="change from:body"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be missing something, why do we need this hx-trigger?

Copy link
Owner

Choose a reason for hiding this comment

The 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
hx-trigger="change from:body"
hx-trigger="change from:#showAdminLinkSetting"

Copy link
Owner

@goksan goksan Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep things consistent and kebab-case show-admin-link-setting

@@ -17325,6 +17406,7 @@ func getConfigSettings(w http.ResponseWriter, r *http.Request) {
GitHubToken: githubToken,
GitHubWebhookSecret: githubWebhookSecret,
Domain: metaDomain,
ShowAdminLink: metaShowAdminLink,
Ctx: getPageCtx(r),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want this here, this is GET admin/settings/config-settings

hx-trigger="change from:body"
hx-post="/admin/settings"
/>
Show 'Manage this page'-link on Status Page
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "Show manage link on status page" would be neater

Comment on lines +15690 to +15692
<div class="checkbox-group">
<label>
<input
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is a bit off in this region

@goksan
Copy link
Owner

goksan commented Sep 6, 2024

Thanks again for the PR.

No plans to include something like this right now.

@goksan goksan closed this Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants