File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ module Authenticatable
1010 before_action :authenticate_request!
1111 before_action :set_current_user
1212 before_action :set_current_organization
13+ around_action :set_organization_context
1314 end
1415
1516 private
@@ -132,4 +133,20 @@ def render_forbidden(message = 'Forbidden')
132133 }
133134 } , status : :forbidden
134135 end
136+
137+ def set_organization_context
138+ # Set thread-local variables for OrganizationScoped concern
139+ if current_organization && current_user
140+ Thread . current [ :current_organization_id ] = current_organization . id
141+ Thread . current [ :current_user_id ] = current_user . id
142+ Thread . current [ :current_user_role ] = current_user . role
143+ end
144+
145+ yield
146+ ensure
147+ # Always reset thread-local variables
148+ Thread . current [ :current_organization_id ] = nil
149+ Thread . current [ :current_user_id ] = nil
150+ Thread . current [ :current_user_role ] = nil
151+ end
135152end
You can’t perform that action at this time.
0 commit comments