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

P2P matching & Form #730

Merged
merged 36 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6538209
Add SystemSetting to enable peer-to-peer matching
indiebrain Sep 22, 2020
7c4d225
Add contribution show view
indiebrain Sep 22, 2020
eb3bea3
Create methods to anonymize PII contact info
eabousaif Sep 23, 2020
3c967a7
Add box to show view and modify anonymize method
eabousaif Sep 23, 2020
d9d4e46
Enhance anonymize name method and display info in show page
eabousaif Sep 23, 2020
77edc60
Masks user name
acherukuri Sep 23, 2020
1882769
Adds claim this ask form
acherukuri Sep 23, 2020
ab37473
String interpolate contribution type in button
eabousaif Sep 23, 2020
f692602
View contribution when P2P matching enabled
acherukuri Sep 23, 2020
d6be53c
Renames claim ask routes & form
acherukuri Sep 23, 2020
3cf7a3c
Removes gitignore changes
acherukuri Sep 23, 2020
1d74214
Avoid regex for anonymizing name & email
acherukuri Sep 23, 2020
bb1c2e8
Creates person record if absent
acherukuri Sep 24, 2020
16e9f33
Does null check for person contact method
acherukuri Sep 24, 2020
fc97485
Sends P2P email & logs communication
acherukuri Sep 24, 2020
0e60800
Updates contribution state & hides the claim button if matched
acherukuri Sep 24, 2020
91b07ce
Adds TODO for handling match race condition
acherukuri Sep 24, 2020
9f79a66
Includes user message in the email
acherukuri Sep 24, 2020
69e6b6f
Minor fix to button
eabousaif Sep 24, 2020
006a0ea
Minor button fix
eabousaif Sep 24, 2020
4dee09a
Refactors contributions controller
acherukuri Sep 24, 2020
8ffb5fb
Adds an alert if the contribution has no email
acherukuri Sep 24, 2020
2337e58
Revert "Add SystemSetting to enable peer-to-peer matching"
acherukuri Sep 24, 2020
ce12d1d
Uses P2P exchange type setting
acherukuri Sep 24, 2020
22de765
Extracts claim logic to nested resource
acherukuri Sep 24, 2020
4eff8d5
Reverts mailcatcher settings in dev ENV
acherukuri Sep 24, 2020
5e3747c
Fixes indentation in P2P mailer
acherukuri Sep 24, 2020
ac5c9a2
Renames contributions helper to claims helper
acherukuri Sep 24, 2020
a6abc95
Removes unnecessary safe nav operators
acherukuri Sep 24, 2020
0e5fc04
Uses keyword args for alias & message in P2P mailer
acherukuri Sep 25, 2020
a0bb4e8
Extract anonymize name & email logic to Util class
acherukuri Sep 25, 2020
0ca77df
Uses keyword args for create person from P2P params method
acherukuri Sep 25, 2020
26b0e59
Address comments from https://github.com/rubyforgood/mutual-aid/pull/…
acherukuri Sep 25, 2020
82ae80e
Prefer model method, controller logic over helper module
solebared Sep 25, 2020
bab988e
Restricts preferred contact to just email for now
acherukuri Sep 25, 2020
f7774ce
Saves person email if absent in system
acherukuri Sep 25, 2020
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ yarn-debug.log*

# Ignore vim swapfiles
# .*.swp

vendor/bundle
eabousaif marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions app/blueprints/contribution_blueprint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class ContributionBlueprint < Blueprinter::Base
field :respond_path do |contribution, options|
options[:respond_path]&.call(contribution.id)
end
field :view_path do |contribution, options|
options[:view_path]&.call(contribution.id)
end
field :match_path do |contribution, options|
options[:match_path]&.call(contribution.id)
end
Expand Down
20 changes: 20 additions & 0 deletions app/controllers/contributions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ def index
end
end

def show
contribution = Listing.find(params[:id])

render(
:show,
locals: {
contribution: contribution,
}
)
end

def claim_ask_form
contribution_id = params[:id]
render locals: { contribution_id: contribution_id }
end
eabousaif marked this conversation as resolved.
Show resolved Hide resolved

