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 %> +<%= t "javascripts.site.createnote_disabled_tooltip" %>