Skip to content

Commit

Permalink
Follow-up emails for draft news
Browse files Browse the repository at this point in the history
  • Loading branch information
nono committed May 1, 2013
1 parent 21956b3 commit 0b849fd
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 9 deletions.
6 changes: 6 additions & 0 deletions app/assets/javascripts/application.coffee
Expand Up @@ -142,6 +142,12 @@ $("#account_user_attributes_avatar").change ->
url = window.URL.createObjectURL(@files[0])
$(@).parents("form").find(".avatar").attr "src", url

# Follow-up
$("#followup").click ->
$("#followup").hide()
$("#followup_form").show()
false

# Admins
$("#admin_49_3").click ->
$("#admin_49_3").hide()
Expand Down
3 changes: 3 additions & 0 deletions app/assets/stylesheets/RonRonnement.css.scss
Expand Up @@ -184,6 +184,9 @@ button, input[type='submit'] {
&.rewrite_news {
background: url("/images/icones/pen.png") no-repeat 2px 2px $C_CLAIR;
}
&#followup {
background: url("/images/icones/at.png") no-repeat 2px 2px $C_CLAIR;
}
}

.edit_client_app a,
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/redaction/news_controller.rb
Expand Up @@ -63,6 +63,12 @@ def reorganized
redirect_to [@news.draft? ? :redaction : :moderation, @news]
end

def followup
enforce_followup_permission(@news)
NewsNotifications.followup(@news, params[:message]).deliver
redirect_to [:redaction, @news], :notice => "Courriel de relance envoyé"
end

def submit
if @news.unlocked?
@news.submit_and_notify(current_user)
Expand Down
33 changes: 24 additions & 9 deletions app/mailers/news_notifications.rb
Expand Up @@ -3,11 +3,11 @@
# This mailer is used to notify news writers when their news are accepted or refused.
#
class NewsNotifications < ActionMailer::Base
default :from => "LinuxFr.org <moderateurs@linuxfr.org>",
:cc => "LinuxFr.org <moderateurs@linuxfr.org>"
MODERATORS = "Equipe de modération LinuxFr.org <moderateurs@linuxfr.org>"
EDITORS = "Equipe de rédaction LinuxFr.org <redacteurs@linuxfr.org>"

def accept(news)
send_email "Dépêche acceptée :", news
send_moderation_email "Dépêche acceptée :", news
end

def self.refuse_with_message(news, message, template)
Expand All @@ -25,31 +25,46 @@ def self.refuse_with_message(news, message, template)
def refuse(news, message)
@news = news
@message = message
send_email "Dépêche refusée :", news
send_moderation_email "Dépêche refusée :", news
end

def refuse_template(news, message, template)
@news = news
@message = message.present? ? "Le modérateur a tenu à ajouter : #{message}\n\n" : ""
@response= Response.find(template)
send_email "Dépêche refusée :", news
send_moderation_email "Dépêche refusée :", news
end

def refuse_en(news)
@news = news
send_email "Rejected news:", news
send_moderation_email "Rejected news:", news
end

def rewrite(news)
send_email "Dépêche renvoyée en rédaction :", news
send_redaction_mail "Dépêche renvoyée en rédaction :", news
end

def followup(news, message)
@message = message.present? ? "\n#{message}\n" : ""
send_redaction_mail "Relance", news
end

protected

def send_email(subject, news)
def send_redaction_mail(subject, news)
@news = news
mail :from => EDITORS,
:to => EDITORS,
:bcc => news.attendees.map(&:account).compact.map(&:email),
:subject => "[LinuxFr.org] #{subject} #{news.title}"
end

def send_moderation_email(subject, news)
@news = news
headers["X-Moderator"] = news.moderator.name
mail :to => news.author_email,
mail :from => MODERATORS,
:to => news.author_email,
:cc => MODERATORS,
:subject => "[LinuxFr.org] #{subject} #{news.title}"
end

Expand Down
4 changes: 4 additions & 0 deletions app/models/news.rb
Expand Up @@ -320,6 +320,10 @@ def rewritable_by?(account)
refusable_by? account
end

def followupable_by?(account)
draft? && account.admin?
end

def reassignable_by?(account)
account.moderator? || account.admin?
end
Expand Down
13 changes: 13 additions & 0 deletions app/views/news_notifications/followup.text.erb
@@ -0,0 +1,13 @@
Bonjour,

vous avez créé ou contribué à la dépêche en rédaction :
<%= @news.title %>

Il semblerait qu'elle nécessite encore un peu de travail pour être finalisée.
Vous pouvez la compléter à cette URL :
<%= redaction_news_url @news %>

Merci d'avance.
<%= @message %>
--
L'équipe LinuxFr.org
10 changes: 10 additions & 0 deletions app/views/redaction/news/show.html.haml
Expand Up @@ -30,6 +30,16 @@
= link_to "Réorganiser", reorganize_redaction_news_path(@news), :class => "reorganize"
- if current_account.amr? || @news.submitted_by?(current_account)
= button_to "Soumettre la dépêche", submit_redaction_news_path(@news), :class => "submit_news"
- if current_account.can_followup? @news
%button#followup Relancer les rédacteurs
#followup_form(style="display: none;")
= form_tag followup_redaction_news_path(@news) do
%p
Vous pouvez envoyer un message de relance aux participants de cette dépêche
pour leur demander de finaliser cette dépêche. N'hésitez pas à leur donner
des précisions (date de sortie imminente, demande de précisions, etc.).
= text_area_tag :message
= submit_tag 'Envoyer'

%article
%strong Attention :
Expand Down
1 change: 1 addition & 0 deletions config/initializers/canable.rb
Expand Up @@ -26,6 +26,7 @@ def enforce_#{can}_permission(resource, message="")
Canable.add(:accept, :acceptable)
Canable.add(:refuse, :refusable)
Canable.add(:rewrite, :rewritable)
Canable.add(:followup,:followupable)
Canable.add(:reassign,:reassignable)
Canable.add(:reset, :resetable)
Canable.add(:ppp, :pppable)
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -115,6 +115,7 @@
member do
get "/revisions/:revision" => :revision, :as => :revision
post :submit
post :followup
get :reorganize
put :reorganized
end
Expand Down
Binary file added public/images/icones/at.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0b849fd

Please sign in to comment.