From 74dcd75a8c2a4220d5bb23317c9f5deb55575128 Mon Sep 17 00:00:00 2001 From: raluka Date: Wed, 26 Aug 2015 22:09:36 +0200 Subject: [PATCH] created can_manage_comments helper for rendering button --- app/helpers/application_helper.rb | 4 ++++ app/models/ability.rb | 4 ++-- app/models/user.rb | 2 +- app/views/layouts/_navigation.html.haml | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 54d79425..7f24331e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -263,6 +263,10 @@ module ApplicationHelper end end + def can_manage_comments(conference) + (current_user.has_role? :organizer, conference) || (current_user.has_role? :cfp, conference) + end + def sign_in_path if CONFIG['authentication']['ichain']['enabled'] new_user_ichain_session_path diff --git a/app/models/ability.rb b/app/models/ability.rb index 974f3993..28acd4f0 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -137,7 +137,7 @@ class Ability can :manage, Sponsor, 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 [:index, :create], Comment, commentable_type: 'Event', + can :index, Comment, commentable_type: 'Event', commentable_id: Event.where(conference_id: conf_ids_for_organizer).pluck(:id) end @@ -157,7 +157,7 @@ class Ability can :manage, CallForPaper, conference_id: conf_ids_for_cfp can :manage, Commercial, commercialable_type: 'Event', commercialable_id: Event.where(conference_id: conf_ids_for_cfp).pluck(:id) - can [:index, :create], Comment, commentable_type: 'Event', + can :index, Comment, commentable_type: 'Event', commentable_id: Event.where(conference_id: conf_ids_for_cfp).pluck(:id) end diff --git a/app/models/user.rb b/app/models/user.rb index 6ffd2059..cba11d58 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/layouts/_navigation.html.haml b/app/views/layouts/_navigation.html.haml index 60e32c12..1f66af8b 100644 --- a/app/views/layouts/_navigation.html.haml +++ b/app/views/layouts/_navigation.html.haml @@ -25,7 +25,7 @@ %b.caret %ul.dropdown-menu = render 'layouts/user_menu' - - if can? :index, Comment #TODO modify condition + - if can_manage_comments(@conference) %ul.nav.navbar-nav.navbar-right %li.dropdown %a.dropdown-toggle{"data-toggle" => "dropdown", :href => "#", id: "unread-comments-preview"}