Module: RoleAuthorization::ViewSecurity::InstanceMethods

Defined in:
lib/role_authorization/view_security.rb

Instance Method Summary collapse

Instance Method Details

#button_to_secured(name, options = {}, html_options = nil) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/role_authorization/view_security.rb', line 60

def button_to_secured(name, options = {}, html_options = nil)
  url = url_for(options)

  method = (html_options && html_options.has_key?(:method)) ? html_options[:method] : :post

  if authorized?(url, method)
    return button_to_open(name, url, html_options)
  else
    return ""
  end
end

#form_for_secured(record, options = {}, &proc) ⇒ Object



18
19
20
21
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
# File 'lib/role_authorization/view_security.rb', line 18

def form_for_secured(record, options = {}, &proc)
  url = url_for(options[:url] || record)

  # pretty much taken from form_for to figure out
  # the correct method to use
  object = case record
           when String, Symbol
             nil
           when Array
             record.last
           else
             record
           end
  object = convert_to_model(object)

  method = if options[:html] && options[:html].has_key?(:method)
             options[:html][:method]
           elsif object && object.respond_to?(:persisted?) && object.persisted?
             :put
           else
             :post
           end

  if authorized?(url, method)
    return form_for_open(record, options, &proc)
  else
    return ""
  end
end


72
73
74
75
# File 'lib/role_authorization/view_security.rb', line 72

def link_to_or_show(name, options = {}, html_options = nil)
  lnk = link_to(name, options, html_options)
  lnk.length == 0 ? name : lnk
end


48
49
50
51
52
53
54
55
56
57
58
# File 'lib/role_authorization/view_security.rb', line 48

def link_to_secured(name, options = {}, html_options = nil)
  url = url_for(options)

  method = (html_options && html_options.has_key?(:method)) ? html_options[:method] : :get

  if authorized?(url, method)
    return link_to_open(name, url, html_options)
  else
    return ""
  end
end