feat(custom-roles): align chatwoot permissions

This commit is contained in:
2026-06-05 11:14:38 +08:00
parent b5f2a47ef8
commit 8b3b532c65
20 changed files with 681 additions and 226 deletions
+1
View File
@@ -138,6 +138,7 @@ func (r *AccountUserRepo) FindByUserWithAccounts(ctx context.Context, userID uin
var accountUsers []model.AccountUser
err := r.db.WithContext(ctx).
Preload("Account").
Preload("CustomRole").
Where("user_id = ?", userID).
Order("active_at DESC").
Order("id ASC").
+10 -4
View File
@@ -73,7 +73,13 @@ func (r *CustomRoleRepo) Update(ctx context.Context, role *model.CustomRole) err
// Delete soft-deletes a custom role (GORM DeletedAt field).
func (r *CustomRoleRepo) Delete(ctx context.Context, id, accountID uint) error {
return r.db.WithContext(ctx).
Where("id = ? AND account_id = ?", id, accountID).
Delete(&model.CustomRole{}).Error
}
return r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
if err := tx.Model(&model.AccountUser{}).
Where("account_id = ? AND custom_role_id = ?", accountID, id).
Updates(map[string]interface{}{"role": "agent", "custom_role_id": 0}).Error; err != nil {
return err
}
return tx.Where("id = ? AND account_id = ?", id, accountID).
Delete(&model.CustomRole{}).Error
})
}