mcms_authentication 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +17 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/images/background/page_bg.png +0 -0
  5. data/app/assets/images/background/text_field_background.png +0 -0
  6. data/app/assets/images/icons/accept.png +0 -0
  7. data/app/assets/images/icons/add.png +0 -0
  8. data/app/assets/images/icons/application_edit.png +0 -0
  9. data/app/assets/images/icons/cancel.png +0 -0
  10. data/app/assets/images/icons/delete.png +0 -0
  11. data/app/assets/images/icons/email_go.png +0 -0
  12. data/app/assets/images/rails.png +0 -0
  13. data/app/assets/javascripts/application.js +42 -0
  14. data/app/assets/javascripts/authentication_global.js +17 -0
  15. data/app/assets/stylesheets/application.css +33 -0
  16. data/app/assets/stylesheets/authentication_global.css +424 -0
  17. data/app/controllers/application_controller.rb +36 -0
  18. data/app/controllers/home_controller.rb +44 -0
  19. data/app/controllers/roles_controller.rb +375 -0
  20. data/app/controllers/users_controller.rb +202 -0
  21. data/app/models/ability.rb +82 -0
  22. data/app/models/existing_model.rb +24 -0
  23. data/app/models/plugin.rb +30 -0
  24. data/app/models/role.rb +70 -0
  25. data/app/models/roles_user.rb +33 -0
  26. data/app/models/user.rb +90 -0
  27. data/app/views/home/index.html.erb +18 -0
  28. data/app/views/layouts/users/_javascript.html.erb +3 -0
  29. data/app/views/layouts/users/_stylesheet.html.erb +3 -0
  30. data/app/views/layouts/users/devise.html.erb +40 -0
  31. data/app/views/layouts/users/home.html.erb +99 -0
  32. data/app/views/roles/_form.html.erb +240 -0
  33. data/app/views/roles/_form.js.erb +113 -0
  34. data/app/views/roles/edit.html.erb +26 -0
  35. data/app/views/roles/index.html.erb +73 -0
  36. data/app/views/roles/new.html.erb +25 -0
  37. data/app/views/users/_role.js.erb +47 -0
  38. data/app/views/users/confirmations/new.html.erb +29 -0
  39. data/app/views/users/edit.html.erb +131 -0
  40. data/app/views/users/index.html.erb +81 -0
  41. data/app/views/users/mailer/confirmation_instructions.html.erb +22 -0
  42. data/app/views/users/mailer/reset_password_instructions.html.erb +26 -0
  43. data/app/views/users/mailer/unlock_instructions.html.erb +24 -0
  44. data/app/views/users/new.html.erb +113 -0
  45. data/app/views/users/passwords/edit.html.erb +38 -0
  46. data/app/views/users/passwords/new.html.erb +32 -0
  47. data/app/views/users/sessions/new.html.erb +84 -0
  48. data/app/views/users/shared/_links.erb +39 -0
  49. data/app/views/users/unlocks/new.html.erb +25 -0
  50. data/config/initializers/constants.rb +30 -0
  51. data/config/initializers/devise.rb +217 -0
  52. data/config/locales/devise.en.yml +57 -0
  53. data/config/locales/en.yml +10 -0
  54. data/config/routes.rb +24 -0
  55. data/db/migrate/20120605112804_devise_create_users.rb +68 -0
  56. data/db/migrate/20120608104637_create_roles.rb +30 -0
  57. data/db/migrate/20120608140424_create_roles_users.rb +25 -0
  58. data/db/migrate/20120612050932_create_plugins.rb +14 -0
  59. data/db/migrate/20120625114340_create_existing_models.rb +9 -0
  60. data/db/migrate/20120711064709_add_username_to_users.rb +9 -0
  61. data/db/seeds.rb +29 -0
  62. data/lib/generators/mcms_authentication/USAGE +8 -0
  63. data/lib/generators/mcms_authentication/mcms_authentication_generator.rb +110 -0
  64. data/lib/generators/mcms_authentication/templates/asset_manager.rb +117 -0
  65. data/lib/generators/mcms_authentication/templates/models.rb +189 -0
  66. data/lib/mcms_authentication.rb +4 -0
  67. data/lib/mcms_authentication/engine.rb +20 -0
  68. data/lib/mcms_authentication/seeds.rb +14 -0
  69. data/lib/mcms_authentication/version.rb +3 -0
  70. data/lib/tasks/mcms_authentication_tasks.rake +4 -0
  71. data/test/dummy/README.rdoc +261 -0
  72. data/test/dummy/Rakefile +7 -0
  73. data/test/dummy/app/assets/javascripts/application.js +15 -0
  74. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  75. data/test/dummy/app/controllers/application_controller.rb +3 -0
  76. data/test/dummy/app/helpers/application_helper.rb +2 -0
  77. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  78. data/test/dummy/config.ru +4 -0
  79. data/test/dummy/config/application.rb +59 -0
  80. data/test/dummy/config/boot.rb +10 -0
  81. data/test/dummy/config/database.yml +25 -0
  82. data/test/dummy/config/environment.rb +5 -0
  83. data/test/dummy/config/environments/development.rb +37 -0
  84. data/test/dummy/config/environments/production.rb +67 -0
  85. data/test/dummy/config/environments/test.rb +37 -0
  86. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  87. data/test/dummy/config/initializers/inflections.rb +15 -0
  88. data/test/dummy/config/initializers/mime_types.rb +5 -0
  89. data/test/dummy/config/initializers/secret_token.rb +7 -0
  90. data/test/dummy/config/initializers/session_store.rb +8 -0
  91. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  92. data/test/dummy/config/locales/en.yml +5 -0
  93. data/test/dummy/config/routes.rb +58 -0
  94. data/test/dummy/public/404.html +26 -0
  95. data/test/dummy/public/422.html +26 -0
  96. data/test/dummy/public/500.html +25 -0
  97. data/test/dummy/public/favicon.ico +0 -0
  98. data/test/dummy/script/rails +6 -0
  99. data/test/fixtures/existing_models.yml +11 -0
  100. data/test/functional/home_controller_test.rb +7 -0
  101. data/test/integration/navigation_test.rb +10 -0
  102. data/test/mcms_authentication_test.rb +7 -0
  103. data/test/test_helper.rb +15 -0
  104. data/test/unit/existing_model_test.rb +7 -0
  105. data/test/unit/helpers/home_helper_test.rb +4 -0
  106. metadata +234 -0
