social_stream 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/app/controllers/activities_controller.rb +1 -0
  2. data/app/controllers/avatars_controller.rb +17 -10
  3. data/app/controllers/comments_controller.rb +2 -0
  4. data/app/controllers/conversations_controller.rb +98 -103
  5. data/app/controllers/groups_controller.rb +3 -1
  6. data/app/controllers/likes_controller.rb +2 -0
  7. data/app/controllers/messages_controller.rb +4 -0
  8. data/app/controllers/posts_controller.rb +2 -2
  9. data/app/controllers/ties_controller.rb +6 -0
  10. data/app/helpers/subjects_helper.rb +32 -7
  11. data/app/helpers/ties_helper.rb +7 -2
  12. data/app/models/activity.rb +1 -1
  13. data/app/models/actor.rb +5 -8
  14. data/app/models/relation.rb +65 -0
  15. data/app/models/tie.rb +27 -7
  16. data/app/views/activities/_child.html.erb +1 -5
  17. data/app/views/activities/_root.html.erb +2 -4
  18. data/app/views/avatars/_form.html.erb +5 -16
  19. data/app/views/avatars/_precrop.html.erb +24 -17
  20. data/app/views/avatars/index.html.erb +47 -36
  21. data/app/views/avatars/new.html.erb +19 -3
  22. data/app/views/contacts/index.html.erb +1 -1
  23. data/app/views/contacts/index.js.erb +2 -0
  24. data/app/views/conversations/_conversation_full.html.erb +2 -1
  25. data/app/views/conversations/_index.html.erb +0 -7
  26. data/app/views/conversations/_show.html.erb +0 -7
  27. data/app/views/conversations/index.html.erb +9 -1
  28. data/app/views/conversations/index.js.erb +1 -0
  29. data/app/views/conversations/show.html.erb +1 -1
  30. data/app/views/conversations/show.js.erb +2 -0
  31. data/app/views/groups/_new.html.erb +9 -2
  32. data/app/views/groups/new.html.erb +5 -1
  33. data/app/views/layouts/_header.erb +23 -1
  34. data/app/views/layouts/_representation.html.erb +1 -1
  35. data/app/views/messages/new.html.erb +1 -1
  36. data/app/views/messages/new.js.erb +3 -0
  37. data/app/views/profiles/_profile.html.erb +18 -13
  38. data/app/views/profiles/edit.html.erb +29 -4
  39. data/app/views/profiles/update.js.erb +3 -3
  40. data/app/views/subjects/_toolbar_home_menu_options.html.erb +1 -1
  41. data/app/views/subjects/_toolbar_home_menu_options_subjects.html.erb +2 -2
  42. data/app/views/subjects/_toolbar_logo.html.erb +14 -2
  43. data/app/views/subjects/_toolbar_message_menu.html.erb +1 -1
  44. data/app/views/subjects/_toolbar_profile_menu_tie_options.html.erb +18 -7
  45. data/app/views/ties/_edit.html.erb +102 -0
  46. data/app/views/ties/_new.html.erb +48 -19
  47. data/app/views/ties/edit.html.erb +1 -0
  48. data/config/locales/en.yml +42 -27
  49. data/config/routes.rb +0 -6
  50. data/lib/generators/social_stream/templates/public/images/btn/arrowBlue.png +0 -0
  51. data/lib/generators/social_stream/templates/public/images/btn/shadow.png +0 -0
  52. data/lib/generators/social_stream/templates/public/javascripts/addContact.js +100 -0
  53. data/lib/generators/social_stream/templates/public/javascripts/avatars.js +8 -0
  54. data/lib/generators/social_stream/templates/public/javascripts/hoverIntent.js +84 -0
  55. data/lib/generators/social_stream/templates/public/javascripts/main.js +10 -1
  56. data/lib/generators/social_stream/templates/public/javascripts/menu.js +22 -6
  57. data/lib/generators/social_stream/templates/public/stylesheets/default/activities.css +2 -2
  58. data/lib/generators/social_stream/templates/public/stylesheets/default/addContact.css +29 -0
  59. data/lib/generators/social_stream/templates/public/stylesheets/default/avatars.css +79 -0
  60. data/lib/generators/social_stream/templates/public/stylesheets/default/base.css +44 -5
  61. data/lib/generators/social_stream/templates/public/stylesheets/default/header.css +151 -1
  62. data/lib/generators/social_stream/templates/public/stylesheets/default/home.css +1 -1
  63. data/lib/generators/social_stream/templates/public/stylesheets/default/jquery-ui.css +1 -1
  64. data/lib/generators/social_stream/templates/public/stylesheets/default/messages.css +6 -4
  65. data/lib/social_stream.rb +1 -1
  66. data/lib/social_stream/ability.rb +20 -0
  67. data/lib/social_stream/models/subject.rb +5 -1
  68. data/lib/social_stream/test_helpers/controllers.rb +55 -0
  69. data/lib/social_stream/version.rb +1 -1
  70. data/social_stream.gemspec +1 -1
  71. data/spec/controllers/comments_controller_spec.rb +38 -0
  72. data/spec/controllers/groups_controller_spec.rb +75 -5
  73. data/spec/factories/comment.rb +4 -0
  74. data/spec/models/tie_spec.rb +25 -15
  75. metadata +18 -10
  76. data/app/controllers/pshb_controller.rb +0 -55
  77. data/app/views/ties/new.js.erb +0 -12
  78. data/lib/social_stream/relations.rb +0 -46
