diff --git a/.ruby-version b/.ruby-version index 005119b..338a5b5 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.4.1 +2.6.6 diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..9f0077e --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +ruby 2.6.6 + diff --git a/Gemfile b/Gemfile index 1b23ea7..2db0345 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -ruby "2.4.1" +ruby "2.6.6" git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") diff --git a/Gemfile.lock b/Gemfile.lock index 9b6fa53..377e3d5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,9 +45,9 @@ GEM addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) arel (8.0.0) - bcrypt (3.1.11) + bcrypt (3.1.13) bindex (0.5.0) - builder (3.2.3) + builder (3.2.4) capybara (2.15.1) addressable mini_mime (>= 0.1.3) @@ -62,26 +62,27 @@ GEM connection_pool (2.2.1) crack (0.4.3) safe_yaml (~> 1.0.0) + crass (1.0.6) dalli (2.7.6) declarative (0.0.9) declarative-option (0.1.0) - devise (4.3.0) + devise (4.7.1) bcrypt (~> 3.0) orm_adapter (~> 0.1) - railties (>= 4.1.0, < 5.2) + railties (>= 4.1.0) responders warden (~> 1.2.3) dig_rb (1.0.1) dotenv (1.0.2) dotenv-rails (1.0.2) dotenv (= 1.0.2) - erubi (1.6.1) + erubi (1.9.0) excon (0.58.0) execjs (2.7.0) faraday (0.13.1) multipart-post (>= 1.2, < 3) ffi (1.9.18) - geocoder (1.4.4) + geocoder (1.6.2) globalid (0.4.0) activesupport (>= 4.2.0) google-api-client (0.13.4) @@ -103,7 +104,8 @@ GEM httparty (0.15.6) multi_xml (>= 0.5.2) httpclient (2.8.3) - i18n (0.8.6) + i18n (0.9.5) + concurrent-ruby (~> 1.0) jbuilder (2.7.0) activesupport (>= 4.2.0) multi_json (>= 1.2) @@ -118,7 +120,8 @@ GEM logging (2.2.2) little-plugger (~> 1.1) multi_json (~> 1.10) - loofah (2.0.3) + loofah (2.5.0) + crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.6.6) mime-types (>= 1.16, < 4) @@ -128,15 +131,15 @@ GEM mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) mini_mime (0.1.4) - mini_portile2 (2.2.0) - minitest (5.10.3) + mini_portile2 (2.4.0) + minitest (5.14.0) msgpack (1.1.0) multi_json (1.12.1) multi_xml (0.6.0) multipart-post (2.0.0) nio4r (2.1.0) - nokogiri (1.8.0) - mini_portile2 (~> 2.2.0) + nokogiri (1.10.9) + mini_portile2 (~> 2.4.0) orm_adapter (0.5.0) os (0.9.6) pg (0.21.0) @@ -146,7 +149,7 @@ GEM slop (~> 3.4) public_suffix (3.0.0) puma (3.10.0) - rack (2.0.3) + rack (2.2.2) rack-cors (0.4.1) rack-test (0.6.3) rack (>= 1.0) @@ -165,15 +168,15 @@ GEM rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.0.3) - loofah (~> 2.0) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) railties (5.1.3) actionpack (= 5.1.3) activesupport (= 5.1.3) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (12.0.0) + rake (13.0.1) rb-fsevent (0.10.2) rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) @@ -183,9 +186,9 @@ GEM declarative (< 0.1.0) declarative-option (< 0.2.0) uber (< 0.2.0) - responders (2.4.0) - actionpack (>= 4.2.0, < 5.3) - railties (>= 4.2.0, < 5.3) + responders (3.0.0) + actionpack (>= 5.0) + railties (>= 5.0) retriable (3.1.1) ruby_dep (1.5.0) rubyzip (1.2.1) @@ -231,10 +234,10 @@ GEM dalli msgpack redis - thor (0.20.0) + thor (1.0.1) thread_safe (0.3.6) tilt (2.0.8) - tzinfo (1.2.3) + tzinfo (1.2.7) thread_safe (~> 0.1) uber (0.1.0) uglifier (3.2.0) @@ -244,8 +247,8 @@ GEM jeff (~> 1.0) multi_xml (~> 0.6.0) vcr (3.0.3) - warden (1.2.7) - rack (>= 1.0) + warden (1.2.8) + rack (>= 2.0.6) web-console (3.5.1) actionview (>= 5.0) activemodel (>= 5.0) @@ -295,7 +298,7 @@ DEPENDENCIES webmock (~> 3.0) RUBY VERSION - ruby 2.4.1p111 + ruby 2.6.6p146 BUNDLED WITH - 1.15.4 + 1.17.2 diff --git a/app/controllers/connect/flagged_markers_controller.rb b/app/controllers/connect/flagged_markers_controller.rb index e2ed3f4..bd60c47 100644 --- a/app/controllers/connect/flagged_markers_controller.rb +++ b/app/controllers/connect/flagged_markers_controller.rb @@ -3,7 +3,6 @@ class Connect::FlaggedMarkersController < ApplicationController helper_method :fields def index - logger.info current_user @flagged_markers = ::Connect::Marker.unresolved.flagged end diff --git a/app/controllers/connect/unresolved_markers_controller.rb b/app/controllers/connect/unresolved_markers_controller.rb new file mode 100644 index 0000000..ad51976 --- /dev/null +++ b/app/controllers/connect/unresolved_markers_controller.rb @@ -0,0 +1,30 @@ +class Connect::UnresolvedMarkersController < ApplicationController + before_action :authenticate_admin! + helper_method :fields + + def index + @unresolved_markers = ::Connect::Marker.unresolved.not_flagged.needs.order(:created_at) + end + + def show + @unresolved_marker = ::Connect::Marker.find(params[:id]) + end + + def update + ::Connect::Marker.find(params[:id]).update!(resolved: true) + logger.info "#{current_user.email} marked marker[#{params[:id]}] as resolved." + redirect_to connect_unresolved_markers_url, notice: 'Marker resolved.' + end + + # def destroy + # ::Connect::Marker.find(params[:id]).clear_inappropriate_flag! + # logger.info "#{current_user.email} cleared marker[#{params[:id]}]." + # redirect_to connect_flagged_markers_url, notice: 'Marker cleared.' + # end + + private + + def fields + %w(created_at name phone address categories) + end +end diff --git a/app/models/connect/marker.rb b/app/models/connect/marker.rb index b162986..3e87915 100644 --- a/app/models/connect/marker.rb +++ b/app/models/connect/marker.rb @@ -15,6 +15,8 @@ class Marker < ApplicationRecord scope :by_category, ->(category) { where('categories ? :category', category: category) } scope :by_device_uuid, ->(device_uuid) { where(device_uuid: device_uuid) } scope :by_type, ->(type) { where(marker_type: type) } + scope :haves, ->() { by_type(MARKER_TYPES.first) } + scope :needs, ->() { by_type(MARKER_TYPES.second) } scope :flagged, ->() { where("data ? 'inappropriate_flag'") } scope :not_flagged, ->() { where.not("data ? 'inappropriate_flag'") } scope :resolved, -> { where(resolved: true) } diff --git a/app/views/connect/unresolved_markers/index.html.erb b/app/views/connect/unresolved_markers/index.html.erb new file mode 100644 index 0000000..a6af0eb --- /dev/null +++ b/app/views/connect/unresolved_markers/index.html.erb @@ -0,0 +1,48 @@ +
+ These are map markers from the Disaster Connect app + that have unresolved needs. +
++ As an admin, you have the ability to mark these needs as resolved. Once a need is marked as + resolved, it will remain hidden from public view and this screen as well. +
+ +| + <% fields.map(&:titleize).each do |header| %> + | <%= header %> | + <% end %> ++ |
|---|---|---|
| <%= link_to 'Show', connect_unresolved_marker_path(row) %> | + <% fields.each do |field| %> +<%= row[field] %> | + <% end %> ++ <%= link_to 'Resolve', connect_unresolved_marker_path(row), + method: :patch, + title: "Mark this need as resolved", + class: "button button-outline" %> + | +
<%= JSON.pretty_generate @unresolved_marker.as_json %>
+ <%= notice %>
<%= alert %>
diff --git a/config/connect_categories.yml b/config/connect_categories.yml index 4bbe2c6..d2b9ab7 100644 --- a/config/connect_categories.yml +++ b/config/connect_categories.yml @@ -1,167 +1,118 @@ default: &default categories: - - labor: - - muck: - - trash: - - clean: - - shop: - - laundry: - - cook: - - sit: - - medical: - - equipment: - - construction: - - power_tools: - - tools: - - water_pump: - - protective_gear: - - generator: - - dehumidifier: - - appliances: - - supplies: - - construction: - - home_repair: - - cleaning_supplies: - - household_items: - - personal_care: - - baby_and_child_care: - - clothes: - - medicine: - - furniture: - - fuel: - - transportation: - - pickup_truck: - - bus_or_van: - - tow_truck: - - boat_motor: - - boat_no_motor: - - car: - - housing: - - family: - - individual: - - pets: - - food: - - ready_to_eat: - - baby_formula: - - drinking_water: - - canned_food: - - dry_foods: - - basic_staples: + - flour: + - 5kg: + - 10kg: + - rice: + - 1kg: + - 2kg: + - 5kg: + - lentil: + - 500g: + - 1kg: + - 2kg: + - 5kg: + - oil: + - 500ml: + - 1L: + - 2L: + - sugar: + - 1kg: + - 2kg: + - 5kg: + - tea_leaves: + - 250g: + - 500g: + - 1kg: + - potato: + - 1kg: + - 2kg: + - 5kg: + - onion: + - 1kg: + - 2kg: + - 5kg: + - milk_powder: + - 200g: + - 500g: + - soap: + - 1qty: + - 2qty: + - 5qty: + - salt: + - 1kg: + - 2kg: + - chilli_powder: + - 200g: + - turmeric: + - 200g: + - coriander_powder: + - 200g: + - garam_masala: + - 200g: icons: - # Category keys that need icons will have their - # corresponding icon key listed here - labor: user-md - equipment: wrench - supplies: shopping-basket - transportation: car - housing: bed - food: cutlery + categories: cutlery en: - categories: I need help with - labor: Labor - muck: Mucking - trash: Hauling Heavy Trash - clean: Cleaning - shop: Shopping - laundry: Laundry - cook: Cooking - sit: Baby Sitting - medical: Healthcare - home_repair: Home Repair - electrician: Electrical Issues - legal: Legal Issues - pest_control: Pest or Animal Control - counselor: Counseling - equipment: Equipment - construction: Construction - power_tools: Power Tools - tools: Tools - water_pump: Water Pumps - protective_gear: Protective Gear - generator: Generators - dehumidifier: Dehumidifiers - appliances: Appliances - other_equipment: Other Equipment - supplies: Supplies - cleaning_supplies: Cleaning Supplies - household_items: Household Items - personal_care: Personal Care - baby_and_child_care: Baby & Child Care - clothes: Clothes - medicine: Medicine - furniture: Furniture - fuel: Fuel - transportation: Transportation - pickup_truck: Pickup Truck - bus_or_van: Bus or Van - tow_truck: Tow Truck - boat_motor: Boat (motor) - boat_no_motor: Boat (no motor) - car: Car - housing: Housing - family: Family Housing - individual: Individual Housing - pets: Pet Housing - food: Food - ready_to_eat: Ready to Eat Food - baby_formula: Baby Formula - drinking_water: Drinking Water - canned_food: Canned Food - dry_foods: Dry Foods - basic_staples: Basic Staples - es: - categories: Necesito ayuda con - labor: Labor - muck: Limpieza - trash: Retirar escombros/basura - clean: Limpiar - shop: Comprar - laundry: Lavar - cook: Cocinar - sit: Cuidar niños - medical: Ayuda medica - home_repair: Reparaciones - electrician: Problemas electricos - legal: Problemas legales - pest_control: Control de animales/pestes - counselor: Terapia - equipment: Equipo - construction: Construccion - power_tools: Herramientas electricas - tools: Herramientas - water_pump: Bomba de agua - protective_gear: Equipo de protección - generator: Generadores - dehumidifier: Deshumidificadores - appliances: Aparatos del hogar - other_equipment: Equipo en general - supplies: Suministros - cleaning_supplies: Suministros de limpieza - household_items: Articulos del hogar - personal_care: Cuidado personal - baby_and_child_care: Cuidado de niños/bebes - clothes: Ropa - medicine: Medicina - furniture: Muebles - fuel: Combustible - transportation: Transportacion - pickup_truck: Camioneta - bus_or_van: Camion - tow_truck: Remolque - boat_motor: Barco (motor) - boat_no_motor: Barco (sin motor) - car: Coche - housing: Hospedaje - family: Hospedaje familiar - individual: Hospedaje individual - pets: Hospedaje para mascotas - food: Alimento - ready_to_eat: Alimentos rapidos - baby_formula: Alimentos para bebe - drinking_water: Agua potable - canned_food: Comida enlatada - dry_foods: Comida seca - basic_staples: Comida basica + categories: Groceries needed + 10kg: 10 kg + 1kg: 1 kg + 1L: 1 L + 1qty: 1 qty + 200g: 200 g + 250g: 250 g + 2kg: 2 kg + 2L: 2 L + 2qty: 2 qty + 500g: 500 g + 500ml: 500 ml + 5kg: 5 kg + 5qty: 5 qty + chilli_powder: Red chilli powder + coriander_powder: Dhaniya (Coriander) powder + flour: Wheat flour + garam_masala: Garam masala + lentil: Lentil + milk_powder: Milk powder + oil: Edible oil + onion: Onion + potato: Potato + rice: Rice + salt: Salt + soap: Soap + sugar: Sugar + tea_leaves: Tea leaves + turmeric: Turmeric + hi: + # These keys need to be translated into Hindi + categories: किराने का सामान की जरूरत + 10kg: 10 किग्रा + 1kg: 1 किग्रा + 1L: 1 ली + 1qty: 1 मात्रा + 200g: 200 ग्रा + 250g: 250 ग्रा + 2kg: 2 किग्रा + 2L: 2 ली + 2qty: 2 मात्रा + 500g: 500 ग्रा + 500ml: 500 मिली + 5kg: 5 किग्रा + 5qty: 5 मात्रा + chilli_powder: लाल मिर्च + coriander_powder: धनिया पाउडर + flour: आटा + garam_masala: गरम मसाला + lentil: दाल + milk_powder: दूध पाउडर + oil: खाद्य तेल + onion: प्याज + potato: आलू + rice: चावल + salt: नमक + soap: साबुन + sugar: शक्कर + tea_leaves: चाय पत्ती + turmeric: हल्दी development: <<: *default diff --git a/config/routes.rb b/config/routes.rb index dfad7b7..9b0c792 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -21,6 +21,7 @@ resources :amazon_products, except: [:new, :create, :destroy] namespace :connect do resources :flagged_markers, only: [:index, :show, :update, :destroy] + resources :unresolved_markers, only: [:index, :show, :update] end root to: "splash#index" diff --git a/test/controllers/connect/unresolved_markers_controller_test.rb b/test/controllers/connect/unresolved_markers_controller_test.rb new file mode 100644 index 0000000..76a4ab7 --- /dev/null +++ b/test/controllers/connect/unresolved_markers_controller_test.rb @@ -0,0 +1,33 @@ +require 'test_helper' + +class UnresolvedMarkersControllerTest < ActionDispatch::IntegrationTest + include Devise::Test::IntegrationHelpers + + fixtures :all + + test "only admins can access index" do + get connect_unresolved_markers_path + assert_redirected_to root_path + sign_in users(:admin) + get connect_unresolved_markers_path + assert_response :success + end + + test "only admins can access show" do + get connect_unresolved_marker_path(connect_markers(:need)) + assert_redirected_to root_path + sign_in users(:admin) + get connect_unresolved_marker_path(connect_markers(:need)) + assert_response :success + end + + test "Can resolve a marker" do + sign_in users(:admin) + marker = connect_markers(:need) + refute(marker.resolved?) + patch connect_unresolved_marker_path(marker) + assert_redirected_to connect_unresolved_markers_path + marker.reload + assert(marker.resolved?) + end +end diff --git a/test/models/connect/marker_test.rb b/test/models/connect/marker_test.rb index 6b6a31e..164b16d 100644 --- a/test/models/connect/marker_test.rb +++ b/test/models/connect/marker_test.rb @@ -97,6 +97,14 @@ def setup assert Connect::Marker.by_type(@marker.marker_type).all? { |m| m.marker_type == @marker.marker_type } end + test 'scope by haves' do + assert Connect::Marker.haves.all? { |m| m.marker_type == 'have' } + end + + test 'scope by needs' do + assert Connect::Marker.needs.all? { |m| m.marker_type == 'need' } + end + test 'scope resolved' do assert Connect::Marker.resolved.all? { |m| m.resolved } end