diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb
index fb4036d3..c5b9870a 100644
--- a/app/controllers/maps_controller.rb
+++ b/app/controllers/maps_controller.rb
@@ -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
diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb
index 779e11cf..c992bd14 100644
--- a/app/controllers/topics_controller.rb
+++ b/app/controllers/topics_controller.rb
@@ -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
diff --git a/app/services/follow_service.rb b/app/services/follow_service.rb
index 9c0693de..53add1cf 100644
--- a/app/services/follow_service.rb
+++ b/app/services/follow_service.rb
@@ -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
diff --git a/app/views/map_mailer/_unfollow.html.erb b/app/views/map_mailer/_unfollow.html.erb
new file mode 100644
index 00000000..e69de29b
diff --git a/app/views/map_mailer/_unfollow.text.erb b/app/views/map_mailer/_unfollow.text.erb
new file mode 100644
index 00000000..e69de29b
diff --git a/app/views/topic_mailer/_unfollow.html.erb b/app/views/topic_mailer/_unfollow.html.erb
new file mode 100644
index 00000000..fd178254
--- /dev/null
+++ b/app/views/topic_mailer/_unfollow.html.erb
@@ -0,0 +1,4 @@
+
+<% topic = @entity || entity %>
+You are receiving this email because you are following this topic.
+<%= link_to 'Unfollow', unfollow_from_email_topic_url(topic) %>
\ No newline at end of file
diff --git a/app/views/topic_mailer/_unfollow.text.erb b/app/views/topic_mailer/_unfollow.text.erb
new file mode 100644
index 00000000..50e00bd8
--- /dev/null
+++ b/app/views/topic_mailer/_unfollow.text.erb
@@ -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) %>
\ No newline at end of file
diff --git a/app/views/topic_mailer/added_to_map.html.erb b/app/views/topic_mailer/added_to_map.html.erb
index a2435272..c33eb5ba 100644
--- a/app/views/topic_mailer/added_to_map.html.erb
+++ b/app/views/topic_mailer/added_to_map.html.erb
@@ -8,4 +8,6 @@
<%= link_to 'Go to Topic', topic_url(topic), style: button_style %>
-<%= link_to 'Go to Map', map_url(event.map), style: button_style %>
\ No newline at end of file
+<%= link_to 'Go to Map', map_url(event.map), style: button_style %>
+
+<%= render :partial => 'topic_mailer/unfollow' %>
\ No newline at end of file
diff --git a/app/views/topic_mailer/added_to_map.text.erb b/app/views/topic_mailer/added_to_map.text.erb
index 183d1e8e..7d95bb24 100644
--- a/app/views/topic_mailer/added_to_map.text.erb
+++ b/app/views/topic_mailer/added_to_map.text.erb
@@ -3,4 +3,6 @@
<%= event.user.name %> added topic <%= topic.name %> to map <%= event.map.name %>
topic_url(topic)
-map_url(event.map)
\ No newline at end of file
+map_url(event.map)
+
+<%= render :partial => 'topic_mailer/unfollow' %>
\ No newline at end of file
diff --git a/app/views/topic_mailer/connected.html.erb b/app/views/topic_mailer/connected.html.erb
index 306e40c4..276b4a7b 100644
--- a/app/views/topic_mailer/connected.html.erb
+++ b/app/views/topic_mailer/connected.html.erb
@@ -12,4 +12,6 @@
<% end %>
-<%= link_to 'View the connection', topic_url(topic1), style: button_style %>
\ No newline at end of file
+<%= link_to 'View the connection', topic_url(topic1), style: button_style %>
+
+<%= render :partial => 'topic_mailer/unfollow' %>
\ No newline at end of file
diff --git a/app/views/topic_mailer/connected.text.erb b/app/views/topic_mailer/connected.text.erb
index 33afd027..06be9d7f 100644
--- a/app/views/topic_mailer/connected.text.erb
+++ b/app/views/topic_mailer/connected.text.erb
@@ -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) %>
\ No newline at end of file
+<%= topic_url(topic1) %>
+
+<%= render :partial => 'topic_mailer/unfollow' %>
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index e5be7aac..80c0dbb4 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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
diff --git a/spec/mailers/previews/map_mailer_preview.rb b/spec/mailers/previews/map_mailer_preview.rb
index 05368443..9766c0da 100644
--- a/spec/mailers/previews/map_mailer_preview.rb
+++ b/spec/mailers/previews/map_mailer_preview.rb
@@ -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
diff --git a/spec/mailers/previews/topic_mailer_preview.rb b/spec/mailers/previews/topic_mailer_preview.rb
new file mode 100644
index 00000000..7ce12b8d
--- /dev/null
+++ b/spec/mailers/previews/topic_mailer_preview.rb
@@ -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