Redmine: check if the user has a specific privilege -


trying write plug-in need check if user has particular permission . example thinking of this

if (user.current has "view_private_notes" )  end 

check user model. there near exact want:

  # return true if user allowed specified action on specific context   # action can be:   # * parameter-like hash (eg. :controller => 'projects', :action => 'edit')   # * permission symbol (eg. :edit_project)   # context can be:   # * project : returns true if user allowed specified action on project   # * array of projects : returns true if user allowed on every project   # * nil options[:global] set : check if user has @ least 1 role allowed action,   #   or falls non member / anonymous permissions depending if user logged   def allowed_to?(action, context, options={}, &block) 

you can extend existing models plugin , add methods combining existing:

//init.rb

 actiondispatch::callbacks.to_prepare   unless user.included_modules.include?(myplugin::userpatch)     user.send(:include, myplugin::userpatch)   end  end 

//user_patch.rb this:

 def self.included(base)    base.class_eval      unloadable     # need pass context able trigger allowed_to method in old way.    has_right_view_project(project,context)      self.allowed_to?({:controller => context[:controller], :action => context[:action]}, project, :global => true)    end  end 

actually it's easy use existing methods.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -