include ability to unfollow from email
This commit is contained in:
parent
013e3c7f21
commit
2b34d84715
14 changed files with 69 additions and 12 deletions
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
class MapsController < ApplicationController
|
||||
before_action :require_user, only: [:create, :update, :destroy, :events, :follow, :unfollow]
|
||||
before_action :set_map, only: [:show, :conversation, :update, :destroy, :contains, :events, :export, :follow, :unfollow]
|
||||
before_action :set_map, only: [:show, :conversation, :update, :destroy, :contains, :events, :export, :follow, :unfollow, :unfollow_from_email]
|
||||
after_action :verify_authorized
|
||||
|
||||
# GET maps/:id
|
||||
|
@ -164,6 +164,17 @@ class MapsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# GET maps/:id/unfollow_from_email
|
||||
def unfollow_from_email
|
||||
FollowService.unfollow(@map, current_user)
|
||||
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
redirect_to map_path(@map), notice: 'You are no longer following this map'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_map
|
||||
|
|
|
@ -3,7 +3,9 @@ class TopicsController < ApplicationController
|
|||
include TopicsHelper
|
||||
|
||||
before_action :require_user, only: [:create, :update, :destroy, :follow, :unfollow]
|
||||
before_action :set_topic, only: [:show, :update, :relative_numbers, :relatives, :network, :destroy, :follow, :unfollow]
|
||||
before_action :set_topic, only: [:show, :update, :relative_numbers,
|
||||
:relatives, :network, :destroy,
|
||||
:follow, :unfollow, :unfollow_from_email]
|
||||
after_action :verify_authorized, except: :autocomplete_topic
|
||||
|
||||
respond_to :html, :js, :json
|
||||
|
@ -185,6 +187,17 @@ class TopicsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# GET topics/:id/unfollow_from_email
|
||||
def unfollow_from_email
|
||||
FollowService.unfollow(@topic, current_user)
|
||||
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
redirect_to topic_path(@topic), notice: 'You are no longer following this topic'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_topic
|
||||
|
|
|
@ -10,11 +10,11 @@ class FollowService
|
|||
follow.follow_reason.update_attribute(reason, true)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def unfollow(entity, user)
|
||||
Follow.where(followed: entity, user: user).destroy_all
|
||||
end
|
||||
|
||||
|
||||
def remove_reason(entity, user, reason)
|
||||
return unless FollowReason::REASONS.include?(reason)
|
||||
follow = Follow.where(followed: entity, user: user).first
|
||||
|
@ -25,9 +25,9 @@ class FollowService
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
|
||||
|
||||
def is_tester(user)
|
||||
%w(connorturland@gmail.com devin@callysto.com chessscholar@gmail.com solaureum@gmail.com ishanshapiro@gmail.com).include?(user.email)
|
||||
end
|
||||
|
|
0
app/views/map_mailer/_unfollow.html.erb
Normal file
0
app/views/map_mailer/_unfollow.html.erb
Normal file
0
app/views/map_mailer/_unfollow.text.erb
Normal file
0
app/views/map_mailer/_unfollow.text.erb
Normal file
4
app/views/topic_mailer/_unfollow.html.erb
Normal file
4
app/views/topic_mailer/_unfollow.html.erb
Normal file
|
@ -0,0 +1,4 @@
|
|||
<hr>
|
||||
<% topic = @entity || entity %>
|
||||
You are receiving this email because you are following this topic.
|
||||
<%= link_to 'Unfollow', unfollow_from_email_topic_url(topic) %>
|
3
app/views/topic_mailer/_unfollow.text.erb
Normal file
3
app/views/topic_mailer/_unfollow.text.erb
Normal file
|
@ -0,0 +1,3 @@
|
|||
<% topic = @entity || entity %>
|
||||
You are receiving this email because you are following this topic.
|
||||
To unfollow, go to: <%= unfollow_from_email_topic_url(topic) %>
|
|
@ -8,4 +8,6 @@
|
|||
</p>
|
||||
|
||||
<%= link_to 'Go to Topic', topic_url(topic), style: button_style %>
|
||||
<%= link_to 'Go to Map', map_url(event.map), style: button_style %>
|
||||
<%= link_to 'Go to Map', map_url(event.map), style: button_style %>
|
||||
|
||||
<%= render :partial => 'topic_mailer/unfollow' %>
|
|
@ -3,4 +3,6 @@
|
|||
<%= event.user.name %> added topic <%= topic.name %> to map <%= event.map.name %>
|
||||
|
||||
topic_url(topic)
|
||||
map_url(event.map)
|
||||
map_url(event.map)
|
||||
|
||||
<%= render :partial => 'topic_mailer/unfollow' %>
|
|
@ -12,4 +12,6 @@
|
|||
<% end %>
|
||||
</p>
|
||||
|
||||
<%= link_to 'View the connection', topic_url(topic1), style: button_style %>
|
||||
<%= link_to 'View the connection', topic_url(topic1), style: button_style %>
|
||||
|
||||
<%= render :partial => 'topic_mailer/unfollow' %>
|
|
@ -5,4 +5,6 @@
|
|||
<%= synapse.user.name %> connected topic <%= topic1.name %> to topic <%= topic2.name %>
|
||||
<%= synapse.desc.length > 0 ? ' with the description' + synapse.desc : '' %>
|
||||
|
||||
<%= topic_url(topic1) %>
|
||||
<%= topic_url(topic1) %>
|
||||
|
||||
<%= render :partial => 'topic_mailer/unfollow' %>
|
|
@ -50,6 +50,7 @@ Metamaps::Application.routes.draw do
|
|||
post :unstar, to: 'stars#destroy', default: { format: :json }
|
||||
post :follow, default: { format: :json }
|
||||
post :unfollow, default: { format: :json }
|
||||
get :unfollow_from_email
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -87,6 +88,7 @@ Metamaps::Application.routes.draw do
|
|||
get :relatives
|
||||
post :follow, default: { format: :json }
|
||||
post :unfollow, default: { format: :json }
|
||||
get :unfollow_from_email
|
||||
end
|
||||
collection do
|
||||
get :autocomplete_topic
|
||||
|
|
|
@ -6,12 +6,12 @@ class MapMailerPreview < ActionMailer::Preview
|
|||
MapMailer.invite_to_edit(user_map)
|
||||
end
|
||||
|
||||
def access_request_email
|
||||
def access_request
|
||||
request = AccessRequest.first
|
||||
MapMailer.access_request(request)
|
||||
end
|
||||
|
||||
def access_approved_email
|
||||
def access_approved
|
||||
request = AccessRequest.first
|
||||
MapMailer.access_approved(request)
|
||||
end
|
||||
|
|
16
spec/mailers/previews/topic_mailer_preview.rb
Normal file
16
spec/mailers/previews/topic_mailer_preview.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
# Preview all emails at http://localhost:3000/rails/mailers/topic_mailer
|
||||
class TopicMailerPreview < ActionMailer::Preview
|
||||
def added_to_map
|
||||
event = Event.where(kind: 'topic_added_to_map').first
|
||||
user = User.first
|
||||
TopicMailer.added_to_map(event, user)
|
||||
end
|
||||
|
||||
def connected
|
||||
synapse = Synapse.first
|
||||
topic = synapse.topic1
|
||||
user = User.first
|
||||
TopicMailer.connected(synapse, topic, user)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue