Skip to content

Commit

Permalink
Notify orgs admins (CCO) when membership remove their membership
Browse files Browse the repository at this point in the history
  • Loading branch information
markets committed Dec 29, 2024
1 parent 0b6df07 commit 3d103a1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/controllers/members_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ def destroy
toggle_active_posts
@member.destroy

OrganizationNotifier.member_deleted(@member).deliver_now

redirect_to request.referer.include?(organizations_path) ? organizations_path : manage_users_path
end

Expand Down
14 changes: 13 additions & 1 deletion app/mailers/organization_notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def new_petition(petition)
I18n.with_locale(locale) do
mail(
subject: "New Application - #{organization.name}",
bcc: organization.users.joins(:members).where(members: { manager: true }).pluck(:email).uniq
bcc: organization.all_managers.pluck(:email).uniq
)
end
end
Expand All @@ -34,4 +34,16 @@ def petition_sent(petition)
)
end
end

def member_deleted(member)
@user = member.user
organization = member.organization

I18n.with_locale(locale) do
mail(
subject: "Membership deleted - #{organization.name}",
bcc: organization.all_managers.pluck(:email).uniq
)
end
end
end
8 changes: 6 additions & 2 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@ class Organization < ApplicationRecord
before_validation :ensure_url
after_create :create_account

def to_s
"#{name}"
end

def all_transfers_with_accounts
all_transfers.
includes(movements: { account: :accountable }).
order("transfers.created_at DESC").
distinct
end

def to_s
"#{name}"
def all_managers
users.where(members: { manager: true })
end

def display_name_with_uid
Expand Down
1 change: 1 addition & 0 deletions app/views/organization_notifier/member_deleted.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
User <%= @user.username %> has unsubscribed from the organization.
2 changes: 1 addition & 1 deletion app/views/organizations/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</tr>
</thead>
<tbody>
<%= render partial: 'organizations_row', collection: @user_organizations, as: :org if !params[:page] || params[:page] == '1' %>
<%= render partial: 'organizations_row', collection: @user_organizations, as: :org if @user_organizations.present? %>
<%= render partial: 'organizations_row', collection: @organizations, as: :org %>
</tbody>
</table>
Expand Down

0 comments on commit 3d103a1

Please sign in to comment.