@@ -1,5 +1,6 @@
1
1
  class ActivitiesController < InheritedResources::Base
2
2
  belongs_to_subjects
3
+ actions :index
3
4
 
4
5
  respond_to :js
5
6
 
@@ -8,22 +8,22 @@ class AvatarsController < InheritedResources::Base
8
8
  new_logo = Avatar.find(params[:id])
9
9
 
10
10
  if (new_logo.actor == current_subject.actor)
11
-
11
+
12
12
  actual_logo = current_subject.avatars.active.first
13
13
  if !actual_logo.blank?
14
- actual_logo.active = false
15
- actual_logo.save
14
+ actual_logo.active = false
15
+ actual_logo.save
16
16
  end
17
-
18
- new_logo.active = true
19
- new_logo.save
17
+
18
+ new_logo.active = true
19
+ new_logo.save
20
20
  end
21
21
  end
22
22
  redirect_to avatars_path
23
23
  end
24
24
 
25
25
  def create
26
- @avatar = Avatar.create(params[:logo])
26
+ @avatar = Avatar.create(params[:avatar])
27
27
 
28
28
  if @avatar.new_record?
29
29
  render :new
@@ -32,13 +32,20 @@ class AvatarsController < InheritedResources::Base
32
32
  @avatar.actor_id = current_subject.actor.id
33
33
  if !current_subject.avatars.blank?
34
34
  actual_logo = current_subject.avatars.active.first
35
- actual_logo.active = false
36
- actual_logo.save
35
+ actual_logo.active = false
36
+ actual_logo.save
37
37
  end
38
38
  @avatar.active = true
39
39
  @avatar.save
40
- redirect_to [current_subject, :profile]
40
+ redirect_to avatars_path
41
+ #redirect_to [current_subject, :profile]
41
42
  end
42
43
  end
43
44
 
45
+ protected
46
+
47
+ def begin_of_association_chain
48
+ current_subject
49
+ end
50
+
44
51
  end
@@ -1,4 +1,6 @@
1
1
  class CommentsController < InheritedResources::Base
2
+ load_and_authorize_resource
3
+
2
4
  respond_to :html, :xml, :js
3
5
 
4
6
  def destroy
@@ -1,107 +1,102 @@
1
1
  class ConversationsController < ApplicationController
2
2
 
