mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-30 09:56:23 -07:00
Rebuild board if a ban adds a ban message to a post
This commit is contained in:
parent
5ccf90e04a
commit
92fb3bdb1f
3 changed files with 44 additions and 1 deletions
|
@ -15,7 +15,7 @@ const (
|
|||
// selects all columns from DBPREFIXboards
|
||||
selectBoardsBaseSQL = `SELECT
|
||||
DBPREFIXboards.id, section_id, uri, dir, navbar_position, title, subtitle, description,
|
||||
max_file_size, max_threads, default_style, locked, created_at, anonymous_name, force_anonymous,
|
||||
max_file_size, max_threads, default_style, DBPREFIXboards.locked, created_at, anonymous_name, force_anonymous,
|
||||
autosage_after, no_images_after, max_message_length, min_message_length, allow_embeds, redirect_to_thread,
|
||||
require_file, enable_catalog
|
||||
FROM DBPREFIXboards
|
||||
|
|
|
@ -142,6 +142,8 @@ type IPBan struct {
|
|||
RangeEnd string // sql: range_end
|
||||
IssuedAt time.Time // sql: issued_at
|
||||
IPBanBase
|
||||
|
||||
board *Board
|
||||
}
|
||||
|
||||
// Deprecated: Use the RangeStart and RangeEnd fields or gcutil.GetIPRangeSubnet.
|
||||
|
@ -158,6 +160,26 @@ func (ipb *IPBan) IP() (string, error) {
|
|||
return inet.String(), nil
|
||||
}
|
||||
|
||||
func (ipb *IPBan) BannedPostBoard(requestOptions ...*RequestOptions) (*Board, error) {
|
||||
if ipb.board != nil {
|
||||
return ipb.board, nil
|
||||
}
|
||||
if ipb.BannedForPostID == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
opts := setupOptionsWithTimeout(requestOptions...)
|
||||
board, err := getBoardBase(opts,
|
||||
`INNER JOIN DBPREFIXthreads t ON t.board_id = DBPREFIXboards.id INNER JOIN DBPREFIXposts p ON p.thread_id = t.id WHERE p.id = ?`,
|
||||
*ipb.BannedForPostID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ipb.board = board
|
||||
|
||||
return ipb.board, nil
|
||||
}
|
||||
|
||||
// IsBanned returns true if the given IP is banned
|
||||
func (ipb *IPBan) IsBanned(ipStr string) (bool, error) {
|
||||
ipn, err := gcutil.GetIPRangeSubnet(ipb.RangeStart, ipb.RangeEnd)
|
||||
|
|
|
@ -74,6 +74,27 @@ func bansCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.Sta
|
|||
Msg("Unable to set banned message")
|
||||
return "", server.NewServerError("failed to set banned message", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
board, err := ban.BannedPostBoard()
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().
|
||||
Int("postID", *ban.BannedForPostID).
|
||||
Msg("Unable to get board from banned post")
|
||||
return "", server.NewServerError("failed to get board from banned post", http.StatusInternalServerError)
|
||||
}
|
||||
if board == nil {
|
||||
errEv.Caller().
|
||||
Int("postID", *ban.BannedForPostID).
|
||||
Msg("Unable to get board from banned post (ban.BannedPostBoard() returned nil board)")
|
||||
return "", server.NewServerError("failed to get board from banned post", http.StatusInternalServerError)
|
||||
}
|
||||
gcutil.LogStr("rebuildBoard", board.Dir, infoEv, errEv)
|
||||
if err = building.BuildBoards(true, board.ID); err != nil {
|
||||
errEv.Err(err).Caller().
|
||||
Int("postID", *ban.BannedForPostID).
|
||||
Msg("Unable to rebuild board")
|
||||
return "", server.NewServerError("failed to rebuild board", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
infoEv.Msg("Added IP ban")
|
||||
} else if banForm.PostID > 0 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue