Skip to content

Commit 0c6de8c

Browse files
committed
stricter restrictions on creating anonymous notes
1 parent a06fbdc commit 0c6de8c

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

app/assets/javascripts/index/new_note.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ OSM.NewNote = function (map) {
149149
createNote(location, text, (feature) => {
150150
if (typeof OSM.user === "undefined") {
151151
const anonymousNotesCount = Number(OSM.cookies.get("_osm_anonymous_notes_count")) || 0;
152-
OSM.cookies.set("_osm_anonymous_notes_count", anonymousNotesCount + 1, { expires: 30 });
152+
OSM.cookies.set("_osm_anonymous_notes_count", anonymousNotesCount + 1, { expires: 14 });
153153
}
154154
content.find("textarea").val("");
155155
addCreatedNoteMarker(feature);

app/views/notes/new.html.erb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
<% set_title(t(".title")) %>
22

33
<%= render "sidebar_header", :title => t(".title") %>
4-
4+
<% soft_anonymous_notes_limit_reached = !current_user && @anonymous_notes_count >= 5
5+
hard_anonymous_notes_limit_reached = !current_user && @anonymous_notes_count >= 10
6+
warn_class = hard_anonymous_notes_limit_reached ? "alert-danger" : "alert-warning" %>
57
<div class="note">
68
<p class="alert alert-info"><%= t(".intro") %></p>
79
<% if !current_user %>
8-
<div class="alert alert-warning pb-0">
10+
<div class="alert <%= warn_class %> pb-0">
911
<p><%= t ".anonymous_warning_html",
1012
:log_in => link_to(t(".anonymous_warning_log_in"), login_path(:referer => new_note_path)),
1113
:sign_up => link_to(t(".anonymous_warning_sign_up"), new_user_path) %></p>
12-
<% if @anonymous_notes_count >= 10 %>
14+
<% if soft_anonymous_notes_limit_reached %>
1315
<p><%= t ".counter_warning_html",
1416
:x_anonymous_notes => t(".x_anonymous_notes", :count => @anonymous_notes_count),
1517
:contribute_by_yourself => link_to(t(".counter_warning_guide_link.text"), t(".counter_warning_guide_link.url")),
1618
:community_can_help => link_to(t(".counter_warning_forum_link.text"), t(".counter_warning_forum_link.url")) %></p>
1719
<% end %>
1820
</div>
1921
<% end %>
22+
<% if !hard_anonymous_notes_limit_reached %>
2023
<p class="alert alert-warning" id="new-note-zoom-warning" hidden><%= t "javascripts.site.createnote_disabled_tooltip" %></p>
2124
<form action="#">
2225
<input type="hidden" name="lon" autocomplete="off">
@@ -28,4 +31,5 @@
2831
<%= submit_tag t(".add"), :name => "add", :disabled => 1, :class => "btn btn-primary" %>
2932
</div>
3033
</form>
34+
<% end %>
3135
</div>

test/system/create_note_test.rb

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,30 +100,38 @@ def teardown
100100
end
101101
end
102102

103-
test "encouragement to contribute appears after 10 created notes and disappears after login" do
104-
check_encouragement_while_creating_notes(10)
103+
test "encouragement to contribute appears after 5 created notes and disappears after login" do
104+
check_encouragement_while_creating_notes(5)
105105

106106
sign_in_as(create(:user))
107107

108108
check_no_encouragement_while_logging_out
109109
end
110110

111-
test "encouragement to contribute appears after 10 created notes and disappears after email signup" do
112-
check_encouragement_while_creating_notes(10)
111+
test "encouragement to contribute appears after 5 created notes and disappears after email signup" do
112+
check_encouragement_while_creating_notes(5)
113113

114114
sign_up_with_email
115115

116116
check_no_encouragement_while_logging_out
117117
end
118118

119-
test "encouragement to contribute appears after 10 created notes and disappears after google signup" do
120-
check_encouragement_while_creating_notes(10)
119+
test "encouragement to contribute appears after 5 created notes and disappears after google signup" do
120+
check_encouragement_while_creating_notes(5)
121121

122122
sign_up_with_google
123123

124124
check_no_encouragement_while_logging_out
125125
end
126126

127+
test "strict encouragement to contribute appears after 10 created notes and disappears after login" do
128+
check_strict_encouragement_while_creating_notes(5, 10)
129+
130+
sign_in_as(create(:user))
131+
132+
check_no_encouragement_while_logging_out
133+
end
134+
127135
private
128136

129137
def check_encouragement_while_creating_notes(encouragement_threshold)
@@ -147,6 +155,32 @@ def check_encouragement_while_creating_notes(encouragement_threshold)
147155
end
148156
end
149157

158+
def check_strict_encouragement_while_creating_notes(encouragement_threshold, strict_encouragement_threshold)
159+
strict_encouragement_threshold.times do |n|
160+
visit new_note_path(:anchor => "map=16/0/#{0.001 * n}")
161+
162+
within_sidebar do
163+
if n < encouragement_threshold
164+
assert_no_content(/already posted at least \d+ anonymous note/)
165+
else
166+
assert_content(/already posted at least \d+ anonymous note/)
167+
end
168+
169+
fill_in "text", :with => "new note ##{n + 1}"
170+
click_on "Add Note"
171+
172+
assert_content "new note ##{n + 1}"
173+
end
174+
end
175+
176+
visit new_note_path(:anchor => "map=16/0/#{0.001 * strict_encouragement_threshold}")
177+
178+
within_sidebar do
179+
assert_content(/already posted at least #{strict_encouragement_threshold} anonymous note/)
180+
assert_no_button "Add Note"
181+
end
182+
end
183+
150184
def check_no_encouragement_while_logging_out
151185
visit new_note_path(:anchor => "map=16/0/0")
152186

0 commit comments

Comments
 (0)