From f5d5f755bbe04df0c98a63a28f51440ab0206567 Mon Sep 17 00:00:00 2001 From: Azareal Date: Mon, 25 Sep 2017 01:48:35 +0100 Subject: [PATCH] Added the Update method to *Forum and fixed a bug where forum updates would bypass the forumView cache. Fixed a bug in MemoryForumStore's CacheSet where it requires new entries to exist, even though they don't need to. Fixed a bug where the Reports could be deleted. Fixed a bug in the JS where the inline forum editor stopped working. Fixed a bug in Shadow where the Add Group header was pushed to the side by the previous element's margin. Fixed a bug in the Forum Editor where the Active input's initial value was inverted. --- forum.go | 23 ++++++++++++++++++++-- forum_store.go | 10 ++++++---- panel_routes.go | 35 +++++++-------------------------- public/global.js | 3 ++- templates/panel-forum-edit.html | 4 ++-- templates/panel-forums.html | 4 ++-- themes/shadow/public/main.css | 5 ++--- user.go | 5 ++++- 8 files changed, 46 insertions(+), 43 deletions(-) diff --git a/forum.go b/forum.go index f697a3b0..a1fdf735 100644 --- a/forum.go +++ b/forum.go @@ -1,8 +1,12 @@ package main //import "fmt" -import "strconv" -import _ "github.com/go-sql-driver/mysql" +import ( + "strconv" + "strings" + + _ "github.com/go-sql-driver/mysql" +) type ForumAdmin struct { ID int @@ -39,6 +43,21 @@ type ForumSimple struct { Preset string } +func (forum *Forum) Update(name string, desc string, active bool, preset string) error { + if name == "" { + name = forum.Name + } + preset = strings.TrimSpace(preset) + _, err := updateForumStmt.Exec(name, desc, active, preset, forum.ID) + if err != nil { + return err + } + if forum.Preset != preset || preset == "custom" || preset == "" { + permmapToQuery(presetToPermmap(preset), forum.ID) + } + _ = fstore.Reload(forum.ID) +} + // TODO: Replace this sorting mechanism with something a lot more efficient // ? - Use sort.Slice instead? type SortForum []*Forum diff --git a/forum_store.go b/forum_store.go index 6a36bcd5..73abbf68 100644 --- a/forum_store.go +++ b/forum_store.go @@ -8,6 +8,7 @@ package main import ( "database/sql" + "errors" "log" "sort" "sync" @@ -28,7 +29,7 @@ type ForumStore interface { Get(id int) (*Forum, error) GetCopy(id int) (Forum, error) BypassGet(id int) (*Forum, error) - Reload(id int) error // ? - Should we move this to TopicCache? Might require us to do a lot more casting in Gosora though... + Reload(id int) error // ? - Should we move this to ForumCache? It might require us to do some unnecessary casting though //Update(Forum) error Delete(id int) error IncrementTopicCount(id int) error @@ -216,9 +217,6 @@ func (mfs *MemoryForumStore) Reload(id int) error { } func (mfs *MemoryForumStore) CacheSet(forum *Forum) error { - if !mfs.Exists(forum.ID) { - return ErrNoRows - } mfs.forums.Store(forum.ID, forum) mfs.rebuildView() return nil @@ -278,7 +276,11 @@ func (mfs *MemoryForumStore) CacheDelete(id int) { mfs.rebuildView() } +// TODO: Add a hook to allow plugin_socialgroups to detect when one of it's forums has just been deleted? func (mfs *MemoryForumStore) Delete(id int) error { + if id == 1 { + return errors.New("You cannot delete the Reports forum") + } forumUpdateMutex.Lock() defer forumUpdateMutex.Unlock() _, err := mfs.delete.Exec(id) diff --git a/panel_routes.go b/panel_routes.go index 4f26c602..9e2edac7 100644 --- a/panel_routes.go +++ b/panel_routes.go @@ -417,11 +417,6 @@ func routePanelForumsEditSubmit(w http.ResponseWriter, r *http.Request, user Use return } - forumName := r.PostFormValue("forum_name") - forumDesc := r.PostFormValue("forum_desc") - forumPreset := stripInvalidPreset(r.PostFormValue("forum_preset")) - forumActive := r.PostFormValue("forum_active") - forum, err := fstore.Get(fid) if err == ErrNoRows { LocalErrorJSQ("The forum you're trying to edit doesn't exist.", w, r, user, isJs) @@ -431,40 +426,23 @@ func routePanelForumsEditSubmit(w http.ResponseWriter, r *http.Request, user Use return } - if forumName == "" { - forumName = forum.Name - } + forumName := r.PostFormValue("forum_name") + forumDesc := r.PostFormValue("forum_desc") + forumPreset := stripInvalidPreset(r.PostFormValue("forum_preset")) + forumActive := r.PostFormValue("forum_active") - var active bool + var active = false if forumActive == "" { active = forum.Active } else if forumActive == "1" || forumActive == "Show" { active = true - } else { - active = false } - forumUpdateMutex.Lock() - _, err = updateForumStmt.Exec(forumName, forumDesc, active, forumPreset, fid) + err = forum.Update(forumName, forumDesc, active, forumPreset) if err != nil { InternalErrorJSQ(err, w, r, isJs) return } - if forum.Name != forumName { - forum.Name = forumName - } - if forum.Desc != forumDesc { - forum.Desc = forumDesc - } - if forum.Active != active { - forum.Active = active - } - if forum.Preset != forumPreset { - forum.Preset = forumPreset - } - forumUpdateMutex.Unlock() - - permmapToQuery(presetToPermmap(forumPreset), fid) if !isJs { http.Redirect(w, r, "/panel/forums/", http.StatusSeeOther) @@ -473,6 +451,7 @@ func routePanelForumsEditSubmit(w http.ResponseWriter, r *http.Request, user Use } } +// ! This probably misses the forumView cache func routePanelForumsEditPermsSubmit(w http.ResponseWriter, r *http.Request, user User, sfid string) { _, ok := SimplePanelUserCheck(w, r, &user) if !ok { diff --git a/public/global.js b/public/global.js index a32e7ebc..96deddb6 100644 --- a/public/global.js +++ b/public/global.js @@ -305,11 +305,12 @@ $(document).ready(function(){ //console.log("Field Type",field_type) //console.log("Field Value '" + field_value + "'") for (var i = 0; i < itLen; i++) { + var sel = ""; if(field_value == i || field_value == it[i]) { sel = "selected "; this.classList.remove(field_name + '_' + it[i]); this.innerHTML = ""; - } else sel = ""; + } out += ""; } this.innerHTML = ""; diff --git a/templates/panel-forum-edit.html b/templates/panel-forum-edit.html index 6bc08d11..9eb78459 100644 --- a/templates/panel-forum-edit.html +++ b/templates/panel-forum-edit.html @@ -21,8 +21,8 @@ var form_vars = {'perm_preset': ['can_moderate','can_post','read_only','no_acces
diff --git a/templates/panel-forums.html b/templates/panel-forums.html index 6085e9cb..ab1859f5 100644 --- a/templates/panel-forums.html +++ b/templates/panel-forums.html @@ -39,7 +39,7 @@
@@ -49,7 +49,7 @@
diff --git a/themes/shadow/public/main.css b/themes/shadow/public/main.css index 0faf6884..beccba17 100644 --- a/themes/shadow/public/main.css +++ b/themes/shadow/public/main.css @@ -393,15 +393,14 @@ textarea.large { /* Mini paginators aka panel paginators */ .pageset { margin-top: 4px; - clear: both; - height: 32px; + display: flex; + flex-direction: row; } .pageitem { background-color: rgb(61,61,61); padding: 10px; margin-right: 4px; font-size: 13px; - float: left; } .rowlist.bgavatars .rowitem { diff --git a/user.go b/user.go index 1a607634..6eab9fce 100644 --- a/user.go +++ b/user.go @@ -107,7 +107,7 @@ func (user *User) RevertGroupUpdate() error { } // TODO: Use a transaction here -// TODO: Add a Deactivate method? +// ? - Add a Deactivate method? Not really needed, if someone's been bad you could do a ban, I guess it might be useful, if someone says that email x isn't actually owned by the user in question? func (user *User) Activate() (err error) { _, err = activateUserStmt.Exec(user.ID) if err != nil { @@ -201,6 +201,7 @@ func (user *User) decreasePostStats(wcount int, topic bool) error { return err } +// TODO: Write unit tests for this func (user *User) initPerms() { if user.TempGroup != 0 { user.Group = user.TempGroup @@ -272,6 +273,7 @@ func SendValidationEmail(username string, email string, token string) bool { return SendEmail(email, subject, msg) } +// TODO: Write units tests for this func wordsToScore(wcount int, topic bool) (score int) { if topic { score = 2 @@ -288,6 +290,7 @@ func wordsToScore(wcount int, topic bool) (score int) { return score } +// TODO: Write unit tests for this func buildProfileURL(slug string, uid int) string { if slug == "" { return "/user/" + strconv.Itoa(uid)