Module: LogicalAuthz::Helper
- Included in:
- Application
- Defined in:
- app/helpers/logical_authz_helper.rb
Instance Method Summary collapse
- #authorized?(criteria = nil) ⇒ Boolean
- #authorized_menu(*items) {|items| ... } ⇒ Object
- #authorized_url?(options, html_options = nil) ⇒ Boolean
- #button_to_if_authorized(name, options = {}, html_options = {}) ⇒ Object
- #button_to_remote_if_authorized(name, options = {}, html_options = nil) ⇒ Object
- #controller_pairs ⇒ Object
- #criteria_from_url(url, html_options = nil) ⇒ Object
- #groups ⇒ Object
- #laz_debug ⇒ Object
- #link_to_if_authorized(name, options = nil, html_options = nil) ⇒ Object
- #link_to_remote_if_authorized(name, options = {}, html_options = nil) ⇒ Object
-
#nonmembered_groups(user) ⇒ Object
returns an array of group names and ids (suitable for select_tag) for which <user> is not a member.
Instance Method Details
#authorized?(criteria = nil) ⇒ Boolean
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/helpers/logical_authz_helper.rb', line 22 def (criteria=nil) criteria ||= {} laz_debug{"Helper authorizing: #{LogicalAuthz.inspect_criteria(criteria)}"} criteria = { :controller => controller_path, :action => action_name, :id => params[:id] }.merge(criteria) criteria[:params] = criteria.dup unless criteria.has_key?(:group) or criteria.has_key?(:user) controller = case self when ActionView::Base self.controller else self #XXX ??? end criteria[:user] = AuthnFacade.current_user(controller) end result = LogicalAuthz.(criteria) return result end |
#authorized_menu(*items) {|items| ... } ⇒ Object
98 99 100 101 102 |
# File 'app/helpers/logical_authz_helper.rb', line 98 def (*items) yield(items) if items.all? do |item| [*item].last end end |
#authorized_url?(options, html_options = nil) ⇒ Boolean
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/helpers/logical_authz_helper.rb', line 82 def (, = nil) ||= {} params = {} if Hash === params = else params = criteria_from_url() end if params.nil? true #We can't work out where it is, so we have no opinion #XXX: Shouldn't this be false? else (params) end end |
#button_to_if_authorized(name, options = {}, html_options = {}) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/helpers/logical_authz_helper.rb', line 119 def (name, = {}, = {}) url = if((url, )) (name, , ) else if block_given? yield else "" end end end |
#button_to_remote_if_authorized(name, options = {}, html_options = nil) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'app/helpers/logical_authz_helper.rb', line 145 def (name, = {}, = nil) url = [:url] if((url, )) (name, , ) else if block_given? yield else "" end end end |
#controller_pairs ⇒ Object
61 62 63 64 65 |
# File 'app/helpers/logical_authz_helper.rb', line 61 def controller_pairs controllers = ActionController::Routing::possible_controllers controllers -= %w{rails/info application authz rails_info} controllers.map{|c| [c.classify, c]} end |
#criteria_from_url(url, html_options = nil) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/helpers/logical_authz_helper.rb', line 67 def criteria_from_url(url, = nil) return nil if url.nil? uri = URI.parse(url_for(url)) path = uri.path querystring = uri.query http_method = (.nil? ? nil : [:method]) || :get begin params = Rails.application.routes.recognize_path(path, :method => http_method) rescue ActionController::RoutingError => ex Rails.logger.info{"Asked to authorize url: #{.inspect} - couldn't route: #{ex.class.name}: #{ex.}"} return nil end querystring.blank? ? params : params.merge(Rack::Utils.parse_query(querystring).symbolize_keys!) end |
#groups ⇒ Object
55 56 57 58 59 |
# File 'app/helpers/logical_authz_helper.rb', line 55 def groups LogicalAuthz::group_model.all.map do |group| [group.name, group.id ] end end |
#laz_debug ⇒ Object
16 17 18 19 20 |
# File 'app/helpers/logical_authz_helper.rb', line 16 def laz_debug if block_given? LogicalAuthz::laz_debug{yield} end end |
#link_to_if_authorized(name, options = nil, html_options = nil) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'app/helpers/logical_authz_helper.rb', line 104 def (name, = nil, = nil) ||= {} ||= {} url = if((url, )) link_to(name, , ) else if block_given? yield else "" end end end |
#link_to_remote_if_authorized(name, options = {}, html_options = nil) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'app/helpers/logical_authz_helper.rb', line 132 def (name, = {}, = nil) url = [:url] if((url, )) link_to_remote(name, , ) else if block_given? yield else "" end end end |
#nonmembered_groups(user) ⇒ Object
returns an array of group names and ids (suitable for select_tag) for which <user> is not a member
51 52 53 |
# File 'app/helpers/logical_authz_helper.rb', line 51 def nonmembered_groups(user) (LogicalAuthz::group_model.all - user.groups).map { |g| [ g.name, g.id ] } end |