1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-27 11:26:22 -07:00

Fix manage router group not showing login page

This commit is contained in:
Eggbertx 2024-08-30 21:54:51 -07:00
parent 930250c694
commit 641d46d822
4 changed files with 8 additions and 70 deletions

View file

@ -139,26 +139,6 @@ declare global {
fingerprint?: string;
}
/**
* An object representing the settings for fingerprinting images and if enabled,
* video thumbnails
*/
interface FingerprintingOptions {
/**
* If true, allow fingerprinting of video thumbnails
*/
fingerprintVideoThumbs: boolean;
/**
* A list of file extensions for images that gochan is presumed to be able to
* thumbnail
*/
imageExtensions: string[];
/**
* A list of file extensions for videos
*/
videoExtensions: string[];
}
/**
* An object representing a staff member retreived by requesting /manage/staffinfo
*/
@ -175,10 +155,10 @@ declare global {
* 3 = administrator.
*/
rank: number;
/**
* A list of pages that the logged in user has access to
*/
actions?: StaffAction[]
fingerprinting?: FingerprintingOptions;
}
/**

View file

@ -61,24 +61,6 @@ type Action struct {
var actions []Action
// returns the action by its ID, or nil if it doesn't exist
func getAction(id string, rank int) *Action {
var action *Action
for a := range actions {
if actions[a].ID == id {
action = &actions[a]
break
}
}
if action == nil {
return nil
}
if rank == NoPerms && action.Permissions > NoPerms {
return &loginAction
}
return action
}
func RegisterManagePage(id string, title string, permissions int, jsonOutput int, callback CallbackFunction) {
action := Action{
ID: id,

View file

@ -10,20 +10,10 @@ import (
"github.com/gochan-org/gochan/pkg/gcsql"
"github.com/gochan-org/gochan/pkg/gctemplates"
"github.com/gochan-org/gochan/pkg/gcutil"
"github.com/gochan-org/gochan/pkg/posting/uploads"
"github.com/gochan-org/gochan/pkg/server/serverutil"
"github.com/rs/zerolog"
)
var (
loginAction = Action{
ID: "login",
Title: "Login",
Permissions: NoPerms,
Callback: loginCallback,
}
)
func loginCallback(writer http.ResponseWriter, request *http.Request, staff *gcsql.Staff, _ bool, _, errEv *zerolog.Event) (output interface{}, err error) {
systemCritical := config.GetSystemCriticalConfig()
if staff.Rank > 0 {
@ -63,17 +53,10 @@ func loginCallback(writer http.ResponseWriter, request *http.Request, staff *gcs
return
}
type fingerprintingOptions struct {
FingerprintVideoThumbs bool `json:"fingerprintVideoThumbs"`
ImageExtensions []string `json:"imageExtensions,omitempty"`
VideoExtensions []string `json:"videoExtensions,omitempty"`
}
type staffInfoJSON struct {
Username string `json:"username"`
Rank int `json:"rank"`
Actions []Action `json:"actions,omitempty"`
Fingerprinting *fingerprintingOptions `json:"fingerprinting,omitempty"`
Username string `json:"username"`
Rank int `json:"rank"`
Actions []Action `json:"actions,omitempty"`
}
func staffInfoCallback(_ http.ResponseWriter, _ *http.Request, staff *gcsql.Staff, _ bool, _ *zerolog.Event, _ *zerolog.Event) (output interface{}, err error) {
@ -84,16 +67,10 @@ func staffInfoCallback(_ http.ResponseWriter, _ *http.Request, staff *gcsql.Staf
if staff.Rank >= JanitorPerms {
info.Actions = getAvailableActions(staff.Rank, false)
}
if staff.Rank >= ModPerms {
info.Fingerprinting = &fingerprintingOptions{
FingerprintVideoThumbs: config.GetSiteConfig().FingerprintVideoThumbnails,
ImageExtensions: uploads.ImageExtensions,
VideoExtensions: uploads.VideoExtensions,
}
}
return info, nil
}
func registerNoPermPages() {
RegisterManagePage("staffinfo", "", NoPerms, AlwaysJSON, staffInfoCallback)
RegisterManagePage("login", "Login", NoPerms, NoJSON, loginCallback)
}

View file

@ -65,8 +65,7 @@ func setupManageFunction(action *Action) bunrouter.HandlerFunc {
if staff.Username == "" && action.Permissions > NoPerms {
// action with permissions requested and user is not logged in, have them go to login page
actionCB = loginCallback
}
if staff.Rank < action.Permissions {
} else if staff.Rank < action.Permissions {
writer.WriteHeader(http.StatusForbidden)
gcutil.LogWarning().
Str("ip", gcutil.GetRealIP(request)).