Issue#15: Added Comment Notifications: notification_emails and comments view
This commit is contained in:
parent
a73ca335a9
commit
38e8be8793
16 changed files with 155 additions and 13 deletions
9
app/controllers/admin/comments_controller.rb
Normal file
9
app/controllers/admin/comments_controller.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
module Admin
|
||||||
|
class CommentsController < Admin::BaseController
|
||||||
|
load_and_authorize_resource
|
||||||
|
|
||||||
|
def index
|
||||||
|
@ordered_events = Event.order(:title).all
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -27,7 +27,6 @@ module Admin
|
||||||
@recent_users = User.limit(5).order(created_at: :desc)
|
@recent_users = User.limit(5).order(created_at: :desc)
|
||||||
@recent_events = Event.limit(5).order(created_at: :desc)
|
@recent_events = Event.limit(5).order(created_at: :desc)
|
||||||
@recent_registrations = Registration.limit(5).order(created_at: :desc)
|
@recent_registrations = Registration.limit(5).order(created_at: :desc)
|
||||||
|
|
||||||
@top_submitter = Conference.get_top_submitter
|
@top_submitter = Conference.get_top_submitter
|
||||||
|
|
||||||
@submissions = {}
|
@submissions = {}
|
||||||
|
|
|
||||||
|
|
@ -278,4 +278,8 @@ module ApplicationHelper
|
||||||
new_user_registration_path
|
new_user_registration_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def unread_notifications(user)
|
||||||
|
@unread_notifications = Comment.find_since_last_login(user)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,22 @@ class Mailbot < ActionMailer::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def send_notification_email_for_comment(comment)
|
||||||
|
@comment = comment
|
||||||
|
@event = @comment.commentable
|
||||||
|
@conference = @event.conference
|
||||||
|
recipients = User.comment_notifiable(@conference) # with scope
|
||||||
|
recipients.each do |user|
|
||||||
|
@user = user
|
||||||
|
mail(to: @user.email,
|
||||||
|
from: @conference.contact.email,
|
||||||
|
reply_to: @conference.contact.email,
|
||||||
|
template_path: 'admin/emails',
|
||||||
|
template_name: 'comment_template',
|
||||||
|
subject: "New comment has been posted for #{@event.title}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def build_email(conference, to, subject, body)
|
def build_email(conference, to, subject, body)
|
||||||
mail(to: to,
|
mail(to: to,
|
||||||
from: conference.contact.email,
|
from: conference.contact.email,
|
||||||
|
|
|
||||||
|
|
@ -137,6 +137,7 @@ class Ability
|
||||||
can :manage, Sponsor, conference_id: conf_ids_for_organizer
|
can :manage, Sponsor, conference_id: conf_ids_for_organizer
|
||||||
can :manage, SponsorshipLevel, conference_id: conf_ids_for_organizer
|
can :manage, SponsorshipLevel, conference_id: conf_ids_for_organizer
|
||||||
can :manage, Ticket, conference_id: conf_ids_for_organizer
|
can :manage, Ticket, conference_id: conf_ids_for_organizer
|
||||||
|
can :manage, Comment, conference_id: conf_ids_for_organizer
|
||||||
end
|
end
|
||||||
|
|
||||||
def signed_in_with_cfp_role(user)
|
def signed_in_with_cfp_role(user)
|
||||||
|
|
@ -155,6 +156,7 @@ class Ability
|
||||||
can :manage, CallForPaper, conference_id: conf_ids_for_cfp
|
can :manage, CallForPaper, conference_id: conf_ids_for_cfp
|
||||||
can :manage, Commercial, commercialable_type: 'Event',
|
can :manage, Commercial, commercialable_type: 'Event',
|
||||||
commercialable_id: Event.where(conference_id: conf_ids_for_cfp).pluck(:id)
|
commercialable_id: Event.where(conference_id: conf_ids_for_cfp).pluck(:id)
|
||||||
|
can :manage, Comment, conference_id: conf_ids_for_cfp
|
||||||
end
|
end
|
||||||
|
|
||||||
def signed_in_with_info_desk_role(user)
|
def signed_in_with_info_desk_role(user)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ class Comment < ActiveRecord::Base
|
||||||
attr_accessible :commentable, :body, :user_id
|
attr_accessible :commentable, :body, :user_id
|
||||||
validates_presence_of :body
|
validates_presence_of :body
|
||||||
validates_presence_of :user
|
validates_presence_of :user
|
||||||
|
after_create :send_notification
|
||||||
|
|
||||||
# NOTE: install the acts_as_votable plugin if you
|
# NOTE: install the acts_as_votable plugin if you
|
||||||
# want user to vote on the quality of comments.
|
# want user to vote on the quality of comments.
|
||||||
|
|
@ -40,9 +41,18 @@ class Comment < ActiveRecord::Base
|
||||||
where(commentable_type: commentable_str.to_s, commentable_id: commentable_id).order('created_at DESC')
|
where(commentable_type: commentable_str.to_s, commentable_id: commentable_id).order('created_at DESC')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scope :find_since_last_login, lambda { |user|
|
||||||
|
where(created_at: (user.last_sign_in_at..Time.now)).order(created_at: :desc)
|
||||||
|
}
|
||||||
# Helper class method to look up a commentable object
|
# Helper class method to look up a commentable object
|
||||||
# given the commentable class name and id
|
# given the commentable class name and id
|
||||||
def self.find_commentable(commentable_str, commentable_id)
|
def self.find_commentable(commentable_str, commentable_id)
|
||||||
commentable_str.constantize.find(commentable_id)
|
commentable_str.constantize.find(commentable_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def send_notification
|
||||||
|
Mailbot.delay.send_notification_email_for_comment(self)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ class EmailSettings < ActiveRecord::Base
|
||||||
h['registration_end_date'] = conference.registration_period.end_date
|
h['registration_end_date'] = conference.registration_period.end_date
|
||||||
end
|
end
|
||||||
|
|
||||||
if !event.nil?
|
if event
|
||||||
h['eventtitle'] = event.title
|
h['eventtitle'] = event.title
|
||||||
h['proposalslink'] = Rails.application.routes.url_helpers.conference_proposal_index_url(
|
h['proposalslink'] = Rails.application.routes.url_helpers.conference_proposal_index_url(
|
||||||
conference.short_title, host: CONFIG['url_for_emails'])
|
conference.short_title, host: CONFIG['url_for_emails'])
|
||||||
|
|
@ -67,6 +67,8 @@ class EmailSettings < ActiveRecord::Base
|
||||||
parse_template(conf_update_template, values)
|
parse_template(conf_update_template, values)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
def parse_template(text, values)
|
def parse_template(text, values)
|
||||||
values.each do |key, value|
|
values.each do |key, value|
|
||||||
if value.kind_of?(Date)
|
if value.kind_of?(Date)
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,9 @@ class User < ActiveRecord::Base
|
||||||
|
|
||||||
before_create :setup_role
|
before_create :setup_role
|
||||||
|
|
||||||
|
# add scope
|
||||||
|
scope :comment_notifiable, ->(conference) {joins(:roles).where('roles.name IN (?)', [:organizer, :cfp]).where('roles.resource_id = ?', conference.id)}
|
||||||
|
|
||||||
# Include default devise modules. Others available are:
|
# Include default devise modules. Others available are:
|
||||||
# :token_authenticatable, :confirmable,
|
# :token_authenticatable, :confirmable,
|
||||||
# :lockable, :timeoutable and :omniauthable
|
# :lockable, :timeoutable and :omniauthable
|
||||||
|
|
|
||||||
16
app/views/admin/comments/_all_comments.html.haml
Normal file
16
app/views/admin/comments/_all_comments.html.haml
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
.panel.well
|
||||||
|
-@ordered_events.each do |event|
|
||||||
|
- if event.comment_threads.count > 0
|
||||||
|
%panel
|
||||||
|
%panel.panel-header
|
||||||
|
%h4.title
|
||||||
|
= link_to event.title, admin_conference_event_path(event.conference.short_title, event)
|
||||||
|
%hr
|
||||||
|
-event.comment_threads.order(created_at: :desc).each do |comment|
|
||||||
|
%panel-body
|
||||||
|
%ul.list-unstyled
|
||||||
|
%li= comment.body
|
||||||
|
%ul.list-inline
|
||||||
|
%li Posted by: #{comment.user.name}
|
||||||
|
%li Created at: #{comment.created_at}
|
||||||
|
%hr
|
||||||
14
app/views/admin/comments/_posted_comments.html.haml
Normal file
14
app/views/admin/comments/_posted_comments.html.haml
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
.panel.well
|
||||||
|
-@ordered_events.each do |event|
|
||||||
|
- if event.comment_threads.find_comments_by_user(current_user).count > 0
|
||||||
|
%panel
|
||||||
|
%panel.panel-header
|
||||||
|
%h4.title
|
||||||
|
= link_to event.title, admin_conference_event_path(event.conference.short_title, event)
|
||||||
|
%hr
|
||||||
|
-event.comment_threads.find_comments_by_user(current_user).each do |comment|
|
||||||
|
%panel-body
|
||||||
|
%ul.list-unstyled
|
||||||
|
%li= comment.body
|
||||||
|
%li Created at: #{comment.created_at}
|
||||||
|
%hr
|
||||||
16
app/views/admin/comments/_unread_comments.html.haml
Normal file
16
app/views/admin/comments/_unread_comments.html.haml
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
.panel.well
|
||||||
|
-@ordered_events.each do |event|
|
||||||
|
- if event.comment_threads.find_since_last_login(current_user).count > 0
|
||||||
|
%panel
|
||||||
|
%panel.panel-header
|
||||||
|
%h4.title
|
||||||
|
= link_to event.title, admin_conference_event_path(event.conference.short_title, event)
|
||||||
|
%hr
|
||||||
|
-event.comment_threads.find_since_last_login(current_user).each do |comment|
|
||||||
|
%panel-body
|
||||||
|
%ul.list-unstyled
|
||||||
|
%li= comment.body
|
||||||
|
%ul.list-inline
|
||||||
|
%li Posted by: #{comment.user.name}
|
||||||
|
%li Created at: #{comment.created_at}
|
||||||
|
%hr
|
||||||
23
app/views/admin/comments/index.html.haml
Normal file
23
app/views/admin/comments/index.html.haml
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
%h1 Comments
|
||||||
|
.row
|
||||||
|
.col-lg-12
|
||||||
|
%ul.nav.nav-tabs#commentsTable
|
||||||
|
%li.active
|
||||||
|
%a{:href=>"#unread_comments", "data-toggle"=>"tab"}
|
||||||
|
%span.fa.fa-comment
|
||||||
|
Unread comments
|
||||||
|
%li
|
||||||
|
%a{:href=>"#all_comments", "data-toggle"=>"tab"}
|
||||||
|
%span.fa.fa-comments-o
|
||||||
|
Comments
|
||||||
|
%li
|
||||||
|
%a{:href=>"#posted_comments", "data-toggle"=>"tab"}
|
||||||
|
%span.fa.fa-pencil
|
||||||
|
Posted Comments
|
||||||
|
.tab-content
|
||||||
|
.tab-pane.active#unread_comments
|
||||||
|
= render partial: 'unread_comments'
|
||||||
|
.tab-pane#all_comments
|
||||||
|
= render partial: 'all_comments'
|
||||||
|
.tab-pane#posted_comments
|
||||||
|
= render partial: 'posted_comments'
|
||||||
10
app/views/admin/emails/comment_template.text.erb
Normal file
10
app/views/admin/emails/comment_template.text.erb
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
Dear <%= @user.name %>,
|
||||||
|
|
||||||
|
User <%= @comment.user.name %> posted a new comment for event <%= @event.title %> of <%= @conference.short_title %> .
|
||||||
|
|
||||||
|
"<%= @comment.body %>"
|
||||||
|
|
||||||
|
To reply to this comment, please go to <%= h( admin_conference_event_url(@conference.short_title, @event)) %>
|
||||||
|
|
||||||
|
Best wishes,
|
||||||
|
<%= @conference.short_title %> Team
|
||||||
|
|
@ -13,17 +13,32 @@
|
||||||
%ul.nav.navbar-nav#splash-nav
|
%ul.nav.navbar-nav#splash-nav
|
||||||
= content_for :splash_nav
|
= content_for :splash_nav
|
||||||
-if user_signed_in?
|
-if user_signed_in?
|
||||||
%ul.nav.navbar-nav.navbar-right
|
.btn-group.pull-right
|
||||||
%li.dropdown
|
%ul.nav.navbar-nav.navbar-right
|
||||||
%a.dropdown-toggle{"data-toggle" => "dropdown", :href => "#", id: "current-user-detail"}
|
%li.dropdown
|
||||||
- if not current_user.name.blank?
|
%a.dropdown-toggle{"data-toggle" => "dropdown", :href => "#", id: "current-user-detail"}
|
||||||
#{current_user.name}
|
- if not current_user.name.blank?
|
||||||
-else
|
#{current_user.name}
|
||||||
#{current_user.email}
|
-else
|
||||||
= image_tag(current_user.gravatar_url(size: '18'), title: "Yo #{current_user.name}!", :alt => '')
|
#{current_user.email}
|
||||||
%b.caret
|
= image_tag(current_user.gravatar_url(size: '18'), title: "Yo #{current_user.name}!", :alt => '')
|
||||||
%ul.dropdown-menu
|
%b.caret
|
||||||
= render 'layouts/user_menu'
|
%ul.dropdown-menu
|
||||||
|
= render 'layouts/user_menu'
|
||||||
|
- if can? :manage, Conference
|
||||||
|
%ul.nav.navbar-nav.navbar-right
|
||||||
|
%li.dropdown
|
||||||
|
%a.dropdown-toggle{"data-toggle" => "dropdown", :href => "#", id: "unread-comments-preview"}
|
||||||
|
- if unread_notifications(current_user)
|
||||||
|
Notifications (#{unread_notifications(current_user).length})
|
||||||
|
%b.caret
|
||||||
|
%ul.dropdown-menu
|
||||||
|
- unread_notifications(current_user).limit(5).each do |unread_comment|
|
||||||
|
%li= link_to("New comment for: #{unread_comment.commentable.title}", admin_conference_event_path(unread_comment.commentable.conference.short_title, unread_comment.commentable_id))
|
||||||
|
%li.divider
|
||||||
|
%li= link_to 'See comments', admin_comments_path
|
||||||
|
-else
|
||||||
|
No Notifications
|
||||||
- else
|
- else
|
||||||
%ul.nav.navbar-nav.navbar-right
|
%ul.nav.navbar-nav.navbar-right
|
||||||
- if CONFIG['authentication']['ichain']['enabled']
|
- if CONFIG['authentication']['ichain']['enabled']
|
||||||
|
|
|
||||||
2
app/views/layouts/_unread_comment.html.haml
Normal file
2
app/views/layouts/_unread_comment.html.haml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
%li= link_to("New comment for: #{unread_comment.commentable.title}", admin_conference_event_path(unread_comment.commentable.conference.short_title, unread_comment.commentable_id))
|
||||||
|
|
||||||
|
|
@ -15,6 +15,7 @@ Osem::Application.routes.draw do
|
||||||
namespace :admin do
|
namespace :admin do
|
||||||
resources :users
|
resources :users
|
||||||
resources :people
|
resources :people
|
||||||
|
resources :comments
|
||||||
resources :conference do
|
resources :conference do
|
||||||
member do
|
member do
|
||||||
get :roles
|
get :roles
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue