Commit 17911b99 authored by dgt's avatar dgt

WIP: remove user participations when group membership ends

parent 04f15db5
Pipeline #18180 passed with stage
in 20 minutes and 33 seconds
......@@ -156,6 +156,14 @@ module Group::Users
membership = memberships.find_by_user_id(user.id)
raise ErrorMessage.new('no such membership') unless membership
# removing all participations (makes the stars disappear - not sure
# if we want this)
pages = membership.group.pages_owned
pages.each do |page|
page.users.delete user if page.users.include? user
page.save!
end
user.clear_peer_cache_of_my_peers
membership.destroy
Notice::UserRemovedNotice.create! group: self, user: user
......@@ -169,6 +177,7 @@ module Group::Users
committees.each do |committe|
committe.remove_user!(user) unless committe.users.find_by_id(user.id).blank?
end
end
def open_membership?
......
......@@ -11,7 +11,11 @@ class User::ParticipationPolicy < ApplicationPolicy
elsif participation.user_id == page.owner_id and page.owner_type == 'User'
false
else
user.may_admin_page_without?(page, participation)
# FIXME: this is too restrictive, users should be able to remove
# themselves from pages if they are not page owners (which is
# tested above)
# user.may_admin_page_without?(page, participation)
true
end
end
......
......@@ -397,7 +397,8 @@ en:
group_successfully_created: Group was successfully created.
join_group_confirmation: Are you sure you want to join this %{group_type}?
join_group_link: Join %{group_type}
leave_group_confirmation: Are you sure you want to leave this %{group_type}?
leave_group_confirmation: Are you sure you want to leave this %{group_type}? You will
loose access to all pages owned by this %{group_type}.
leave_group_link: Leave %{group_type}
link_name_description: This name is how you will refer to this group in links and
URLs. It must only contain alphanumeric characters, no spaces allowed.
......
......@@ -88,7 +88,7 @@ en:
group_successfully_created: "Group was successfully created."
join_group_confirmation: "Are you sure you want to join this %{group_type}?"
join_group_link: "Join %{group_type}"
leave_group_confirmation: "Are you sure you want to leave this %{group_type}?"
leave_group_confirmation: "Are you sure you want to leave this %{group_type}? You will loose access to all pages owned by this %{group_type}."
leave_group_link: "Leave %{group_type}"
link_name_description: "This name is how you will refer to this group in links and URLs. It must only contain alphanumeric characters, no spaces allowed."
network_initial_member: "Choose an organization to be an initial member of this network."
......
......@@ -77,4 +77,41 @@ class GroupExpellTest < IntegrationTest
assert_no_content 'animals'
end
end
def test_do_not_list_group_pages_after_expel
# ensure everyone is a longterm member
Time.stub(:now, 2.weeks.from_now) do
@user = users(:blue)
page = create_page(owner: groups(:animals), title: 'animals secrets')
page.add(users(:kangaroo), star: true, access: :admin)
page.save!
login
visit '/animals'
click_on 'Members'
assert first('tr.even').has_content? 'Kangaroo!'
first('tr.even').click_on 'Remove'
logout
@user = users(:penguin)
login
visit '/animals'
click_on 'Members'
click_on 'Request to Remove Member is pending'
click_on 'Approve'
click_on 'Members'
assert_no_content 'Kangaroo!'
logout
@user = users(:kangaroo)
login
visit '/animals'
assert_no_content 'animals secrets'
end
end
protected
def create_page(options = {})
defaults = { title: 'untitled page', public: false }
Page.create(defaults.merge(options))
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment