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
Updated by Rostyslav Ruban about 5 years ago
So, I write that code and it work's
require_dependency "timelog_controller" module TimelogControllerPath def self.included(base) # :nodoc: base.send(:include, InstanceMethods) base.class_eval do alias_method :new_without_allowed_to_create, :new alias_method :new, :new_with_allowed_to_create # alias_method :allowed_to_create, :new end end module ClassMethods end module InstanceMethods def new_with_allowed_to_create if !User.current.allowed_to?(:manual_time_edit, @project) render_403 :message =>l(:manual_edit_denied) return end new_without_allowed_to_create end end end TimelogController.send :include, TimelogControllerPath
Updated by Go MAEDA about 5 years ago
- Status changed from New to Closed
Please use forums for questions. Issues are used to report a bug, suggesting a new feature, or submitting a patch. Reading How to request help may be helpful for you.
Actions