Modify the way Friends are added
This commit is contained in:
parent
1732325768
commit
2b7a48029b
14 changed files with 77 additions and 77 deletions
|
@ -28,7 +28,7 @@ class DiaryEntriesController < ApplicationController
|
|||
end
|
||||
elsif params[:friends]
|
||||
if current_user
|
||||
@title = t ".title_friends"
|
||||
@title = t ".title_followed"
|
||||
entries = DiaryEntry.where(:user => current_user.friends)
|
||||
else
|
||||
require_user
|
||||
|
|
|
@ -18,7 +18,7 @@ class FriendshipsController < ApplicationController
|
|||
friendship.befriender = current_user
|
||||
friendship.befriendee = @friend
|
||||
if current_user.friends_with?(@friend)
|
||||
flash[:warning] = t ".already_a_friend", :name => @friend.display_name
|
||||
flash[:warning] = t ".already_followed", :name => @friend.display_name
|
||||
elsif current_user.friendships.where(:created_at => Time.now.utc - 1.hour..).count >= current_user.max_friends_per_hour
|
||||
flash[:error] = t ".limit_exceeded"
|
||||
elsif friendship.save
|
||||
|
@ -40,7 +40,7 @@ class FriendshipsController < ApplicationController
|
|||
Friendship.where(:befriender => current_user, :befriendee => @friend).delete_all
|
||||
flash[:notice] = t ".success", :name => @friend.display_name
|
||||
else
|
||||
flash[:error] = t ".not_a_friend", :name => @friend.display_name
|
||||
flash[:error] = t ".not_followed", :name => @friend.display_name
|
||||
end
|
||||
|
||||
referer = safe_referer(params[:referer]) if params[:referer]
|
||||
|
|
|
@ -32,7 +32,7 @@ module ChangesetsHelper
|
|||
|
||||
def changeset_index_title(params, user)
|
||||
if params[:friends] && user
|
||||
t "changesets.index.title_friend"
|
||||
t "changesets.index.title_followed"
|
||||
elsif params[:nearby] && user
|
||||
t "changesets.index.title_nearby"
|
||||
elsif params[:display_name]
|
||||
|
|
|
@ -123,7 +123,7 @@ class UserMailer < ApplicationMailer
|
|||
with_recipient_locale friendship.befriendee do
|
||||
@friendship = friendship
|
||||
@viewurl = user_url(@friendship.befriender)
|
||||
@friendurl = make_friend_url(@friendship.befriender)
|
||||
@followurl = follow_url(@friendship.befriender)
|
||||
@author = @friendship.befriender.display_name
|
||||
|
||||
attach_user_avatar(@friendship.befriender)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<% user_data = {
|
||||
:lon => contact.home_lon,
|
||||
:lat => contact.home_lat,
|
||||
:icon => image_path(type == "friend" ? "marker-blue.png" : "marker-green.png"),
|
||||
:icon => image_path(type == "following" ? "marker-blue.png" : "marker-green.png"),
|
||||
:description => render(:partial => "popup", :object => contact, :locals => { :type => type })
|
||||
} %>
|
||||
<%= tag.div :class => "clearfix row", :data => { :user => user_data } do %>
|
||||
|
@ -36,9 +36,9 @@
|
|||
<li><%= link_to t("users.show.send message"), new_message_path(contact) %></li>
|
||||
<li>
|
||||
<% if current_user.friends_with?(contact) %>
|
||||
<%= link_to t("users.show.remove as friend"), remove_friend_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :post %>
|
||||
<%= link_to t("users.show.unfollow"), remove_friend_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :post %>
|
||||
<% else %>
|
||||
<%= link_to t("users.show.add as friend"), make_friend_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :post %>
|
||||
<%= link_to t("users.follow"), make_friend_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :post %>
|
||||
<% end %>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
@ -27,19 +27,19 @@
|
|||
</div>
|
||||
|
||||
<div class="col-md">
|
||||
<h2><%= t ".my friends" %></h2>
|
||||
<h2><%= t ".followings" %></h2>
|
||||
|
||||
<% if friends.empty? %>
|
||||
<%= t ".no friends" %>
|
||||
<%= t ".no followings" %>
|
||||
<% else %>
|
||||
<nav class='secondary-actions mb-3'>
|
||||
<ul class='clearfix'>
|
||||
<li><%= link_to t(".friends_changesets"), friend_changesets_path %></li>
|
||||
<li><%= link_to t(".friends_diaries"), friends_diary_entries_path %></li>
|
||||
<li><%= link_to t(".followed_changesets"), friend_changesets_path %></li>
|
||||
<li><%= link_to t(".followed_diaries"), friends_diary_entries_path %></li>
|
||||
</ul>
|
||||
</nav>
|
||||
<div>
|
||||
<%= render :partial => "contact", :collection => friends, :locals => { :type => "friend" } %>
|
||||
<%= render :partial => "contact", :collection => friends, :locals => { :type => "following" } %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<p><%= t ".hi", :to_user => @friendship.befriendee.display_name %></p>
|
||||
|
||||
<p><%= t ".had_added_you", :user => @friendship.befriender.display_name %></p>
|
||||
<p><%= t ".followed_you", :user => @friendship.befriender.display_name %></p>
|
||||
|
||||
<%= message_body do %>
|
||||
<p><%= t ".see_their_profile_html", :userurl => link_to(@viewurl, @viewurl) %></p>
|
||||
|
||||
<% unless @friendship.befriendee.friends_with?(@friendship.befriender) -%>
|
||||
<p><%= t ".befriend_them_html", :befriendurl => link_to(@friendurl, @friendurl) %></p>
|
||||
<p><%= t ".follow_them_html", :followurl => link_to(@followurl, @followurl) %></p>
|
||||
<% end -%>
|
||||
<% end %>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<%= t ".hi", :to_user => @friendship.befriendee.display_name %>
|
||||
|
||||
<%= t '.had_added_you', :user => @friendship.befriender.display_name %>
|
||||
<%= t '.followed_you', :user => @friendship.befriender.display_name %>
|
||||
|
||||
<%= t '.see_their_profile', :userurl => @viewurl %>
|
||||
|
||||
<% unless @friendship.befriendee.friends_with?(@friendship.befriender) -%>
|
||||
<%= t '.befriend_them', :befriendurl => @friendurl %>
|
||||
<%= t '.follow_them', :followurl => @followurl %>
|
||||
<% end -%>
|
||||
|
|
|
@ -84,9 +84,9 @@
|
|||
<% if current_user %>
|
||||
<li>
|
||||
<% if current_user.friends_with?(@user) %>
|
||||
<%= link_to t(".remove as friend"), remove_friend_path(:display_name => @user.display_name), :method => :post %>
|
||||
<%= link_to t(".unfollow"), remove_friend_path(:display_name => @user.display_name), :method => :post %>
|
||||
<% else %>
|
||||
<%= link_to t(".add as friend"), make_friend_path(:display_name => @user.display_name), :method => :post %>
|
||||
<%= link_to t(".follow"), make_friend_path(:display_name => @user.display_name), :method => :post %>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
|
|
@ -92,7 +92,7 @@ en:
|
|||
support_url: Support URL
|
||||
allow_read_prefs: read their user preferences
|
||||
allow_write_prefs: modify their user preferences
|
||||
allow_write_diary: create diary entries, comments and make friends
|
||||
allow_write_diary: create diary entries and comments
|
||||
allow_write_api: modify the map
|
||||
allow_read_gpx: read their private GPS traces
|
||||
allow_write_gpx: upload GPS traces
|
||||
|
@ -478,7 +478,7 @@ en:
|
|||
title: "Changesets"
|
||||
title_user: "Changesets by %{user}"
|
||||
title_user_link_html: "Changesets by %{user_link}"
|
||||
title_friend: "Changesets by my friends"
|
||||
title_followed: "Changesets by followings"
|
||||
title_nearby: "Changesets by nearby users"
|
||||
empty: "No changesets found."
|
||||
empty_area: "No changesets in this area."
|
||||
|
@ -544,17 +544,17 @@ en:
|
|||
popup:
|
||||
your location: "Your location"
|
||||
nearby mapper: "Nearby mapper"
|
||||
friend: "Friend"
|
||||
following: "Following"
|
||||
show:
|
||||
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
|
||||
my friends: My friends
|
||||
no friends: You have not added any friends yet.
|
||||
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."
|
||||
friends_changesets: "friends' changesets"
|
||||
friends_diaries: "friends' diary entries"
|
||||
followed_changesets: "changesets"
|
||||
followed_diaries: "diary entries"
|
||||
nearby_changesets: "nearby user changesets"
|
||||
nearby_diaries: "nearby user diary entries"
|
||||
diary_entries:
|
||||
|
@ -565,7 +565,7 @@ en:
|
|||
use_map_link: Use Map
|
||||
index:
|
||||
title: "Users' Diaries"
|
||||
title_friends: "Friends' Diaries"
|
||||
title_followed: "Followings' Diaries"
|
||||
title_nearby: "Nearby Users' Diaries"
|
||||
user_title: "%{user}'s Diary"
|
||||
in_language_title: "Diary Entries in %{language}"
|
||||
|
@ -688,17 +688,17 @@ en:
|
|||
description: Couldn't find a file/directory/API operation by that name on the OpenStreetMap server (HTTP 404)
|
||||
friendships:
|
||||
make_friend:
|
||||
heading: "Add %{user} as a friend?"
|
||||
button: "Add as friend"
|
||||
success: "%{name} is now your friend!"
|
||||
failed: "Sorry, failed to add %{name} as a friend."
|
||||
already_a_friend: "You are already friends with %{name}."
|
||||
limit_exceeded: "You have friended a lot of users recently. Please wait a while before trying to friend any more."
|
||||
heading: "Do you want to follow %{user}?"
|
||||
button: "Follow User"
|
||||
success: "You are now following %{name}!"
|
||||
failed: "Sorry, your request to follow %{name} has failed."
|
||||
already_followed: "You already follow %{name}."
|
||||
limit_exceeded: "You have followed a lot of users recently. Please wait a while before trying to follow any more."
|
||||
remove_friend:
|
||||
heading: "Unfriend %{user}?"
|
||||
button: "Unfriend"
|
||||
success: "%{name} was removed from your friends."
|
||||
not_a_friend: "%{name} is not one of your friends."
|
||||
heading: "Do you want to unfollow %{user}?"
|
||||
button: "Unfollow"
|
||||
success: "You successfully unfollowed %{name}."
|
||||
not_followed: "You are not following %{name}."
|
||||
geocoder:
|
||||
search:
|
||||
title:
|
||||
|
@ -1662,12 +1662,12 @@ en:
|
|||
footer_html: "You can also read the message at %{readurl} and you can send a message to the author at %{replyurl}"
|
||||
friendship_notification:
|
||||
hi: "Hi %{to_user},"
|
||||
subject: "[OpenStreetMap] %{user} added you as a friend"
|
||||
had_added_you: "%{user} has added you as a friend on OpenStreetMap."
|
||||
subject: "[OpenStreetMap] %{user} followed you"
|
||||
followed_you: "%{user} is now following you on OpenStreetMap."
|
||||
see_their_profile: "You can see their profile at %{userurl}."
|
||||
see_their_profile_html: "You can see their profile at %{userurl}."
|
||||
befriend_them: "You can also add them as a friend at %{befriendurl}."
|
||||
befriend_them_html: "You can also add them as a friend at %{befriendurl}."
|
||||
follow_them: "You can also follow them at %{followurl}."
|
||||
follow_them_html: "You can also follow them at %{followurl}."
|
||||
gpx_details:
|
||||
details: "Your file details:"
|
||||
filename: Filename
|
||||
|
@ -2698,7 +2698,7 @@ en:
|
|||
openid: Sign-in using OpenStreetMap
|
||||
read_prefs: Read user preferences
|
||||
write_prefs: Modify user preferences
|
||||
write_diary: Create diary entries, comments and make friends
|
||||
write_diary: Create diary entries and comments
|
||||
write_api: Modify the map
|
||||
read_gpx: Read private GPS traces
|
||||
write_gpx: Upload GPS traces
|
||||
|
@ -2818,8 +2818,8 @@ en:
|
|||
edits: Edits
|
||||
traces: Traces
|
||||
notes: Map Notes
|
||||
remove as friend: Unfriend
|
||||
add as friend: Add Friend
|
||||
unfollow: Unfollow
|
||||
follow: Follow
|
||||
mapper since: "Mapper since:"
|
||||
last map edit: "Last map edit:"
|
||||
no activity yet: "No activity yet"
|
||||
|
|
|
@ -5,24 +5,24 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
|
|||
# test all routes which lead to this controller
|
||||
def test_routes
|
||||
assert_routing(
|
||||
{ :path => "/user/username/make_friend", :method => :get },
|
||||
{ :controller => "friendships", :action => "make_friend", :display_name => "username" }
|
||||
{ :path => "/user/username/follow", :method => :get },
|
||||
{ :controller => "friendships", :action => "follow", :display_name => "username" }
|
||||
)
|
||||
assert_routing(
|
||||
{ :path => "/user/username/make_friend", :method => :post },
|
||||
{ :controller => "friendships", :action => "make_friend", :display_name => "username" }
|
||||
{ :path => "/user/username/follow", :method => :post },
|
||||
{ :controller => "friendships", :action => "follow", :display_name => "username" }
|
||||
)
|
||||
assert_routing(
|
||||
{ :path => "/user/username/remove_friend", :method => :get },
|
||||
{ :controller => "friendships", :action => "remove_friend", :display_name => "username" }
|
||||
{ :path => "/user/username/unfollow", :method => :get },
|
||||
{ :controller => "friendships", :action => "unfollow", :display_name => "username" }
|
||||
)
|
||||
assert_routing(
|
||||
{ :path => "/user/username/remove_friend", :method => :post },
|
||||
{ :controller => "friendships", :action => "remove_friend", :display_name => "username" }
|
||||
{ :path => "/user/username/unfollow", :method => :post },
|
||||
{ :controller => "friendships", :action => "unfollow", :display_name => "username" }
|
||||
)
|
||||
end
|
||||
|
||||
def test_make_friend
|
||||
def test_follow
|
||||
# Get users to work with
|
||||
user = create(:user)
|
||||
friend = create(:user)
|
||||
|
@ -44,7 +44,7 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
|
|||
# When logged in a GET should get a confirmation page
|
||||
get make_friend_path(friend)
|
||||
assert_response :success
|
||||
assert_template :make_friend
|
||||
assert_template :follow
|
||||
assert_select "form" do
|
||||
assert_select "input[type='hidden'][name='referer']", 0
|
||||
assert_select "input[type='submit']", 1
|
||||
|
@ -58,7 +58,7 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
end
|
||||
assert_redirected_to user_path(friend)
|
||||
assert_match(/is now your friend/, flash[:notice])
|
||||
assert_match(/You are now following/, flash[:notice])
|
||||
assert Friendship.find_by(:befriender => user, :befriendee => friend)
|
||||
email = ActionMailer::Base.deliveries.first
|
||||
assert_equal 1, email.to.count
|
||||
|
@ -72,11 +72,11 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
end
|
||||
assert_redirected_to user_path(friend)
|
||||
assert_match(/You are already friends with/, flash[:warning])
|
||||
assert_match(/You already follow/, flash[:warning])
|
||||
assert Friendship.find_by(:befriender => user, :befriendee => friend)
|
||||
end
|
||||
|
||||
def test_make_friend_with_referer
|
||||
def test_follow_with_referer
|
||||
# Get users to work with
|
||||
user = create(:user)
|
||||
friend = create(:user)
|
||||
|
@ -88,7 +88,7 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
|
|||
# The GET should preserve any referer
|
||||
get make_friend_path(friend), :params => { :referer => "/test" }
|
||||
assert_response :success
|
||||
assert_template :make_friend
|
||||
assert_template :follow
|
||||
assert_select "form" do
|
||||
assert_select "input[type='hidden'][name='referer'][value='/test']", 1
|
||||
assert_select "input[type='submit']", 1
|
||||
|
@ -102,7 +102,7 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
end
|
||||
assert_redirected_to "/test"
|
||||
assert_match(/is now your friend/, flash[:notice])
|
||||
assert_match(/You are now following/, flash[:notice])
|
||||
assert Friendship.find_by(:befriender => user, :befriendee => friend)
|
||||
email = ActionMailer::Base.deliveries.first
|
||||
assert_equal 1, email.to.count
|
||||
|
@ -110,7 +110,7 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
|
|||
ActionMailer::Base.deliveries.clear
|
||||
end
|
||||
|
||||
def test_make_friend_unknown_user
|
||||
def test_follow_unknown_user
|
||||
# Should error when a bogus user is specified
|
||||
session_for(create(:user))
|
||||
get make_friend_path("No Such User")
|
||||
|
@ -118,7 +118,7 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_template :no_such_user
|
||||
end
|
||||
|
||||
def test_remove_friend
|
||||
def test_unfollow
|
||||
# Get users to work with
|
||||
user = create(:user)
|
||||
friend = create(:user)
|
||||
|
@ -141,7 +141,7 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
|
|||
# When logged in a GET should get a confirmation page
|
||||
get remove_friend_path(friend)
|
||||
assert_response :success
|
||||
assert_template :remove_friend
|
||||
assert_template :unfollow
|
||||
assert_select "form" do
|
||||
assert_select "input[type='hidden'][name='referer']", 0
|
||||
assert_select "input[type='submit']", 1
|
||||
|
@ -151,17 +151,17 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
|
|||
# When logged in a POST should remove the friendship
|
||||
post remove_friend_path(friend)
|
||||
assert_redirected_to user_path(friend)
|
||||
assert_match(/was removed from your friends/, flash[:notice])
|
||||
assert_match(/You successfully unfollowed/, flash[:notice])
|
||||
assert_nil Friendship.find_by(:befriender => user, :befriendee => friend)
|
||||
|
||||
# A second POST should report that the friendship does not exist
|
||||
post remove_friend_path(friend)
|
||||
assert_redirected_to user_path(friend)
|
||||
assert_match(/is not one of your friends/, flash[:error])
|
||||
assert_match(/You are not following/, flash[:error])
|
||||
assert_nil Friendship.find_by(:befriender => user, :befriendee => friend)
|
||||
end
|
||||
|
||||
def test_remove_friend_with_referer
|
||||
def test_unfollow_with_referer
|
||||
# Get users to work with
|
||||
user = create(:user)
|
||||
friend = create(:user)
|
||||
|
@ -174,7 +174,7 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
|
|||
# The GET should preserve any referer
|
||||
get remove_friend_path(friend), :params => { :referer => "/test" }
|
||||
assert_response :success
|
||||
assert_template :remove_friend
|
||||
assert_template :unfollow
|
||||
assert_select "form" do
|
||||
assert_select "input[type='hidden'][name='referer'][value='/test']", 1
|
||||
assert_select "input[type='submit']", 1
|
||||
|
@ -184,11 +184,11 @@ class FriendshipsControllerTest < ActionDispatch::IntegrationTest
|
|||
# When logged in a POST should remove the friendship and refer
|
||||
post remove_friend_path(friend), :params => { :referer => "/test" }
|
||||
assert_redirected_to "/test"
|
||||
assert_match(/was removed from your friends/, flash[:notice])
|
||||
assert_match(/You successfully unfollowed/, flash[:notice])
|
||||
assert_nil Friendship.find_by(:befriender => user, :befriendee => friend)
|
||||
end
|
||||
|
||||
def test_remove_friend_unknown_user
|
||||
def test_unfollow_unknown_user
|
||||
# Should error when a bogus user is specified
|
||||
session_for(create(:user))
|
||||
get remove_friend_path("No Such User")
|
||||
|
|
|
@ -56,7 +56,7 @@ class Oauth2AuthorizedApplicationsControllerTest < ActionDispatch::IntegrationTe
|
|||
assert_select "li", :count => 3
|
||||
assert_select "li", :text => "Read user preferences"
|
||||
assert_select "li", :text => "Modify user preferences"
|
||||
assert_select "li", :text => "Create diary entries, comments and make friends"
|
||||
assert_select "li", :text => "Create diary entries and comments"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
require "application_system_test_case"
|
||||
|
||||
class DashboardSystemTest < ApplicationSystemTestCase
|
||||
test "show no users if have no friends" do
|
||||
test "show no users if have no followings" do
|
||||
user = create(:user)
|
||||
sign_in_as(user)
|
||||
|
||||
visit dashboard_path
|
||||
assert_text "You have not added any friends yet."
|
||||
assert_text "You have not followed any user yet."
|
||||
end
|
||||
|
||||
test "show users if have friends" do
|
||||
|
@ -17,9 +17,9 @@ class DashboardSystemTest < ApplicationSystemTestCase
|
|||
sign_in_as(user)
|
||||
|
||||
visit dashboard_path
|
||||
assert_no_text "You have not added any friends yet."
|
||||
assert_no_text "You have not followed any user yet."
|
||||
|
||||
friends_heading = find :element, "h2", :text => "My friends"
|
||||
friends_heading = find :element, "h2", :text => "Followings"
|
||||
others_heading = find :element, "h2", :text => "Other nearby users"
|
||||
|
||||
assert_link friend_user.display_name, :below => friends_heading, :above => others_heading
|
||||
|
|
|
@ -8,11 +8,11 @@ class FriendshipsTest < ApplicationSystemTestCase
|
|||
|
||||
with_settings(:max_friends_per_hour => 0) do
|
||||
visit user_path(befriendee)
|
||||
assert_link "Add Friend"
|
||||
assert_link "Follow"
|
||||
|
||||
click_on "Add Friend"
|
||||
assert_text "You have friended a lot of users recently"
|
||||
assert_link "Add Friend"
|
||||
click_on "Follow"
|
||||
assert_text "You have followed a lot of users recently"
|
||||
assert_link "Follow"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue