From 3a19b07882530f48a7c24111f60f5a0766cc7d62 Mon Sep 17 00:00:00 2001 From: Cameron Matheson Date: Wed, 8 Aug 2012 15:46:06 -0600 Subject: [PATCH] messageable_users: it's ok to message yourself fixes #9829 users without any enrollments weren't included in User.messageable_users, but messaging yourself should always be allowed. Test plan: * log in as a user without any enrollments - Go to your inbox. You should be able to message yourself by searching for your name. OR - Go to your profile page on an account with profiles enabled. You should be able to see your profile. Change-Id: If5182d807fe2f3150999d442d30202c22dffa4d1 Reviewed-on: https://gerrit.instructure.com/12819 Tested-by: Jenkins Reviewed-by: Jon Jensen --- app/models/user.rb | 6 ++++++ spec/models/user_spec.rb | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index ccfb374ec98..e64191c7c39 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2301,6 +2301,12 @@ class User < ActiveRecord::Base AND user_account_associations.user_id = users.id #{user_condition_sql} SQL + user_sql << <<-SQL unless options[:context] + SELECT #{MESSAGEABLE_USER_COLUMN_SQL}, NULL AS course_id, NULL AS group_id, NULL AS roles + FROM users + WHERE id = #{self.id} + #{user_condition_sql} + SQL if options[:ids] # provides a way for this user to start a conversation with someone diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 10e17aa9f70..071c9fdfec4 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -791,6 +791,10 @@ describe User do @deleted_user.destroy end + it "should include yourself even when not enrolled in courses" do + @student.messageable_users(:ids => [@student.id]).should eql [@student] + end + it "should only return users from the specified context and type" do set_up_course_with_users @course.enroll_user(@student, 'StudentEnrollment', :enrollment_state => 'active')