rails: Redmine使用權限設定心得

來源:互聯網
上載者:User

由於最近需要對redmine系統進行外掛程式的開發,難於需要用到許可權管理,也總結了一些設定的心得,與大家分享。如果有不正確的,歡迎指出與交流。


(1)init.rb中project_menu:

只有使用者在該項目中扮演的角色對於該:controller:action具有許可權時才會在項目菜單中顯示(包括題目下方的菜單和配置中的tab菜單等)

其中,permission函數的options參數可以設定這些值:

①:public=>true,表示不設使用權限設定

②:require=>:loggedin和:require=>:member,分別阻止Anonymous和Non member(對應許可權報表中的Anonymous和Non member,若寫上:require=>:member,則在許可權報表中的Anonymous和Non member將不能勾選)

PS:這裡的init.rb指的是外掛程式中根目錄中的init.rb,若要改變父工程的使用權限設定,可以到父工程根目錄/lib/redmine.rb中設定

 

(2)init.rb中account_menu:

可以利用Proc.new {}裡執行邏輯判斷語句

Example:    :if => Proc.new { |p| User.current.logged? }

PS:p是本應用程式,例如可以使用p.project訪問controller中擷取的@project

 

(3)controller中:

①若當前controller只針對一個project:可以在before_filter處設定,步驟為::find_project,:authorize

PS:authorize函數中調用了User.current.allowed_to?函數

②若當前controller針對多個project:需要自行寫一個函數,在函數中顯示地調用User.current.allowed_to?(:permission, @project)進行判斷

PS:User.current.allowed_to?函數中調用了Role.allowed_to?函數

 

(4)html.erb中:

 ①針對#(使用者、項目、許可權)三元組,可以這樣使用:User.current.allowed_to?(:permission, @project)

②針對#(角色、許可權)二元組,可以這樣使用:role.allowed_to?(:permission)

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.