Project

General

Profile

Custom Plugin with Permission

Added by Fernando Paiva about 8 years ago

Hi,

I created a plugin named "Dashboard" that creates a link in top bar. How do I show/hide the link according the user permission?

init.rb:

Redmine::Plugin.register :dashboard do
  name 'Dashboard'
  author 'Fernando Paiva'
  description 'Dashboard IT Projects'
  version '1.0.0.0'

  permission :view_dashboard, :dashboard => :index

  menu :top_menu, 
       :Dashboard, {:controller => 'dashboard', :action => 'index'}, 
       :caption => 'Dashboard', 
       :if =>  Proc.new { User.current.logged? &&
                         (User.current.allowed_to?(:view_dashboard, nil, :global => true) || User.current.admin?)
                        }

end

More prints attached.

Thanks!
Fernando


Replies (1)

RE: Custom Plugin with Permission - Added by Ruby Monk over 3 years ago

you need to specify either a project that belongs to the user or an array of projects

menu :top_menu,
       :Dashboard, { :controller => 'dashboard', action: 'index' },
       caption: 'your_locale_dashboard,
       :if =>  Proc.new { User.current.logged? && (User.current.allowed_to?(:view_labor_calendars, User.current.projects.to_a) || User.current.admin?)
       }
    (1-1/1)