Skip to content

Commit 3d103a1

Browse files
committed
Notify orgs admins (CCO) when membership remove their membership
1 parent 0b6df07 commit 3d103a1

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

app/controllers/members_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ def destroy
66
toggle_active_posts
77
@member.destroy
88

9+
OrganizationNotifier.member_deleted(@member).deliver_now
10+
911
redirect_to request.referer.include?(organizations_path) ? organizations_path : manage_users_path
1012
end
1113

app/mailers/organization_notifier.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def new_petition(petition)
1919
I18n.with_locale(locale) do
2020
mail(
2121
subject: "New Application - #{organization.name}",
22-
bcc: organization.users.joins(:members).where(members: { manager: true }).pluck(:email).uniq
22+
bcc: organization.all_managers.pluck(:email).uniq
2323
)
2424
end
2525
end
@@ -34,4 +34,16 @@ def petition_sent(petition)
3434
)
3535
end
3636
end
37+
38+
def member_deleted(member)
39+
@user = member.user
40+
organization = member.organization
41+
42+
I18n.with_locale(locale) do
43+
mail(
44+
subject: "Membership deleted - #{organization.name}",
45+
bcc: organization.all_managers.pluck(:email).uniq
46+
)
47+
end
48+
end
3749
end

app/models/organization.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,19 @@ class Organization < ApplicationRecord
3333
before_validation :ensure_url
3434
after_create :create_account
3535

36+
def to_s
37+
"#{name}"
38+
end
39+
3640
def all_transfers_with_accounts
3741
all_transfers.
3842
includes(movements: { account: :accountable }).
3943
order("transfers.created_at DESC").
4044
distinct
4145
end
4246

43-
def to_s
44-
"#{name}"
47+
def all_managers
48+
users.where(members: { manager: true })
4549
end
4650

4751
def display_name_with_uid
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
User <%= @user.username %> has unsubscribed from the organization.

app/views/organizations/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
</tr>
3232
</thead>
3333
<tbody>
34-
<%= render partial: 'organizations_row', collection: @user_organizations, as: :org if !params[:page] || params[:page] == '1' %>
34+
<%= render partial: 'organizations_row', collection: @user_organizations, as: :org if @user_organizations.present? %>
3535
<%= render partial: 'organizations_row', collection: @organizations, as: :org %>
3636
</tbody>
3737
</table>

0 commit comments

Comments
 (0)