diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b3379b91a1..fa15ea90a0 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -112,7 +112,6 @@ Rails/ActionControllerFlashBeforeRender: Exclude: - 'app/controllers/application_controller.rb' - 'app/controllers/confirmations_controller.rb' - - 'app/controllers/friendships_controller.rb' - 'app/controllers/issue_comments_controller.rb' - 'app/controllers/messages_controller.rb' - 'app/controllers/passwords_controller.rb' @@ -142,7 +141,6 @@ Rails/InverseOf: Exclude: - 'app/models/changeset.rb' - 'app/models/diary_entry.rb' - - 'app/models/friendship.rb' - 'app/models/issue.rb' - 'app/models/message.rb' - 'app/models/note.rb' diff --git a/app/controllers/follows_controller.rb b/app/controllers/follows_controller.rb index d267777c19..39d6191cd8 100644 --- a/app/controllers/follows_controller.rb +++ b/app/controllers/follows_controller.rb @@ -13,20 +13,20 @@ class FollowsController < ApplicationController before_action :lookup_friend def show - @already_follows = current_user.friends_with?(@friend) + @already_follows = current_user.follows?(@friend) end def create follow = Follow.new follow.follower = current_user follow.following = @friend - if current_user.friends_with?(@friend) + if current_user.follows?(@friend) 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" elsif follow.save flash[:notice] = t ".success", :name => @friend.display_name - UserMailer.friendship_notification(follow).deliver_later + UserMailer.follow_notification(follow).deliver_later else follow.add_error(t(".failed", :name => @friend.display_name)) end @@ -37,7 +37,7 @@ def create end def destroy - if current_user.friends_with?(@friend) + if current_user.follows?(@friend) Follow.where(:follower => current_user, :following => @friend).delete_all flash[:notice] = t ".success", :name => @friend.display_name else diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index fea73c710c..6098162852 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -119,7 +119,7 @@ def diary_comment_notification(comment, recipient) end end - def friendship_notification(follow) + def follow_notification(follow) with_recipient_locale follow.following do @follow = follow @viewurl = user_url(@follow.follower) diff --git a/app/models/user.rb b/app/models/user.rb index ec3883bc6f..16f733c882 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -282,8 +282,8 @@ def distance(nearby_user) OSM::GreatCircle.new(home_lat, home_lon).distance(nearby_user.home_lat, nearby_user.home_lon) end - def friends_with?(new_friend) - follows.exists?(:following => new_friend) + def follows?(user) + follows.exists?(:following => user) end ## @@ -411,12 +411,12 @@ def max_messages_per_hour max_messages.clamp(0, Settings.max_messages_per_hour) end - def max_friends_per_hour + def max_follows_per_hour account_age_in_seconds = Time.now.utc - created_at account_age_in_hours = account_age_in_seconds / 3600 - recent_friends = 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_friends.clamp(0, Settings.max_friends_per_hour) + recent_follows = Follow.where(:following => self).where(:created_at => Time.now.utc - 3600..).count + max_follows = account_age_in_hours.ceil + recent_follows - (active_reports * 10) + max_follows.clamp(0, Settings.max_follows_per_hour) end def max_changeset_comments_per_hour diff --git a/app/views/dashboards/_contact.html.erb b/app/views/dashboards/_contact.html.erb index 4547a2d751..8e78524dec 100644 --- a/app/views/dashboards/_contact.html.erb +++ b/app/views/dashboards/_contact.html.erb @@ -35,7 +35,7 @@
- <%= render :partial => "contact", :collection => friends, :locals => { :type => "following" } %> + <%= render :partial => "contact", :collection => followings, :locals => { :type => "following" } %>
<% end %> diff --git a/app/views/user_mailer/friendship_notification.html.erb b/app/views/user_mailer/follow_notification.html.erb similarity index 84% rename from app/views/user_mailer/friendship_notification.html.erb rename to app/views/user_mailer/follow_notification.html.erb index 16ddcad491..48b037d57e 100644 --- a/app/views/user_mailer/friendship_notification.html.erb +++ b/app/views/user_mailer/follow_notification.html.erb @@ -5,7 +5,7 @@ <%= message_body do %>

