public
Description: The beer wiki site for real beer nerds
Homepage: http://barleysodas.com
Clone URL: git://github.com/penguincoder/barleysodas.git
barleysodas / generate_permissions
100644 54 lines (49 sloc) 1.873 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
Permission.destroy_all
 
base_actions = ApplicationController.action_methods
# i should probably figure out all of the children of ApplicationController
# rather than defining them here.
controllers = [ PagesController, DiscussionsController, StylesController,
  PeoplesController, BeersController, BreweriesController, RolesController,
  GalleriesController, TagImagesController, FriendsController,
  ExperiencesController, InvitationsController ]
controllers.each do |c|
  actions = c.action_methods - base_actions
  cname = c.controller_name
  actions.each { |a| Permission.create(:controller => cname, :action => a) }
end
 
r = Role.base_role
Permission.find(:all,
  :conditions => [ 'controller = ?', 'pages' ]).each do |p|
  next if [ 'new', 'create', 'edit', 'update', 'destroy' ].include?(p.action)
  r.permissions << p
end
Permission.find(:all,
  :conditions => [ 'controller = ?', 'styles' ]).each do |p|
  next if [ 'new', 'create', 'edit', 'update', 'destroy' ].include?(p.action)
  r.permissions << p
end
Permission.find(:all,
  :conditions => [ 'controller = ?', 'galleries' ]).each do |p|
  next if [ 'new', 'create', 'edit', 'update', 'destroy' ].include?(p.action)
  r.permissions << p
end
Permission.find(:all,
  :conditions => [ 'controller = ?', 'tag_images' ]).each do |p|
  next if [ 'show', 'create', 'destroy', 'taggable_search' ].include?(p.action)
  r.permissions << p
end
Permission.find(:all,
  :conditions => [ 'controller = ?', 'friends' ]).each do |p|
  next if [ 'edit', 'create', 'destroy' ].include?(p.action)
  r.permissions << p
end
Permission.find(:all,
  :conditions => [ 'controller = ?', 'experiences' ]).each do |p|
  next unless [ 'show' ].include?(p.action)
  r.permissions << p
end
 
r2 = Role.admin_role
Permission.find(:all).each do |p|
  r2.permissions << p unless r.permissions.include?(p)
end
 
puts "All permissions created"