Merge branch 'pull/5512'
This commit is contained in:
commit
2074e9dce2
13 changed files with 32 additions and 34 deletions
|
@ -112,7 +112,6 @@ Rails/ActionControllerFlashBeforeRender:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'app/controllers/application_controller.rb'
|
- 'app/controllers/application_controller.rb'
|
||||||
- 'app/controllers/confirmations_controller.rb'
|
- 'app/controllers/confirmations_controller.rb'
|
||||||
- 'app/controllers/friendships_controller.rb'
|
|
||||||
- 'app/controllers/issue_comments_controller.rb'
|
- 'app/controllers/issue_comments_controller.rb'
|
||||||
- 'app/controllers/messages_controller.rb'
|
- 'app/controllers/messages_controller.rb'
|
||||||
- 'app/controllers/passwords_controller.rb'
|
- 'app/controllers/passwords_controller.rb'
|
||||||
|
@ -142,7 +141,6 @@ Rails/InverseOf:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'app/models/changeset.rb'
|
- 'app/models/changeset.rb'
|
||||||
- 'app/models/diary_entry.rb'
|
- 'app/models/diary_entry.rb'
|
||||||
- 'app/models/friendship.rb'
|
|
||||||
- 'app/models/issue.rb'
|
- 'app/models/issue.rb'
|
||||||
- 'app/models/message.rb'
|
- 'app/models/message.rb'
|
||||||
- 'app/models/note.rb'
|
- 'app/models/note.rb'
|
||||||
|
|
|
@ -13,20 +13,20 @@ class FollowsController < ApplicationController
|
||||||
before_action :lookup_friend
|
before_action :lookup_friend
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@already_follows = current_user.friends_with?(@friend)
|
@already_follows = current_user.follows?(@friend)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
follow = Follow.new
|
follow = Follow.new
|
||||||
follow.follower = current_user
|
follow.follower = current_user
|
||||||
follow.following = @friend
|
follow.following = @friend
|
||||||
if current_user.friends_with?(@friend)
|
if current_user.follows?(@friend)
|
||||||
flash[:warning] = t ".already_followed", :name => @friend.display_name
|
flash[:warning] = t ".already_followed", :name => @friend.display_name
|
||||||
elsif current_user.follows.where(:created_at => Time.now.utc - 1.hour..).count >= current_user.max_friends_per_hour
|
elsif current_user.follows.where(:created_at => Time.now.utc - 1.hour..).count >= current_user.max_follows_per_hour
|
||||||
flash[:error] = t ".limit_exceeded"
|
flash[:error] = t ".limit_exceeded"
|
||||||
elsif follow.save
|
elsif follow.save
|
||||||
flash[:notice] = t ".success", :name => @friend.display_name
|
flash[:notice] = t ".success", :name => @friend.display_name
|
||||||
UserMailer.friendship_notification(follow).deliver_later
|
UserMailer.follow_notification(follow).deliver_later
|
||||||
else
|
else
|
||||||
follow.add_error(t(".failed", :name => @friend.display_name))
|
follow.add_error(t(".failed", :name => @friend.display_name))
|
||||||
end
|
end
|
||||||
|
@ -37,7 +37,7 @@ class FollowsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
if current_user.friends_with?(@friend)
|
if current_user.follows?(@friend)
|
||||||
Follow.where(:follower => current_user, :following => @friend).delete_all
|
Follow.where(:follower => current_user, :following => @friend).delete_all
|
||||||
flash[:notice] = t ".success", :name => @friend.display_name
|
flash[:notice] = t ".success", :name => @friend.display_name
|
||||||
else
|
else
|
||||||
|
|
|
@ -119,7 +119,7 @@ class UserMailer < ApplicationMailer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def friendship_notification(follow)
|
def follow_notification(follow)
|
||||||
with_recipient_locale follow.following do
|
with_recipient_locale follow.following do
|
||||||
@follow = follow
|
@follow = follow
|
||||||
@viewurl = user_url(@follow.follower)
|
@viewurl = user_url(@follow.follower)
|
||||||
|
|
|
@ -282,8 +282,8 @@ class User < ApplicationRecord
|
||||||
OSM::GreatCircle.new(home_lat, home_lon).distance(nearby_user.home_lat, nearby_user.home_lon)
|
OSM::GreatCircle.new(home_lat, home_lon).distance(nearby_user.home_lat, nearby_user.home_lon)
|
||||||
end
|
end
|
||||||
|
|
||||||
def friends_with?(new_friend)
|
def follows?(user)
|
||||||
follows.exists?(:following => new_friend)
|
follows.exists?(:following => user)
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -411,12 +411,12 @@ class User < ApplicationRecord
|
||||||
max_messages.clamp(0, Settings.max_messages_per_hour)
|
max_messages.clamp(0, Settings.max_messages_per_hour)
|
||||||
end
|
end
|
||||||
|
|
||||||
def max_friends_per_hour
|
def max_follows_per_hour
|
||||||
account_age_in_seconds = Time.now.utc - created_at
|
account_age_in_seconds = Time.now.utc - created_at
|
||||||
account_age_in_hours = account_age_in_seconds / 3600
|
account_age_in_hours = account_age_in_seconds / 3600
|
||||||
recent_friends = Follow.where(:following => self).where(:created_at => Time.now.utc - 3600..).count
|
recent_follows = Follow.where(:following => self).where(:created_at => Time.now.utc - 3600..).count
|
||||||
max_friends = account_age_in_hours.ceil + recent_friends - (active_reports * 10)
|
max_follows = account_age_in_hours.ceil + recent_follows - (active_reports * 10)
|
||||||
max_friends.clamp(0, Settings.max_friends_per_hour)
|
max_follows.clamp(0, Settings.max_follows_per_hour)
|
||||||
end
|
end
|
||||||
|
|
||||||
def max_changeset_comments_per_hour
|
def max_changeset_comments_per_hour
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
<ul class='clearfix text-body-secondary'>
|
<ul class='clearfix text-body-secondary'>
|
||||||
<li><%= link_to t("users.show.send message"), new_message_path(contact) %></li>
|
<li><%= link_to t("users.show.send message"), new_message_path(contact) %></li>
|
||||||
<li>
|
<li>
|
||||||
<% if current_user.friends_with?(contact) %>
|
<% if current_user.follows?(contact) %>
|
||||||
<%= link_to t("users.show.unfollow"), follow_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :delete %>
|
<%= link_to t("users.show.unfollow"), follow_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :delete %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= link_to t("users.show.follow"), follow_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :post %>
|
<%= link_to t("users.show.follow"), follow_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :post %>
|
||||||
|
|
|
@ -22,14 +22,14 @@
|
||||||
<%= tag.div "", :id => "map", :class => "content_map border border-secondary-subtle rounded z-0", :data => { :user => user_data } %>
|
<%= tag.div "", :id => "map", :class => "content_map border border-secondary-subtle rounded z-0", :data => { :user => user_data } %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% friends = @user.followings %>
|
<% followings = @user.followings %>
|
||||||
<% nearby = @user.nearby - friends %>
|
<% nearby = @user.nearby - followings %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md">
|
<div class="col-md">
|
||||||
<h2><%= t ".followings" %></h2>
|
<h2><%= t ".followings" %></h2>
|
||||||
|
|
||||||
<% if friends.empty? %>
|
<% if followings.empty? %>
|
||||||
<%= t ".no followings" %>
|
<%= t ".no followings" %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<nav class='secondary-actions mb-3'>
|
<nav class='secondary-actions mb-3'>
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
<div>
|
<div>
|
||||||
<%= render :partial => "contact", :collection => friends, :locals => { :type => "following" } %>
|
<%= render :partial => "contact", :collection => followings, :locals => { :type => "following" } %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<%= message_body do %>
|
<%= message_body do %>
|
||||||
<p><%= t ".see_their_profile_html", :userurl => link_to(@viewurl, @viewurl) %></p>
|
<p><%= t ".see_their_profile_html", :userurl => link_to(@viewurl, @viewurl) %></p>
|
||||||
|
|
||||||
<% unless @follow.following.friends_with?(@follow.follower) -%>
|
<% unless @follow.following.follows?(@follow.follower) -%>
|
||||||
<p><%= t ".follow_them_html", :followurl => link_to(@followurl, @followurl) %></p>
|
<p><%= t ".follow_them_html", :followurl => link_to(@followurl, @followurl) %></p>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
<% end %>
|
<% end %>
|
|
@ -4,6 +4,6 @@
|
||||||
|
|
||||||
<%= t '.see_their_profile', :userurl => @viewurl %>
|
<%= t '.see_their_profile', :userurl => @viewurl %>
|
||||||
|
|
||||||
<% unless @follow.following.friends_with?(@follow.follower) -%>
|
<% unless @follow.following.follows?(@follow.follower) -%>
|
||||||
<%= t '.follow_them', :followurl => @followurl %>
|
<%= t '.follow_them', :followurl => @followurl %>
|
||||||
<% end -%>
|
<% end -%>
|
|
@ -83,7 +83,7 @@
|
||||||
</li>
|
</li>
|
||||||
<% if current_user %>
|
<% if current_user %>
|
||||||
<li>
|
<li>
|
||||||
<% if current_user.friends_with?(@user) %>
|
<% if current_user.follows?(@user) %>
|
||||||
<%= link_to t(".unfollow"), follow_path(:display_name => @user.display_name), :method => :delete %>
|
<%= link_to t(".unfollow"), follow_path(:display_name => @user.display_name), :method => :delete %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= link_to t(".follow"), follow_path(:display_name => @user.display_name), :method => :post %>
|
<%= link_to t(".follow"), follow_path(:display_name => @user.display_name), :method => :post %>
|
||||||
|
|
|
@ -540,7 +540,7 @@ en:
|
||||||
title: My Dashboard
|
title: My Dashboard
|
||||||
no_home_location_html: "%{edit_profile_link} and set your home location to see nearby users."
|
no_home_location_html: "%{edit_profile_link} and set your home location to see nearby users."
|
||||||
edit_your_profile: Edit your profile
|
edit_your_profile: Edit your profile
|
||||||
followings: Followings
|
followings: Followings
|
||||||
no followings: You have not followed any user yet.
|
no followings: You have not followed any user yet.
|
||||||
nearby users: "Other nearby users"
|
nearby users: "Other nearby users"
|
||||||
no nearby users: "There are no other users who admit to mapping nearby yet."
|
no nearby users: "There are no other users who admit to mapping nearby yet."
|
||||||
|
@ -1654,7 +1654,7 @@ en:
|
||||||
header_html: "%{from_user} has sent you a message through OpenStreetMap with the subject %{subject}:"
|
header_html: "%{from_user} has sent you a message through OpenStreetMap with the subject %{subject}:"
|
||||||
footer: "You can also read the message at %{readurl} and you can send a message to the author at %{replyurl}"
|
footer: "You can also read the message at %{readurl} and you can send a message to the author at %{replyurl}"
|
||||||
footer_html: "You can also read the message at %{readurl} and you can send a message to the author at %{replyurl}"
|
footer_html: "You can also read the message at %{readurl} and you can send a message to the author at %{replyurl}"
|
||||||
friendship_notification:
|
follow_notification:
|
||||||
hi: "Hi %{to_user},"
|
hi: "Hi %{to_user},"
|
||||||
subject: "[OpenStreetMap] %{user} followed you"
|
subject: "[OpenStreetMap] %{user} followed you"
|
||||||
followed_you: "%{user} is now following you on OpenStreetMap."
|
followed_you: "%{user} is now following you on OpenStreetMap."
|
||||||
|
|
|
@ -63,8 +63,8 @@ max_messages_per_hour: 60
|
||||||
default_message_query_limit: 100
|
default_message_query_limit: 100
|
||||||
# Maximum number of messages returned by inbox and outbox message api
|
# Maximum number of messages returned by inbox and outbox message api
|
||||||
max_message_query_limit: 100
|
max_message_query_limit: 100
|
||||||
# Rate limit for friending
|
# Rate limit for following
|
||||||
max_friends_per_hour: 60
|
max_follows_per_hour: 60
|
||||||
# Rate limit for changeset comments
|
# Rate limit for changeset comments
|
||||||
min_changeset_comments_per_hour: 1
|
min_changeset_comments_per_hour: 1
|
||||||
initial_changeset_comments_per_hour: 6
|
initial_changeset_comments_per_hour: 6
|
||||||
|
|
|
@ -136,18 +136,18 @@ class UserTest < ActiveSupport::TestCase
|
||||||
assert_predicate user, :valid?, "user_0 display_name is invalid but it hasn't been changed"
|
assert_predicate user, :valid?, "user_0 display_name is invalid but it hasn't been changed"
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_friends_with
|
def test_follows
|
||||||
alice = create(:user, :active)
|
alice = create(:user, :active)
|
||||||
bob = create(:user, :active)
|
bob = create(:user, :active)
|
||||||
charlie = create(:user, :active)
|
charlie = create(:user, :active)
|
||||||
create(:follow, :follower => alice, :following => bob)
|
create(:follow, :follower => alice, :following => bob)
|
||||||
|
|
||||||
assert alice.friends_with?(bob)
|
assert alice.follows?(bob)
|
||||||
assert_not alice.friends_with?(charlie)
|
assert_not alice.follows?(charlie)
|
||||||
assert_not bob.friends_with?(alice)
|
assert_not bob.follows?(alice)
|
||||||
assert_not bob.friends_with?(charlie)
|
assert_not bob.follows?(charlie)
|
||||||
assert_not charlie.friends_with?(bob)
|
assert_not charlie.follows?(bob)
|
||||||
assert_not charlie.friends_with?(alice)
|
assert_not charlie.follows?(alice)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_users_nearby
|
def test_users_nearby
|
||||||
|
|
|
@ -6,7 +6,7 @@ class FollowsTest < ApplicationSystemTestCase
|
||||||
|
|
||||||
sign_in_as create(:user)
|
sign_in_as create(:user)
|
||||||
|
|
||||||
with_settings(:max_friends_per_hour => 0) do
|
with_settings(:max_follows_per_hour => 0) do
|
||||||
visit user_path(following)
|
visit user_path(following)
|
||||||
assert_link "Follow"
|
assert_link "Follow"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue