Project

General

Profile

Path a function in a plugin

Added by Luis Serrano Aranda almost 13 years ago

'Im making a plugin based in the last path of the issue http://www.redmine.org/issues/8488, and I have problems patching the method self.visible_condition

I write:

require_dependency 'issue'

module IssuePatch
    def self.included(base)  # :nodoc:
        base.send(:include, InstanceMethods)
        base.class_eval do
            named_scope :visible, lambda {|*args| { :include => [ :project, :watchers], 
                                                                :conditions => Issue.visible_condition(args.shift || User.current, *args)
            }}
           alias_method_chain :self.visible_condition, :patch  # Error
           alias_method_chain :visible?, :patch 
        end
    end

    module InstanceMethods
        # Returns a SQL conditions string used to find all issues visible by the specified user
        def self.visible_condition_with_patch(user, options={})
            Project.allowed_to_condition(user, :view_issues, options) do |role, user|
                case role.issues_visibility
                    when 'all'
                        nil
                    when 'default'
                        user_ids = [user.id] + user.groups.map(&:id)
                        "(#{table_name}.is_private = #{connection.quoted_false} OR #{table_name}.author_id = #{user.id} OR #{Watcher.table_name}.user_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))" 
                    when 'own'
                        user_ids = [user.id] + user.groups.map(&:id)
                        "(#{table_name}.author_id = #{user.id} OR #{Watcher.table_name}.user_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))" 
                    else
                        '1=0'
                end
            end
        end

        def visible_with_patch?(usr=nil)
            (usr || User.current).allowed_to?(:view_issues, self.project) do |role, user|
                case role.issues_visibility
                    when 'all'
                        true
                    when 'default'
                        !self.is_private? || self.author == user || self.watched_by?(user) || user.is_or_belongs_to?(assigned_to) 
                    when 'own'
                         self.author == user || self.watched_by?(user) || user.is_or_belongs_to?(assigned_to) 
                    else
                         false
                end
            end
        end

        # Override the acts_as_watchable default to allow any user with view issues
        # rights to watch/see this issue.
        def addable_watcher_users
            users = self.project.users.sort - self.watcher_users
            users.reject! {|user| !user.allowed_to?(:view_issues, self.project)}
            users
        end
    end
end

And when I migrate the plugin redmine returns a error:

undefined method `visible_condition' for :self:Symbol

Could you helpme ?

thanks in advance