feat(custom-roles): align chatwoot permissions
This commit is contained in:
@@ -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").
|
||||
|
||||
@@ -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
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user