From 9a3860f796225152c0d2f77579a145c984c88d43 Mon Sep 17 00:00:00 2001 From: Amy Gale Ruth Bowersox Date: Sat, 28 Feb 2026 22:58:56 -0700 Subject: [PATCH] import posts at least partially tested, we should do some more work on it - also, a few other bugs have been stomped --- .vscode/launch.json | 8 +++++ communityadmin.go | 7 ++--- conferenceadmin.go | 7 ++++- database/conference.go | 22 ++++++++++++-- database/user.go | 4 ++- setup/database-contents.sql | 2 +- setup/database.sql | 2 +- ui/views/conf_import.jet | 2 +- ui/views/conflist.jet | 58 ++++++++++++++++++++----------------- util/random.go | 28 ++++++++++++++---- 10 files changed, 96 insertions(+), 44 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 79982f5..0189096 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -19,5 +19,13 @@ "program": "${workspaceFolder}", "args": ["-C", "${workspaceFolder}/test.yaml"] }, + { + "name": "Import Test", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${workspaceFolder}", + "args": ["-C", "${workspaceFolder}/test2.yaml"] + }, ] } diff --git a/communityadmin.go b/communityadmin.go index 2f0fde6..875e31d 100644 --- a/communityadmin.go +++ b/communityadmin.go @@ -782,11 +782,10 @@ func CreateCommunity(ctxt ui.AmContext) (string, any) { } var testcomm *database.Community testcomm, err = database.AmGetCommunityByAlias(ctxt.Ctx(), dlg.Field("alias").Value) - if err != nil { - return dlg.RenderError(ctxt, err.Error()) - } - if testcomm != nil { + if err == nil { return dlg.RenderError(ctxt, fmt.Sprintf("A community with the alias \"%s\" already exists; please try again.", testcomm.Alias)) + } else if err != database.ErrNoCommunity { + return dlg.RenderError(ctxt, err.Error()) } var hideDir, hideSearch bool switch dlg.Field("hidemode").Value { diff --git a/conferenceadmin.go b/conferenceadmin.go index ea9e85c..78567b0 100644 --- a/conferenceadmin.go +++ b/conferenceadmin.go @@ -765,6 +765,7 @@ func ConferenceImport(ctxt ui.AmContext) (string, any) { if ctxt.Verb() == "GET" { ctxt.VarMap().Set("confName", conf.Name) + ctxt.VarMap().Set("selfLink", fmt.Sprintf("/comm/%s/conf/%s/import", comm.Alias, ctxt.GetScratch("currentAlias"))) ctxt.SetFrameTitle("Import Messages: " + conf.Name) return "framed", "conf_import.jet" } @@ -784,6 +785,7 @@ func ConferenceImport(ctxt ui.AmContext) (string, any) { default: ctxt.VarMap().Set("errorMessage", "Invalid matching parameter.") ctxt.VarMap().Set("confName", conf.Name) + ctxt.VarMap().Set("selfLink", fmt.Sprintf("/comm/%s/conf/%s/import", comm.Alias, ctxt.GetScratch("currentAlias"))) ctxt.SetFrameTitle("Import Messages: " + conf.Name) return "framed", "conf_import.jet" } @@ -792,6 +794,7 @@ func ConferenceImport(ctxt ui.AmContext) (string, any) { if err != nil { ctxt.VarMap().Set("errorMessage", err.Error()) ctxt.VarMap().Set("confName", conf.Name) + ctxt.VarMap().Set("selfLink", fmt.Sprintf("/comm/%s/conf/%s/import", comm.Alias, ctxt.GetScratch("currentAlias"))) ctxt.SetFrameTitle("Import Messages: " + conf.Name) return "framed", "conf_import.jet" } @@ -799,6 +802,7 @@ func ConferenceImport(ctxt ui.AmContext) (string, any) { if err != nil { ctxt.VarMap().Set("errorMessage", err.Error()) ctxt.VarMap().Set("confName", conf.Name) + ctxt.VarMap().Set("selfLink", fmt.Sprintf("/comm/%s/conf/%s/import", comm.Alias, ctxt.GetScratch("currentAlias"))) ctxt.SetFrameTitle("Import Messages: " + conf.Name) return "framed", "conf_import.jet" } @@ -807,11 +811,12 @@ func ConferenceImport(ctxt ui.AmContext) (string, any) { if err != nil { ctxt.VarMap().Set("errorMessage", err.Error()) ctxt.VarMap().Set("confName", conf.Name) + ctxt.VarMap().Set("selfLink", fmt.Sprintf("/comm/%s/conf/%s/import", comm.Alias, ctxt.GetScratch("currentAlias"))) ctxt.SetFrameTitle("Import Messages: " + conf.Name) return "framed", "conf_import.jet" } - ctxt.VarMap().Set("backLink", "/sysadmin") + ctxt.VarMap().Set("backLink", fmt.Sprintf("/comm/%s/conf/%s/manage", comm.Alias, ctxt.GetScratch("currentAlias"))) ctxt.VarMap().Set("headline", fmt.Sprintf("Processed %d topic(s) and added %d new post(s).", topics, posts)) ctxt.VarMap().Set("scroll", scroll) ctxt.SetFrameTitle("Import Results") diff --git a/database/conference.go b/database/conference.go index 0abd2b0..678bb9e 100644 --- a/database/conference.go +++ b/database/conference.go @@ -568,8 +568,17 @@ func (c *Conference) TouchPost(ctx context.Context, tx *sqlx.Tx, u *User, lastPo // UnreadMessages returns the total number of unread messages in a conference for a user. func (c *Conference) UnreadMessages(ctx context.Context, u *User) (int32, error) { + var count int32 + err := amdb.GetContext(ctx, &count, `SELECT COUNT(*) FROM topics t LEFT JOIN topicsettings s + ON t.topicid = s.topicid AND s.uid = ? WHERE t.confid = ? AND t.archived = 0 AND (s.hidden IS NULL OR s.hidden = 0)`, u.Uid, c.ConfId) + if err != nil { + return -1, err + } + if count == 0 { + return 0, nil + } var rc int32 - err := amdb.GetContext(ctx, &rc, `SELECT SUM(t.top_message - IFNULL(s.last_message,-1)) + err = amdb.GetContext(ctx, &rc, `SELECT SUM(t.top_message - IFNULL(s.last_message,-1)) FROM topics t LEFT JOIN topicsettings s ON t.topicid = s.topicid AND s.uid = ? WHERE t.confid = ? AND t.archived = 0 AND (s.hidden IS NULL OR s.hidden = 0)`, u.Uid, c.ConfId) return rc, err @@ -1284,10 +1293,17 @@ func AmCreateConference(ctx context.Context, comm *Community, name, alias, descr } // Get the current "last" sequence number. - var seq int - if err = tx.GetContext(ctx, &seq, "SELECT MAX(sequence) FROM commtoconf WHERE commid = ?", comm.Id); err != nil { + seq := 0 + count := 0 + if err = tx.GetContext(ctx, &count, "SELECT COUNT(*) FROM commtoconf WHERE commid = ?", comm.Id); err != nil { return nil, err } + if count > 0 { + if err = tx.GetContext(ctx, &seq, "SELECT MAX(sequence) FROM commtoconf WHERE commid = ?", comm.Id); err != nil { + return nil, err + } + } + // else assume we start with a 0 sequence // Link the conference into the community, and set the hide flag. if _, err = tx.ExecContext(ctx, "INSERT INTO commtoconf (commid, confid, sequence, hide_list) VALUES (?, ?, ?, ?)", comm.Id, rc.ConfId, diff --git a/database/user.go b/database/user.go index 5c385cb..1086f39 100644 --- a/database/user.go +++ b/database/user.go @@ -757,9 +757,11 @@ func AmCreateNewUser(ctx context.Context, username string, password string, remi } // Insert the user record. + ecn := util.GenerateRandomConfirmationNumber() + log.Debugf("generated E-mail confirmation number %d", ecn) _, err = tx.ExecContext(ctx, `INSERT INTO users (username, passhash, verify_email, lockout, email_confnum, base_lvl, created, lastaccess, passreminder, description, dob) VALUES (?, ?, 0, 0, ?, ?, NOW(), NOW(), ?, '', ?)`, - username, hashPassword(password), util.GenerateRandomConfirmationNumber(), AmDefaultRole("Global.NewUser").Level(), + username, hashPassword(password), ecn, AmDefaultRole("Global.NewUser").Level(), reminder, dob) if err != nil { return nil, err diff --git a/setup/database-contents.sql b/setup/database-contents.sql index a1d3f9d..4ed66e1 100644 --- a/setup/database-contents.sql +++ b/setup/database-contents.sql @@ -61,7 +61,7 @@ CREATE TABLE users ( verify_email TINYINT DEFAULT 0, lockout TINYINT DEFAULT 0, access_tries SMALLINT DEFAULT 0, - email_confnum MEDIUMINT DEFAULT 0, + email_confnum INT DEFAULT 0, base_lvl SMALLINT UNSIGNED NOT NULL, created DATETIME NOT NULL, lastaccess DATETIME, diff --git a/setup/database.sql b/setup/database.sql index 8b2a3c1..de30439 100644 --- a/setup/database.sql +++ b/setup/database.sql @@ -69,7 +69,7 @@ CREATE TABLE users ( verify_email TINYINT DEFAULT 0, lockout TINYINT DEFAULT 0, access_tries SMALLINT DEFAULT 0, - email_confnum MEDIUMINT DEFAULT 0, + email_confnum INT DEFAULT 0, base_lvl SMALLINT UNSIGNED NOT NULL, created DATETIME NOT NULL, lastaccess DATETIME, diff --git a/ui/views/conf_import.jet b/ui/views/conf_import.jet index 2b11fbf..5c85363 100644 --- a/ui/views/conf_import.jet +++ b/ui/views/conf_import.jet @@ -31,7 +31,7 @@ {{ end }} -
+