Fixed a bug where forums inheriting from the group didn't appear on the forum list and the topic list.

Cleaned up the logic in preRoute slightly.
Reordered the logic in preRoute so that the CSP is set for the PreError too.
Clear a user's cached data when their IP changes.
Hide the comment header when there aren't any comments.
This commit is contained in:
Azareal 2018-11-29 17:27:17 +10:00
parent 2e1916f3c9
commit 27fb79d4d5
7 changed files with 50 additions and 40 deletions

View File

@ -90,10 +90,13 @@ func (fps *MemoryForumPermsStore) Reload(fid int) error {
return err
}
DebugLog("gid: ", gid)
DebugLogf("perms: %+v\n", perms)
pperms, err := fps.parseForumPerm(perms)
if err != nil {
return err
}
DebugLogf("pperms: %+v\n", pperms)
forumPerms[gid] = pperms
}
DebugLogf("forumPerms: %+v\n", forumPerms)
@ -139,6 +142,9 @@ func (fps *MemoryForumPermsStore) Reload(fid int) error {
}
forumPerm, ok = forumPerms[group.ID]
if !ok {
if group.Perms.ViewTopic {
group.CanSee = append(group.CanSee, fid)
}
continue
}

View File

@ -14,6 +14,7 @@ import (
// TODO: Preload Trumboyg on Cosora on the forum list
type Header struct {
Title string
//Title []byte // Experimenting with []byte for increased efficiency, let's avoid converting too many things to []byte, as it involves a lot of extra boilerplate
NoticeList []string
Scripts []string
//Preload []string
@ -30,6 +31,7 @@ type Header struct {
Path string
MetaDesc string
StartedAt time.Time
Elapsed1 string
Writer http.ResponseWriter
ExtData ExtData
}
@ -350,6 +352,7 @@ type PanelEditGroupPage struct {
type GroupForumPermPreset struct {
Group *Group
Preset string
DefaultPreset bool
}
type PanelEditForumPage struct {

View File

@ -234,6 +234,12 @@ func preRoute(w http.ResponseWriter, r *http.Request) (User, bool) {
*usercpy = *userptr
usercpy.Init() // TODO: Can we reduce the amount of work we do here?
// TODO: Add a config setting to disable this header
// TODO: Have this header cover more things
if Site.EnableSsl {
w.Header().Set("Content-Security-Policy", "upgrade-insecure-requests")
}
// TODO: WIP. Refactor this to eliminate the unnecessary query
// TODO: Better take proxies into consideration
host, _, err := net.SplitHostPort(r.RemoteAddr)
@ -253,23 +259,14 @@ func preRoute(w http.ResponseWriter, r *http.Request) (User, bool) {
}
}
// TODO: Add a config setting to disable this header
// TODO: Have this header cover more things
if Site.EnableSsl {
w.Header().Set("Content-Security-Policy", "upgrade-insecure-requests")
}
if userptr == &GuestUser {
usercpy.LastIP = host
return *usercpy, true
}
if host != usercpy.LastIP {
if usercpy.Loggedin && host != usercpy.LastIP {
err = usercpy.UpdateIP(host)
if err != nil {
InternalError(err, w, r)
return *usercpy, false
}
usercpy.LastIP = host
}
return *usercpy, true

View File

@ -333,6 +333,10 @@ func (user *User) ChangeGroup(group int) (err error) {
// ! Only updates the database not the *User for safety reasons
func (user *User) UpdateIP(host string) error {
_, err := userStmts.updateLastIP.Exec(host, user.ID)
ucache := Users.GetCache()
if ucache != nil {
ucache.Remove(user.ID)
}
return err
}
@ -429,6 +433,9 @@ func (user *User) InitPerms() {
user.Perms = group.Perms
user.PluginPerms = group.PluginPerms
}
/*if len(group.CanSee) == 0 {
panic("should not be zero")
}*/
user.IsAdmin = user.IsSuperAdmin || group.IsAdmin
user.IsSuperMod = user.IsAdmin || group.IsMod

View File

@ -50,7 +50,6 @@ type Guild struct {
type Page struct {
Title string
CurrentUser common.User
Header *common.Header
ItemList []*common.TopicsRow
Forum *common.Forum
@ -62,14 +61,12 @@ type Page struct {
// ListPage is a page struct for constructing a list of every guild
type ListPage struct {
Title string
CurrentUser common.User
Header *common.Header
GuildList []*Guild
}
type MemberListPage struct {
Title string
CurrentUser common.User
Header *common.Header
ItemList []Member
Guild *Guild
@ -386,7 +383,7 @@ func PreRenderViewForum(w http.ResponseWriter, r *http.Request, user *common.Use
if guildData, ok := pi.Header.ExtData.Items["guilds_current_group"]; ok {
guildItem := guildData.(*Guild)
guildpi := Page{pi.Title, pi.CurrentUser, pi.Header, pi.ItemList, pi.Forum, guildItem, pi.Page, pi.LastPage}
guildpi := Page{pi.Title, pi.Header, pi.ItemList, pi.Forum, guildItem, pi.Page, pi.LastPage}
err := common.Templates.ExecuteTemplate(w, "guilds_view_guild.html", guildpi)
if err != nil {
common.LogError(err)

View File

@ -124,7 +124,6 @@ func ForumsDeleteSubmit(w http.ResponseWriter, r *http.Request, user common.User
if err != nil {
return common.LocalError("The provided Forum ID is not a valid number.", w, r, user)
}
err = common.Forums.Delete(fid)
if err == sql.ErrNoRows {
return common.LocalError("The forum you're trying to delete doesn't exist.", w, r, user)
@ -176,7 +175,8 @@ func ForumsEdit(w http.ResponseWriter, r *http.Request, user common.User, sfid s
} else if err != nil {
return common.InternalError(err, w, r)
}
gplist = append(gplist, common.GroupForumPermPreset{group, common.ForumPermsToGroupForumPreset(forumPerms)})
preset := common.ForumPermsToGroupForumPreset(forumPerms)
gplist = append(gplist, common.GroupForumPermPreset{group, preset, preset == "default"})
}
if r.FormValue("updated") == "1" {

View File

@ -71,10 +71,10 @@
<input name="ban-duration-months" type="number" value="0" min="0" />
</div>
</div>
<!--<div class="formrow">
{{/**<!--<div class="formrow">
<div class="formitem formlabel"><a>{{lang "profile_ban_user_reason"}}</a></div>
<div class="formitem"><textarea name="ban-reason" placeholder="A really horrible person" required></textarea></div>
</div>-->
</div>-->**/}}
<div class="formrow">
<div class="formitem"><button name="ban-button" class="formbutton form_middle_button">{{lang "profile_ban_user_button"}}</button></div>
</div>
@ -82,9 +82,9 @@
</form>
{{end}}
<div id="profile_comments_head" class="colstack_item colstack_head hash_hide">
{{if .ItemList}}<div id="profile_comments_head" class="colstack_item colstack_head hash_hide">
<div class="rowitem"><h1><a>{{lang "profile_comments_head"}}</a></h1></div>
</div>
</div>{{end}}
<div id="profile_comments" class="colstack_item hash_hide">{{template "profile_comments_row.html" . }}</div>
{{if .CurrentUser.Loggedin}}