Forums » Development »
How to get group_id of Current User in my_plugin/init.rb
Added by anhkhoa Michel about 10 years ago
Hi every body. This is bug very very big with Me.In my_plugin\view... Code:
<% user = User.find(User.current) >
< @g_ids = user.groups.map &:id >
It is OK. But in Init.rb,user = User.find(User.current)
@g_ids = user.groups.map x%x:id . That false. When I debug. @g_ids = nil. Please help me!!!!
Replies (2)
RE: How to get group_id of Current User in my_plugin/init.rb - Added by Martin Denizet (redmine.org team member) about 10 years ago
Hello Anhkhoa,
init.rb
is called when the app is loaded, not when a user loads a page.
That's why User.current
will default to Anonymous.
Cheers,
RE: How to get group_id of Current User in my_plugin/init.rb - Added by anhkhoa Michel about 10 years ago
Thank you very much. I want to set default view issues with every group. In my_plugin/init.rb. I add code.
Redmine::MenuManager.map :project_menu do |menu|
menu.push :tracker1, { :controller => 'issues', :action => 'index',:query_id=>5 },:param => :project_id,:if => User.current.group_ids==1, :last => true, :caption => 'Query5'
menu.push :tracker1, { :controller => 'issues', :action => 'index',:query_id=>6 },:param => :project_id,:if => User.current.group_ids==2, :last => true, :caption => 'Query6'
end
.But in init.rb I can't get id_group of current User.I think I should override issue_controller to set default view issue. But i can'nt do it. Can you help me? Please!!!!