public
Fork of insoshi/insoshi
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://insoshi.com
Clone URL: git://github.com/toim/insoshi.git
Added send message to everyone for admins
Michael Hartl (author)
Thu May 08 12:36:21 -0700 2008
commit  81389f1c0a1dc1874f2f5c885fb43efa97233e60
tree    226e293aaccd6e1ecf915f90f1a9bc710c853bfc
parent  0177c8084c6d7da1cec4ecaf6f116c1865caae35
...
58
59
60
61
62
63
64
65
66
67
68
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
71
72
...
58
59
60
 
 
61
 
 
 
 
 
 
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
0
@@ -58,15 +58,35 @@ class MessagesController < ApplicationController
0
   end
0
 
0
   def create
0
- @message = Message.new(params[:message].merge(:sender => current_person,
0
- :recipient => @recipient))
0
     
0
- respond_to do |format|
0
- if @message.save
0
- flash[:success] = 'Message sent!'
0
- format.html { redirect_to messages_url }
0
- else
0
- format.html { render :action => "new" }
0
+ if params["commit"] == "Send to all" and current_person.admin?
0
+ # Send messages to all (active) people.
0
+ messages = Person.active.inject([]) do |messages, person|
0
+ message = Message.new(params[:message].merge(:sender => current_person,
0
+ :recipient => person))
0
+ messages.push(message)
0
+ end
0
+ respond_to do |format|
0
+ @message = messages.first
0
+ if @message.save
0
+ messages.each { |m| m.save }
0
+ flash[:success] = 'Message sent to everyone!'
0
+ format.html { redirect_to messages_url }
0
+ else
0
+ format.html { render :action => "new" }
0
+ end
0
+ end
0
+ else
0
+ @message = Message.new(params[:message].merge(:sender => current_person,
0
+ :recipient => @recipient))
0
+
0
+ respond_to do |format|
0
+ if @message.save
0
+ flash[:success] = 'Message sent!'
0
+ format.html { redirect_to messages_url }
0
+ else
0
+ format.html { render :action => "new" }
0
+ end
0
       end
0
     end
0
   end
...
35
36
37
 
 
 
38
39
40
...
35
36
37
38
39
40
41
42
43
0
@@ -35,6 +35,9 @@
0
     <div class="form_row">
0
       <%= f.submit "Send!", :class => "button", :id => "message_submit" %>
0
       <%= f.submit "Cancel", :class => "button", :id => "cancel" %>
0
+ <%- if current_person?(@recipient) and current_person.admin? -%>
0
+ <%= f.submit "Send to all", :class => "button", :id => "all_people" %>
0
+ <%- end -%>
0
     </div>
0
   <% end %>
0
 <%- end -%>
...
38
39
40
 
 
 
 
 
 
41
42
43
...
38
39
40
41
42
43
44
45
46
47
48
49
0
@@ -38,6 +38,12 @@
0
                   blog_path(@person.blog) %></li>
0
         </ul>
0
       <%- end -%>
0
+
0
+ <%- if current_person?(@person) and current_person.admin? -%>
0
+ <ul class="tools">
0
+ <li><%= email_link @person %> to everyone</li>
0
+ </ul>
0
+ <%- end -%>
0
     </div>
0
     <%= display @person.description %>
0
   </div>
...
72
73
74
 
 
 
 
 
 
 
 
 
 
75
76
77
...
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
0
@@ -72,6 +72,16 @@ describe MessagesController do
0
       end.should change(Message, :count).by(1)
0
     end
0
     
0
+ it "should sent messages to all (active) people" do
0
+ login_as(:admin)
0
+ lambda do
0
+ post :create, :message => { :subject => "The subject",
0
+ :content => "Hey there!" },
0
+ :person_id => @other_person,
0
+ :commit => "Send to all"
0
+ end.should change(Message, :count).by(Person.active.length)
0
+ end
0
+
0
     it "should send a message receipt email" do
0
       lambda do
0
         post :create, :message => { :subject => "The subject",

Comments

    No one has commented yet.