3
- before_filter :get_mailbox, :get_box, :get_actor
4
- def index
5
- if @box.eql?"inbox"
6
- @conversations = @mailbox.inbox.paginate(:per_page => 9, :page => params[:page])
7
- elsif @box.eql?"sentbox"
8
- @conversations = @mailbox.sentbox.paginate(:per_page => 9, :page => params[:page])
9
- else
10
- @conversations = @mailbox.trash.paginate(:per_page => 9, :page => params[:page])
11
- end
12
- end
13
-
14
- def show
15
- @conversation = Conversation.find_by_id(params[:id])
16
- if @conversation.nil? or !@conversation.is_participant?(@actor)
17
- redirect_to conversations_path(:box => @box)
18
- return
19
- end
20
- if @box.eql? 'trash'
21
- @receipts = @conversation.receipts(@actor).trash
22
- else
23
- @receipts = @conversation.receipts(@actor).not_trash
24
- end
25
- render :action => :show
26
- @receipts.mark_as_read
27
- end
28
-
29
- def new
30
-
31
- end
32
-
33
- def edit
34
-
35
- end
36
-
37
- def create
38
-
39
- end
40
-
41
- def update
42
- @conversation = Conversation.find_by_id(params[:id])
43
- if @conversation.nil? or !@conversation.is_participant?(@actor)
44
- redirect_to conversations_path(:box => @box)
45
- return
46
- end
47
-
48
- if params[:untrash].present?
49
- @conversation.untrash(@actor)
50
- end
51
-
52
- if params[:reply_all].present?
53
- last_receipt = @conversation.receipts(@actor).last
54
- @receipt = @actor.reply_to_all(last_receipt, params[:body])
55
- end
56
-
57
- if @box.eql? 'trash'
58
- @receipts = @conversation.receipts(@actor).trash
59
- else
60
- @receipts = @conversation.receipts(@actor).not_trash
61
- end
62
- render :action => :show
63
- @receipts.mark_as_read
64
-
65
- end
66
-
67
- def destroy
68
- @conversation = Conversation.find_by_id(params[:id])
69
- if @conversation.nil? or !@conversation.is_participant?(@actor)
70
- redirect_to conversations_path(:box => @box)
71
- return
72
- end
73
-
74
- @conversation.move_to_trash(@actor)
75
-
76
- if params[:location].present?
77
- case params[:location]
78
- when 'conversation'
79
- redirect_to conversations_path(:box => :trash)
80
- return
81
- else
82
- redirect_to conversations_path(:box => @box,:page => params[:page])
83
- return
84
- end
85
- end
86
- redirect_to conversations_path(:box => @box,:page => params[:page])
87
- end
88
-
89
- private
90
-
91
- def get_mailbox
92
- @mailbox = current_subject.mailbox
93
- end
94
-
95
- def get_actor
96
- @actor = Actor.normalize(current_subject)
97
- end
98
-
99
- def get_box
100
- if params[:box].blank? or !["inbox","sentbox","trash"].include?params[:box]
101
- @box = "inbox"
102
- return
103
- end
104
- @box = params[:box]
105
- end
3
+ before_filter :authenticate_user!
4
+ before_filter :get_mailbox, :get_box, :get_actor
5
+ before_filter :check_current_subject_in_conversation, :only => [:show, :update, :destroy]
6
+ def index
7
+ if @box.eql?"inbox"
8
+ @conversations = @mailbox.inbox.paginate(:per_page => 9, :page => params[:page])
9
+ elsif @box.eql?"sentbox"
10
+ @conversations = @mailbox.sentbox.paginate(:per_page => 9, :page => params[:page])
11
+ else
12
+ @conversations = @mailbox.trash.paginate(:per_page => 9, :page => params[:page])
13
+ end
14
+ end
15
+
16
+ def show
17
+ if @box.eql? 'trash'
18
+ @receipts = @conversation.receipts(@actor).trash
19
+ else
20
+ @receipts = @conversation.receipts(@actor).not_trash
21
+ end
22
+ render :action => :show
23
+ @receipts.mark_as_read
24
+ end
25
+
26
+ def new
27
+
28
+ end
29
+
30
+ def edit
31
+
32
+ end
33
+
34
+ def create
35
+
36
+ end
37
+
38
+ def update
39
+ if params[:untrash].present?
40
+ @conversation.untrash(@actor)
41
+ end
42
+
43
+ if params[:reply_all].present?
44
+ last_receipt = @conversation.receipts(@actor).last
45
+ @receipt = @actor.reply_to_all(last_receipt, params[:body])
46
+ end
47
+
48
+ if @box.eql? 'trash'
49
+ @receipts = @conversation.receipts(@actor).trash
50
+ else
51
+ @receipts = @conversation.receipts(@actor).not_trash
52
+ end
53
+ render :action => :show
54
+ @receipts.mark_as_read
55
+
56
+ end
57
+
58
+ def destroy
59
+
60
+ @conversation.move_to_trash(@actor)
61
+
62
+ if params[:location].present?
63
+ case params[:location]
64
+ when 'conversation'
65
+ redirect_to conversations_path(:box => :trash)
66
+ return
67
+ else
68
+ redirect_to conversations_path(:box => @box,:page => params[:page])
69
+ return
70
+ end
71
+ end
72
+ redirect_to conversations_path(:box => @box,:page => params[:page])
73
+ end
74
+
75
+ private
76
+
77
+ def get_mailbox
78
+ @mailbox = current_subject.mailbox
79
+ end
80
+
81
+ def get_actor
82
+ @actor = Actor.normalize(current_subject)
83
+ end
84
+
85
+ def get_box
86
+ if params[:box].blank? or !["inbox","sentbox","trash"].include?params[:box]
87
+ @box = "inbox"
88
+ return
89
+ end
90
+ @box = params[:box]
91
+ end
92
+
93
+ def check_current_subject_in_conversation
94
+ @conversation = Conversation.find_by_id(params[:id])
95
+
96
+ if @conversation.nil? or !@conversation.is_participant?(@actor)
97
+ redirect_to conversations_path(:box => @box)
98
+ return
99
+ end
100
+ end
106
101
 
