From bcd8e416700b640489230be27839b63eba53d35d Mon Sep 17 00:00:00 2001 From: raluka Date: Thu, 3 Sep 2015 12:17:42 +0200 Subject: [PATCH] added logic for available conferences based on roles in comments_controller.rb --- app/controllers/admin/comments_controller.rb | 4 +-- app/models/user.rb | 2 +- .../admin/comments/_all_comments.html.haml | 30 ++++++++++--------- .../admin/comments/_posted_comments.html.haml | 26 ++++++++-------- .../admin/comments/_unread_comments.html.haml | 30 ++++++++++--------- 5 files changed, 48 insertions(+), 44 deletions(-) diff --git a/app/controllers/admin/comments_controller.rb b/app/controllers/admin/comments_controller.rb index ae6623a1..32ae0e85 100644 --- a/app/controllers/admin/comments_controller.rb +++ b/app/controllers/admin/comments_controller.rb @@ -1,11 +1,9 @@ module Admin class CommentsController < Admin::BaseController - load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource - def index - @ordered_events = Event.order(:title).all + @conferences_available = Conference.with_roles([:admin, :organizer, :cfp], current_user) end end end diff --git a/app/models/user.rb b/app/models/user.rb index cba11d58..6ffd2059 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -29,7 +29,7 @@ class User < ActiveRecord::Base devise(*devise_modules) - has_and_belongs_to_many :roles + has_and_belongs_to_many :roles has_many :openids attr_accessible :email, :password, :password_confirmation, :remember_me, :role_id, :role_ids, diff --git a/app/views/admin/comments/_all_comments.html.haml b/app/views/admin/comments/_all_comments.html.haml index e7db8f0d..3ad58e89 100644 --- a/app/views/admin/comments/_all_comments.html.haml +++ b/app/views/admin/comments/_all_comments.html.haml @@ -1,16 +1,18 @@ .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) + -@conferences_available.each do |conference| + -conference.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) + = conference.title + %hr + -event.comment_threads.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 - -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 diff --git a/app/views/admin/comments/_posted_comments.html.haml b/app/views/admin/comments/_posted_comments.html.haml index 5b41ff56..3cdc2102 100644 --- a/app/views/admin/comments/_posted_comments.html.haml +++ b/app/views/admin/comments/_posted_comments.html.haml @@ -1,14 +1,16 @@ .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) + -@conferences_available.each do |conference| + -conference.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) + = conference.title + %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 - -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 diff --git a/app/views/admin/comments/_unread_comments.html.haml b/app/views/admin/comments/_unread_comments.html.haml index a9960123..8c58193e 100644 --- a/app/views/admin/comments/_unread_comments.html.haml +++ b/app/views/admin/comments/_unread_comments.html.haml @@ -1,16 +1,18 @@ .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) + -@conferences_available.each do |conference| + -conference.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) + = conference.title + %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 - -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