From 0f2df0b9efcfff1d6bb0f7b2d16fa23f85d8708d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Etil=C3=A8ne=20Jourdier?= Date: Sun, 12 Jan 2025 22:42:57 +0100 Subject: [PATCH] display an encouragement to contribute after many anonymous notes create a counter of anonymous notes in a cookie, read by new note controller to display an encouragement to contribute in the already existing anonymous warning if the anonymous visitor has already created at least 10 anonymous notes. Cookie deleted on log-in and sign-up after email validation --- app/assets/javascripts/index/new_note.js | 4 ++++ app/controllers/concerns/session_methods.rb | 2 ++ app/controllers/confirmations_controller.rb | 1 + app/controllers/notes_controller.rb | 1 + app/views/notes/new.html.erb | 14 +++++++++++--- config/locales/en.yml | 12 +++++++++++- 6 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/index/new_note.js b/app/assets/javascripts/index/new_note.js index 885d7d2c9..4f38f8b55 100644 --- a/app/assets/javascripts/index/new_note.js +++ b/app/assets/javascripts/index/new_note.js @@ -162,6 +162,10 @@ OSM.NewNote = function (map) { newNoteMarker.dragging.disable(); createNote(location, text, (feature) => { + if (typeof OSM.user === "undefined") { + var anonymousNotesCount = Number(Cookies.get("_osm_anonymous_notes_count")) || 0; + Cookies.set("_osm_anonymous_notes_count", anonymousNotesCount + 1, { secure: true, expires: 30, path: "/", samesite: "lax" }); + } content.find("textarea").val(""); addCreatedNoteMarker(feature); OSM.router.route("/note/" + feature.properties.id); diff --git a/app/controllers/concerns/session_methods.rb b/app/controllers/concerns/session_methods.rb index 2cfc4e823..4bbfac34f 100644 --- a/app/controllers/concerns/session_methods.rb +++ b/app/controllers/concerns/session_methods.rb @@ -39,6 +39,8 @@ module SessionMethods session[:fingerprint] = user.fingerprint session_expires_after 28.days if session[:remember_me] + cookies.delete :_osm_anonymous_notes_count + target = referer || url_for(:controller => :site, :action => :index) # The user is logged in, so decide where to send them: diff --git a/app/controllers/confirmations_controller.rb b/app/controllers/confirmations_controller.rb index 7bbb3a093..72c1955e0 100644 --- a/app/controllers/confirmations_controller.rb +++ b/app/controllers/confirmations_controller.rb @@ -30,6 +30,7 @@ class ConfirmationsController < ApplicationController user.email_valid = true flash[:notice] = gravatar_status_message(user) if gravatar_enable(user) user.save! + cookies.delete :_osm_anonymous_notes_count referer = safe_referer(params[:referer]) if params[:referer] pending_user = session.delete(:pending_user) diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index c40e776b4..4b4f3d651 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -45,6 +45,7 @@ class NotesController < ApplicationController end def new + @anonymous_notes_count = request.cookies["_osm_anonymous_notes_count"].to_i || 0 render :action => :new_readonly if api_status != "online" end end diff --git a/app/views/notes/new.html.erb b/app/views/notes/new.html.erb index 4ae4a995d..5be707dfe 100644 --- a/app/views/notes/new.html.erb +++ b/app/views/notes/new.html.erb @@ -5,9 +5,17 @@

<%= t(".intro") %>

<% if !current_user %> -

<%= t ".anonymous_warning_html", - :log_in => link_to(t(".anonymous_warning_log_in"), login_path(:referer => new_note_path)), - :sign_up => link_to(t(".anonymous_warning_sign_up"), new_user_path) %>

+
+

<%= t ".anonymous_warning_html", + :log_in => link_to(t(".anonymous_warning_log_in"), login_path(:referer => new_note_path)), + :sign_up => link_to(t(".anonymous_warning_sign_up"), new_user_path) %>

+ <% if @anonymous_notes_count >= 10 %> +

<%= t ".counter_warning_html", + :x_anonymous_notes => t(".x_anonymous_notes", :count => @anonymous_notes_count), + :contribute_by_yourself => link_to(t(".counter_warning_guide_link.text"), t(".counter_warning_guide_link.url")), + :community_can_help => link_to(t(".counter_warning_forum_link.text"), t(".counter_warning_forum_link.url")) %>

+ <% end %> +
<% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index a62f4d34f..d1faa7a50 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3087,9 +3087,19 @@ en: new: title: "New Note" intro: "Spotted a mistake or something missing? Let other mappers know so we can fix it. Move the marker to the correct position and type a note to explain the problem." - anonymous_warning_html: "You are not logged in. Please %{log_in} or %{sign_up} if you want to receive updates for your note." + anonymous_warning_html: "You are not logged in. Please %{log_in} or %{sign_up} to receive updates for your note and help mappers resolve it." anonymous_warning_log_in: "log in" anonymous_warning_sign_up: "sign up" + counter_warning_html: "You have already posted at least %{x_anonymous_notes}, that's great for the community, thank you! Now we encourage you to %{contribute_by_yourself}, it is not that complicated, and %{community_can_help}." + x_anonymous_notes: + one: "%{count} anonymous note" + other: "%{count} anonymous notes" + counter_warning_guide_link: + text: "contribute by yourself" + url: https://wiki.openstreetmap.org/wiki/Beginners%27_guide + counter_warning_forum_link: + text: "the community can help you" + url: https://community.openstreetmap.org/ advice: "Your note is public and may be used to update the map, so don't enter personal information, or information from copyrighted maps or directory listings." add: Add Note new_readonly: -- 2.39.5