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

Draft
wants to merge 11 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/admin/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
column :posts do |organization|
organization.posts.count
end
column :highlighted
actions
end

Expand All @@ -37,6 +38,7 @@

form do |f|
f.inputs do
f.input :highlighted, hint: "Highlighted Time Banks will appear first"
f.input :name
f.input :email
f.input :web
Expand Down Expand Up @@ -71,7 +73,8 @@ def destroy
filter :neighborhood
filter :created_at
filter :updated_at
filter :highlighted

permit_params :name, :email, :web, :phone, :city, :neighborhood,
:address, :description, :public_opening_times, :logo
:address, :description, :public_opening_times, :logo, :highlighted
end
13 changes: 12 additions & 1 deletion app/admin/petition.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
ActiveAdmin.register Petition do
actions :index
actions :index, :destroy

controller do
def destroy
if resource.accepted?
redirect_to admin_petitions_path, alert: "ACCEPTED petitions can't be deleted"
else
super
end
end
end

index do
id_column
Expand All @@ -9,6 +19,7 @@
column :status do |petition|
petition.status.upcase
end
actions
end

filter :organization
Expand Down
4 changes: 4 additions & 0 deletions app/admin/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
redirect_to action: :index
end

scope :all
scope :without_memberships

index do
selectable_column
column do |user|
Expand All @@ -29,6 +32,7 @@
column :posts do |u|
u.posts.count
end
column :created_at
actions
end

Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ ul.statistics li{
padding-left: 1.5rem;
}

.alert a {
text-decoration: underline;
}

