Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impove Onboarding / Membership management process #771

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def after_sign_in_path_for(user)
elsif user.members.present?
users_path
else
page_path("about")
organizations_path
end
end

Expand Down
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why deliver_now instead of deliver_later?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right! I just copy-pasted the same workflow we are already using for emails, but I think this is probably something from the past. I'll move all email delivery to the background queues.


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

Expand Down
16 changes: 14 additions & 2 deletions app/mailers/organization_notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def new_petition(petition)

I18n.with_locale(locale) do
mail(
subject: 'New Application',
bcc: organization.users.joins(:members).where(members: { manager: true }).pluck(:email).uniq
subject: "New Application - #{organization.name}",
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? %>
markets marked this conversation as resolved.
Show resolved Hide resolved
<%= render partial: 'organizations_row', collection: @organizations, as: :org %>
</tbody>
</table>
Expand Down
Loading