@@ -0,0 +1,36 @@
1
+ =begin
2
+
3
+ @File Name :application_controller.rb
4
+
5
+ @Company Name :Mindfire Solutions Pvt. Ltd.
6
+
7
+ @Creator Name :Indranil Mukherjee
8
+
9
+ @Date Created :2012-06-04
10
+
11
+ @Date Modified :2012-06-14
12
+
13
+ @Last Modification Details :Making it as mcms project standard
14
+
15
+ @Purpose :This file is mother of all controllers in the system
16
+ and responsible of doing the common operations for all
17
+ controllers.
18
+
19
+ =end
20
+
21
+
22
+ class ApplicationController < ActionController::Base
23
+
24
+ #this protects from outside forgery , i.e : form submissions from outside (remote side)
25
+ protect_from_forgery
26
+
27
+ # The following snippet is responsible for rescuing from exception generated by CanCan gem
28
+ # for denying a particular module access with a notice to user and redirecting to root_url
29
+ rescue_from CanCan::AccessDenied do |exception|
30
+
31
+ flash[:error] = t(:access_denied,:default => "You are not authorized for doing this operation")
32
+ redirect_to root_url
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,44 @@
1
+ =begin
2
+
3
+ @File Name :home_controller.rb
4
+
5
+ @Company Name :Mindfire Solutions Pvt. Ltd.
6
+
7
+ @Creator Name :Indranil Mukherjee
8
+
9
+ @Date Created :2012-06-04
10
+
11
+ @Date Modified :2012-06-14
12
+
13
+ @Last Modification Details :Making it as mcms project standard
14
+
15
+ @Purpose :This is a controller which has only one action index
16
+ which is the root of the application.
17
+
18
+ =end
19
+
20
+ class HomeController < ApplicationController
21
+
22
+
23
+
24
+
25
+ # This is basically the root path of the application.
26
+ # authentication required because everything will start by superuser
27
+ # in authentication module
28
+
29
+
30
+
31
+ before_filter :authenticate_user!
32
+
33
+ layout HOME_LAYOUT
34
+
35
+ # @Params : No parameter
36
+ # @Returns : Nothing is returned
37
+ # @Purpose : Home page action
38
+
39
+ def index
40
+
41
+ end
42
+
43
+
44
+ end
@@ -0,0 +1,375 @@
1
+ =begin
2
+
3
+ @File Name :roles_controller.rb
4
+
5
+ @Company Name :Mindfire Solutions Pvt. Ltd.
6
+
7
+ @Creator Name :Indranil Mukherjee
8
+
9
+ @Date Created :2012-06-04
10
+
11
+ @Date Modified :2012-06-14
12
+
13
+ @Last Modification Details :Making it as mcms project standard
14
+
15
+ @Purpose :This controller is responsible for creating,
16
+ editing,destroying roles
17
+
18
+ =end
19
+
20
+ class RolesController < ApplicationController
21
+
22
+
23
+
24
+ prepend_before_filter :authenticate_user! #Need authentication for each actions
25
+
26
+ load_and_authorize_resource # Need authorized users for each actions
27
+
28
+ layout HOME_LAYOUT # Following a particular layout.not default one
29
+
30
+ include Models # We need helps of a custom library which is defined in lib/mcms_authentication/models.rb
31
+
32
+
33
+
34
+ # @Params : No parameter
35
+ # @Returns : Nothing is returned GET mcms/roles
36
+ # @Purpose : Showing all existing roles
37
+
38
+ def index
39
+
40
+ @roles = Role.all # fetching all roles
41
+
42
+ respond_to do |f|
43
+
44
+ f.html # output as HTML
45
+
46
+ f.json {render :json => @roles} # output as json
47
+
48
+ end
49
+
50
+ end
51
+
52
+
53
+
54
+ # @Params : No parameter
55
+ # @Returns : Nothing is returned GET mcms/roles/new
56
+ # @Purpose : Instantiating a new role
57
+
58
+ def new
59
+
60
+ @all_plugins = get_all_plugins # getting all plugins(modules) in current application
61
+
62
+ @role = Role.new # instantiating a new role
63
+
64
+ respond_to do |f|
65
+
66
+ f.html # output as HTML
67
+
68
+ f.json {render :json => @role} # output as json
69
+
70
+ end
71
+
72
+ end
73
+
74
+
75
+
76
+ # @Params : Hash
77
+ # @Returns : Nothing is returned POST mcms/roles/
78
+ # @Purpose : Instantiating a new role
79
+
80
+ def create
81
+ # instantiating a role with passed parameters
82
+ @role = Role.new(params[:role])
83
+
84
+ # getting all plugins(modules) in current application
85
+ @all_plugins = get_all_plugins
86
+
87
+
88
+ # for i in 0..@all_plugins.length - 1
89
+ #
90
+ # if((@all_plugins[i]&@all_plugins[i+1]).any?)
91
+ # @all_plugins[i] = (@all_plugins[i] + @all_plugins[i+1]).uniq
92
+ # end
93
+ #
94
+ # end
95
+
96
+ respond_to do |format|
97
+
98
+ if @role.save # saving the role
99
+
100
+ # iterating existing plugins and creating plugin access for the role being saved
101
+ # we have used conditional statements to set boolean values for crud access to each module.
102
+
103
+ @all_plugins.each do |plugin|
104
+
105
+ p = Plugin.new
106
+
107
+ p.role_module = plugin.last
108
+
109
+ models = ExistingModel.find_by_plugin_name(plugin.last)
110
+
111
+ if models.nil?
112
+ plugin.each do |pl|
113
+
114
+ existing_model = ExistingModel.new
115
+ existing_model.plugin_name = plugin.last
116
+ existing_model.model_name = pl
117
+ existing_model.save
118
+
119
+ end
120
+
121
+ end
122
+
123
+ all = plugin.last + ALL
124
+
125
+ read = plugin.last + READ
126
+
127
+ create = plugin.last + CREATE
128
+
129
+ update = plugin.last + UPDATE
130
+
131
+ destroy = plugin.last + DESTROY
132
+
133
+ if params[all] == "1"
134
+
135
+ p.role_manage = true # setting access control
136
+
137
+ else
138
+
139
+ p.role_manage = false # resetting access control
140
+
141
+ end
142
+
143
+
144
+ if params[read] == "1" || params[all] == "1"
145
+
146
+ p.role_read = true
147
+
148
+ else
149
+
150
+ p.role_read = false
151
+
152
+ end
153
+
154
+ if params[create] == "1" || params[all] == "1"
155
+
156
+ p.role_create = true
157
+
158
+ else
159
+
160
+ p.role_create = false
161
+
162
+ end
163
+
164
+ if params[update] == "1" || params[all] == "1"
165
+
166
+ p.role_update = true
167
+
168
+ else
169
+
170
+ p.role_update = false
171
+
172
+ end
173
+
174
+ if params[destroy] == "1" || params[all] == "1"
175
+
176
+ p.role_destroy = true
177
+
178
+ else
179
+
180
+ p.role_destroy = false
181
+
182
+ end
183
+
184
+ p.role_id = @role.id # associating the role being saved
185
+
186
+ p.save # saving each plugin access control
187
+
188
+ end
189
+
190
+ format.html { redirect_to(roles_path,
191
+ :notice => t(:role_create_success,:default => 'Role was successfully created.')) } # HTML response
192
+
193
+ format.json { render :json => @role,
194
+ :status => :created, :location => @role } # json response
195
+ else
196
+
197
+ # if any exception occured recreate the role
198
+ format.html { render :action => "new" } # HTML response
199
+
200
+ format.json { render :json => @role.errors,
201
+ :status => :unprocessable_entity } # json response
202
+
203
+ end
204
+
205
+ end
206
+
207
+ end
208
+
209
+
210
+ # @Params : Integer
211
+ # @Returns : Nothing is returned PUT mcms/roles/1/edit
212
+ # @Purpose : Updating an existing role
213
+
214
+ def edit
215
+
216
+ @all_plugins = get_all_plugins # fetching all the plugins
217
+
218
+ @role = Role.find(params[:id]) # fetching the role to be updated
219
+
220
+ respond_to do |f|
221
+
222
+ f.html #HTML response
223
+
224
+ f.json {render :json => @role} #JSON response
225
+
226
+ end
227
+
228
+ end
229
+
230
+
231
+ # @Params : Integer
232
+ # @Returns : Nothing is returned PUT mcms/roles/1/edit
233
+ # @Purpose : Updating an existing role
234
+
235
+ def update
236
+
237
+ # Finding the role to be updated by ID
238
+ @role = Role.find(params[:id])
239
+
240
+ # Fetching all the available plugins
241
+ @all_plugins = get_all_plugins
242
+
243
+ respond_to do |format|
244
+
245
+ if @role.update_attributes(params[:role]) # updating the role
246
+
247
+ # plugins access control is also updated with conditional checks.
248
+
249
+ @all_plugins.each do |plugin|
250
+
251
+ p = Plugin.find_by_role_module(plugin.last)
252
+
253
+ if p.nil?
254
+
255
+ p = Plugin.new
256
+
257
+ end
258
+ models = ExistingModel.find_by_plugin_name(plugin.last)
259
+
260
+ if models.nil?
261
+
262
+ plugin.each do |pl|
263
+
264
+ existing_model = ExistingModel.new
265
+ existing_model.plugin_name = plugin.last
266
+ existing_model.model_name = pl
267
+ existing_model.save
268
+
269
+ end
270
+
271
+ end
272
+
273
+ p.role_module = plugin.last
274
+
275
+ all = plugin.last + ALL
276
+
277
+ read = plugin.last + READ
278
+
279
+ create = plugin.last + CREATE
280
+
281
+ update = plugin.last + UPDATE
282
+
283
+ destroy = plugin.last + DESTROY
284
+
285
+ if params[all] == "1"
286
+
287
+ p.role_manage = true
288
+ else
289
+ p.role_manage = false
290
+ end
291
+
292
+
293
+ if params[read] == "1" || params[all] == "1"
294
+
295
+ p.role_read = true
296
+ else
297
+ p.role_read = false
298
+ end
299
+
300
+ if params[create] == "1" || params[all] == "1"
301
+
302
+ p.role_create = true
303
+ else
304
+ p.role_create = false
305
+ end
306
+
307
+ if params[update] == "1" || params[all] == "1"
308
+
309
+ p.role_update = true
310
+
311
+ else
312
+
313
+ p.role_update = false
314
+
315
+ end
316
+
317
+ if params[destroy] == "1" || params[all] == "1"
318
+
319
+ p.role_destroy = true
320
+
321
+ else
322
+
323
+ p.role_destroy = false
324
+
325
+ end
326
+
327
+ p.role_id = @role.id
328
+
329
+ p.save
330
+
331
+ end
332
+
333
+
334
+ format.html { redirect_to(roles_path,
335
+ :notice => t(:role_update_success,:default => 'Role was successfully updated.')) } # HTML response
336
+
337
+ format.json { head :no_content } # JSON Response
338
+
339
+ else
340
+
341
+ format.html { render :action => "edit" } # Failed HTML response to update again
342
+
343
+ format.json { render :json => @role.errors,
344
+ :status => :unprocessable_entity } # Failed JSON response to update again
345
+
346
+ end
347
+
348
+ end
349
+
350
+ end
351
+
352
+
353
+
354
+ # @Params : Integer
355
+ # @Returns : Nothing is returned DELETE mcms/roles/1/
356
+ # @Purpose : Destroying an existing role
357
+
358
+ def destroy
359
+
360
+ @role = Role.find(params[:id]) # Select a role to be destroyed
361
+
362
+ @role.destroy # delete the role
363
+
364
+ respond_to do |format|
365
+
366
+ format.html { redirect_to roles_url } # HTML response
367
+
368
+ format.json { head :no_content } # JSON response
369
+
370
+ end
371
+
372
+ end
373
+
374
+ end
375
+