Sha256: 1a920ebd28b06ab0ba6564b3a2d17bf442231888d4c50fd9e4a1685a15fca342
Contents?: true
Size: 1.08 KB
Versions: 13
Compression:
Stored size: 1.08 KB
Contents
module Actions module Middleware class KeepCurrentUser < Dynflow::Middleware def delay(*args) pass(*args).tap { store_current_user } end def plan(*args) with_current_user do pass(*args).tap { store_current_user } end end def run(*args) restore_curent_user { pass(*args) } end def finalize restore_curent_user { pass } end # Run all execution plan lifecycle hooks as the original user def hook(*args) restore_curent_user { pass(*args) } end private def with_current_user if User.current || action.input[:current_user_id].nil? yield else restore_curent_user { yield } end end def store_current_user action.input[:current_user_id] = User.current.try(:id) end def restore_curent_user User.current = User.unscoped.find(action.input[:current_user_id]) if action.input[:current_user_id].present? yield ensure User.current = nil end end end end
Version data entries
13 entries across 13 versions & 1 rubygems