diff --git a/app/assets/images/discussion_settings.png b/app/assets/images/discussion_settings.png new file mode 100644 index 0000000..2d7a1df Binary files /dev/null and b/app/assets/images/discussion_settings.png differ diff --git a/app/controllers/comment_thread_subscriptions_controller.rb b/app/controllers/comment_thread_subscriptions_controller.rb index 1bd38b6..b6dc1c5 100644 --- a/app/controllers/comment_thread_subscriptions_controller.rb +++ b/app/controllers/comment_thread_subscriptions_controller.rb @@ -40,7 +40,7 @@ def destroy respond_to do |format| format.html do - if @comment_thread.commentable_type == 'Message' + if @comment_thread.commentable_type == 'Discussion' redirect_to inbox_path else redirect_to(polymorphic_path([@commentable, :comments])) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 3689bc3..b5e41e6 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -30,7 +30,7 @@ def new @comment = Comment.new @comment.comment_thread = @comment_thread @comment.creator = present_user - if @comment_thread.commentable_type == 'Message' + if @comment_thread.commentable_type == 'Discussion' @create_verb = 'Send' @comment_name = 'Reply' else @@ -55,7 +55,7 @@ def create @comment.comment_thread = @comment_thread @comment.creator = present_user - if @comment_thread.commentable_type == 'Message' + if @comment_thread.commentable_type == 'Discussion' @comment_notice = 'Reply sent.' @hide_votes = true else @@ -94,7 +94,7 @@ def show def edit raise SecurityTransgression unless present_user.can_update?(@comment) - if @comment_thread.commentable_type == 'Message' + if @comment_thread.commentable_type == 'Discussion' @comment_name = 'Reply' else @comment_name = 'Comment' @@ -110,7 +110,7 @@ def edit def update raise SecurityTransgression unless present_user.can_update?(@comment) - if @comment_thread.commentable_type == 'Message' + if @comment_thread.commentable_type == 'Discussion' @comment_notice = 'Reply updated.' else @comment_notice = 'Comment updated.' diff --git a/app/controllers/messages_controller.rb b/app/controllers/discussions_controller.rb similarity index 51% rename from app/controllers/messages_controller.rb rename to app/controllers/discussions_controller.rb index 926d579..57bced6 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/discussions_controller.rb @@ -1,19 +1,19 @@ # Copyright 2011-2012 Rice University. Licensed under the Affero General Public # License version 3 or later. See the COPYRIGHT file for details. -class MessagesController < ApplicationController +class DiscussionsController < ApplicationController before_filter :include_jquery - before_filter :get_message, :only => [:add_recipient, :search_recipients, :leave] + before_filter :get_discussion, :only => [:add_recipient, :search_recipients, :leave] - # GET /messages/1 + # GET /discussions/1 def show - @message = Message.find(params[:id]) + @discussion = Discussion.find(params[:id]) - raise SecurityTransgression unless present_user.can_read?(@message) + raise SecurityTransgression unless present_user.can_read?(@discussion) - @message.comment_thread.mark_as_read_for(present_user) + @discussion.comment_thread.mark_as_read_for(present_user) present_user.reload respond_to do |format| @@ -21,55 +21,55 @@ def show end end - # GET /messages/new + # GET /discussions/new def new - @message = Message.new + @discussion = Discussion.new - raise SecurityTransgression unless present_user.can_create?(@message) + raise SecurityTransgression unless present_user.can_create?(@discussion) respond_to do |format| - if @message.save - @message.comment_thread.subscribe!(present_user) - format.html { redirect_to @message } + if @discussion.save + @discussion.comment_thread.subscribe!(present_user) + format.html { redirect_to @discussion } else format.html { redirect_to inbox_path } end end end - # PUT /messages/1 + # PUT /discussions/1 def update - @message = Message.find(params[:id]) + @discussion = Discussion.find(params[:id]) - raise SecurityTransgression unless present_user.can_create?(@message) + raise SecurityTransgression unless present_user.can_create?(@discussion) - @message.subject = params[:message][:subject] + @discussion.subject = params[:discussion][:subject] @comment = Comment.new - @comment.message = params[:message][:body] - @comment.comment_thread = @message.comment_thread + @comment.message = params[:discussion][:body] + @comment.comment_thread = @discussion.comment_thread @comment.creator = present_user raise SecurityTransgression unless present_user.can_create?(@comment) respond_to do |format| - if @message.save && @comment.save - @message.comment_thread.add_unread_except_for(present_user) + if @discussion.save && @comment.save + @discussion.comment_thread.add_unread_except_for(present_user) flash[:notice] = 'Message was sent successfully.' - format.html { redirect_to @message } + format.html { redirect_to @discussion } else - format.html { redirect_to @message } + format.html { redirect_to @discussion } end end end def leave - @message.comment_thread.unsubscribe!(present_user) + @discussion.comment_thread.unsubscribe!(present_user) end def new_recipient @action_dialog_title = "Add a recipient" - @action_search_path = message_search_recipients_path(params[:message_id]) + @action_search_path = discussion_search_recipients_path(params[:discussion_id]) respond_to do |format| format.js { render :template => 'users/action_new' } @@ -82,39 +82,39 @@ def search_recipients @users = User.search(@selected_type, @text_query) @users.reject! do |user| - @message.has_recipient?(user) + @discussion.has_recipient?(user) end - @action_partial = 'messages/create_recipient_form' + @action_partial = 'discussions/create_recipient_form' respond_to do |format| format.js { render :template => 'users/action_search' } end end - # POST /messages/1/add_recipient + # POST /discussions/1/add_recipient def add_recipient - raise SecurityTransgression unless present_user.can_update?(@message) + raise SecurityTransgression unless present_user.can_update?(@discussion) @recipient = User.find_by_username(params[:username]) if @recipient.nil? flash[:alert] = 'User ' + params[:username] + ' not found!' respond_to do |format| - format.html { redirect_to @message } + format.html { redirect_to @discussion } format.js { render :template => 'shared/display_flash' } end return end respond_to do |format| - if @message.comment_thread.subscribe!(@recipient) - @message.comment_thread.mark_as_unread_for(@recipient) - format.html { redirect_to @message } + if @discussion.comment_thread.subscribe!(@recipient) + @discussion.comment_thread.mark_as_unread_for(@recipient) + format.html { redirect_to @discussion } format.js else - flash[:alert] = @message.comment_thread.errors.values.to_sentence - format.html { redirect_to @message } + flash[:alert] = @discussion.comment_thread.errors.values.to_sentence + format.html { redirect_to @discussion } format.js { render :template => 'shared/display_flash' } end end @@ -122,8 +122,8 @@ def add_recipient protected - def get_message - @message = Message.find(params[:message_id]) + def get_discussion + @discussion = Discussion.find(params[:discussion_id]) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fc1947e..b6808fe 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -143,8 +143,8 @@ def commentable_name(comment_thread) question_id_text(comment_thread.commentable.question) when 'Project' comment_thread.commentable.name - when 'Message' - "message: " + comment_thread.commentable.subject + when 'Discussion' + "discussion: " + comment_thread.commentable.subject end end diff --git a/test/unit/message_test.rb b/app/helpers/discussions_helper.rb similarity index 50% rename from test/unit/message_test.rb rename to app/helpers/discussions_helper.rb index c4ce2dd..fac42c6 100644 --- a/test/unit/message_test.rb +++ b/app/helpers/discussions_helper.rb @@ -1,11 +1,5 @@ # Copyright 2011-2012 Rice University. Licensed under the Affero General Public # License version 3 or later. See the COPYRIGHT file for details. -require 'test_helper' - -class MessageTest < ActiveSupport::TestCase - # Replace this with your real tests. - test "the truth" do - assert true - end +module DiscussionsHelper end diff --git a/app/mailers/subscription_notifier.rb b/app/mailers/subscription_notifier.rb index dd1072b..4c4b774 100644 --- a/app/mailers/subscription_notifier.rb +++ b/app/mailers/subscription_notifier.rb @@ -10,7 +10,7 @@ def comment_created_email(comment) mail(:bcc => @active_subscribers.reject{ |as| as == @creator }.collect { |as| as.email }, :subject => @creator.full_name + - (@is_message ? " sent you a message: " + @commentable.subject : + (@is_discussion ? " sent you a message: " + @commentable.subject : " has commented on a thread to which you subscribe")).deliver end @@ -23,7 +23,7 @@ def setup_variables(comment) @commentable = @comment_thread.commentable.becomes( Kernel.const_get(@comment_thread.commentable_type)) @active_subscribers = User.subscribers_for(@comment_thread).active_users - @is_message = @comment_thread.commentable_type == 'Message' + @is_discussion = @comment_thread.commentable_type == 'Discussion' end end diff --git a/app/models/comment.rb b/app/models/comment.rb index ecaf1c8..c5e2e16 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -29,16 +29,16 @@ def can_be_created_by?(user) end def can_be_updated_by?(user) - !user.is_anonymous? && user == creator && (comment_thread.commentable_type != 'Message' || comment_thread.comments.last == self) + !user.is_anonymous? && user == creator && (comment_thread.commentable_type != 'Discussion' || comment_thread.comments.last == self) end def can_be_destroyed_by?(user) !user.is_anonymous? && (user == creator || user.is_administrator?) && - (comment_thread.commentable_type != 'Message' || comment_thread.comments.last == self) + (comment_thread.commentable_type != 'Discussion' || comment_thread.comments.last == self) end def can_be_voted_on_by?(user) - can_be_read_by?(user) && user != creator && comment_thread.commentable_type != 'Message' + can_be_read_by?(user) && user != creator && comment_thread.commentable_type != 'Discussion' end end diff --git a/app/models/comment_thread_subscription.rb b/app/models/comment_thread_subscription.rb index 05e9c22..5111bcf 100644 --- a/app/models/comment_thread_subscription.rb +++ b/app/models/comment_thread_subscription.rb @@ -10,34 +10,33 @@ class CommentThreadSubscription < ActiveRecord::Base validates_uniqueness_of :user_id, :scope => :comment_thread_id - scope :message_subscriptions, joins{comment_thread}.where{comment_thread.commentable_type == "Message"} + scope :discussion_subscriptions, joins{comment_thread}.where{comment_thread.commentable_type == "Discussion"} - def self.message_subscriptions_for(user) - where{user_id == user.id}.message_subscriptions + def self.discussion_subscriptions_for(user) + where{user_id == user.id}.discussion_subscriptions end def mark_all_as_read! update_attribute(:unread_count, 0) - update_message_cache + update_discussion_cache end def mark_all_as_unread! update_attribute(:unread_count, comment_thread.comments.count) - update_message_cache + update_discussion_cache end def add_unread! update_attribute(:unread_count, unread_count + 1) - update_message_cache + update_discussion_cache end protected - def update_message_cache - return unless comment_thread.commentable_type == 'Message' - user.update_attribute(:unread_message_count, - Array.new(CommentThreadSubscription.message_subscriptions_for(user)).sum { |ms| - ms.unread_count }) + def update_discussion_cache + return unless comment_thread.commentable_type == 'Discussion' + user.update_attribute(:unread_discussion_count, + Array.new(CommentThreadSubscription.discussion_subscriptions_for(user)).sum { |ms| + ms.unread_count }) end - end diff --git a/app/models/message.rb b/app/models/discussion.rb similarity index 85% rename from app/models/message.rb rename to app/models/discussion.rb index 49ba3c6..89766e4 100644 --- a/app/models/message.rb +++ b/app/models/discussion.rb @@ -1,7 +1,7 @@ # Copyright 2011-2012 Rice University. Licensed under the Affero General Public # License version 3 or later. See the COPYRIGHT file for details. -class Message < ActiveRecord::Base +class Discussion < ActiveRecord::Base has_one :comment_thread, :as => :commentable, :dependent => :destroy before_validation :build_comment_thread, :on => :create @@ -12,8 +12,8 @@ class Message < ActiveRecord::Base attr_accessible #none - def self.messages_for(user) - CommentThreadSubscription.message_subscriptions_for(user).collect { |cts| cts.comment_thread.commentable } + def self.discussions_for(user) + CommentThreadSubscription.discussion_subscriptions_for(user).collect { |cts| cts.comment_thread.commentable } end def subject @@ -59,7 +59,7 @@ def can_be_joined_by?(user) def subject_not_changed return if !subject_changed? || comment_thread.comments.blank? - errors.add(:base, "You can't change a message's subject after it is sent.") + errors.add(:base, "You can't change a discussion's subject after it is sent.") false end diff --git a/app/models/user.rb b/app/models/user.rb index 1ac0f1a..0abf056 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -128,8 +128,8 @@ def can_join?(container_type, container_id) return Question.find(container_id).can_be_joined_by?(self) when 'project' return Project.find(container_id).can_be_joined_by?(self) - when 'message' - return Message.find(container_id).can_be_joined_by?(self) + when 'discussion' + return Discussion.find(container_id).can_be_joined_by?(self) end end diff --git a/app/views/comment_thread_subscriptions/_subscription_link.html.erb b/app/views/comment_thread_subscriptions/_subscription_link.html.erb index b47640f..dd8d2c7 100644 --- a/app/views/comment_thread_subscriptions/_subscription_link.html.erb +++ b/app/views/comment_thread_subscriptions/_subscription_link.html.erb @@ -7,10 +7,10 @@ subscription ||= false %> <% sub_string = subscription ? "Unsubscribe" : "Subscribe" %> -<% show_confirm = (subscription && commentable.comment_thread.commentable_type == 'Message') %> +<% show_confirm = (subscription && commentable.comment_thread.commentable_type == 'Discussion') %> <%= link_to sub_string, polymorphic_path([sub_string.downcase, commentable, :comments]), :confirm => (show_confirm ? "Are you sure?\n" + - "Once you unsubscribe from this message, " + + "Once you unsubscribe from this discussion, " + "you will not be able to see it anymore." : nil), :remote => true %> diff --git a/app/views/comment_thread_subscriptions/destroy.js.erb b/app/views/comment_thread_subscriptions/destroy.js.erb index 8795f71..edbf544 100644 --- a/app/views/comment_thread_subscriptions/destroy.js.erb +++ b/app/views/comment_thread_subscriptions/destroy.js.erb @@ -1,7 +1,7 @@ <%# Copyright 2011-2012 Rice University. Licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file for details. %> -<% if @comment_thread.commentable_type == 'Message' %> +<% if @comment_thread.commentable_type == 'Discussion' %> window.location.replace("<%= escape_javascript(inbox_path) %>") <% else %> <%= display_flash %> diff --git a/app/views/comments/create.js.erb b/app/views/comments/create.js.erb index 1950837..9117f3c 100644 --- a/app/views/comments/create.js.erb +++ b/app/views/comments/create.js.erb @@ -3,7 +3,7 @@ <%= display_flash(false) %> -<% if @comment_thread.commentable_type == 'Message' %> +<% if @comment_thread.commentable_type == 'Discussion' %> $(".edit_link").hide(); $(".delete_link").hide(); <% end %> diff --git a/app/views/messages/_create_recipient_form.html.erb b/app/views/discussions/_create_recipient_form.html.erb similarity index 85% rename from app/views/messages/_create_recipient_form.html.erb rename to app/views/discussions/_create_recipient_form.html.erb index c1ccc1d..81aed08 100644 --- a/app/views/messages/_create_recipient_form.html.erb +++ b/app/views/discussions/_create_recipient_form.html.erb @@ -3,9 +3,9 @@ <%# Callers must supply a 'user' local variable %> -<%= form_tag(message_add_recipient_path(@message), +<%= form_tag(discussion_add_recipient_path(@discussion), :method => :post, :remote => true) do %> <%= hidden_field_tag :username, user.username %> <%= submit_tag "Add", :class => submit_classes, :onclick => please_wait_js %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/discussions/_discussion_list.html.erb b/app/views/discussions/_discussion_list.html.erb new file mode 100644 index 0000000..0e0b5ea --- /dev/null +++ b/app/views/discussions/_discussion_list.html.erb @@ -0,0 +1,22 @@ +<%# Copyright 2011-2012 Rice University. Licensed under the Affero General Public + License version 3 or later. See the COPYRIGHT file for details. %> + +<% discussions = Discussion.discussions_for(current_user) %> + + + + + + + + style="display:none"<% end %>> + + + <% discussions.each do |discussion| %> + <%= render :partial => 'discussions/discussion_list_row', :locals => {:discussion => discussion} %> + <% end %> +
SubjectRecipients
No Discussions
+ +
+ +<%= link_to "New discussion", new_discussion_path %> diff --git a/app/views/discussions/_discussion_list_row.html.erb b/app/views/discussions/_discussion_list_row.html.erb new file mode 100644 index 0000000..92e043a --- /dev/null +++ b/app/views/discussions/_discussion_list_row.html.erb @@ -0,0 +1,16 @@ +<%# Copyright 2011-2012 Rice University. Licensed under the Affero General Public + License version 3 or later. See the COPYRIGHT file for details. %> + +<% # Clients of this partial must supply the following variable: + # discussion +%> +<% unread_count = discussion.comment_thread.subscription_for(current_user).unread_count %> + + <% if unread_count > 0 %> + <%= link_to discussion.subject + " (" + unread_count.to_s + ")", discussion %> + <% else %> + <%= link_to discussion.subject, discussion %> + <% end %> + <%= link_to "Leave this discussion", discussion_leave_path(discussion), :remote => true %> + <%= discussion.recipients.collect { |r| r.full_name }.to_sentence %> + diff --git a/app/views/messages/_form.html.erb b/app/views/discussions/_form.html.erb similarity index 84% rename from app/views/messages/_form.html.erb rename to app/views/discussions/_form.html.erb index 5614b6d..2a72891 100644 --- a/app/views/messages/_form.html.erb +++ b/app/views/discussions/_form.html.erb @@ -1,7 +1,7 @@ <%# Copyright 2011-2012 Rice University. Licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file for details. %> -<%= form_for(@message) do |f| %> +<%= form_for(@discussion) do |f| %>
<%= f.label :subject, "Subject:" %> @@ -15,6 +15,6 @@
<%= f.submit :class => "#{submit_classes}", - :value => "Send" %> + :value => "Create New Discussion" %>
<% end %> diff --git a/app/views/messages/_recipient.html.erb b/app/views/discussions/_recipient.html.erb similarity index 66% rename from app/views/messages/_recipient.html.erb rename to app/views/discussions/_recipient.html.erb index fbb60dc..974e0f9 100644 --- a/app/views/messages/_recipient.html.erb +++ b/app/views/discussions/_recipient.html.erb @@ -1,4 +1,4 @@ <%# Copyright 2011-2012 Rice University. Licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file for details. %> -[<%= full_name_link(recipient) %>] \ No newline at end of file +[<%= full_name_link(recipient) %>] diff --git a/app/views/messages/_show.html.erb b/app/views/discussions/_show.html.erb similarity index 82% rename from app/views/messages/_show.html.erb rename to app/views/discussions/_show.html.erb index a731e14..309e439 100644 --- a/app/views/messages/_show.html.erb +++ b/app/views/discussions/_show.html.erb @@ -2,7 +2,7 @@ License version 3 or later. See the COPYRIGHT file for details. %>
-Subject: <%= message.subject %> +Subject: <%= discussion.subject %>
diff --git a/app/views/messages/add_recipient.js.erb b/app/views/discussions/add_recipient.js.erb similarity index 100% rename from app/views/messages/add_recipient.js.erb rename to app/views/discussions/add_recipient.js.erb diff --git a/app/views/discussions/leave.js.erb b/app/views/discussions/leave.js.erb new file mode 100644 index 0000000..859b2f9 --- /dev/null +++ b/app/views/discussions/leave.js.erb @@ -0,0 +1,10 @@ +<%# Copyright 2011-2012 Rice University. Licensed under the Affero General Public + License version 3 or later. See the COPYRIGHT file for details. %> + +$("#discussion_<%= @discussion.id %>").remove(); + +<% flash[:notice] = "You just left the discussion with subject '#{@discussion.subject}'" %> + +<%= display_flash %> + +show_none_row_if_needed("discussion_table"); diff --git a/app/views/messages/show.html.erb b/app/views/discussions/show.html.erb similarity index 72% rename from app/views/messages/show.html.erb rename to app/views/discussions/show.html.erb index 68e5d45..5e06212 100644 --- a/app/views/messages/show.html.erb +++ b/app/views/discussions/show.html.erb @@ -1,34 +1,34 @@ <%# Copyright 2011-2012 Rice University. Licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file for details. %> -<%= pageHeading("Viewing message") %> +<%= pageHeading("Viewing Discussion") %>
To: - <% @message.recipients.each do |recipient| %> + <% @discussion.recipients.each do |recipient| %> <%= render :partial => 'recipient', :locals => {:recipient => recipient} %> <% end %> <%= link_to "Add recipients ...", - message_new_recipient_path(@message), + discussion_new_recipient_path(@discussion), :remote => true %>
-<% if @message.comment_thread.comments.blank? %> +<% if @discussion.comment_thread.comments.blank? %> <%= render 'form' %> <% else %> -<%= render :partial => 'show', :locals => {:message => @message} %> +<%= render :partial => 'show', :locals => {:discussion => @discussion} %> <% end %>
-<% if !@message.comment_thread.comments.blank? %> -<%= render :partial => 'comments/index', :locals => {:commentable => @message, +<% if !@discussion.comment_thread.comments.blank? %> +<%= render :partial => 'comments/index', :locals => {:commentable => @discussion, :hide_header => true, :hide_link => true, :hide_votes => true, diff --git a/app/views/help/discussion_help.html.erb b/app/views/help/discussion_help.html.erb new file mode 100644 index 0000000..d87a522 --- /dev/null +++ b/app/views/help/discussion_help.html.erb @@ -0,0 +1,17 @@ +<%# Copyright 2011-2012 Rice University. Licensed under the Affero General Public + License version 3 or later. See the COPYRIGHT file for details. %> + +<%=pageHeading("Discussions")%> +
Discussions
+
+
+

Discussions in Quadbase are different than what one would think, you can't specifically send a discussion to someone as you would in an email. Instead discussions are automatically generated when question attributes are altered from the default settings.

+

The alterable attributes include toggling role requests and adding a collaborator to a workspace. Settings regarding when discussions are sent to a user are personable, and can be edited under the account tab on the upper-right hand corner of every Quadbase page. Click on this tab, and you will see discussion settings towards the bottom.

+
+ <%=image_tag("account_tab.png", {:border => 1})%> +
+

These discussion settings are in the form of check boxes. Click on the boxes next to the setting you want to alter, and then click the update button near the bottom left of the screen. Here is an example configuration for discussion settings.

+
+ <%=image_tag("discussion_settings.png", {:border => 1})%> +
+

Play around with the discussion settings to see when you would prefer to be notified of new entries in a discussion

diff --git a/app/views/help/roles_help.html.erb b/app/views/help/roles_help.html.erb index 2a98fa9..e7112e0 100644 --- a/app/views/help/roles_help.html.erb +++ b/app/views/help/roles_help.html.erb @@ -42,4 +42,4 @@
<%=image_tag("message_roles.png", {:border => 1})%>
-

If the user accepts the role request, he or she becomes the author or copyright holder or whatever role was assigned to them. If the user rejects the role request, the roles remain unchanged and as they were before the role change request was made.

\ No newline at end of file +

If the user accepts the role request, he or she becomes the author or copyright holder or whatever role was assigned to them. If the user rejects the role request, the roles remain unchanged and as they were before the role change request was made.

diff --git a/app/views/help/topics/_discussions.html.erb b/app/views/help/topics/_discussions.html.erb new file mode 100644 index 0000000..1141d95 --- /dev/null +++ b/app/views/help/topics/_discussions.html.erb @@ -0,0 +1,4 @@ +<%# Copyright 2011-2012 Rice University. Licensed under the Affero General Public + License version 3 or later. See the COPYRIGHT file for details. %> + +Discussions allow you to communicate with other Quadbase users. They work just like e-mail discussions, except that e-mail addresses are never revealed. diff --git a/app/views/inbox/index.html.erb b/app/views/inbox/index.html.erb index e67a407..fe8ed13 100644 --- a/app/views/inbox/index.html.erb +++ b/app/views/inbox/index.html.erb @@ -45,10 +45,10 @@
- Messages <%= link_to_help "messages" %> + Discussions <%= link_to_help "discussions" %>
- <%= render :partial => 'messages/message_list' %> + <%= render :partial => 'discussions/discussion_list' %>
diff --git a/app/views/messages/_message_list.html.erb b/app/views/messages/_message_list.html.erb deleted file mode 100644 index 05a93d6..0000000 --- a/app/views/messages/_message_list.html.erb +++ /dev/null @@ -1,22 +0,0 @@ -<%# Copyright 2011-2012 Rice University. Licensed under the Affero General Public - License version 3 or later. See the COPYRIGHT file for details. %> - -<% messages = Message.messages_for(current_user) %> - - - - - - - - style="display:none"<% end %>> - - - <% messages.each do |message| %> - <%= render :partial => 'messages/message_list_row', :locals => {:message => message} %> - <% end %> -
SubjectRecipients
None
- -
- -<%= link_to "New Message", new_message_path %> diff --git a/app/views/messages/_message_list_row.html.erb b/app/views/messages/_message_list_row.html.erb deleted file mode 100644 index 851d180..0000000 --- a/app/views/messages/_message_list_row.html.erb +++ /dev/null @@ -1,16 +0,0 @@ -<%# Copyright 2011-2012 Rice University. Licensed under the Affero General Public - License version 3 or later. See the COPYRIGHT file for details. %> - -<% # Clients of this partial must supply the following variable: - # message -%> -<% unread_count = message.comment_thread.subscription_for(current_user).unread_count %> - - <% if unread_count > 0 %> - <%= link_to message.subject + " (" + unread_count.to_s + ")", message %> - <% else %> - <%= link_to message.subject, message %> - <% end %> - <%= link_to "Leave this message", message_leave_path(message), :remote => true %> - <%= message.recipients.collect { |r| r.full_name }.to_sentence %> - diff --git a/app/views/messages/leave.js.erb b/app/views/messages/leave.js.erb deleted file mode 100644 index 4cc8032..0000000 --- a/app/views/messages/leave.js.erb +++ /dev/null @@ -1,10 +0,0 @@ -<%# Copyright 2011-2012 Rice University. Licensed under the Affero General Public - License version 3 or later. See the COPYRIGHT file for details. %> - -$("#message_<%= @message.id %>").remove(); - -<% flash[:notice] = "You just left the message with subject '#{@message.subject}'" %> - -<%= display_flash %> - -show_none_row_if_needed("message_table"); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index a4e0518..f48957c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -94,7 +94,7 @@ def votable get 'help/images', :to => 'help#image_help', :as => 'images' get 'help/dialog', :to => 'help#dialog', :as => 'dialog' get 'help/comments', :to => 'help#comments', :as => 'comments' - get 'help/messages', :to => 'help#message_help', :as => "messages" + get 'help/discussions', :to => 'help#discussion_help', :as => "discussions" get 'help/roles', :to => 'help#roles_help', :as => 'roles' get 'help/topic/:topic_name', :to => 'help#topic', :as => 'topic_help' @@ -212,7 +212,7 @@ def votable votable end - resources :messages, :only => [:new, :show, :update] do + resources :discussions, :only => [:new, :show, :update] do get 'new_recipient' post 'search_recipients' post 'add_recipient' diff --git a/db/migrate/20120614200100_rename_messages_to_discussions.rb b/db/migrate/20120614200100_rename_messages_to_discussions.rb new file mode 100644 index 0000000..6395988 --- /dev/null +++ b/db/migrate/20120614200100_rename_messages_to_discussions.rb @@ -0,0 +1,11 @@ +class RenameMessagesToDiscussions < ActiveRecord::Migration + def up + rename_table :messages, :discussions + rename_column :users, :unread_message_count, :unread_discussion_count + end + + def down + rename_table :discussions, :messages + rename_column :users, :unread_discussion_count, :unread_message_count + end +end diff --git a/db/schema.rb b/db/schema.rb index 9a5fd96..ac009f4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120424015013) do +ActiveRecord::Schema.define(:version => 20120614200100) do create_table "announcements", :force => true do |t| t.integer "user_id" @@ -82,6 +82,12 @@ t.datetime "updated_at", :null => false end + create_table "discussions", :force => true do |t| + t.string "subject" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "licenses", :force => true do |t| t.string "short_name" t.string "long_name" @@ -123,12 +129,6 @@ t.string "required_logic_library_version_ids" end - create_table "messages", :force => true do |t| - t.string "subject" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - create_table "project_members", :force => true do |t| t.integer "project_id" t.integer "user_id" @@ -260,12 +260,12 @@ end create_table "users", :force => true do |t| - t.string "email", :default => "", :null => false - t.string "encrypted_password", :default => "", :null => false + t.string "email", :default => "", :null => false + t.string "encrypted_password", :default => "", :null => false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", :default => 0 + t.integer "sign_in_count", :default => 0 t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" @@ -273,17 +273,17 @@ t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" - t.integer "failed_attempts", :default => 0 + t.integer "failed_attempts", :default => 0 t.string "unlock_token" t.datetime "locked_at" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "first_name" t.string "last_name" - t.boolean "is_administrator", :default => false + t.boolean "is_administrator", :default => false t.string "username" t.datetime "disabled_at" - t.integer "unread_message_count", :default => 0 + t.integer "unread_discussion_count", :default => 0 end add_index "users", ["confirmation_token"], :name => "index_users_on_confirmation_token", :unique => true diff --git a/test/factories.rb b/test/factories.rb index 2a6edd6..1f2f858 100644 --- a/test/factories.rb +++ b/test/factories.rb @@ -266,9 +266,11 @@ def make_project(options = {}) f.association :comment_thread f.association :user end - - factory :message do |f| + + factory :discussion do |f| f.subject {FactoryGirl.generate :content} + f.body {FactoryGirl.generate :content} + f.association :comment_thread end factory :deputization do |f| diff --git a/test/functional/discussions_controller_test.rb b/test/functional/discussions_controller_test.rb new file mode 100644 index 0000000..40e2465 --- /dev/null +++ b/test/functional/discussions_controller_test.rb @@ -0,0 +1,59 @@ +# Copyright 2011-2012 Rice University. Licensed under the Affero General Public +# License version 3 or later. See the COPYRIGHT file for details. + +require 'test_helper' + +class DiscussionsControllerTest < ActionController::TestCase + + setup do + @user = FactoryGirl.create(:user) + @discussion = FactoryGirl.create(:discussion) + @discussion.comment_thread.subscribe!(@user) + end + + test "should not get new not logged in" do + get :new + assert_redirected_to login_path + end + + test "should get new" do + user_login + get :new + assert_redirected_to discussion_path(assigns[:discussion]) + end + + test "should not show discussion not logged in" do + get :show, :id => @discussion.to_param + assert_redirected_to login_path + end + + test "should not show discussion not authorized" do + user_login + get :show, :id => @discussion.to_param + assert_response(403) + end + + test "should show discussion" do + sign_in @user + get :show, :id => @discussion.to_param + assert_response :success + end + + test "should not update discussion not logged in" do + put :update, :id => @discussion.to_param, :discussion => @discussion.attributes + assert_redirected_to login_path + end + + test "should not update discussion not authorized" do + user_login + put :update, :id => @discussion.to_param, :discussion => @discussion.attributes + assert_response(403) + end + + test "should update discussion" do + sign_in @user + put :update, :id => @discussion.to_param, :discussion => @discussion.attributes + assert_redirected_to discussion_path(assigns(:discussion)) + end + +end diff --git a/test/functional/help_controller_test.rb b/test/functional/help_controller_test.rb index 55ef272..098e817 100644 --- a/test/functional/help_controller_test.rb +++ b/test/functional/help_controller_test.rb @@ -41,7 +41,7 @@ class HelpControllerTest < ActionController::TestCase end test "should get topic" do - get :topic, :topic_name => "messages" + get :topic, :topic_name => "discussions" assert_response :success end diff --git a/test/functional/messages_controller_test.rb b/test/functional/messages_controller_test.rb deleted file mode 100644 index 9d4bddd..0000000 --- a/test/functional/messages_controller_test.rb +++ /dev/null @@ -1,59 +0,0 @@ -# Copyright 2011-2012 Rice University. Licensed under the Affero General Public -# License version 3 or later. See the COPYRIGHT file for details. - -require 'test_helper' - -class MessagesControllerTest < ActionController::TestCase - - setup do - @user = FactoryGirl.create(:user) - @message = FactoryGirl.create(:message) - @message.comment_thread.subscribe!(@user) - end - - test "should not get new not logged in" do - get :new - assert_redirected_to login_path - end - - test "should get new" do - user_login - get :new - assert_redirected_to message_path(assigns[:message]) - end - - test "should not show message not logged in" do - get :show, :id => @message.to_param - assert_redirected_to login_path - end - - test "should not show message not authorized" do - user_login - get :show, :id => @message.to_param - assert_response(403) - end - - test "should show message" do - sign_in @user - get :show, :id => @message.to_param - assert_response :success - end - - test "should not update message not logged in" do - put :update, :id => @message.to_param, :message => @message.attributes - assert_redirected_to login_path - end - - test "should not update message not authorized" do - user_login - put :update, :id => @message.to_param, :message => @message.attributes - assert_response(403) - end - - test "should update message" do - sign_in @user - put :update, :id => @message.to_param, :message => @message.attributes - assert_redirected_to message_path(assigns(:message)) - end - -end diff --git a/test/unit/discussion_test.rb b/test/unit/discussion_test.rb new file mode 100644 index 0000000..ad9afe7 --- /dev/null +++ b/test/unit/discussion_test.rb @@ -0,0 +1,34 @@ +# Copyright 2011-2012 Rice University. Licensed under the Affero General Public +# License version 3 or later. See the COPYRIGHT file for details. + +require 'test_helper' + +class DiscussionTest < ActiveSupport::TestCase + + test "cannot mass-assign comment_thread, subject, body" do + ct = FactoryGirl.create(:comment_thread) + d = Discussion.new(:comment_thread => ct, :subject => 'head', :body => 'bod') + assert d.comment_thread != ct + assert d.subject != 'head' + assert d.body != 'bod' + end + + test "should have a recipient when subscribed" do + discussion = FactoryGirl.create(:discussion) + user = FactoryGirl.create(:user) + discussion.comment_thread.subscribe!(user) + assert discussion.has_recipient?(user) + end + + test "should delete discussion when no recipients are left" do + discussion = FactoryGirl.create(:discussion) + user = FactoryGirl.create(:user) + ct = discussion.comment_thread + ct.subscribe!(user) + assert discussion.has_recipient?(user) + + ct.unsubscribe!(user) + assert_raise(ActiveRecord::RecordNotFound) { Discussion.find(discussion.id) } + end + +end diff --git a/test/unit/helpers/messages_helper_test.rb b/test/unit/helpers/discussions_helper_test.rb similarity index 77% rename from test/unit/helpers/messages_helper_test.rb rename to test/unit/helpers/discussions_helper_test.rb index a365652..461c049 100644 --- a/test/unit/helpers/messages_helper_test.rb +++ b/test/unit/helpers/discussions_helper_test.rb @@ -3,5 +3,5 @@ require 'test_helper' -class MessagesHelperTest < ActionView::TestCase +class DiscussionsHelperTest < ActionView::TestCase end