def claim_ask
eabousaif marked this conversation as resolved.
Show resolved Hide resolved
redirect_to contribution_path(params[:id])
eabousaif marked this conversation as resolved.
Show resolved Hide resolved
end

def combined_form
end

Expand Down
1 change: 1 addition & 0 deletions app/controllers/system_settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def set_primary_organization

def system_setting_params
params.require(:system_setting).permit(
:allow_peer_to_peer_matching,
:allow_sms,
:exchange_type,
:separate_asks_offers,
Expand Down
4 changes: 4 additions & 0 deletions app/javascript/pages/browse/TileListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
<div class="buttonSpacing" v-if="respond_path">
<a :href="respond_path" class="button icon-list is-primary"><span class=""> Respond</span></a>
</div>
<div class="buttonSpacing" v-if="view_path">
<a :href="view_path" class="button icon-list is-primary"><span class=""> View</span></a>
</div>
</div>
</li>
</template>
Expand All @@ -59,6 +62,7 @@ export default {
contact_types: {type: Array, default: () => []},
profile_path: String,
respond_path: String,
view_path: String,
match_path: String
},
components: {
Expand Down
5 changes: 4 additions & 1 deletion app/models/browse_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ def contributions
def options
return {} unless context

{ respond_path: ->(id) { context.respond_contribution_path(id)} }
{
respond_path: ->(id) { context.respond_contribution_path(id)},
view_path: ->(id) { context.contribution_path(id)}
eabousaif marked this conversation as resolved.
Show resolved Hide resolved
}
end

private
Expand Down
13 changes: 13 additions & 0 deletions app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ def offer_tag_list
offers.any? ? offers&.map(&:all_tags_unique) : []
end

def anonymize_email
person_email = email.gsub!(/\A(.).*@.*(.)\z/, '\1******@******\2')
end

def anonymize_name
person_name = name.split(" ")
person_name.map do |name|
initial = name[0]
name = '*' * name.length
initial + name[1..-1]
end.join(" ")
end

private def preferred_contact_method_present!
return unless preferred_contact_method
field = preferred_contact_method.field
Expand Down
2 changes: 2 additions & 0 deletions app/models/system_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def peer_to_peer?
#
# id :bigint not null, primary key
# about_us_text :text
# allow_peer_to_peer_matching :boolean default(FALSE), not null
# allow_sms :boolean default(FALSE), not null
# announcements_module :boolean default(TRUE), not null
# chat_module :boolean default(TRUE), not null
Expand All @@ -69,6 +70,7 @@ def peer_to_peer?
# confirmation_page_text_footer :string
# confirmation_page_text_header :string
# confirmation_page_text_link_header :string
# display_navbar :boolean default(FALSE)
# donations_module :boolean default(TRUE), not null
# exchange_type :string default("peer_to_peer"), not null
# landing_page_text_how :text
Expand Down
20 changes: 20 additions & 0 deletions app/views/contributions/claim_ask_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<section>
<h1 class="title">Claim This Ask</h1>
<div class="box">
<p class="mb-2">
Information you enter here will be delivered directly to the other party.
Remember to protect yourself and never provide sensitive personal info to
strangers.
</p>

<%= simple_form_for :peer_to_peer_match, url: claim_ask_contribution_path(contribution_id) do |f| %>
<%= f.input :provider_alias, as: :string, label: false, placeholder: "Alias or handle (do not use your real name here)" %>
<%= f.input :preferred_contact_method, collection: ContactMethod.pluck(:name, :id), label: "Contact Method" %>
<%= f.input :message, as: :text, placeholder: "Add some introductory text here. We do not share your contact information
with the other party. Please only share information that you are comfortable
sharing to facilitate this conversation.".squish %>
<%= f.button :submit, "I understand, let's go!", class: "is-primary" %>
<% end %>
</div>
<%= link_to "<i class=\"fas fa-arrow-left\"></i> Nevermind, I'm not ready".html_safe, :back %>
</section>
11 changes: 11 additions & 0 deletions app/views/contributions/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<section class="section">
<h2>Request for Contribution</h2>
<h1 class="title"><%= contribution.type %>: <%= contribution.all_tags_unique.map(&:humanize).join(", ") %></h1>
solebared marked this conversation as resolved.
Show resolved Hide resolved
<br>
<div class="box">
<p><strong><%= contribution.person.anonymize_name %></strong> - <%= contribution.person.anonymize_email %></p>
<p class="subtitle"><%= contribution.description %></p>
<%= button_to "Claim this Ask", claim_ask_form_contribution_path(contribution), class: "button is-primary", method: :get %>
eabousaif marked this conversation as resolved.
Show resolved Hide resolved
</div>
<%= link_to "<i class=\"fas fa-arrow-left\"></i> View Contributions".html_safe, contributions_path %>
</section>
1 change: 1 addition & 0 deletions app/views/system_settings/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<div class="form-inputs">
<%= f.input :exchange_type, as: :select, collection: @exchange_types %>
<%= f.input :separate_asks_offers, as: :radio_buttons, label: "Separate ask and offer forms" %>
<%= f.input :allow_peer_to_peer_matching, as: :radio_buttons %>
solebared marked this conversation as resolved.
Show resolved Hide resolved
<%= f.input :allow_sms, as: :radio_buttons %>
<%= f.input :display_navbar, as: :radio_buttons, hint: "Display the navbar on the Community Resources and Annoucements pages" %>
<%= f.input :community_resources_module, as: :radio_buttons %>
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
resources :contact_methods
get "/combined_form", to: "contributions#combined_form", as: "combined_form"
get "/thank_you", to: "contributions#thank_you", as: "contribution_thank_you"
resources :contributions, only: [:index] do
resources :contributions, only: [:index, :show] do
member do
get "/respond", to: "contributions#respond", as: "respond"
get "/triage", to: "contributions#triage", as: "triage"
patch "/triage", to: "contributions#triage_update"
post "/triage", to: "contributions#triage_update"
post :claim_ask
get :claim_ask_form
end
end
resources :custom_form_questions
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20200922151556_add_peer_to_peer_matching.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPeerToPeerMatching < ActiveRecord::Migration[6.0]
def change
add_column :system_settings, :allow_peer_to_peer_matching, :boolean, null: false, default: false
end
end
solebared marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_09_06_172102) do
ActiveRecord::Schema.define(version: 2020_09_22_151556) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -446,6 +446,7 @@
t.string "confirmation_page_text_link_header"
t.string "confirmation_page_text_footer"
t.boolean "display_navbar", default: false
t.boolean "allow_peer_to_peer_matching", default: false, null: false
end

create_table "taggings", id: :serial, force: :cascade do |t|
Expand Down
1 change: 1 addition & 0 deletions spec/blueprints/contribution_blueprint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
# "publish_until_humanized" => "this year",
"created_at" => (contribution.created_at.to_f * 1000), # Javascript wants miliseconds, not seconds
'respond_path' => nil,
'view_path' => nil,
'profile_path' => nil,
'match_path' => nil,
"service_area" => {"id" => contribution.service_area.id, "name" => expected_area_name},
Expand Down
2 changes: 2 additions & 0 deletions spec/factories/system_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#
# id :bigint not null, primary key
# about_us_text :text
# allow_peer_to_peer_matching :boolean default(FALSE), not null
# allow_sms :boolean default(FALSE), not null
# announcements_module :boolean default(TRUE), not null
# chat_module :boolean default(TRUE), not null
Expand All @@ -17,6 +18,7 @@
# confirmation_page_text_footer :string
# confirmation_page_text_header :string
# confirmation_page_text_link_header :string
# display_navbar :boolean default(FALSE)
# donations_module :boolean default(TRUE), not null
# exchange_type :string default("peer_to_peer"), not null
# landing_page_text_how :text
Expand Down
12 changes: 12 additions & 0 deletions spec/requests/contributions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,16 @@
expect(response_ids).not_to include(no_tags_correct_area_listing.id)
end
end

describe "GET /contributions/:id" do
it "is successful" do
contribution = create(:listing)

get(
contribution_url(contribution),
)

expect(response).to be_successful
end
end
end