Actions
Patch #32635
closedHow to write wrapper for timelog_controlller "create" method in my plugin?
Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Plugin API
Target version:
-
Start date:
Due date:
% Done:
0%
Estimated time:
Description
I write experimental code inside the core timelog_controller and test it.
if @time_entry.project && (!User.current.allowed_to?(:log_time, @time_entry.project)||!User.current.allowed_to?(:manual_time_edit, @time_entry.project)) render_403 :message =>l(:manual_edit_denied) return end
So I want to move that logic for my plugin.
How can I check user permission for the project before called "create" method?
I tried to extend my method - I create controller file with the same name inside my plugin/app/controllers folder.
module TimelogControllerPath def self.included(base) # :nodoc: base.send(:include, InstanceMethods) base.class_eval do alias_method_chain :create, :allowed_to_create end end module InstanceMethods # Adds a rates tab to the user administration page def allowed_to_create p "Test" end end end
And add this code to init.rb of my plugin, but have "uninitialized constant TimelogControllerPath" error.
Rails.application.config.to_prepare do TimelogController.send(:include, TimelogControllerPath) end
Actions