1

我正在尝试使用本文之后的新功能扩展存储库控制器: http ://www.redmine.org/projects/redmine/wiki/Plugin_Internals

一切似乎都正常,但是当我单击调用我的扩展功能的按钮时,我收到此错误:

过滤器链停止为:授权渲染或重定向完成 403 Forbidden in 5ms (ActiveRecord: 2.0ms)

按照我的相关代码。

在 lib/client 中创建的 client.rb

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)

初始化.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

路线.rb

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

在我看来,我调用函数 exec_client 如下所示:

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

如果有人感兴趣,下面是完整的日志错误:

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)

怎么了?

4

2 回答 2

1

我已经解决了这个问题。

正如我所注意到的,问题在于执行该功能的权限。

我刚刚在 init.rb 中添加了权限(参见下面的代码),它使我可以访问执行该函数。

  permission :repositories, :repositories => :exec_client

上面列出的另一个权限(参见 init.rb 代码)是另一个不直接链接到执行功能的权限的东西。那个小细节给了我很大的麻烦。

我希望这对某人有用。关于答案的任何问题,请争论!;)

谢谢!

于 2013-07-24T20:28:07.883 回答
1

在我的补丁上,我输入了以下代码:

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
于 2013-11-12T11:22:52.067 回答