Commit 79274989dfaae9697ff2253243c895284799e0aa
1 parent
e445ecc3
Exists in
master
and in
29 other branches
ActionItem35: finished action item
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1858 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
16 changed files
with
67 additions
and
30 deletions
Show diff stats
app/controllers/my_profile/profile_members_controller.rb
@@ -23,7 +23,7 @@ class ProfileMembersController < MyProfileController | @@ -23,7 +23,7 @@ class ProfileMembersController < MyProfileController | ||
23 | end | 23 | end |
24 | 24 | ||
25 | def change_role | 25 | def change_role |
26 | - @roles = Role.find(:all).select{ |r| r.has_kind?(:profile) } | 26 | + @roles = profile.roles |
27 | @member = Person.find(params[:id]) | 27 | @member = Person.find(params[:id]) |
28 | @associations = @member.find_roles(@profile) | 28 | @associations = @member.find_roles(@profile) |
29 | end | 29 | end |
app/helpers/application_helper.rb
@@ -322,7 +322,7 @@ module ApplicationHelper | @@ -322,7 +322,7 @@ module ApplicationHelper | ||
322 | 322 | ||
323 | bt_submit = submit_tag(label, html_options.merge(:class => the_class)) | 323 | bt_submit = submit_tag(label, html_options.merge(:class => the_class)) |
324 | 324 | ||
325 | - bt_submit | 325 | + bt_submit + bt_cancel |
326 | end | 326 | end |
327 | 327 | ||
328 | def button_to_function(type, label, js_code, html_options = {}) | 328 | def button_to_function(type, label, js_code, html_options = {}) |
app/helpers/forms_helper.rb
1 | module FormsHelper | 1 | module FormsHelper |
2 | 2 | ||
3 | def generate_form( name, obj, fields={} ) | 3 | def generate_form( name, obj, fields={} ) |
4 | - | ||
5 | labelled_form_for name, obj do |f| | 4 | labelled_form_for name, obj do |f| |
6 | - | ||
7 | f.text_field(:name) | 5 | f.text_field(:name) |
8 | - | ||
9 | end | 6 | end |
10 | - | ||
11 | end | 7 | end |
12 | 8 | ||
13 | def labelled_radio_button( human_name, name, value, checked = false, options = {} ) | 9 | def labelled_radio_button( human_name, name, value, checked = false, options = {} ) |
14 | - options[:id] ||= 'radio-' + rand.to_s | 10 | + options[:id] ||= 'radio-' + FormsHelper.next_id_number |
15 | radio_button_tag( name, value, checked, options ) + | 11 | radio_button_tag( name, value, checked, options ) + |
16 | content_tag( 'label', human_name, :for => options[:id] ) | 12 | content_tag( 'label', human_name, :for => options[:id] ) |
17 | end | 13 | end |
18 | 14 | ||
19 | def labelled_check_box( human_name, name, value = "1", checked = false, options = {} ) | 15 | def labelled_check_box( human_name, name, value = "1", checked = false, options = {} ) |
20 | - options[:id] ||= 'checkbox-' + rand.to_s | 16 | + options[:id] ||= 'checkbox-' + FormsHelper.next_id_number |
21 | check_box_tag( name, value, checked, options ) + | 17 | check_box_tag( name, value, checked, options ) + |
22 | content_tag( 'label', human_name, :for => options[:id] ) | 18 | content_tag( 'label', human_name, :for => options[:id] ) |
23 | end | 19 | end |
24 | 20 | ||
21 | +protected | ||
22 | + def self.next_id_number | ||
23 | + if defined? @@id_num | ||
24 | + @@id_num.next! | ||
25 | + else | ||
26 | + @@id_num = '0' | ||
27 | + end | ||
28 | + end | ||
25 | end | 29 | end |
app/models/environment.rb
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | # domains. | 3 | # domains. |
4 | class Environment < ActiveRecord::Base | 4 | class Environment < ActiveRecord::Base |
5 | 5 | ||
6 | - PERMISSIONS[:environment] = { | 6 | + PERMISSIONS['Environment'] = { |
7 | 'view_environment_admin_panel' => N_('View environment admin panel'), | 7 | 'view_environment_admin_panel' => N_('View environment admin panel'), |
8 | 'edit_environment_features' => N_('Edit environment features'), | 8 | 'edit_environment_features' => N_('Edit environment features'), |
9 | 'edit_environment_design' => N_('Edit environment design'), | 9 | 'edit_environment_design' => N_('Edit environment design'), |
app/models/person.rb
@@ -66,7 +66,7 @@ class Person < Profile | @@ -66,7 +66,7 @@ class Person < Profile | ||
66 | def is_admin? | 66 | def is_admin? |
67 | role_assignments.map{|ra|ra.role.permissions}.any? do |ps| | 67 | role_assignments.map{|ra|ra.role.permissions}.any? do |ps| |
68 | ps.any? do |p| | 68 | ps.any? do |p| |
69 | - ActiveRecord::Base::PERMISSIONS[:environment].keys.include?(p) | 69 | + ActiveRecord::Base::PERMISSIONS['Environment'].keys.include?(p) |
70 | end | 70 | end |
71 | end | 71 | end |
72 | end | 72 | end |
app/models/profile.rb
@@ -13,9 +13,15 @@ class Profile < ActiveRecord::Base | @@ -13,9 +13,15 @@ class Profile < ActiveRecord::Base | ||
13 | def self.moderator | 13 | def self.moderator |
14 | ::Role.find_by_key('profile_moderator') | 14 | ::Role.find_by_key('profile_moderator') |
15 | end | 15 | end |
16 | + def self.owner | ||
17 | + ::Role.find_by_key('profile_owner') | ||
18 | + end | ||
19 | + def self.editor | ||
20 | + ::Role.find_by_key('profile_editor') | ||
21 | + end | ||
16 | end | 22 | end |
17 | 23 | ||
18 | - PERMISSIONS[:profile] = { | 24 | + PERMISSIONS['Profile'] = { |
19 | 'edit_profile' => N_('Edit profile'), | 25 | 'edit_profile' => N_('Edit profile'), |
20 | 'destroy_profile' => N_('Destroy profile'), | 26 | 'destroy_profile' => N_('Destroy profile'), |
21 | 'manage_memberships' => N_('Manage memberships'), | 27 | 'manage_memberships' => N_('Manage memberships'), |
@@ -26,7 +32,7 @@ class Profile < ActiveRecord::Base | @@ -26,7 +32,7 @@ class Profile < ActiveRecord::Base | ||
26 | 'validate_enterprise' => N_('Validate enterprise'), | 32 | 'validate_enterprise' => N_('Validate enterprise'), |
27 | 'peform_task' => N_('Peform task'), | 33 | 'peform_task' => N_('Peform task'), |
28 | } | 34 | } |
29 | - | 35 | + |
30 | acts_as_accessible | 36 | acts_as_accessible |
31 | 37 | ||
32 | acts_as_having_boxes | 38 | acts_as_having_boxes |
app/views/profile_members/change_role.rhtml
1 | -<%= _('Changing role of %s') % @member.name %> | 1 | +<h3> <%= _('Changing role of %s') % @member.name %> </h3> |
2 | 2 | ||
3 | <% labelled_form_for :member, @member, :url => {:action => 'update_roles'} do |f| %> | 3 | <% labelled_form_for :member, @member, :url => {:action => 'update_roles'} do |f| %> |
4 | 4 | ||
5 | <%= _('Roles:') %> <br> | 5 | <%= _('Roles:') %> <br> |
6 | <% @roles.each do |r| %> | 6 | <% @roles.each do |r| %> |
7 | - <%= check_box_tag "roles[]", r.id, @associations.map(&:role).include?(r) %> | ||
8 | - <%= r.name.capitalize %><br/> | 7 | + <%= labelled_check_box(r.name, 'roles[]', r.id, @associations.map(&:role).include?(r) ) %><br/> |
9 | <% end %> | 8 | <% end %> |
10 | <%= hidden_field_tag 'person', @member.id %> | 9 | <%= hidden_field_tag 'person', @member.id %> |
11 | 10 |
app/views/profile_members/index.rhtml
@@ -2,12 +2,20 @@ | @@ -2,12 +2,20 @@ | ||
2 | 2 | ||
3 | <%= link_to _('Affiliate yourself'), :action => 'add_role', :person => current_user.person, :role => @member_role if @member_role %> | 3 | <%= link_to _('Affiliate yourself'), :action => 'add_role', :person => current_user.person, :role => @member_role if @member_role %> |
4 | 4 | ||
5 | -<ul> | 5 | +<table> |
6 | + <tr> | ||
7 | + <th><%= _('Member') %></th> | ||
8 | + <th><%= _('Actions') %></th> | ||
9 | + </tr> | ||
6 | <% @members.each do |m| %> | 10 | <% @members.each do |m| %> |
7 | - <li> <%= m.name %> | ||
8 | - <%= link_to _('Edit member role'), :action => 'change_role', :id => m %> | ||
9 | - <%= link_to _('Remove member'), :action => 'unassociate', :id => m %></li> | 11 | + <tr> |
12 | + <td><%= m.name %> </td> | ||
13 | + <td> | ||
14 | + <%= button :edit, _('Edit'), :action => 'change_role', :id => m %> | ||
15 | + <%= button :delete, _('Remove'), :action => 'unassociate', :id => m %> | ||
16 | + </td> | ||
17 | + </tr> | ||
10 | <% end %> | 18 | <% end %> |
11 | -</ul> | 19 | +</table> |
12 | 20 | ||
13 | <%= link_to _('Back'), :controller => 'profile_editor' %> | 21 | <%= link_to _('Back'), :controller => 'profile_editor' %> |
app/views/role/_form.rhtml
@@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
6 | 6 | ||
7 | <%= _('Permissions:') %> <br> | 7 | <%= _('Permissions:') %> <br> |
8 | <% permissions.keys.each do |p| %> | 8 | <% permissions.keys.each do |p| %> |
9 | - <%= labelled_form_field(permission_name(p), (check_box_tag "role[permissions][]", p, @role.has_permission?(p))) %> | 9 | + <%= labelled_check_box(permission_name(p), (check_box_tag "role[permissions][]", p, @role.has_permission?(p))) %> <br/> |
10 | <% end %> | 10 | <% end %> |
11 | 11 | ||
12 | <% button_bar do %> | 12 | <% button_bar do %> |
app/views/role/new.rhtml
1 | <h2> <%= _('New Role') %> </h2> | 1 | <h2> <%= _('New Role') %> </h2> |
2 | 2 | ||
3 | <% ActiveRecord::Base::PERMISSIONS.keys.each do |perm_class| %> | 3 | <% ActiveRecord::Base::PERMISSIONS.keys.each do |perm_class| %> |
4 | - <h3> <%= perm_class %> </h3> | 4 | + <h3> <%= gettext(perm_class.downcase).capitalize %> </h3> |
5 | <%= render :partial => 'form', :locals => { :mode => :new, :permissions => ActiveRecord::Base::PERMISSIONS[perm_class] } %> | 5 | <%= render :partial => 'form', :locals => { :mode => :new, :permissions => ActiveRecord::Base::PERMISSIONS[perm_class] } %> |
6 | <% end %> | 6 | <% end %> |
po/pt_BR/noosfero.po
@@ -10,7 +10,7 @@ msgid "" | @@ -10,7 +10,7 @@ msgid "" | ||
10 | msgstr "" | 10 | msgstr "" |
11 | "Project-Id-Version: noosfero 0.9.0\n" | 11 | "Project-Id-Version: noosfero 0.9.0\n" |
12 | "POT-Creation-Date: 2008-04-29 08:47-0300\n" | 12 | "POT-Creation-Date: 2008-04-29 08:47-0300\n" |
13 | -"PO-Revision-Date: 2008-05-24 13:59-0300\n" | 13 | +"PO-Revision-Date: 2008-05-29 13:04-0300\n" |
14 | "Last-Translator: Joenio Costa <joenio@colivre.coop.br>\n" | 14 | "Last-Translator: Joenio Costa <joenio@colivre.coop.br>\n" |
15 | "Language-Team: \n" | 15 | "Language-Team: \n" |
16 | "MIME-Version: 1.0\n" | 16 | "MIME-Version: 1.0\n" |
@@ -2816,7 +2816,7 @@ msgstr "Permissões" | @@ -2816,7 +2816,7 @@ msgstr "Permissões" | ||
2816 | 2816 | ||
2817 | #: app/views/role/new.rhtml:1 | 2817 | #: app/views/role/new.rhtml:1 |
2818 | msgid "New Role" | 2818 | msgid "New Role" |
2819 | -msgstr "Nova papel" | 2819 | +msgstr "Novo Papel" |
2820 | 2820 | ||
2821 | #: app/views/role/_form.rhtml:7 | 2821 | #: app/views/role/_form.rhtml:7 |
2822 | msgid "Permissions:" | 2822 | msgid "Permissions:" |
test/functional/profile_members_controller_test.rb
@@ -55,6 +55,8 @@ class ProfileMembersControllerTest < Test::Unit::TestCase | @@ -55,6 +55,8 @@ class ProfileMembersControllerTest < Test::Unit::TestCase | ||
55 | assert_response :success | 55 | assert_response :success |
56 | assert_equal member, assigns('member') | 56 | assert_equal member, assigns('member') |
57 | assert_template 'change_role' | 57 | assert_template 'change_role' |
58 | + assert_tag :tag => 'input', :attributes => { :type => 'checkbox', :name => 'roles[]'} | ||
59 | + assert_tag :tag => 'label', :content => role.name | ||
58 | end | 60 | end |
59 | 61 | ||
60 | should 'update roles' do | 62 | should 'update roles' do |
@@ -73,7 +75,5 @@ class ProfileMembersControllerTest < Test::Unit::TestCase | @@ -73,7 +75,5 @@ class ProfileMembersControllerTest < Test::Unit::TestCase | ||
73 | member.reload | 75 | member.reload |
74 | assert member.find_roles(ent).map(&:role).include?(orole) | 76 | assert member.find_roles(ent).map(&:role).include?(orole) |
75 | assert !member.find_roles(ent).map(&:role).include?(role) | 77 | assert !member.find_roles(ent).map(&:role).include?(role) |
76 | - | ||
77 | - | ||
78 | end | 78 | end |
79 | end | 79 | end |
test/functional/search_controller_test.rb
@@ -839,5 +839,4 @@ class SearchControllerTest < Test::Unit::TestCase | @@ -839,5 +839,4 @@ class SearchControllerTest < Test::Unit::TestCase | ||
839 | assert_not_includes assigns(:regions), r2 | 839 | assert_not_includes assigns(:regions), r2 |
840 | assert_no_tag :tag => 'ul', :descendant => { :tag => 'li', :content => r2.name } | 840 | assert_no_tag :tag => 'ul', :descendant => { :tag => 'li', :content => r2.name } |
841 | end | 841 | end |
842 | - | ||
843 | end | 842 | end |
vendor/plugins/access_control/lib/acts_as_accessible.rb
@@ -27,5 +27,11 @@ class ActiveRecord::Base | @@ -27,5 +27,11 @@ class ActiveRecord::Base | ||
27 | def members | 27 | def members |
28 | role_assignments.map(&:accessor).uniq | 28 | role_assignments.map(&:accessor).uniq |
29 | end | 29 | end |
30 | + | ||
31 | + def roles | ||
32 | + Role.find(:all).select do |r| | ||
33 | + r.permissions.any?{ |p| PERMISSIONS[self.class.base_class.name].include?(p) } | ||
34 | + end | ||
35 | + end | ||
30 | end | 36 | end |
31 | end | 37 | end |
vendor/plugins/access_control/lib/role.rb
@@ -10,6 +10,14 @@ class Role < ActiveRecord::Base | @@ -10,6 +10,14 @@ class Role < ActiveRecord::Base | ||
10 | super(*args) | 10 | super(*args) |
11 | end | 11 | end |
12 | 12 | ||
13 | + def key=(value) | ||
14 | + if self[:key] && system | ||
15 | + raise ArgumentError, 'Can\'t change key of system role' | ||
16 | + else | ||
17 | + self[:key] = value | ||
18 | + end | ||
19 | + end | ||
20 | + | ||
13 | def permissions | 21 | def permissions |
14 | self[:permissions] ||= [] | 22 | self[:permissions] ||= [] |
15 | end | 23 | end |
@@ -19,7 +27,7 @@ class Role < ActiveRecord::Base | @@ -19,7 +27,7 @@ class Role < ActiveRecord::Base | ||
19 | end | 27 | end |
20 | 28 | ||
21 | def has_kind?(k) | 29 | def has_kind?(k) |
22 | - permissions.any?{|p| perms[k].keys.include?(p)} | 30 | + perms[k] && permissions.any?{|p| perms[k].keys.include?(p)} |
23 | end | 31 | end |
24 | 32 | ||
25 | def kind | 33 | def kind |
vendor/plugins/access_control/test/role_test.rb
@@ -59,13 +59,11 @@ class RoleTest < Test::Unit::TestCase | @@ -59,13 +59,11 @@ class RoleTest < Test::Unit::TestCase | ||
59 | end | 59 | end |
60 | 60 | ||
61 | def test_should_not_allow_to_remove_system_defined_roles | 61 | def test_should_not_allow_to_remove_system_defined_roles |
62 | - | ||
63 | role = Role.create!(:name => 'not to be removed', :permissions => [], :system => true) | 62 | role = Role.create!(:name => 'not to be removed', :permissions => [], :system => true) |
64 | 63 | ||
65 | count = Role.count | 64 | count = Role.count |
66 | role.destroy | 65 | role.destroy |
67 | assert_equal count, Role.count | 66 | assert_equal count, Role.count |
68 | - | ||
69 | end | 67 | end |
70 | 68 | ||
71 | def test_should_have_an_empty_array_as_permissions_by_default | 69 | def test_should_have_an_empty_array_as_permissions_by_default |
@@ -91,4 +89,13 @@ class RoleTest < Test::Unit::TestCase | @@ -91,4 +89,13 @@ class RoleTest < Test::Unit::TestCase | ||
91 | assert_equal 'another_key', role.key | 89 | assert_equal 'another_key', role.key |
92 | end | 90 | end |
93 | 91 | ||
92 | + def test_should_have_kind | ||
93 | + role = Role.create!(:name => 'a test role', :permissions => ['perm1']) | ||
94 | + role.stubs(:perms).returns({'kind1' => {'perm1' => 'perm1 name', 'perm2' => 'perm2 name'}, 'kind2' => {'perm3' => 'perm3 name'}}) | ||
95 | + | ||
96 | + assert role.has_kind?('kind1') | ||
97 | + assert ! role.has_kind?('kind2') | ||
98 | + assert ! role.has_kind?('kind3') | ||
99 | + end | ||
100 | + | ||
94 | end | 101 | end |