fixed bug with auto-join communities
This commit is contained in:
@@ -774,20 +774,19 @@ func AmGetCommunityAccessLevel(ctx context.Context, uid int32, commid int32) (ui
|
||||
/* AmAutoJoinCommunities joins the specified user to any communities they're not yet a part of.
|
||||
* Parameters:
|
||||
* ctx - Standard Go context value.
|
||||
* tx - The current transaction to be used for database access.
|
||||
* user - The user to be auto-joined to communities.
|
||||
* Returns:
|
||||
* Standard Go error status.
|
||||
*/
|
||||
func AmAutoJoinCommunities(ctx context.Context, tx *sqlx.Tx, user *User) error {
|
||||
func AmAutoJoinCommunities(ctx context.Context, user *User) error {
|
||||
// get list of current communities
|
||||
var current []int32 = make([]int32, 0)
|
||||
if err := tx.SelectContext(ctx, ¤t, "SELECT commid FROM commmember WHERE uid = ?", user.Uid); err != nil {
|
||||
if err := amdb.SelectContext(ctx, ¤t, "SELECT commid FROM commmember WHERE uid = ?", user.Uid); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// look for candidate communities
|
||||
rows, err := tx.QueryxContext(ctx, `SELECT m.commid, m.locked FROM users u, communities c, commmember m
|
||||
rows, err := amdb.QueryxContext(ctx, `SELECT m.commid, m.locked FROM users u, communities c, commmember m
|
||||
WHERE m.uid = u.uid AND m.commid = c.commid AND u.is_anon = 1 AND c.join_lvl <= ?`, user.BaseLevel)
|
||||
if err == nil {
|
||||
defer rows.Close()
|
||||
@@ -799,7 +798,7 @@ func AmAutoJoinCommunities(ctx context.Context, tx *sqlx.Tx, user *User) error {
|
||||
break
|
||||
}
|
||||
if !slices.Contains(current, cid) {
|
||||
_, err = tx.ExecContext(ctx, "INSERT INTO commmember (commid, uid, granted_lvl, locked) VALUES (?, ?, ?, ?)",
|
||||
_, err = amdb.ExecContext(ctx, "INSERT INTO commmember (commid, uid, granted_lvl, locked) VALUES (?, ?, ?, ?)",
|
||||
cid, user.Uid, grantLevel, lock)
|
||||
if err != nil {
|
||||
break
|
||||
|
||||
+10
-20
@@ -242,13 +242,6 @@ func (u *User) ConfirmEMailAddress(ctx context.Context, confnum int32, remoteIP
|
||||
defer func() {
|
||||
AmStoreAudit(ar)
|
||||
}()
|
||||
success := false
|
||||
tx := amdb.MustBegin()
|
||||
defer func() {
|
||||
if !success {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
log.Debugf("ConfirmEMailAddress for UID %d", u.Uid)
|
||||
u.Mutex.Lock()
|
||||
@@ -262,16 +255,13 @@ func (u *User) ConfirmEMailAddress(ctx context.Context, confnum int32, remoteIP
|
||||
ar = AmNewAudit(AuditVerifyEmailFail, u.Uid, remoteIP, "Invalid confirmation number")
|
||||
return errors.New("confirmation number is incorrect. Please try again")
|
||||
}
|
||||
_, err := tx.ExecContext(ctx, "UPDATE users SET verify_email = 1, base_lvl = ? WHERE uid = ?",
|
||||
_, err := amdb.ExecContext(ctx, "UPDATE users SET verify_email = 1, base_lvl = ? WHERE uid = ?",
|
||||
AmDefaultRole("Global.AfterVerify").Level(), u.Uid)
|
||||
if err == nil {
|
||||
u.VerifyEMail = true
|
||||
u.BaseLevel = AmDefaultRole("Global.AfterVerify").Level()
|
||||
if err = AmAutoJoinCommunities(ctx, tx, u); err == nil {
|
||||
if err = tx.Commit(); err == nil {
|
||||
success = true
|
||||
ar = AmNewAudit(AuditVerifyEmailOK, u.Uid, remoteIP)
|
||||
}
|
||||
if err = AmAutoJoinCommunities(ctx, u); err == nil {
|
||||
ar = AmNewAudit(AuditVerifyEmailOK, u.Uid, remoteIP)
|
||||
}
|
||||
}
|
||||
return err
|
||||
@@ -765,18 +755,18 @@ func AmCreateNewUser(ctx context.Context, username string, password string, remi
|
||||
tx.ExecContext(ctx, "UNLOCK TABLES;")
|
||||
unlock = false
|
||||
|
||||
// auto-join communities
|
||||
if err = AmAutoJoinCommunities(ctx, tx, user); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: copy conference hotlists
|
||||
|
||||
if err = tx.Commit(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
success = true
|
||||
|
||||
// auto-join communities
|
||||
if err = AmAutoJoinCommunities(ctx, user); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: copy conference hotlists
|
||||
|
||||
// operation was a success - add an audit record
|
||||
ar = AmNewAudit(AuditAccountCreated, user.Uid, remoteIP)
|
||||
return user, nil
|
||||
|
||||
Reference in New Issue
Block a user