107
102
  end
@@ -1,6 +1,8 @@
1
1
  class GroupsController < InheritedResources::Base
2
+ load_and_authorize_resource
3
+
2
4
  respond_to :html, :xml, :js
3
-
5
+
4
6
  def index
5
7
  @groups = Group.alphabetic.
6
8
  letter(params[:letter]).
@@ -1,4 +1,6 @@
1
1
  class LikesController < ApplicationController
2
+ before_filter :authenticate_user!
3
+
2
4
  # POST /activities/1/like.js
3
5
  def create
4
6
  @like = Like.new(current_subject, params[:activity_id])
@@ -1,6 +1,10 @@
1
1
  class MessagesController < ApplicationController
2
2
 
3
3
  before_filter :get_mailbox, :get_box, :get_actor
4
+
5
+ def index
6
+ redirect_to conversations_path(:box => @box)
7
+ end
4
8
  # GET /messages/1
5
9
  # GET /messages/1.xml
6
10
  def show
@@ -1,8 +1,8 @@
1
1
  class PostsController < InheritedResources::Base
2
- respond_to :html, :xml, :js
3
-
4
2
  load_and_authorize_resource
5
3
 
4
+ respond_to :html, :xml, :js
5
+
6
6
  def destroy
7
7
  @post_activity = resource.post_activity
8
8
 
@@ -9,6 +9,12 @@ class TiesController < InheritedResources::Base
9
9
  end
10
10
  end
11
11
 
12
+ def update
13
+ update do |format|
14
+ format.html { redirect_to resource.receiver_subject }
15
+ end
16
+ end
17
+
12
18
  def suggestion
13
19
  @tie = current_subject.suggestion
14
20
  render :layout => false
@@ -11,6 +11,20 @@ module SubjectsHelper
11
11
  #
12
12
  # The menu option allows overwriting a menu slot with the content of the given block
13
13
  #
