cream 0.8.6 → 0.8.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/Changelog.txt +6 -1
  2. data/Design Ideas.textile +463 -0
  3. data/Gemfile +1 -0
  4. data/README.textile +158 -34
  5. data/Rakefile +8 -7
  6. data/VERSION +1 -1
  7. data/app/views/cream/menu/_admin_login_items.html.erb +2 -2
  8. data/app/views/cream/menu/_login_items.html.erb +2 -2
  9. data/app/views/cream/menu/_registration_items.html.erb +2 -2
  10. data/config/locales/cream.da.yml +16 -0
  11. data/cream.gemspec +38 -27
  12. data/lib/cream.rb +1 -0
  13. data/lib/cream/configure/after_init/role_config.rb +25 -21
  14. data/lib/cream/configure/rails.rb +8 -5
  15. data/lib/cream/controller/application_controller.rb +22 -0
  16. data/lib/cream/helper/role.rb +102 -11
  17. data/lib/generators/cream/app/app_generator.rb +50 -26
  18. data/lib/generators/cream/full_config/full_config_generator.rb +44 -9
  19. data/lib/generators/cream/helpers/all.rb +1 -0
  20. data/lib/generators/cream/helpers/execute_helper.rb +0 -4
  21. data/lib/generators/cream/helpers/gemfile_helper.rb +28 -0
  22. data/lib/generators/cream/helpers/orm_helper.rb +6 -2
  23. data/lib/generators/cream/helpers/strategy_helper.rb +28 -0
  24. data/lib/generators/cream/views/haml_util.rb +3 -4
  25. data/lib/generators/cream/views/views_generator.rb +13 -13
  26. data/lib/generators/devise/config/app_helper.rb +1 -1
  27. data/lib/generators/devise/config/config_generator.rb +1 -3
  28. data/lib/generators/devise/config/{gem_helper.rb → gem_config_helper.rb} +0 -23
  29. data/lib/generators/devise/customize/customize_generator.rb +49 -0
  30. data/lib/generators/devise/customize/customize_messages.rb +52 -0
  31. data/lib/generators/devise/customize/helpers/query_customizers.rb +43 -0
  32. data/lib/generators/devise/customize/helpers/recover_login.rb +80 -0
  33. data/lib/generators/devise/customize/helpers/username_helper.rb +149 -0
  34. data/lib/generators/devise/users/users_generator.rb +1 -3
  35. data/lib/generators/permits/config/config_generator.rb +1 -3
  36. data/lib/generators/roles/config/config_generator.rb +26 -4
  37. data/sandbox/any_user.rb +98 -0
  38. data/{lib/generators → sandbox}/cream_refactor.rb +0 -0
  39. data/sandbox/str_test.rb +50 -0
  40. data/spec/cream/configure/rails_role_spec.rb +1 -1
  41. data/spec/cream/helper/role_spec.rb +71 -21
  42. data/wiki/Cream-generators-overview.textile +79 -0
  43. data/wiki/How to gollum wiki.txt +13 -0
  44. metadata +107 -72
  45. data/wiki/CONFIG_GENERATOR.txt +0 -21
  46. data/wiki/DESIGN.txt +0 -21
  47. data/wiki/INSTALLATION.txt +0 -6
  48. data/wiki/PERMITS.txt +0 -32
  49. data/wiki/ROLE_STRATEGIES.txt +0 -40
  50. data/wiki/SPEC_NOTES.txt +0 -6
  51. data/wiki/VIEWS_GENERATOR.txt +0 -35
  52. data/wiki/VIEW_HELPERS.txt +0 -162
