Module: AeUsers::ControllerExtensions::RequirePermission::ClassMethods
- Defined in:
- lib/ae_users.rb
Instance Method Summary collapse
- #require_class_permission(perm_name, conditions = {}) ⇒ Object
- #require_login(conditions = {}) ⇒ Object
- #require_permission(perm_name, conditions = {}) ⇒ Object
- #rest_edit_permissions(options = {}) ⇒ Object
- #rest_permissions(options = {}) ⇒ Object
- #rest_view_permissions(options = {}) ⇒ Object
Instance Method Details
#require_class_permission(perm_name, conditions = {}) ⇒ Object
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
# File 'lib/ae_users.rb', line 502 def (perm_name, conditions = {}) delegated = false if conditions[:class_name] cn = conditions[:class_name] delegated = true elsif conditions[:class_param] cpn = conditions[:class_param] end before_filter conditions do |controller| if cn.nil? and cpn cn = controller.params[cpn] delegated = true end controller_cn = controller.class.name.gsub(/Controller$/, "").singularize cn ||= controller_cn full_perm_name = "#{perm_name}_#{cn.tableize}" if delegated msg = "Sorry, but you are not permitted to #{perm_name} #{controller_cn.tableize.humanize.downcase} in this #{cn.tableize.humanize.singularize.downcase}." else msg = "Sorry, but you are not permitted to #{perm_name} #{cn.tableize.humanize.downcase}." end controller.(nil, full_perm_name, msg) end end |
#require_login(conditions = {}) ⇒ Object
491 492 493 494 495 496 497 498 499 500 |
# File 'lib/ae_users.rb', line 491 def require_login(conditions = {}) before_filter conditions do |controller| if not controller.logged_in? controller.attempt_login_from_params if not controller.logged_in? controller.access_denied "Sorry, but you need to be logged in to view that page." end end end end |
#require_permission(perm_name, conditions = {}) ⇒ Object
527 528 529 530 531 532 533 534 535 536 537 538 539 |
# File 'lib/ae_users.rb', line 527 def (perm_name, conditions = {}) if conditions[:class_name] cn = conditions[:class_name] end id_param = conditions[:id_param] || :id before_filter conditions do |controller| cn ||= controller.class.name.gsub(/Controller$/, "").singularize o = eval(cn).find(controller.params[id_param]) if not o.nil? controller.(o, perm_name, "Sorry, but you are not permitted to #{perm_name} this #{cn.tableize.singularize.humanize.downcase}.") end end end |
#rest_edit_permissions(options = {}) ⇒ Object
541 542 543 544 545 546 547 548 549 550 551 552 |
# File 'lib/ae_users.rb', line 541 def ( = {}) = { :restrict_create => false, }.update() restrict_create = [:restrict_create] .delete(:restrict_create) ("edit", { :only => [:edit, :update] }.update()) if restrict_create ("create", { :only => [:new, :create] }.update()) end ("destroy", { :only => [:destroy] }.update()) end |
#rest_permissions(options = {}) ⇒ Object
568 569 570 571 |
# File 'lib/ae_users.rb', line 568 def ( = {}) () () end |
#rest_view_permissions(options = {}) ⇒ Object
554 555 556 557 558 559 560 561 562 563 564 565 566 |
# File 'lib/ae_users.rb', line 554 def ( = {}) = { :restrict_list => false, }.update() restrict_list = [:restrict_list] .delete(:restrict_list) if restrict_list ("list", { :only => [:index] }.update()) elsif [:class_name] ("show", { :only => [:index], :id_param => "#{[:class_name].tableize}_id" }.update()) end ("show", { :only => [:show] }.update()) end |