public
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/insoshi/insoshi.git
Comment walls only accessible to contacts
Michael Hartl (author)
Mon May 05 15:59:19 -0700 2008
commit  a3663713eb3bfb9c702905ec0beee31eb5a22f5a
tree    59d4afadba08819af95af716ba8548fcf70fee3b
parent  1d721421f0b50b7adc430a7f1c9b9a9f46221c7d
...
5
6
7
 
8
9
10
...
50
51
52
 
 
 
 
53
54
 
 
55
56
57
58
 
 
 
 
59
60
61
 
 
 
 
62
63
64
...
5
6
7
8
9
10
11
...
51
52
53
54
55
56
57
58
 
59
60
61
 
 
 
62
63
64
65
66
67
68
69
70
71
72
73
74
75
0
@@ -5,6 +5,7 @@ class CommentsController < ApplicationController
0
   before_filter :login_required
0
   before_filter :get_instance_vars
0
   before_filter :authorize_destroy, :only => [:destroy]
0
+ before_filter :connection_required
0
 
0
   # Used for both wall and blog comments.
0
   def new
0
@@ -50,15 +51,25 @@ class CommentsController < ApplicationController
0
         @post = Post.find(params[:post_id])
0
       end
0
     end
0
+
0
+ def person
0
+ @person || @blog.person
0
+ end
0
     
0
- def authorize_destroy
0
+ # Require the users to be connected.
0
+ def connection_required
0
       if wall?
0
- redirect_to home_url unless current_person?(@person)
0
- else
0
- redirect_to home_url unless current_person?(@blog.person)
0
+ unless connected_to?(person)
0
+ flash[:notice] = "You must be contacts to complete that action"
0
+ redirect_to @person
0
+ end
0
       end
0
     end
0
     
0
+ def authorize_destroy
0
+ redirect_to home_url unless current_person?(person)
0
+ end
0
+
0
     ## Handle wall and blog comments in a uniform manner.
0
     
0
     # Return the comments array for the given resource.
...
4
5
6
 
 
 
 
 
7
...
4
5
6
7
8
9
10
11
12
0
@@ -4,4 +4,9 @@ module SharedHelper
0
   def current_person?(person)
0
     logged_in? and person == current_person
0
   end
0
+
0
+ # Return true if a person is connected to (or is) the current person
0
+ def connected_to?(person)
0
+ current_person?(person) or Connection.connected?(person, current_person)
0
+ end
0
 end
...
2
3
4
5
6
7
8
9
 
 
 
 
 
 
10
11
12
13
14
 
 
 
 
 
15
16
17
...
2
3
4
 
 
 
 
 
5
6
7
8
9
10
11
 
 
 
 
12
13
14
15
16
17
18
19
0
@@ -2,16 +2,18 @@
0
   <div class="wall">
0
     <h2>Comment Wall</h2>
0
     <a name="wall"></a>
0
-
0
- <% form_for :comment, :url => person_comments_path(@person) do |f| %>
0
- <div class="form_row">
0
- <%= f.text_area :body, :rows => 2 %>
0
- </div>
0
+
0
+ <%- if connected_to?(@person) -%>
0
+ <% form_for :comment, :url => person_comments_path(@person) do |f| %>
0
+ <div class="form_row">
0
+ <%= f.text_area :body, :rows => 2 %>
0
+ </div>
0
   
0
- <div class="form_row">
0
- <%= submit_tag "Submit", :class => "button" %>
0
- </div>
0
- <% end %>
0
+ <div class="form_row">
0
+ <%= submit_tag "Submit", :class => "button" %>
0
+ </div>
0
+ <% end %>
0
+ <%- end -%>
0
 
0
     <%- unless @person.comments.empty? -%>
0
       <ul class="list comments full">
...
69
70
71
 
72
73
74
...
69
70
71
72
73
74
75
0
@@ -69,6 +69,7 @@ describe CommentsController do
0
     before(:each) do
0
       @commenter = login_as(:aaron)
0
       @person = people(:quentin)
0
+ Connection.connect(@person, @commenter)
0
     end
0
   
0
     it "should have working pages" do

Comments

    No one has commented yet.