Model Patch with alias_method_chain not working

Added by Dirk König almost 8 years ago

Hi!

I'am writing an plugin for redmine- the plugin should make it possible to set or remove rights for a role in each project.

My idea was to wrap the User.def allowed_to?(action, project, options={}) instance- method and combine it with the original one. My source-code:


#lib/projectpermissions_user_patch.rb
require_dependency 'user'

module ProjectPermissionsUserPatch
  def self.included(base)
    base.send(:include, InstanceMethods)
    base.class_eval do
      alias_method_chain :allowed_to?, :in_project
    end
  end

  module InstanceMethods
    def allowed_to_with_in_project? (action, project, options={})
       return false
    end
  end
end

User.send(:include, ProjectPermissionsUserPatch)

and

#redmine_projectpermissions/init.rb
require 'redmine'
require 'projectpermissions_user_patch'

Redmine::Plugin.register :redmine_projectpermissions do
  name 'Redmine Projectpermissions plugin'
  author 'Me'
  description 'description'
  version '0.0.1'
end

But it doesn't work- the method self.included(base) is executed. But the allowed_to? is not redirected, its the method from the original User class. What I'am doing wrong?

Thank you in advance,
Dirk