Commit f688afe0c4746433a8d54ff84587ae99a5aa7b3b
1 parent
90f24f9a
Exists in
master
and in
29 other branches
ActionItem568: owner can destroy community
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2295 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
6 changed files
with
87 additions
and
4 deletions
Show diff stats
app/controllers/my_profile/memberships_controller.rb
| ... | ... | @@ -33,4 +33,14 @@ class MembershipsController < MyProfileController |
| 33 | 33 | end |
| 34 | 34 | end |
| 35 | 35 | |
| 36 | + def destroy_community | |
| 37 | + @community = Community.find(params[:id]) | |
| 38 | + if request.post? | |
| 39 | + if @community.destroy | |
| 40 | + flash[:notice] = _('%s was destroyed!') % @community.display_name | |
| 41 | + redirect_to :action => 'index' | |
| 42 | + end | |
| 43 | + end | |
| 44 | + end | |
| 45 | + | |
| 36 | 46 | end | ... | ... |
| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | +<h1><%= _('Destroy %s') % @community.display_name %></h1> | |
| 2 | + | |
| 3 | +<p><strong><%= _('Are you sure you want to destroy %s?') % @community.display_name %></strong></p> | |
| 4 | + | |
| 5 | +<% form_tag do %> | |
| 6 | + <%= hidden_field_tag(:confirmation, 1) %> | |
| 7 | + <%= submit_button(:ok, _("Yes, I want to destroy.") % @community.display_name) %> | |
| 8 | + <%= button(:cancel, _("No, I don't want."), :action => 'index') %> | |
| 9 | +<% end %> | ... | ... |
app/views/memberships/index.rhtml
| ... | ... | @@ -12,13 +12,13 @@ |
| 12 | 12 | <strong><%= membership.display_name %></strong><br/> |
| 13 | 13 | <%= _('Role: %s') % rolename_for(profile, membership) %> <br/> |
| 14 | 14 | <%= _('Type: %s') % _(membership.class.name) %> <br/> |
| 15 | - <%= _('Description: %s') % membership.description + '<br/>' if membership.kind_of?(Community) %> | |
| 15 | + <%= _('Description: %s') % membership.description + '<br/>' if membership.community? %> | |
| 16 | 16 | <%= _('Members: %s') % membership.members.size.to_s %> <br/> |
| 17 | 17 | <%= _('Created at: %s') % show_date(membership.created_at) %> <br/> |
| 18 | 18 | <%= [ link_to(_('Manage'), membership.admin_url), |
| 19 | - link_to(_('Leave'), { :profile => profile.identifier, :controller => 'memberships', :action => 'leave', :id => membership.id }), | |
| 20 | - link_to(_('Destroy'), { :profile => profile.identifier, :controller => 'memberships', :action => 'destroy', :id => membership.id }) | |
| 21 | - ].join(', ') | |
| 19 | + link_to(_('Leave'), { :profile => profile.identifier, :controller => 'memberships', :action => 'leave', :id => membership }), | |
| 20 | + (membership.community? && user.has_permission?(:destroy_profile, membership) ? link_to(_('Destroy'), { :action => 'destroy_community', :id => membership }) : nil) | |
| 21 | + ].compact.join(', ') | |
| 22 | 22 | %> |
| 23 | 23 | </span> |
| 24 | 24 | </li> | ... | ... |
test/fixtures/roles.yml
test/functional/memberships_controller_test.rb
| ... | ... | @@ -171,4 +171,48 @@ class MembershipsControllerTest < Test::Unit::TestCase |
| 171 | 171 | assert_tag :tag => 'a', :content => 'Register a new Enterprise' |
| 172 | 172 | end |
| 173 | 173 | |
| 174 | + should 'render destroy_community template' do | |
| 175 | + community = Community.create!(:name => 'A community to destroy') | |
| 176 | + get :destroy_community, :profile => 'testuser', :id => community.id | |
| 177 | + assert_template 'destroy_community' | |
| 178 | + end | |
| 179 | + | |
| 180 | + should 'display destroy link only to communities' do | |
| 181 | + community = Community.create!(:name => 'A community to destroy') | |
| 182 | + enterprise = Enterprise.create!(:name => 'A enterprise test', :identifier => 'enterprise-test') | |
| 183 | + | |
| 184 | + person = Person['testuser'] | |
| 185 | + community.add_admin(person) | |
| 186 | + enterprise.add_admin(person) | |
| 187 | + | |
| 188 | + get :index, :profile => 'testuser' | |
| 189 | + | |
| 190 | + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testuser/memberships/destroy_community/#{community.id}" } | |
| 191 | + assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/testuser/memberships/destroy_community/#{enterprise.id}" } | |
| 192 | + end | |
| 193 | + | |
| 194 | + should 'be able to destroy communities' do | |
| 195 | + community = Community.create!(:name => 'A community to destroy') | |
| 196 | + | |
| 197 | + person = Person['testuser'] | |
| 198 | + community.add_admin(person) | |
| 199 | + | |
| 200 | + assert_difference Community, :count, -1 do | |
| 201 | + post :destroy_community, :profile => 'testuser', :id => community.id | |
| 202 | + end | |
| 203 | + end | |
| 204 | + | |
| 205 | + should 'not display destroy link to normal members' do | |
| 206 | + community = Community.create!(:name => 'A community to destroy') | |
| 207 | + | |
| 208 | + person = Person['testuser'] | |
| 209 | + community.add_member(person) | |
| 210 | + | |
| 211 | + login_as('testuser') | |
| 212 | + get :index, :profile => 'testuser' | |
| 213 | + | |
| 214 | + assert_template 'index' | |
| 215 | + assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/testuser/memberships/destroy_community/#{community.id}" } | |
| 216 | + end | |
| 217 | + | |
| 174 | 218 | end | ... | ... |
test/unit/community_test.rb
| ... | ... | @@ -64,4 +64,23 @@ class CommunityTest < Test::Unit::TestCase |
| 64 | 64 | assert_not_includes c.members, p |
| 65 | 65 | end |
| 66 | 66 | |
| 67 | + should 'clear relationships after destroy' do | |
| 68 | + c = Community.create!(:name => 'my test profile', :identifier => 'mytestprofile') | |
| 69 | + member = create_user('memberuser').person | |
| 70 | + admin = create_user('adminuser').person | |
| 71 | + moderator = create_user('moderatoruser').person | |
| 72 | + | |
| 73 | + c.add_member(member) | |
| 74 | + c.add_admin(admin) | |
| 75 | + c.add_moderator(moderator) | |
| 76 | + | |
| 77 | + relationships = c.role_assignments | |
| 78 | + assert_not_nil relationships | |
| 79 | + | |
| 80 | + c.destroy | |
| 81 | + relationships.each do |i| | |
| 82 | + assert !RoleAssignment.exists?(i.id) | |
| 83 | + end | |
| 84 | + end | |
| 85 | + | |
| 67 | 86 | end | ... | ... |