15
16
17
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/generators/vigilante/install/install_generator.rb', line 15
def adapt_application_controller
inject_into_file "app/controllers/application_controller.rb", :after => "class ApplicationController < ActionController::Base" do "\n protected_by_vigilante\n\n #----------------------------------\n # Begin Vigilante glue code\n #\n # note: you can easily rename the functions, the function-names are configured in the\n # the @vigilante_config.yml@ configuration file.\n #\n #----------------------------------\n\n\n # retrieves the current context, this is called at the top of the @check_permissions@ function.\n # This means that inside a nested resource, the nested resources should be retrieved before the\n # @check_permissions@ is called, e.g. in a @:before_filter@. This is considered good practice anyway.\n #\n def current_context\n # example :\n # context = @blog || @blogs\n # context = [context] unless context.nil? || context.is_a?(Array)\n nil\n end\n\n\n # retrieves the id from your chosen context-object. You should rename to something more meaningful\n # like\n #\n # get_blog_id_from_context_object\n #\n # As the extents are stored by id, this is used to check which permissions are valid for you (in this context).\n #\n def get_context_id_from_context_object(obj)\n=begin\n # example\n logger.debug \"get_asp_id_from_context_object received \\\#{obj.inspect}\"\n blog_id = if obj.is_a?(Blog)\nobj.id\n elsif obj.is_a?(Post) || obj.is_a?(Author)\nobj.blog_id\n else\n0\n end\n blog_id.to_s\n=end\n \"0\"\n end\n\n # this is used by the finders, to allow automatic finding of the resources, if needed\n # You should rename this, for clarity sake, to which parameter you look for (nested resource)\n # In this case:\n # find_blog_by_blog_id\n #\n #\n def find_context_by_context_id\n=begin\n @blog = Blog.find_by_id(params[:blog_id]) if params[:blog_id].present?\n=end\n end\n\n #----------------------------------\n # End Vigilante glue code\n #----------------------------------\n\n"
end
end
|