Question

I'm trying to extend the repository controller with a new function following this article: http://www.redmine.org/projects/redmine/wiki/Plugin_Internals

All seems to work right, but when I click on the button which call my extended function I get this error:

Filter chain halted as :authorize rendered or redirected Completed 403 Forbidden in 5ms (ActiveRecord: 2.0ms)

Following my related codes.

client.rb created in lib/client

require_dependency 'repositories_controller'

module RepositoriesPatch
    def self.included(base)

      base.send(:include, InstanceMethods)
    end

    module InstanceMethods
        def exec_client
          [...]
        end
    end
end

Repository.send(:include, RepositoriesPatch)

init.rb

#encoding: utf-8

require_dependency 'client/client'

Redmine::Plugin.register :gerar_versao_projeto do
  name 'Gerar Versão Projeto'
  [...]

  project_module :repository do
     permission :view_repository, :repository => :exec_client
  end

  Rails.configuration.to_prepare do 
   RepositoriesController.send(:include, RepositoriesPatch)
  end
end

routes.rb

match '/projects/:id/repository', :action => 'exec_client', :controller => 'repositories', :via => :post

In my view I call the function exec_client as listed below:

<%= button_to_function l(:gerar_build_project), remote_function(:action => 'exec_client', :controller => 'repositories')%>

If someone interest, below is the complete log error:

Started POST "/projects/teste1/repository" for 127.0.0.1 at 2013-07-19 16:51:53 -0300
Processing by RepositoriesController#exec_client as JS
  Parameters: {"authenticity_token"=>"9JifnciRmiVCbf5uFWWGmSeePp4m0IM74UR10kGemHA=", "id"=>"teste1"}
  ←[1m←[35m (0.0ms)←[0m  SELECT MAX(`settings`.`updated_on`) AS max_id FROM `settings`
  ←[1m←[36mUser Load (0.0ms)←[0m  ←[1mSELECT `users`.* FROM `users` WHERE `users`.`type` IN ('User', 'AnonymousUser') AND `users`.`id` = 1 AND (us
ers.status = 1) LIMIT 1←[0m
  ←[1m←[35mProject Load (0.0ms)←[0m  SELECT `projects`.* FROM `projects` WHERE `projects`.`identifier` = 'teste1' LIMIT 1
  ←[1m←[36mRepository Load (0.0ms)←[0m  ←[1mSELECT `repositories`.* FROM `repositories` WHERE `repositories`.`project_id` = 1 AND (is_default = 1)
 LIMIT 1←[0m
  ←[1m←[35mEnabledModule Load (0.0ms)←[0m  SELECT name FROM `enabled_modules` WHERE `enabled_modules`.`project_id` = 1
Filter chain halted as :authorize rendered or redirected
Completed 403 Forbidden in 6ms (ActiveRecord: 0.0ms)

What's going wrong?

Was it helpful?

Solution 2

On my patch I put the following code:

module RepositoriesPatch
    def self.included(base)
      base.send(:include, InstanceMethods)
      base.class_eval do
        unloadable
          #THE BEFORE_FILTER IS WHO GIVES THE AUTHORIZATION TO EXECUTE THE FUNCTION
          before_filter :authorize, :except => [:exec_client]
      end
    end
end

OTHER TIPS

I've solved the question.

As I noticed, the problem was with the permission to execute the function.

I just added the permission (see the code below) in the init.rb that gave me access to execute the function.

  permission :repositories, :repositories => :exec_client

The other permission listed above (see in init.rb code) is another thing not directly linked to the permission to execute the function. That little detail gave me in a big trouble.

I hope this can be useful to someone. Any question about the answer, please argue! ;)

Thanks!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top