@@ -1,21 +0,0 @@
1
- The *config* generator generates a configuration initializer file for setting up `cream` to use a particular role strategy.
2
-
3
- <pre>$ rails g cream:config --strategy NAME</pre>
4
-
5
- NAME is the name of a role strategy.
6
-
7
- Strategies with a single role for each user
8
- * admin_field
9
- * role_string
10
- * one_role
11
-
12
- Strategies with multiple roles for each user
13
- * roles_mask
14
- * many_roles
15
-
16
- Currently role groups are not supported. Feel free to provide an add-on to support this or integrate with an existing 'role group' solution.
17
-
18
- Example usage:
19
-
20
- <pre>$ rails g cream:config --strategy admin_field</pre>
21
-
data/wiki/DESIGN.txt DELETED
@@ -1,21 +0,0 @@
1
- # Design and plans for the future...
2
-
3
- 1) Specs for generators
4
- Currently there are a few generators. I have found some good examples of how to write generator tests (using test_unit) in the rails3-generators project.
5
- I am porting this to RSpec 2 and will then write generator specs next.
6
-
7
- 2) New hook-in approach for controller and view methods
8
- I will change how the methods are added to Rails controllers and views using a new approach I found and used in the Netzke project.
9
-
10
- 3) Create specs for the custom methods
11
- 4) Create cucumber features for various Role scenarios
12
- 5) Add Mongoid and Mongo Mapper ORM support
13
- Mongoid currently supported by Devise, and Mongo Mapper will be supported after Rails 3 release I think (have heard?)
14
-
15
- 6) Add Data Mapper support
16
- dm-devise project almost done by jm81 as per. July 9, 2010
17
-
18
- 7) Add support for Canable (jnunemaker), an even simpler permission system alternative to CanCan.
19
- I already added generators and specs to this gem.
20
-
21
- Feel free to suggest other improvements etc ;)
@@ -1,6 +0,0 @@
1
- This gem has been designed for Rails 3 only. Any back port to Rails 2 is most welcome ;)
2
-
3
- Insert <pre>gem 'auth-assistant'</pre> in your Rails 3 Gemfile
4
-
5
- <pre>$ bundle install</pre>
6
-
data/wiki/PERMITS.txt DELETED
@@ -1,32 +0,0 @@
1
- Authorization is setup by designing permits for each can of role to do certain actions.
2
- The config generator generates a default permits.rb file in /lib
3
-
4
- Please see "cancan 1.3 wiki":http://wiki.github.com/ryanb/cancan/upgrading-to-13 for more options
5
- you can use in designing your Permits. The 'owns' convenience method provided, now uses the new hash option so it
6
- is also available in the controller using fx:
7
-
8
- <pre>Book.accessible_by(current_ability)</pre>
9
-
10
- The user can manage any Comment instance if 'user' field on instance points to the user, marking ownership
11
- <pre>user.owns(Comment)</pre>
12
-
13
- Override default 'user_id' field used by owns, to instead use 'author' as ownership key (foreign key) pointing to the user (user.id).
14
- <pre>user.owns(Book, :author)</pre>
15
-
16
- Example:
17
- <pre>module RolePermit
18
- class Moderator
19
- def initialize(ability)
20
- super
21
- end
22
-
23
- def permit?(user)
24
- super
25
- return if !user.role?(:moderator)
26
- can :read, :all
27
-
28
- user.owns(Comment)
29
- user.owns(Book, :author)
30
- end
31
- end
32
- end</pre>
@@ -1,40 +0,0 @@
1
- *Cream* supports single and multiple role strategies. Currently groups are not supported.
2
-
3
- Note: Maybe roles support could be integrated in the future using an existing solution for roles and groups?
4
-
5
- h2. Single role per user
6
-
7
- * admin_field
8
- * role_field (role : string in users table)
9
- * role_assignment (role_id -> role.id)
10
-
11
- h3. admin_field
12
- Uses the field *admin : boolean* in the _users_ table
13
-
14
- h3. role_field
15
- Uses the field *role : string* in the _users_ table
16
-
17
- h3. role_assignment
18
- Uses the field *role_id :integer* in the _users_ table.
19
- A _roles_ table has id and name fields, where name is the name of the role.
20
- `users.role_id` points to `role.id` in a 1-M relation.
21
-
22
- Many (M) users can have the same (1) role. Any user can however only have a single role.
23
-
24
- h2. Multiple roles per user
25
- * roles mask
26
- * roles_field
27
- * multi_role_assignment
28
-
29
- h3. roles mask
30
- Uses the field *role_masks : integer* in the _users_ table.
31
- Each bit of the integer matches a given role.
32
-
33
- h3. roles_field
34
- Uses the field *roles : string* in the _users_ table.
35
- Currently "experimental".
36
-
37
- h3. multi_role_assignment
38
- Uses the field *role_assignment_id : integer* in the _users_ table.
39
- A _roles_ table has id and name fields, where name is the name of the role.
40
- A _role_assignments_ table has _role_id_ and _user_id_ fields, linking the assignment to a user in the users table and a role in the roles table.
data/wiki/SPEC_NOTES.txt DELETED
@@ -1,6 +0,0 @@
1
- # Notes and Status
2
-
3
- Currently these specs are a work in progress.
4
- I am first building up a skeleton structure for the specs and then plan to gradually implement them as described in the DESIGN.txt document :)
5
-
6
- You are most welcome to help in the effort!
@@ -1,35 +0,0 @@
1
- The `views` generator generates views (partials) for use with menus.
2
-
3
- It is sometimes the case that you want to have menu items in a main navigation menu that enable the user to log in/out, register a new user account or edit an existing user account. The menu items partials ensure that these menuitems are only shown as appropriate in relation to the current user login status, so that log out and edit account is only shown if the user is currently logged in and vice-versa.
4
-
5
- <pre>$ rails g cream:views</pre>
6
-
7
- Create HAML views
8
-
9
- <pre>$ rails g cream:views --template_engine haml</pre>
10
-
11
- Example usage:
12
- <pre>ul.menu
13
- render 'cream/login_items'
14
- render 'cream/registration_items'
15
-
16
- ul.admin_menu_
17
- render 'cream/admin_login_items'</pre>
18
-
19
-
20
- <pre>module RolePermit
21
- class Moderator
22
- def initialize(ability)
23
- super
24
- end
25
-
26
-
27
- def permit?(user)
28
- super
29
- return if !user.role?(:moderator)
30
- can :read, :all
31
- user.owns(Comment)
32
- user.owns(Book, :author)
33
- end
34
- end
35
- end</pre>
@@ -1,162 +0,0 @@
1
- ## View helpers ##
2
-
3
- Currently the view helpers only target use with devise and cancan.
4
- The default labels are always loaded from the `cream` locale file, which is generated by the `config` generator.
5
-
6
- ### Rest link helpers ###
7
-
8
- Display a link (anchor tag) for a given object only if the current user has permission to execute that action.
9
-
10
- * show_link or read_link
11
- * edit_link or update_link
12
- * create_link or new_link
13
- * destroy_link or delete_link
14
-
15
- Each Rest helper method takes an object for which to create the link. Optionally provide a label as the second argument.
16
-
17
- Example usage:
18
-
19
- <%= create_link project %>
20
- <%= create_link project, 'Create new project' %>
21
-
22
- ### Session link helpers ###
23
-
24
- Show links for performing user authentication and registration actions
25
-
26
- * log_out_link or sign_out_link
27
- * log_in_link or sign_in_link
28
-
29
- Each of these methods take an optional options hash.
30
- If no role option given, they default to create link for basic 'user' role.
31
-
32
- Example usage:
33
-
34
- <%= log_out_link %>
35
- <%= log_out_link :label => 'Log me out' %>
36
- <%= log_out_link :role => 'admin', :label => 'Log me out' %>
37
-
38
-
39
- ### Registration link helpers ###
40
-
41
- Show links for performing user authentication and registration actions
42
-
43
- * register_link or sign_up_link
44
- * edit_profile_link or edit_registration_link
45
-
46
- Each of these methods take an optional options hash.
47
- If no role option given, they default to create link for basic 'user' role.
48
-
49
- Example usage:
50
-
51
- <%= register_link %>
52
- <%= register_link :label => 'Register me' %>
53
- <%= register_link :role => 'admin', :label => 'Register me' %>
54
-
55
- ### Registration Menu item helpers ###
56
-
57
- Show menu links for registration conditionally
58
-
59
- * edit_user_menu_item or edit_registration_menu_item
60
- * register_menu_item or sign_up_menu_item
61
-
62
- 1) only shown if user is currently logged in
63
- 2) only shown if user is NOT currently logged in (and hence already registered)
64
-
65
- Example usage:
66
-
67
- ul.menu
68
- <%= register_menu_item %>
69
-
70
- ### Session Menu item helpers ###
71
-
72
- Show menu links for session operations conditionally
73
-
74
- * logout_menu_item or sign_out_menu_item
75
- * login_menu_item or sign_in_menu_item
76
-
77
- 1) only shown if user is currently logged in
78
- 2) only shown if user is NOT currently logged in
79
-
80
- ul.menu
81
- <%= login_menu_item %>
82
- <%= logout_menu_item %>
83
-
84
-
85
- ## Block helpers ##
86
-
87
- Execute block if user is logged in (or not logged in)
88
- * user_block
89
- * not_user_block
90
-
91
- Execute block if user is logged and is admin (or not admin)
92
- * admin_block
93
- * not_admin_block
94
-
95
- Execute block if ip is localhost (or not localhost)
96
- * localhost_block
97
- * not_localhost_block
98
-
99
- Execute block if role is included in list of roles (or not)
100
- * roles_block
101
- * not_roles_block
102
-
103
- ## Block area helpers ##
104
-
105
- Create div.user 'area' and execute block if user is logged in as a user (or not)
106
-
107
- * user_area
108
- * not_user_area
109
-
110
- Create div.admin 'area' and execute block if user is admin (or not admin)
111
-
112
- * admin_area
113
- * not_admin_area
114
-
115
- Example:
116
- <pre>
117
- <% admin_area do %>
118
- ul.admin_menu
119
- ...
120
-
121
- If logged in as admin, results in:
122
-
123
- div.admin
124
- ul.admin_menu
125
- ...
126
- </pre>
127
-
128
- ## Roles block area helpers ##
129
-
130
- Creates are if role is one included in list of roles (or not)
131
-
132
- * roles_area
133
- * not_roles_area
134
-
135
- Example:
136
- <pre>
137
- <% roles_area 'admin, 'editor', :class => 'special' do %>
138
- ul.admin_menu
139
- ...
140
-
141
- If logged in as either 'editor' or 'admin', results in:
142
-
143
- div.special
144
- ul.admin_menu
145
- ...
146
-
147
- </pre>
148
-
149
- ## Misc helpers ##
150
-
151
- * user? -
152
- * admin?
153
- * role?
154
- * localhost?
155
-
156
- Examples
157
- <pre>
158
- <%= current_user.username if user? %>
159
- <%= "Admin: #{current_user.username}" if admin? %>
160
- <%= "Special user!" if role?('admin', 'reviewer') %>
161
- <%= "Running on localhost!" if localhost? %>
162
- </pre>