14
+ #
15
+ # Autoexpanding a menu section on your view:
16
+ #
17
+ # Toolbar allows you to autoexpand certain menu section that may be of interest for your view.
18
+ # For example, the messages menu when you are looking your inbox. This is done through :option element.
19
+ #
20
+ # To get it working, you should use the proper :option to be expanded, ":option => :messages" in the
21
+ # mentioned example. This will try, automatically, to expand the section of the menu where its root
22
+ # list link, the one expanding the section, has an id equal to "#messages_menu". If you use
23
+ # ":options => :contacts" it will try to expand "#contacts_menu".
24
+ #
25
+ # For now its working with :option => :messages, :contacts or :groups
26
+ #
27
+ #
14
28
  # Examples:
15
29
  #
16
30
  # Render the home toolbar:
@@ -29,6 +43,7 @@ module SubjectsHelper
29
43
  #
30
44
  # <% toolbar :profile => @group, :option => :contacts %>
31
45
  #
46
+
32
47
  def toolbar(options = {}, &block)
33
48
  if options[:option] && block_given?
34
49
  menu_options[options[:option]] = capture(&block)
@@ -44,15 +59,25 @@ module SubjectsHelper
44
59
 
45
60
  case request.format
46
61
  when Mime::JS
47
- <<-EOJ
48
- $('#toolbar').html("#{ escape_javascript(content) }");
49
- EOJ
62
+ response = <<-EOJ
63
+
64
+ $('#toolbar').html("#{ escape_javascript(content) }");
65
+ initMenu();
66
+ expandSubMenu('#{ options[:option] }');
67
+ EOJ
68
+
69
+ response.html_safe
50
70
  else
51
- content_for(:toolbar) do
52
- content
53
- end
71
+ content_for(:toolbar) do
72
+ content
54
73
  end
55
-
74
+ content_for(:javascript) do
75
+ <<-EOJ
76
+ expandSubMenu('#{ options[:option] }');
77
+ EOJ
78
+ end
79
+ end
80
+
56
81
  end
57
82
 
58
83
  # Cache menu options for toolbar
@@ -22,11 +22,16 @@ module TiesHelper
22
22
  new_tie_path("tie[sender_id]" => tie.sender.id,
23
23
  "tie[receiver_id]" => tie.receiver.id),
24
24
  :title => t("contact.new.title",
25
- :name => tie.receiver_subject.name),
26
- :remote => true
25
+ :name => tie.receiver_subject.name)
27
26
  end
28
27
 
29
28
  def link_follow_state
30
29
  link_to("Unfollow", home_path)
31
30
  end
31
+
32
+
33
+ def get_permission_id(action,object,function)
34
+ return Permission.find_by_action_and_function_and_object(action,object,function).id
35
+ end
36
+
32
37
  end
@@ -137,7 +137,7 @@ class Activity < ActiveRecord::Base
137
137
  def title view
138
138
  case verb
139
139
  when "follow", "make-friend"
140
- I18n.t "activity.verb.#{ verb }.title",
140
+ I18n.t "activity.verb.#{ verb }.#{ tie.receiver.subject_type }.title",
141
141
  :subject => view.link_name(sender_subject),
142
142
  :contact => view.link_name(receiver_subject)
143
143
  when "post"
data/app/models/actor.rb CHANGED
@@ -67,7 +67,7 @@ class Actor < ActiveRecord::Base
67
67
  joins(:received_ties).merge(Tie.sent_by(a))
68
68
  }
69
69
 
70
- after_create :initialize_ties
70
+ after_create :create_initial_relations
71
71
 
72
72
  after_create :create_profile
73
73
 
@@ -229,7 +229,7 @@ class Actor < ActiveRecord::Base
229
229
 
230
230
  # Set of ties sent by this actor received by a
231
231
  def ties_to(a)
232
- sent_ties.received_by(a)
232
+ sent_ties.received_by(a).original
233
233
  end
234
234
 
235
235
  def ties_to?(a)
@@ -301,11 +301,8 @@ class Actor < ActiveRecord::Base
301
301
 
302
302
  private
303
303
 
304
- def initialize_ties
305
- ::SocialStream::Relations.create(subject_type).each do |r|
306
- sent_ties.create! :receiver => self,
307
- :relation => r
308
- end
304
+ # After create callback
305
+ def create_initial_relations
306
+ Relation.defaults_for(self)
309
307
  end
310
-
311
308
  end