Skip to content

Commit

Permalink
fix to sunspot config and additional activity grid tweaks
Browse files Browse the repository at this point in the history
refactor Rails.root to request.host

update for mailers too

mailer reqeust.host fixes in tests

more mailer test tweaks

mailer test fixes 2

more mailer test refactoring

ActionMailer host changes in test and app

more test tweaks

test helper

specifying hosts for mailers in dev and test

revision timing change for order

render body test w/ request host param

render_body_email, not render_body

hostname env. config and activity feed html tweak

mailer/request.host additions

style tweak

last domain tweak
  • Loading branch information
jywarren committed Oct 15, 2016
1 parent 17398e4 commit 9b6486e
Show file tree
Hide file tree
Showing 60 changed files with 212 additions and 189 deletions.
12 changes: 12 additions & 0 deletions app/assets/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,15 @@ table th a {
table th a:hover {
color: #aaa;
}

@media (max-width:768px) {
table {
font-size: 90%;
}
}

@media (max-width:400px) {
table {
font-size: 80%;
}
}
4 changes: 2 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def current_user
@current_user = nil
elsif @current_user.try(:drupal_user).try(:status) == 5
# Tell the user they are banned. Fails b/c redirect to require below.
flash[:warning] = "The user '#{@current_user.username}' has been placed in moderation; please see <a href='https://#{Rails.root}/wiki/moderators'>our moderation policy</a> and contact <a href='mailto:moderators@#{Rails.root}'>moderators@#{Rails.root}</a> if you believe this is in error."
flash[:warning] = "The user '#{@current_user.username}' has been placed in moderation; please see <a href='https://#{request.host}/wiki/moderators'>our moderation policy</a> and contact <a href='mailto:moderators@#{request.host}'>moderators@#{request.host}</a> if you believe this is in error."
# Same effect as if the user clicked logout:
current_user_session.destroy
# Ensures no code will use old @current_user info. Treat the user
Expand Down Expand Up @@ -142,7 +142,7 @@ def alert_and_redirect_moderated
# no notification; don't let people easily fish for existing draft titles; we should try to 404 it
redirect_to "/"
elsif @node.author.status == 5
flash.now[:warning] = "The user '#{@node.author.username}' has been placed <a href='https://#{Rails.root}/wiki/moderators'>in moderation</a> and will not be able to respond to comments."
flash.now[:warning] = "The user '#{@node.author.username}' has been placed <a href='https://#{request.host}/wiki/moderators'>in moderation</a> and will not be able to respond to comments."
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/legacy_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def openid_username
end

def file
redirect_to "//#{Rails.root}/sites/default/files/"+params[:filename]+"."+params[:format], :status => 301
redirect_to "//#{request.host}/sites/default/files/"+params[:filename]+"."+params[:format], :status => 301
end

# def image
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/openid_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def decision
def server
if @server.nil?
server_url = url_for :action => 'index', :only_path => false
dir = Pathname.new(Rails.root).join('db').join('openid-store')
dir = Pathname.new(request.host).join('db').join('openid-store')
store = OpenID::Store::Filesystem.new(dir)
@server = Server.new(store, server_url)
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/tag_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ def barnstar
else
flash[:notice] = I18n.t('tag_controller.barnstar_awarded', :url1 => "/wiki/barnstars#"+params[:star].split('-').each{|w| w.capitalize!}.join('+')+"+Barnstar", :star => params[:star], :url2 => "/profile/"+node.author.name, :awardee => node.author.name).html_safe
# on success add comment
barnstar_info_link = '<a href="//' + Rails.root.to_s + '/wiki/barnstars">barnstar</a>'
barnstar_info_link = '<a href="//' + request.host.to_s + '/wiki/barnstars">barnstar</a>'
node.add_comment({
:subject => 'barnstar',
:uid => current_user.uid,
:body => "#{current_user.username} awards a #{barnstar_info_link} to #{node.drupal_users.name} for their awesome contribution!"
:body => "@#{current_user.username} awards a #{barnstar_info_link} to #{node.drupal_users.name} for their awesome contribution!"
})
end
redirect_to node.path + "?_=" + Time.now.to_i.to_s
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/wiki_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class WikiController < ApplicationController
before_filter :require_user, :only => [:new, :create, :edit, :update, :delete]

def subdomain
url = "//#{Rails.root}/wiki/"
url = "//#{request.host}/wiki/"
case request.subdomain
when "new-york-city",
"gulf-coast",
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def insert_extras(body)
output += ' <td class="author"><a href="/profile/' + node.author.username + '">@' + node.author.username + '</a></td>'
output += ' <td class="time">' + (node.has_power_tag('time') ? node.power_tag('time') : '-') + '</td>'
output += ' <td class="difficulty">' + (node.has_power_tag('difficulty') ? node.power_tag('difficulty') : '-') + '</td>'
output += ' <td class="replications">' + node.response_count('replication').to_s + ' replications</td>'
output += ' <td class="replications">' + node.response_count('replication').to_s + ' replications: <a href="' + node.path + '#replications">Try it &raquo;</a></td>'
output += '</tr>'
end
output += '</table>'
Expand Down Expand Up @@ -109,7 +109,7 @@ def insert_extras(body)
output += ' <td class="author"><a href="/profile/' + node.author.username + '">@' + node.author.username + '</a></td>'
output += ' <td class="time">' + (node.has_power_tag('time') ? node.power_tag('time') : '-') + '</td>'
output += ' <td class="difficulty">' + (node.has_power_tag('difficulty') ? node.power_tag('difficulty') : '-') + '</td>'
output += ' <td class="builds">' + node.response_count('build').to_s + ' builds</td>'
output += ' <td class="builds">' + node.response_count('build').to_s + ' builds: <a href="' + node.path + '#builds">Try it &raquo;</a></td>'
output += '</tr>'
end
output += '</table>'
Expand Down
8 changes: 4 additions & 4 deletions app/mailers/admin_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class AdminMailer < ActionMailer::Base
default from: "do-not-reply@#{Rails.root}"
default from: "do-not-reply@#{ActionMailer::Base.default_url_options[:host]}"

def notify_node_moderators(node)
subject = "[New Public Lab poster needs moderation] " + node.title
@node = node
moderators = User.where(role: ['moderator', 'admin']).collect(&:email)
mail(
to: "moderators@#{Rails.root}",
to: "moderators@#{ActionMailer::Base.default_url_options[:host]}",
bcc: moderators,
subject: subject
).deliver
Expand Down Expand Up @@ -34,7 +34,7 @@ def notify_moderators_of_approval(node, moderator)
@node = node
moderators = User.where(role: ['moderator', 'admin']).collect(&:email)
mail(
to: "moderators@#{Rails.root}",
to: "moderators@#{ActionMailer::Base.default_url_options[:host]}",
bcc: moderators,
subject: subject
).deliver
Expand All @@ -47,7 +47,7 @@ def notify_moderators_of_spam(node, moderator)
@node = node
moderators = User.where(role: ['moderator', 'admin']).collect(&:email)
mail(
to: "moderators@#{Rails.root}",
to: "moderators@#{ActionMailer::Base.default_url_options[:host]}",
bcc: moderators,
subject: subject
).deliver
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/answer_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class AnswerMailer < ActionMailer::Base
default from: "do-not-reply@#{Rails.root}"
default from: "do-not-reply@#{ActionMailer::Base.default_url_options[:host]}"

def notify_question_author(user, answer)
subject = "[PublicLab] New answer to Question: " + answer.node.title
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/comment_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class CommentMailer < ActionMailer::Base
default from: "do-not-reply@#{Rails.root}"
default from: "do-not-reply@#{ActionMailer::Base.default_url_options[:host]}"

# CommentMailer.notify_of_comment(user,self).deliver
def notify(user,comment)
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/password_reset_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class PasswordResetMailer < ActionMailer::Base
default from: "do-not-reply@#{Rails.root}"
default from: "do-not-reply@#{ActionMailer::Base.default_url_options[:host]}"

# PasswordResetMailer.reset_notify(user).deliver
def reset_notify(user, key)
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/subscription_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class SubscriptionMailer < ActionMailer::Base
default from: "do-not-reply@#{Rails.root}"
default from: "do-not-reply@#{ActionMailer::Base.default_url_options[:host]}"

def notify_node_creation(node)
subject = "[PublicLab] " + (node.has_power_tag('question') ? "Question: " : "") +
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/welcome_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class WelcomeMailer < ActionMailer::Base
#default from: "do-not-reply@#{Rails.root}"
#default from: "do-not-reply@#{ActionMailer::Base.default_url_options[:host]}"

# PasswordResetMailer.reset_notify(user).deliver
def add_to_list(user,list)
Expand Down
4 changes: 2 additions & 2 deletions app/models/concerns/comments_shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module CommentsShared

# filtered version additionally appending http/https
# protocol to protocol-relative URLslike "/foo"
def body_email
self.body.gsub(/([\s|"|'|\[|\(])(\/\/)([\w]?\.?#{Rails.root})/, '\1https://\3')
def body_email(host = "publiclab.org")
self.body.gsub(/([\s|"|'|\[|\(])(\/\/)([\w]?\.?#{host})/, '\1https://\3')
end

def author
Expand Down
10 changes: 5 additions & 5 deletions app/models/drupal_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ def is_image?
def path(size = :default)
if self.is_image?
if size == :thumb
"https://#{Rails.root}/#{self.filepath.gsub('sites/default/files/','sites/default/files/imagecache/thumb/')}"
"/#{self.filepath.gsub('sites/default/files/','sites/default/files/imagecache/thumb/')}"
elsif size == :default
"https://#{Rails.root}/#{self.filepath.gsub('sites/default/files/','sites/default/files/imagecache/default/')}"
"/#{self.filepath.gsub('sites/default/files/','sites/default/files/imagecache/default/')}"
elsif size == :large
"https://#{Rails.root}/#{self.filepath.gsub('sites/default/files/','sites/default/files/imagecache/default/')}"
"/#{self.filepath.gsub('sites/default/files/','sites/default/files/imagecache/default/')}"
elsif size == :original
"https://#{Rails.root}/#{self.filepath}"
"/#{self.filepath}"
end
else
"https://#{Rails.root}/#{self.filepath}"
"/#{self.filepath}"
end
end

Expand Down
8 changes: 4 additions & 4 deletions app/models/drupal_node_revision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ def render_body

# filtered version additionally appending http/https protocol to protocol-relative URLs like "/foo"
# render_body plus making all relative links absolute
def render_body_email
body = self.render_body.gsub(/([\s|"|'|\[|\(])(\/\/)([\w]?\.?#{Rails.root})/, '\1https://\3')
body = body.gsub("href='/","href='https://#{Rails.root}/")
body = body.gsub('href="/','href="https://' + Rails.root.to_s + '/')
def render_body_email(host = "publiclab.org")
body = self.render_body.gsub(/([\s|"|'|\[|\(])(\/\/)([\w]?\.?#{host})/, '\1https://\3')
body = body.gsub("href='/","href='https://#{host}/")
body = body.gsub('href="/','href="https://' + host.to_s + '/')
body
end

Expand Down
6 changes: 1 addition & 5 deletions app/models/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ def path(size = :medium)
else
size = :original
end
if Rails.env == "production"
'https://i.' + Rails.root.to_s + self.photo.url(size)
else
self.photo.url(size).gsub('https://i.' + Rails.root.to_s,'')
end
self.photo.url(size)
end

def filename
Expand Down
6 changes: 1 addition & 5 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,7 @@ def barnstars
end

def photo_path(size = :medium)
if Rails.env == "production"
'//i.' + Rails.root.to_s + self.photo.url(size)
else
self.photo.url(size).gsub("//i.#{Rails.root}",'')
end
self.photo.url(size)
end

def first_time_poster
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/spam.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<h3>Spam moderation:</h3>

<p>Moderators and admins have the ability to "spam" posts if they include inappropriate content, blatant advertising, or are otherwise problematic. If you're not sure, email <a href="mailto:organizers@<%= Rails.root %>">organizers@<%= Rails.root %></a>. If we all work together, we can keep spam to a minimum; thanks for helping out!</p>
<p>Moderators and admins have the ability to "spam" posts if they include inappropriate content, blatant advertising, or are otherwise problematic. If you're not sure, email <a href="mailto:organizers@<%= request.host %>">organizers@<%= request.host %></a>. If we all work together, we can keep spam to a minimum; thanks for helping out!</p>

<hr />

Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/users.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<h3>User moderation:</h3>

<p>Moderators and admins have the ability to ban users if they post inappropriate content, blatant advertising, or are otherwise problematic. If you're not sure, email <a href="mailto:organizers@<%= Rails.root %>">organizers@<%= Rails.root %></a>. If we all work together, we can keep spam to a minimum; thanks for helping out!</p>
<p>Moderators and admins have the ability to ban users if they post inappropriate content, blatant advertising, or are otherwise problematic. If you're not sure, email <a href="mailto:organizers@<%= request.host %>">organizers@<%= request.host %></a>. If we all work together, we can keep spam to a minimum; thanks for helping out!</p>

<hr />

Expand Down
6 changes: 3 additions & 3 deletions app/views/admin_mailer/notify_author_of_approval.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p>Hi! Your post was approved by <a href='https://<%= Rails.root %>/profile/<%= @moderator.username %>'><%= @moderator.username %></a> (a <a href='https://<%= Rails.root %>/wiki/moderation'>community moderator</a>) and is now visible in the <a href='https://<%= Rails.root %>/dashboard'>Public Lab research feed</a>. Thanks for contributing to open research!</p>
<p>Hi! Your post was approved by <a href='https://<%= ActionMailer::Base.default_url_options[:host] %>/profile/<%= @moderator.username %>'><%= @moderator.username %></a> (a <a href='https://<%= ActionMailer::Base.default_url_options[:host] %>/wiki/moderation'>community moderator</a>) and is now visible in the <a href='https://<%= ActionMailer::Base.default_url_options[:host] %>/dashboard'>Public Lab research feed</a>. Thanks for contributing to open research!</p>

<hr />

<p>See your post here: https://<%= Rails.root %><%= @node.path %></p>
<p>See your post here: https://<%= ActionMailer::Base.default_url_options[:host] %><%= @node.path %></p>

<p>Thanks for your patience! We've had to moderate first time posters due to problems with spam. Your posts will no longer be moderated, as long as you follow our <a href="https://<%= Rails.root %>/wiki/moderation">content guidelines</a>.</p>
<p>Thanks for your patience! We've had to moderate first time posters due to problems with spam. Your posts will no longer be moderated, as long as you follow our <a href="https://<%= ActionMailer::Base.default_url_options[:host] %>/wiki/moderation">content guidelines</a>.</p>
10 changes: 5 additions & 5 deletions app/views/admin_mailer/notify_moderators_of_approval.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<p>Post was approved by <a href='https://<%= Rails.root %>/profile/<%= @moderator.username %>'><%= @moderator.username %></a> after entering moderation queue <%= time_ago_in_words(@node.created_at) %> ago and is now visible in the <a href='https://<%= Rails.root %>/dashboard'>Public Lab research feed</a>. Thanks for helping to keep Public Lab a welcoming and spam-free space!</p>
<p>Post was approved by <a href='https://<%= ActionMailer::Base.default_url_options[:host] %>/profile/<%= @moderator.username %>'><%= @moderator.username %></a> after entering moderation queue <%= time_ago_in_words(@node.created_at) %> ago and is now visible in the <a href='https://<%= ActionMailer::Base.default_url_options[:host] %>/dashboard'>Public Lab research feed</a>. Thanks for helping to keep Public Lab a welcoming and spam-free space!</p>

<p>Now, reach out to welcome the new community member; thank them, just say hello, or help them revise/format their post in the comments. You can read and respond to the post here: https://<%= Rails.root %><%= @node.path %></p>
<p>Now, reach out to welcome the new community member; thank them, just say hello, or help them revise/format their post in the comments. You can read and respond to the post here: https://<%= ActionMailer::Base.default_url_options[:host] %><%= @node.path %></p>

<p>View <a href="https://<%= Rails.root %>/profile/<%= @node.author.name %>"><%= @node.author.name %>'s profile</a></p>
<p>View <a href="https://<%= ActionMailer::Base.default_url_options[:host] %>/profile/<%= @node.author.name %>"><%= @node.author.name %>'s profile</a></p>

<hr />

<div style="color:#aaa;">

<p>You received this email because you are <a href="https://<%= Rails.root %>/wiki/moderation">a Public Lab community moderator</a></p>
<p>You received this email because you are <a href="https://<%= ActionMailer::Base.default_url_options[:host] %>/wiki/moderation">a Public Lab community moderator</a></p>

<p>To discuss spam/abuse, forward this to <a href="mailto:moderators@<%= Rails.root %>">moderators@<%= Rails.root %></a></p>
<p>To discuss spam/abuse, forward this to <a href="mailto:moderators@<%= ActionMailer::Base.default_url_options[:host] %>">moderators@<%= ActionMailer::Base.default_url_options[:host] %></a></p>

</div>
12 changes: 6 additions & 6 deletions app/views/admin_mailer/notify_moderators_of_spam.html.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<p>Post was marked as spam by <a href='https://<%= Rails.root %>/profile/<%= @moderator.username %>'><%= @moderator.username %></a> after entering moderation queue <%= time_ago_in_words(@node.created_at) %> ago. The user was also banned from the site.</p>
<p>Post was marked as spam by <a href='https://<%= ActionMailer::Base.default_url_options[:host] %>/profile/<%= @moderator.username %>'><%= @moderator.username %></a> after entering moderation queue <%= time_ago_in_words(@node.created_at) %> ago. The user was also banned from the site.</p>

<p>If you feel this was an error, you can republish this post at <a href='https://<%= Rails.root %>/spam'>Public Lab research feed</a>. To discuss spam/abuse with other moderators, forward this to <a href="mailto:moderators@<%= Rails.root %>">moderators@<%= Rails.root %></a></p>
<p>If you feel this was an error, you can republish this post at <a href='https://<%= ActionMailer::Base.default_url_options[:host] %>/spam'>Public Lab research feed</a>. To discuss spam/abuse with other moderators, forward this to <a href="mailto:moderators@<%= ActionMailer::Base.default_url_options[:host] %>">moderators@<%= ActionMailer::Base.default_url_options[:host] %></a></p>

<p>If this moderation was due to failure to follow <a href="https://<%= Rails.root %>/wiki/moderation">community content guidelines</a>, and not advertising spam, consider reaching out to the poster to explain why you decided to moderate their content. Their email address is: <%= @node.author.mail %></p>
<p>If this moderation was due to failure to follow <a href="https://<%= ActionMailer::Base.default_url_options[:host] %>/wiki/moderation">community content guidelines</a>, and not advertising spam, consider reaching out to the poster to explain why you decided to moderate their content. Their email address is: <%= @node.author.mail %></p>

<p>Thanks for helping to keep Public Lab a welcoming and spam-free space!</p>

<p>View <a href="https://<%= Rails.root %>/profile/<%= @node.author.name %>"><%= @node.author.name %>'s profile</a></p>
<p>View <a href="https://<%= ActionMailer::Base.default_url_options[:host] %>/profile/<%= @node.author.name %>"><%= @node.author.name %>'s profile</a></p>

<hr />

<div style="color:#aaa;">

<p>You received this email because you are <a href="https://<%= Rails.root %>/wiki/moderation">a Public Lab community moderator</a></p>
<p>You received this email because you are <a href="https://<%= ActionMailer::Base.default_url_options[:host] %>/wiki/moderation">a Public Lab community moderator</a></p>

<p>To discuss spam/abuse, forward this to <a href="mailto:moderators@<%= Rails.root %>">moderators@<%= Rails.root %></a></p>
<p>To discuss spam/abuse, forward this to <a href="mailto:moderators@<%= ActionMailer::Base.default_url_options[:host] %>">moderators@<%= ActionMailer::Base.default_url_options[:host] %></a></p>

</div>
Loading

0 comments on commit 9b6486e

Please sign in to comment.