stffn / declarative_authorization

An unmaintained authorization plugin for Rails. Please fork to support current versions of Rails
MIT License
1.24k stars 231 forks source link

Feature request: if_true beside if_attribute and if_permitted_to #179

Open nagyt234 opened 11 years ago

nagyt234 commented 11 years ago

It would be a nice feature to have if_true in a #has_permission_on block, to check conditions of dynamic parameters that have to be met for the user to meet the privileges in this block. This would be especially useful on new, where no attributes are known yet.

E.g:

 role :login do
    includes :guest

    # -- Document

    has_permission_on [:documents], :to => [:manage, :view] do
      if_attribute :folder_id => is_in { Folder.get_folder_ids_permitted(
        user, [:root, :admin, :update]) }
    end
    has_permission_on [:documents], :to => :view do
      if_attribute :folder_id => is_in { Folder.get_folder_ids_permitted(
        user, :read) }
    end
    has_permission_on [:documents], :to => :new do
      if_true {Folder.has_roles_anywhere?(user, [:root, :admin, :update]) }
    end
  end
stevehodges commented 10 years ago

It seems that this could solve my use case as well. I figure that I already have access to user, and should thusly be able to access a boolean on said user.

My use case is checking a boolean on the actual user: if_true user.configurable_setting_boolean?

or if_true user.company.configiruable_setting_boolean?

sneakernets commented 10 years ago

If this can be done, It'd make the ability for me to create a new user through rails much easier.