lib/commontator/controllers.rb in commontator-5.1.0 vs lib/commontator/controllers.rb in commontator-6.0.0.pre.1

- old
+ new

@@ -1,33 +1,39 @@ -require 'commontator/shared_helper' -require 'commontator/security_transgression' +require_relative 'shared_helper' -module Commontator - module Controllers - def self.included(base) - base.helper Commontator::SharedHelper - end - - protected +module Commontator::Controllers + def self.included(base) + base.helper Commontator::SharedHelper + end - def commontator_set_new_comment(thread, user) - return if thread.nil? || thread.config.new_comment_style != :t - new_comment = Comment.new - new_comment.thread = thread - new_comment.creator = user - @new_comment = new_comment if new_comment.can_be_created_by?(user) - end - - def commontator_thread_show(commontable) - user = Commontator.current_user_proc.call(self) - thread = commontable.thread - raise Commontator::SecurityTransgression unless thread.can_be_read_by?(user) - thread.mark_as_read_for(user) - @commontator_page = params[:page] || 1 - @commontator_per_page = params[:per_page] || thread.config.comments_per_page - @commontator_thread_show = true - commontator_set_new_comment(thread, user) - end + def commontator_set_thread_variables + return if @commontator_thread.nil? || !@commontator_thread.can_be_read_by?(@commontator_user) + + @commontator_per_page = params[:per_page] + @commontator_per_page = @commontator_thread.config.comments_per_page \ + if @commontator_per_page.blank? + @commontator_page = params[:page] + @commontator_page = 1 if @commontator_page.blank? + @commontator_show_all = !params[:show_all].blank? && + @commontator_thread.can_be_edited_by?(@commontator_user) + + commontator_set_new_comment + end + + def commontator_set_new_comment + return unless @commontator_thread.config.new_comment_style == :t + + new_comment = Commontator::Comment.new(user: @commontator_user, thread: @commontator_thread) + @commontator_new_comment = new_comment if new_comment.can_be_created_by?(@commontator_user) + end + + def commontator_thread_show(commontable) + commontator_set_user + commontator_set_thread(commontable) + commontator_set_thread_variables + + @commontator_thread_show = true + @commontator_thread.mark_as_read_for(@commontator_user) end end ActionController::Base.send :include, Commontator::Controllers