// fields that contain an error
.field_with_errors{
color: red;
Expand Down
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

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

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def index

organizations = Organization.where.not(id: @user_organizations&.pluck(:id))
organizations = organizations.search_by_query(params[:q]) if params[:q].present?
@organizations = organizations.page(params[:page]).per(25)
@organizations = organizations.order(highlighted: :desc).page(params[:page]).per(25)
end

def show
Expand Down
7 changes: 3 additions & 4 deletions app/controllers/petitions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ class PetitionsController < ApplicationController

def create
petition = Petition.new petition_params
petition.status = "pending"

if petition.save
OrganizationNotifier.new_petition(petition).deliver_now
OrganizationNotifier.petition_sent(petition).deliver_now

flash[:notice] = t('petitions.application_status', status: t("petitions.status.sent"))
else
flash[:error] = t('errors.internal_server_error.description')
flash[:error] = petition.errors.full_messages.to_sentence
end

redirect_back fallback_location: organization_path(petition.organization)
Expand All @@ -25,14 +24,14 @@ def update
petition.user.add_to_organization(petition.organization) if status == 'accepted'
flash[:notice] = t('petitions.application_status', status: t("petitions.status.#{status}"))
else
flash[:error] = t('errors.internal_server_error.description')
flash[:error] = petition.errors.full_messages.to_sentence
end

redirect_to manage_petitions_path
end

def manage
@status = params[:status] || 'pending'
@status = params[:status] || Petition::DEFAULT_STATUS
@users = User.joins(:petitions).where(petitions: { organization_id: current_organization.id, status: @status }).page(params[:page]).per(20)
end

Expand Down
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,8 @@ def alert_class(alert)
'alert-info'
end
end

def show_no_membership_warning?
current_user && !current_user.memberships? && !devise_controller?
end
end
22 changes: 18 additions & 4 deletions app/mailers/organization_notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,37 @@ def recent_posts(posts, locale, users)
def new_petition(petition)
@user = petition.user
organization = petition.organization
org_managers = organization.all_managers

I18n.with_locale(locale) do
I18n.with_locale(org_managers.first&.locale) do
mail(
subject: 'New Application',
bcc: organization.users.joins(:members).where(members: { manager: true }).pluck(:email).uniq
subject: "New Application - #{organization.name}",
bcc: org_managers.pluck(:email).uniq
)
end
end

def petition_sent(petition)
@organization_name = petition.organization.name

I18n.with_locale(locale) do
I18n.with_locale(petition.user.locale) do
mail(
subject: 'Application sent correctly',
to: petition.user.email
)
end
end

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

I18n.with_locale(org_managers.first&.locale) do
mail(
subject: "Membership deleted - #{organization.name}",
bcc: org_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
6 changes: 5 additions & 1 deletion app/models/petition.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
class Petition < ApplicationRecord
enum status: %i[pending accepted declined]
DEFAULT_STATUS = "pending"

enum status: %i[pending accepted declined], _default: DEFAULT_STATUS

belongs_to :user
belongs_to :organization

validates :user_id, uniqueness: { scope: :organization_id }
end
5 changes: 5 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class User < ApplicationRecord
accepts_nested_attributes_for :members, allow_destroy: true

default_scope { order("users.id ASC") }
scope :without_memberships, -> { where.missing(:members) }
scope :actives, -> { joins(:members).where(members: { active: true }) }
scope :online_active, -> { where("sign_in_count > 0") }
scope :notifications, -> { where(notifications: true) }
Expand Down Expand Up @@ -93,6 +94,10 @@ def active?(organization)
organization && !!(as_member_of(organization).try :active)
end

def memberships?
members.any?
end

def member(organization)
members.where(organization_id: organization).first
end
Expand Down
2 changes: 2 additions & 0 deletions app/services/push_notifications/broadcast.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "net/http"

module PushNotifications
class Broadcast
class PostError < ::StandardError; end
Expand Down
3 changes: 3 additions & 0 deletions app/views/application/_no_membership_warning.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="alert alert-info">
<%= t('layouts.application.no_memberhsip_warning', link: organizations_path).html_safe %>
</div>
2 changes: 1 addition & 1 deletion app/views/devise/confirmations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="panel-body">
<h2><%= t(".resend_instructions") %></h2>
<p class="description"><%= t(".resend_instructions_description") %></p>
<%= render 'layouts/messages' %>
<%= render 'application/flash_messages' %>
<%= show_error_messages!(resource) %>
<%= form_for resource, url: confirmation_path(resource_name), html: { method: :post } do |f| %>
<div class="form-group">
Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/passwords/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="panel" id="login-box">
<div class="panel-body">
<h2><%= t(".change_password") %></h2>
<%= render 'layouts/messages' %>
<%= render 'application/flash_messages' %>
<%= show_error_messages!(resource) %>
<%= form_for resource, url: password_path(resource_name), html: { method: :put } do |f| %>
<%= f.hidden_field :reset_password_token %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/passwords/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="panel-body">
<h2><%= t(".forgot_question") %></h2>
<p class="description"><%= t(".forgot_question_description") %></p>
<%= render 'layouts/messages' %>
<%= render 'application/flash_messages' %>
<%= show_error_messages!(resource) %>
<%= form_for resource, url: password_path(resource_name), html: { method: :post } do |f| %>
<div class="form-group">
Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="col-xs-12 col-sm-8 col-md-6 col-lg-6 col-sm-offset-2 col-md-offset-3 col-lg-offset-3">
<div class="panel" id="login-box">
<div class="panel-body">
<%= render 'layouts/messages' %>
<%= render 'application/flash_messages' %>
<%= show_error_messages!(resource) %>
<%= form_for resource, url: session_path(resource_name) do |f| %>
<div class="form-group">
Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/unlocks/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="panel-body">
<h2><%= t(".resend_instructions") %></h2>
<p class="description"><%= t(".resend_instructions_description") %></p>
<%= render 'layouts/messages' %>
<%= render 'application/flash_messages' %>
<%= show_error_messages!(resource) %>
<%= form_for resource, url: unlock_path(resource_name), html: { method: :post } do |f| %>
<div class="form-group">
Expand Down
3 changes: 2 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
<body class="<%= get_body_css_class(controller_name) %>">
<%= render 'navbar' %>
<div class="container content">
<%= render 'layouts/messages' unless devise_controller? %>
<%= render 'application/flash_messages' unless devise_controller? %>
<div class="container-fluid">
<%= render 'application/no_membership_warning' if show_no_membership_warning? %>
<%= yield %>
</div>
<%= organization_logo %>
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 @@
<%= t("organization_notifier.member_deleted.body", user: @user.username) %>
9 changes: 6 additions & 3 deletions config/locales/ca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ ca:
help: Ajuda
login: Entra
manage_memberships: Gestiona membres
no_memberhsip_warning: Recordeu als usuaris sense membresia (15 dies després de registrar-se) que han de sol·licitar membresia a <a href="%{link}">alguna organització</a>, o l'usuari serà eliminat quan porti 1 mes a la plataforma sense cap membresia.
report:
report_title: INFORME
locales:
Expand Down Expand Up @@ -370,6 +371,8 @@ ca:
give_time_for: Transferir temps per aquesta oferta
offered_by: Oferents
organization_notifier:
member_deleted:
body: L'usuari %{username} s'ha donat de baixa de l'organització.
recent_posts:
subject: Butlletí setmanal
text1: 'Últimas ofertas publicadas:'
Expand All @@ -393,8 +396,8 @@ ca:
banner-title: Ets un Banc de Temps?
empower-adbdt: ADBdT
empower-adbdt-title: Associació pel Desenvolupament dels Bancs de Temps
empower-coopdevs: CoopDevs
empower-coopdevs-title: CoopDevs
empower-coopdevs: Coopdevs
empower-coopdevs-title: Coopdevs
empower-github: Github
empower-github-title: Github
empower-showmap: veure mapa
Expand All @@ -417,7 +420,7 @@ ca:
title2: als Bancs de Temps
petitions:
application_sent: Sol·licitud enviada correctament
application_sent_body: Hola! La teva sol·licitud a %{organization_name} s'ha enviat correctament.
application_sent_body: Hola! La teva sol·licitud a %{organization_name} s'ha enviat correctament. Algú de l'equip del banc de temps es posarà en contacte amb tu per finalitzar el procés dalta.
application_status: Sol·licitud %{status}
applications: Sol·licituds
apply: Sol·licita unir-te
Expand Down
7 changes: 5 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ en:
help: Help
login: Login
manage_memberships: Manage memberships
no_memberhsip_warning: Remember users without membership (15 days after register) they should ask for membership in <a href="%{link}">some Organization</a> or the user will be deleted when user have 1 month on the platform without any membership.
report:
report_title: REPORT
locales:
Expand Down Expand Up @@ -370,6 +371,8 @@ en:
give_time_for: Time transfer for this offer
offered_by: Offered by
organization_notifier:
member_deleted:
body: User %{username} has unsubscribed from the organization.
recent_posts:
subject: Newsletter
text1: 'Latest offers published:'
Expand All @@ -393,8 +396,8 @@ en:
banner-title: Are you a Time Bank?
empower-adbdt: ADBdT
empower-adbdt-title: Association for the Development of Time Banks
empower-coopdevs: CoopDevs
empower-coopdevs-title: CoopDevs
empower-coopdevs: Coopdevs
empower-coopdevs-title: Coopdevs
empower-github: Github
empower-github-title: Github
empower-showmap: see map
Expand Down
Loading
Loading