2016-07-12 21 views
-1

免責聲明:我完全新的紅寶石..Ruby on Rails的控制器副本不autorize用戶

我已經複製this controller名稱爲timelog_estimates_controller.rb,改變了類名來創建TimelogEstimatesController不同的路線,但頁面提供我「403禁止」

當我使用原始TimelogController時,它工作得很好。 我想有些事我錯過了。

+0

您發佈的鏈接有誤。 – fabriciofreitag

+0

爲什麼它應該是錯的?我目前正在使用RoR 2.6 – Nikage

+0

你是什麼意思「創建不同的路線」 – engineersmnky

回答

1

Redmine使用聲明性權限。當你創建一個新的控制器時,它和它的動作從權限定義中缺失,因此無法訪問。

要解決您需要將新控制器的相關操作包含到權限定義中的問題。 This is the location in lib/redmine.rb您可能需要修改。複製在這裏爲清楚起見:

map.project_module :time_tracking do |map| 
    map.permission :log_time, {:timelog => [:new, :create]}, :require => :loggedin 
    map.permission :view_time_entries, {:timelog => [:index, :report, :show]}, :read => true 
    map.permission :edit_time_entries, {:timelog => [:edit, :update, :destroy, :bulk_edit, :bulk_update]}, :require => :member 
    map.permission :edit_own_time_entries, {:timelog => [:edit, :update, :destroy,:bulk_edit, :bulk_update]}, :require => :loggedin 
    map.permission :manage_project_activities, {:project_enumerations => [:update, :destroy]}, :require => :member 
    end 

您應該添加類似這樣的東西這個區塊內:

map.permission :view_time_estimates, {:timelog_estimates => [:index, :report, :show]}, :read => true 
    map.permission :edit_time_estimates, {:timelog_estimates => [:edit, :update, :destroy, :bulk_edit, :bulk_update]}, :require => :member 
    map.permission :edit_own_time_estimates, {:timelog_estimates => [:edit, :update, :destroy,:bulk_edit, :bulk_update]}, :require => :loggedin 

授權的作品,通過此調用您的控制器:

before_filter :authorize_global, :only => [:new, :create, :index, :report] 

如果按照authorize_global實施,你會find this

# Authorize the user for the requested action 
    def authorize(ctrl = params[:controller], action = params[:action], global = false) 
    allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global) 
    if allowed 
     true 
    else 
     if @project && @project.archived? 
     render_403 :message => :notice_not_authorized_archived_project 
     else 
     deny_access 
     end 
    end 
    end 

render_403行是您收到錯誤的原因。

+0

對不起,我不明白我在'project_module :time_tracking'? – Nikage

+0

我已經添加了您可能需要的線條。 –

+0

是的,我已經知道了。我發現使用單獨的插件和複製的控制器會更好。除非你的答案符合我的問題,但它是一種硬編碼方式。無論如何,thanx很多! – Nikage