Skip to content

Commit 50ef1c9

Browse files
authored
fix: transient attribute username sent as argument. (#4552)
During queuing of RoleDeletAction, the role_owner object is serialized. In such cases transient attributes such as username will be lost.
1 parent b6a648a commit 50ef1c9

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

app/actions/role_delete.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ class RoleDeleteAction
55
class RoleDeleteError < StandardError
66
end
77

8-
def initialize(user_audit_info, role_owner)
8+
def initialize(user_audit_info, role_owner, role_owner_username)
99
@user_audit_info = user_audit_info
1010
@role_owner = role_owner
11+
@role_owner_username = role_owner_username
1112
end
1213

1314
def delete(roles)
15+
@role_owner.username = @role_owner_username if @role_owner_username.present?
1416
roles.each do |role|
1517
Role.db.transaction do
1618
record_event(role)

app/controllers/v3/roles_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ def destroy
8484
end
8585

8686
role_owner = fetch_role_owner_with_name(role)
87-
delete_action = RoleDeleteAction.new(user_audit_info, role_owner)
87+
# Pass username separately to preserve transient attribute through delayed job serialization
88+
delete_action = RoleDeleteAction.new(user_audit_info, role_owner, role_owner.username)
8889
deletion_job = VCAP::CloudController::Jobs::DeleteActionJob.new(Role, role.guid, delete_action)
8990
pollable_job = Jobs::Enqueuer.new(queue: Jobs::Queues.generic).enqueue_pollable(deletion_job)
9091

spec/unit/actions/role_delete_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module VCAP::CloudController
1212
allow(user_with_role).to receive(:username).and_return('kiwi')
1313
end
1414

15-
subject { RoleDeleteAction.new(user_audit_info, user_with_role) }
15+
subject { RoleDeleteAction.new(user_audit_info, user_with_role, user_with_role.username) }
1616

1717
describe '#delete' do
1818
shared_examples 'deletion' do |opts|

0 commit comments

Comments
 (0)