<%= t ".see_their_profile_html", :userurl => link_to(@viewurl, @viewurl) %>

- <% unless @follow.following.friends_with?(@follow.follower) -%> + <% unless @follow.following.follows?(@follow.follower) -%>

<%= t ".follow_them_html", :followurl => link_to(@followurl, @followurl) %>

<% end -%> <% end %> diff --git a/app/views/user_mailer/friendship_notification.text.erb b/app/views/user_mailer/follow_notification.text.erb similarity index 78% rename from app/views/user_mailer/friendship_notification.text.erb rename to app/views/user_mailer/follow_notification.text.erb index 624ba92b76..7f9ba202ef 100644 --- a/app/views/user_mailer/friendship_notification.text.erb +++ b/app/views/user_mailer/follow_notification.text.erb @@ -4,6 +4,6 @@ <%= t '.see_their_profile', :userurl => @viewurl %> -<% unless @follow.following.friends_with?(@follow.follower) -%> +<% unless @follow.following.follows?(@follow.follower) -%> <%= t '.follow_them', :followurl => @followurl %> <% end -%> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 76bedf60e6..b2247c0d01 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -83,7 +83,7 @@ <% if current_user %>
  • - <% if current_user.friends_with?(@user) %> + <% if current_user.follows?(@user) %> <%= link_to t(".unfollow"), follow_path(:display_name => @user.display_name), :method => :delete %> <% else %> <%= link_to t(".follow"), follow_path(:display_name => @user.display_name), :method => :post %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 42e3f637e9..a112f3b0de 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -540,7 +540,7 @@ en: title: My Dashboard no_home_location_html: "%{edit_profile_link} and set your home location to see nearby users." edit_your_profile: Edit your profile - followings: Followings + followings: Followings no followings: You have not followed any user yet. nearby users: "Other nearby users" 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}:" 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}" - friendship_notification: + follow_notification: hi: "Hi %{to_user}," subject: "[OpenStreetMap] %{user} followed you" followed_you: "%{user} is now following you on OpenStreetMap." diff --git a/config/settings.yml b/config/settings.yml index db871775e7..c791991451 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -63,8 +63,8 @@ max_messages_per_hour: 60 default_message_query_limit: 100 # Maximum number of messages returned by inbox and outbox message api max_message_query_limit: 100 -# Rate limit for friending -max_friends_per_hour: 60 +# Rate limit for following +max_follows_per_hour: 60 # Rate limit for changeset comments min_changeset_comments_per_hour: 1 initial_changeset_comments_per_hour: 6 diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 3b600fc878..5c1c5a26f2 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -136,18 +136,18 @@ def test_display_name_user_id_unchanged_is_valid assert_predicate user, :valid?, "user_0 display_name is invalid but it hasn't been changed" end - def test_friends_with + def test_follows alice = create(:user, :active) bob = create(:user, :active) charlie = create(:user, :active) create(:follow, :follower => alice, :following => bob) - assert alice.friends_with?(bob) - assert_not alice.friends_with?(charlie) - assert_not bob.friends_with?(alice) - assert_not bob.friends_with?(charlie) - assert_not charlie.friends_with?(bob) - assert_not charlie.friends_with?(alice) + assert alice.follows?(bob) + assert_not alice.follows?(charlie) + assert_not bob.follows?(alice) + assert_not bob.follows?(charlie) + assert_not charlie.follows?(bob) + assert_not charlie.follows?(alice) end def test_users_nearby diff --git a/test/system/follows_test.rb b/test/system/follows_test.rb index f9f00ff7ff..176a59428f 100644 --- a/test/system/follows_test.rb +++ b/test/system/follows_test.rb @@ -6,7 +6,7 @@ class FollowsTest < ApplicationSystemTestCase 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) assert_link "Follow"