mirror of
https://github.com/System-End/theseus.git
synced 2026-04-19 16:38:18 +00:00
add opt-out from anonymous map (#149)
* add field & ui for map opt out * no opters out in map data gen
This commit is contained in:
parent
a58bc715c0
commit
5da418169d
7 changed files with 58 additions and 11 deletions
14
app/controllers/public/settings_controller.rb
Normal file
14
app/controllers/public/settings_controller.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
module Public
|
||||
class SettingsController < ApplicationController
|
||||
before_action :authenticate_public_user!
|
||||
|
||||
def anonymous_map
|
||||
end
|
||||
|
||||
def update_anonymous_map
|
||||
current_public_user.update!(opted_out_of_map: params[:opt] == "out")
|
||||
flash[:success] = "k, pls wait for the map to recache itself"
|
||||
redirect_to anonymous_map_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -10,13 +10,14 @@ class Public::UpdateMapDataJob < ApplicationJob
|
|||
private
|
||||
|
||||
def fetch_recent_letters_data
|
||||
# Get mailed letters (any time) and letters received in the last 7 days
|
||||
the_paranoid_few = Public::User.where(opted_out_of_map: true).pluck(:email)
|
||||
recent_letters = Letter.joins(:address, :return_address)
|
||||
.where(
|
||||
"aasm_state = 'mailed' OR (aasm_state = 'received' AND received_at >= ?)",
|
||||
7.days.ago
|
||||
)
|
||||
.includes(:iv_mtr_events, :address, :return_address)
|
||||
.where(
|
||||
"aasm_state = 'mailed' OR (aasm_state = 'received' AND received_at >= ?)",
|
||||
7.days.ago
|
||||
)
|
||||
.includes(:iv_mtr_events, :address, :return_address)
|
||||
.where.not(recipient_email: the_paranoid_few)
|
||||
|
||||
letters_data = recent_letters.map do |letter|
|
||||
event_coords = build_letter_event_coordinates(letter)
|
||||
|
|
|
|||
|
|
@ -2,10 +2,11 @@
|
|||
#
|
||||
# Table name: public_users
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# email :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# id :bigint not null, primary key
|
||||
# email :string
|
||||
# opted_out_of_map :boolean default(FALSE)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
class Public::User < ApplicationRecord
|
||||
has_many :login_codes
|
||||
|
|
|
|||
22
app/views/public/settings/anonymous_map.html.erb
Normal file
22
app/views/public/settings/anonymous_map.html.erb
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<% oo = current_public_user.opted_out_of_map? %>
|
||||
<div class="window" style="width: 320px">
|
||||
<div class="title-bar">
|
||||
<div class="title-bar-text">Opt in or out of the anonymous map</div>
|
||||
<div class="title-bar-controls">
|
||||
<%= w95_title_button_to("Close", public_root_path) %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="window-body">
|
||||
<%= form_with url: update_anonymous_map_path, data: {turbo: false} do |form| %>
|
||||
Your letters currently <b><%= oo ? "don't" : "do" %></b> show up on the anonymous <%= link_to "letter map", map_path %>. <br/>
|
||||
<%= oo ? "They wouldn't be" : "They're not" %> associated with your identity in any way, and the displayed coordinates <%= oo ? "would be" : "are" %> offset from your actual location. <br/> <br/>
|
||||
<% if current_public_user.opted_out_of_map? %>
|
||||
<%= hidden_field_tag :opt, "in" %>
|
||||
<%= form.submit "actually, on second thought i'm cool with that" %>
|
||||
<% else %>
|
||||
<%= hidden_field_tag :opt, "out" %>
|
||||
<%= form.submit "don't show my approximate location in aggregate please" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -602,6 +602,9 @@ Rails.application.routes.draw do
|
|||
get "/lsv/msr/:id/customs_receipt", to: "public/lsv#customs_receipt", as: :msr_customs_receipt
|
||||
post "/lsv/msr/:id/customs_receipt", to: "public/lsv#generate_customs_receipt", as: :msr_generate_customs_receipt
|
||||
|
||||
get "/settings/anonymous_map", to: "public/settings#anonymous_map", as: :anonymous_map
|
||||
post "/settings/anonymous_map", to: "public/settings#update_anonymous_map", as: :update_anonymous_map
|
||||
|
||||
get "/packages/:id/customs_receipt", to: "public/packages#customs_receipt", as: :package_customs_receipt
|
||||
post "/packages/:id/customs_receipt", to: "public/packages#generate_customs_receipt", as: :package_generate_customs_receipt
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
class AddMapOptoutToPublicUsers < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
add_column :public_users, :opted_out_of_map, :boolean, default: false
|
||||
end
|
||||
end
|
||||
3
db/schema.rb
generated
3
db/schema.rb
generated
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[8.0].define(version: 2025_06_01_023335) do
|
||||
ActiveRecord::Schema[8.0].define(version: 2025_07_29_204357) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "citext"
|
||||
enable_extension "pg_catalog.plpgsql"
|
||||
|
|
@ -372,6 +372,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_06_01_023335) do
|
|||
t.string "email"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.boolean "opted_out_of_map", default: false
|
||||
end
|
||||
|
||||
create_table "return_addresses", force: :cascade do |t|
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue