Skip to content

Commit

Permalink
Merge branch 'anonymous-notes-counter'
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Jan 13, 2025
2 parents 5d76ec0 + 0f2df0b commit 1732325
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/assets/javascripts/index/new_note.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/concerns/session_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def successful_login(user, referer = nil)
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:
Expand Down
1 change: 1 addition & 0 deletions app/controllers/confirmations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def confirm
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)
Expand Down
1 change: 1 addition & 0 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def show
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
14 changes: 11 additions & 3 deletions app/views/notes/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
<div class="note">
<p class="alert alert-info"><%= t(".intro") %></p>
<% if !current_user %>
<p class="alert alert-warning"><%= 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) %></p>
<div class="alert alert-warning pb-0">
<p><%= 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) %></p>
<% if @anonymous_notes_count >= 10 %>
<p><%= 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")) %></p>
<% end %>
</div>
<% end %>
<p class="alert alert-warning" id="new-note-zoom-warning" hidden><%= t "javascripts.site.createnote_disabled_tooltip" %></p>
<form action="#">
Expand Down
12 changes: 11 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 1732325

Please sign in to comment.