social_stream-base 0.18.1 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. data/app/assets/javascripts/social_stream.action.js +40 -0
  2. data/app/assets/javascripts/social_stream.comments.js +26 -1
  3. data/app/assets/javascripts/social_stream.timeline.js +15 -7
  4. data/app/assets/javascripts/social_stream.wall.js.erb +1 -0
  5. data/app/assets/stylesheets/social_stream-base.css.scss +13 -0
  6. data/app/models/activity.rb +5 -1
  7. data/app/models/activity_action.rb +6 -0
  8. data/app/models/activity_object.rb +131 -9
  9. data/app/models/actor.rb +2 -0
  10. data/app/models/channel.rb +0 -1
  11. data/app/models/comment.rb +0 -6
  12. data/app/views/activity_actions/_update.js.erb +11 -0
  13. data/app/views/activity_actions/create.js.erb +1 -1
  14. data/app/views/activity_actions/update.js.erb +1 -1
  15. data/app/views/comments/create.js.erb +1 -1
  16. data/app/views/posts/create.js.erb +1 -1
  17. data/db/migrate/20120111141717_create_social_stream.rb +265 -0
  18. data/db/migrate/20120326083509_object_channels_to_actions.rb +45 -0
  19. data/lib/social_stream/ability/base.rb +2 -2
  20. data/lib/social_stream/base/version.rb +1 -1
  21. data/lib/social_stream/controllers/cancan_devise_integration.rb +9 -5
  22. data/lib/social_stream/models/object.rb +0 -72
  23. data/lib/social_stream/models/subject.rb +2 -1
  24. data/lib/social_stream/models/subtype.rb +6 -1
  25. data/spec/controllers/groups_controller_spec.rb +6 -0
  26. data/spec/factories/post.rb +6 -0
  27. data/spec/models/activity_action_spec.rb +35 -0
  28. metadata +69 -77
  29. data/app/assets/stylesheets/social_stream-base.css +0 -5
  30. data/app/views/activity_actions/_update_form.js.erb +0 -2
  31. data/db/migrate/20110610112023_create_social_stream.rb +0 -319
  32. data/db/migrate/20110705103202_empty_ties_count.rb +0 -17
  33. data/db/migrate/20110712090343_remove_spheres.rb +0 -30
  34. data/db/migrate/20110712142140_remove_permission_function.rb +0 -26
  35. data/db/migrate/20110912074426_add_reject_relation.rb +0 -29
  36. data/db/migrate/20111124100618_object_actors.rb +0 -52
  37. data/db/migrate/20111221103509_add_language_field.rb +0 -13
  38. data/db/migrate/20120103103125_add_channels.rb +0 -88
  39. data/db/migrate/20120109081509_update_notify_permissions.rb +0 -15
  40. data/db/migrate/20120111120920_remove_language_default.rb +0 -9
  41. data/db/migrate/20120111141717_activity_channels.rb +0 -74
@@ -0,0 +1,265 @@
1
+ class CreateSocialStream < ActiveRecord::Migration
2
+ def change
3
+ create_table "activities", :force => true do |t|
4
+ t.integer "activity_verb_id"
5
+ t.datetime "created_at"
6
+ t.datetime "updated_at"
7
+ t.string "ancestry"
8
+ t.integer "channel_id"
9
+ end
10
+
11
+ add_index "activities", ["activity_verb_id"], :name => "index_activities_on_activity_verb_id"
12
+ add_index "activities", ["channel_id"], :name => "index_activities_on_channel_id"
13
+
14
+ create_table "activity_object_activities", :force => true do |t|
15
+ t.integer "activity_id"
16
+ t.integer "activity_object_id"
17
+ t.datetime "created_at"
18
+ t.datetime "updated_at"
19
+ t.string "object_type"
20
+ end
21
+
22
+ add_index "activity_object_activities", ["activity_id"], :name => "index_activity_object_activities_on_activity_id"
23
+ add_index "activity_object_activities", ["activity_object_id"], :name => "index_activity_object_activities_on_activity_object_id"
24
+
25
+ create_table "activity_objects", :force => true do |t|
26
+ t.datetime "created_at"
27
+ t.datetime "updated_at"
28
+ t.string "object_type", :limit => 45
29
+ t.integer "like_count", :default => 0
30
+ t.integer "channel_id"
31
+ end
32
+
33
+ add_index "activity_objects", ["channel_id"], :name => "index_activity_objects_on_channel_id"
34
+
35
+ create_table "activity_verbs", :force => true do |t|
36
+ t.string "name", :limit => 45
37
+ t.datetime "created_at"
38
+ t.datetime "updated_at"
39
+ end
40
+
41
+ create_table "actors", :force => true do |t|
42
+ t.string "name"
43
+ t.string "email", :default => "", :null => false
44
+ t.string "slug"
45
+ t.string "subject_type"
46
+ t.boolean "notify_by_email", :default => true
47
+ t.datetime "created_at"
48
+ t.datetime "updated_at"
49
+ t.integer "activity_object_id"
50
+ t.integer "follower_count", :default => 0
51
+ end
52
+
53
+ add_index "actors", ["activity_object_id"], :name => "index_actors_on_activity_object_id"
54
+ add_index "actors", ["email"], :name => "index_actors_on_email"
55
+ add_index "actors", ["slug"], :name => "index_actors_on_slug", :unique => true
56
+
57
+ create_table "audiences", :force => true do |t|
58
+ t.integer "relation_id"
59
+ t.integer "activity_id"
60
+ end
61
+
62
+ add_index "audiences", ["activity_id"], :name => "index_audiences_on_activity_id"
63
+ add_index "audiences", ["relation_id"], :name => "index_audiences_on_relation_id"
64
+
65
+ create_table "authentications", :force => true do |t|
66
+ t.integer "user_id"
67
+ t.string "provider"
68
+ t.string "uid"
69
+ t.datetime "created_at", :null => false
70
+ t.datetime "updated_at", :null => false
71
+ end
72
+
73
+ add_index "authentications", ["user_id"], :name => "index_authentications_on_user_id"
74
+
75
+ create_table "avatars", :force => true do |t|
76
+ t.integer "actor_id"
77
+ t.string "logo_file_name"
78
+ t.string "logo_content_type"
79
+ t.integer "logo_file_size"
80
+ t.datetime "logo_updated_at"
81
+ t.boolean "active", :default => true
82
+ end
83
+
84
+ add_index "avatars", ["actor_id"], :name => "index_avatars_on_actor_id"
85
+
86
+ create_table "channels", :force => true do |t|
87
+ t.integer "author_id"
88
+ t.integer "owner_id"
89
+ t.integer "user_author_id"
90
+ t.datetime "created_at", :null => false
91
+ t.datetime "updated_at", :null => false
92
+ end
93
+
94
+ add_index "channels", ["author_id"], :name => "index_channels_on_author_id"
95
+ add_index "channels", ["owner_id"], :name => "index_channels_on_owner_id"
96
+ add_index "channels", ["user_author_id"], :name => "index_channels_on_user_author_id"
97
+
98
+ create_table "comments", :force => true do |t|
99
+ t.integer "activity_object_id"
100
+ t.text "text"
101
+ t.datetime "created_at"
102
+ t.datetime "updated_at"
103
+ end
104
+
105
+ add_index "comments", ["activity_object_id"], :name => "index_comments_on_activity_object_id"
106
+
107
+ create_table "contacts", :force => true do |t|
108
+ t.integer "sender_id"
109
+ t.integer "receiver_id"
110
+ t.datetime "created_at"
111
+ t.datetime "updated_at"
112
+ t.integer "inverse_id"
113
+ t.integer "ties_count", :default => 0
114
+ end
115
+
116
+ add_index "contacts", ["inverse_id"], :name => "index_contacts_on_inverse_id"
117
+ add_index "contacts", ["receiver_id"], :name => "index_contacts_on_receiver_id"
118
+ add_index "contacts", ["sender_id"], :name => "index_contacts_on_sender_id"
119
+
120
+ create_table "groups", :force => true do |t|
121
+ t.integer "actor_id"
122
+ t.datetime "created_at"
123
+ t.datetime "updated_at"
124
+ end
125
+
126
+ add_index "groups", ["actor_id"], :name => "index_groups_on_actor_id"
127
+
128
+ create_table "permissions", :force => true do |t|
129
+ t.string "action"
130
+ t.string "object"
131
+ t.datetime "created_at"
132
+ t.datetime "updated_at"
133
+ end
134
+
135
+ create_table "posts", :force => true do |t|
136
+ t.integer "activity_object_id"
137
+ t.datetime "created_at"
138
+ t.datetime "updated_at"
139
+ t.text "text"
140
+ end
141
+
142
+ add_index "posts", ["activity_object_id"], :name => "index_posts_on_activity_object_id"
143
+
144
+ create_table "profiles", :force => true do |t|
145
+ t.integer "actor_id"
146
+ t.date "birthday"
147
+ t.datetime "created_at"
148
+ t.datetime "updated_at"
149
+ t.string "organization", :limit => 45
150
+ t.string "phone", :limit => 45
151
+ t.string "mobile", :limit => 45
152
+ t.string "fax", :limit => 45
153
+ t.string "address"
154
+ t.string "city"
155
+ t.string "zipcode", :limit => 45
156
+ t.string "province", :limit => 45
157
+ t.string "country", :limit => 45
158
+ t.integer "prefix_key"
159
+ t.string "description"
160
+ t.string "experience"
161
+ t.string "website"
162
+ t.string "skype", :limit => 45
163
+ t.string "im", :limit => 45
164
+ end
165
+
166
+ add_index "profiles", ["actor_id"], :name => "index_profiles_on_actor_id"
167
+
168
+ create_table "relation_permissions", :force => true do |t|
169
+ t.integer "relation_id"
170
+ t.integer "permission_id"
171
+ t.datetime "created_at"
172
+ t.datetime "updated_at"
173
+ end
174
+
175
+ add_index "relation_permissions", ["permission_id"], :name => "index_relation_permissions_on_permission_id"
176
+ add_index "relation_permissions", ["relation_id"], :name => "index_relation_permissions_on_relation_id"
177
+
178
+ create_table "relations", :force => true do |t|
179
+ t.integer "actor_id"
180
+ t.string "type"
181
+ t.string "name"
182
+ t.datetime "created_at"
183
+ t.datetime "updated_at"
184
+ t.string "sender_type"
185
+ t.string "receiver_type"
186
+ t.string "ancestry"
187
+ end
188
+
189
+ add_index "relations", ["actor_id"], :name => "index_relations_on_actor_id"
190
+ add_index "relations", ["ancestry"], :name => "index_relations_on_ancestry"
191
+
192
+ create_table "ties", :force => true do |t|
193
+ t.integer "contact_id"
194
+ t.integer "relation_id"
195
+ t.datetime "created_at"
196
+ t.datetime "updated_at"
197
+ end
198
+
199
+ add_index "ties", ["contact_id"], :name => "index_ties_on_contact_id"
200
+ add_index "ties", ["relation_id"], :name => "index_ties_on_relation_id"
201
+
202
+ create_table "users", :force => true do |t|
203
+ t.string "encrypted_password", :limit => 128, :default => "", :null => false
204
+ t.string "password_salt"
205
+ t.string "reset_password_token"
206
+ t.datetime "reset_password_sent_at"
207
+ t.datetime "remember_created_at"
208
+ t.integer "sign_in_count", :default => 0
209
+ t.datetime "current_sign_in_at"
210
+ t.datetime "last_sign_in_at"
211
+ t.string "current_sign_in_ip"
212
+ t.string "last_sign_in_ip"
213
+ t.string "authentication_token"
214
+ t.datetime "created_at", :null => false
215
+ t.datetime "updated_at", :null => false
216
+ t.integer "actor_id"
217
+ t.string "language"
218
+ end
219
+
220
+ add_index "users", ["actor_id"], :name => "index_users_on_actor_id"
221
+ add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
222
+
223
+ add_foreign_key "activities", "activity_verbs", :name => "index_activities_on_activity_verb_id"
224
+ add_foreign_key "activities", "channels", :name => "index_activities_on_channel_id"
225
+
226
+ add_foreign_key "activity_object_activities", "activities", :name => "index_activity_object_activities_on_activity_id"
227
+ add_foreign_key "activity_object_activities", "activity_objects", :name => "activity_object_activities_on_activity_object_id"
228
+
229
+ add_foreign_key "activity_objects", "channels", :name => "index_activity_objects_on_channel_id"
230
+
231
+ add_foreign_key "actors", "activity_objects", :name => "actors_on_activity_object_id"
232
+
233
+ add_foreign_key "audiences", "activities", :name => "audiences_on_activity_id"
234
+ add_foreign_key "audiences", "relations", :name => "audiences_on_relation_id"
235
+
236
+ add_foreign_key "authentications", "users", :name => "authentications_on_user_id"
237
+
238
+ add_foreign_key "avatars", "actors", :name => "avatars_on_actor_id"
239
+
240
+ add_foreign_key "channels", "actors", :name => "index_channels_on_author_id", :column => "author_id"
241
+ add_foreign_key "channels", "actors", :name => "index_channels_on_owner_id", :column => "owner_id"
242
+ add_foreign_key "channels", "actors", :name => "index_channels_on_user_author_id", :column => "user_author_id"
243
+
244
+ add_foreign_key "comments", "activity_objects", :name => "comments_on_activity_object_id"
245
+
246
+ add_foreign_key "contacts", "actors", :name => "contacts_on_receiver_id", :column => "receiver_id"
247
+ add_foreign_key "contacts", "actors", :name => "contacts_on_sender_id", :column => "sender_id"
248
+
249
+ add_foreign_key "groups", "actors", :name => "groups_on_actor_id"
250
+
251
+ add_foreign_key "posts", "activity_objects", :name => "posts_on_activity_object_id"
252
+
253
+ add_foreign_key "profiles", "actors", :name => "profiles_on_actor_id"
254
+
255
+ add_foreign_key "relation_permissions", "permissions", :name => "relation_permissions_on_permission_id"
256
+ add_foreign_key "relation_permissions", "relations", :name => "relation_permissions_on_relation_id"
257
+
258
+ add_foreign_key "relations", "actors", :name => "relations_on_actor_id"
259
+
260
+ add_foreign_key "ties", "contacts", :name => "ties_on_contact_id"
261
+ add_foreign_key "ties", "relations", :name => "ties_on_relation_id"
262
+
263
+ add_foreign_key "users", "actors", :name => "users_on_actor_id"
264
+ end
265
+ end
@@ -0,0 +1,45 @@
1
+ class ObjectChannelsToActions < ActiveRecord::Migration
2
+ def up
3
+ add_column :activity_actions, :author, :boolean, :default => false
4
+ add_column :activity_actions, :user_author, :boolean, :default => false
5
+ add_column :activity_actions, :owner, :boolean, :default => false
6
+
7
+ ActivityAction.reset_column_information
8
+ ActivityAction.record_timestamps = false
9
+ ActivityObject.record_timestamps = false
10
+
11
+ ActivityObject.all.each do |ao|
12
+ channel = Channel.find ao.channel_id
13
+
14
+ %w{ author user_author owner }.each do |role|
15
+ next unless channel.__send__ "#{ role }_id"
16
+
17
+ ao.__send__"#{ role }_id=", channel.__send__("#{ role }_id")
18
+ end
19
+
20
+ ao.received_actions.each do |a|
21
+ a.created_at = a.updated_at = ao.created_at
22
+ end
23
+
24
+ ao.save!
25
+ end
26
+
27
+ remove_foreign_key :activity_objects, :name => "index_activity_objects_on_channel_id"
28
+ remove_column :activity_objects, :channel_id
29
+
30
+ ActivityObject.reset_column_information
31
+
32
+ ActivityAction.record_timestamps = true
33
+ ActivityObject.record_timestamps = true
34
+ end
35
+
36
+ def down
37
+ remove_column :activity_actions, :author
38
+ remove_column :activity_actions, :user_author
39
+ remove_column :activity_actions, :owner
40
+
41
+ add_column :activity_objects, :channel_id, :integer
42
+ add_index :activity_objects, :channel_id
43
+ add_foreign_key :activity_actions, :channel_id, :name => "index_activity_objects_on_channel_id"
44
+ end
45
+ end
@@ -22,11 +22,11 @@ module SocialStream
22
22
  end
23
23
 
24
24
  can :update, klass do |k| # can :update, Post do |post|
25
- [k.channel.author_id, k.channel.owner_id].include?(Actor.normalize_id(subject))
25
+ [k.author_id, k.owner_id].include?(Actor.normalize_id(subject))
26
26
  end
27
27
 
28
28
  can :destroy, klass do |k| # can :destroy, Post do |post|
29
- [k.channel.author_id, k.channel.owner_id].include?(Actor.normalize_id(subject))
29
+ [k.author_id, k.owner_id].include?(Actor.normalize_id(subject))
30
30
  end
31
31
  end
32
32
 
@@ -1,5 +1,5 @@
1
1
  module SocialStream
2
2
  module Base
3
- VERSION = "0.18.1".freeze
3
+ VERSION = "0.19.0".freeze
4
4
  end
5
5
  end
@@ -3,7 +3,7 @@ module SocialStream
3
3
  # Common methods added to ApplicationController
4
4
  module CancanDeviseIntegration
5
5
  extend ActiveSupport::Concern
6
-
6
+
7
7
  private
8
8
 
9
9
  # Catch some authorization errors:
@@ -17,14 +17,18 @@ module SocialStream
17
17
  if user_signed_in?
18
18
  if params[:s].present? && controller_name != 'home'
19
19
  redirect_to :home
20
- else
21
- raise exception
20
+ return
22
21
  end
23
22
  else
24
- redirect_to new_user_session_path
23
+ if request.get?
24
+ session["user_return_to"] = request.fullpath
25
+ redirect_to new_user_session_path
26
+ return
27
+ end
25
28
  end
29
+
30
+ raise exception
26
31
  end
27
32
  end
28
33
  end
29
34
  end
30
-
@@ -5,15 +5,9 @@ module SocialStream
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  included do
8
- attr_writer :_relation_ids
9
- attr_accessor :_activity_parent_id
10
-
11
8
  subtype_of :activity_object,
12
9
  :build => { :object_type => to_s }
13
10
 
14
- has_one :channel, :through => :activity_object
15
- has_many :activity_object_activities, :through => :activity_object
16
-
17
11
  unless self == Actor
18
12
  validates_presence_of :author_id, :owner_id, :user_author_id
19
13
 
@@ -28,72 +22,6 @@ module SocialStream
28
22
  merge(ActivityObject.authored_by(subject))
29
23
  }
30
24
  end
31
-
32
- # All the activities with this object
33
- def activities
34
- Activity.
35
- includes(:activity_objects => self.class.to_s.underscore).
36
- where("#{ self.class.quoted_table_name }.id" => self.id)
37
- end
38
-
39
- # Build the post activity when this object is not saved
40
- def build_post_activity
41
- Activity.new :channel => channel!,
42
- :relation_ids => Array(_relation_ids)
43
- end
44
-
45
- def _contact
46
- @_contact ||= author && owner && author.contact_to!(owner)
47
- end
48
-
49
- def _contact_id
50
- _contact.try(:id)
51
- end
52
-
53
- def _relation_ids
54
- @_relation_ids ||=
55
- if _contact_id.nil?
56
- nil
57
- else
58
- # FIXME: repeated in Activity#fill_relations
59
- if _contact.reflexive?
60
- _contact.sender.relation_customs.map(&:id)
61
- else
62
- _contact.
63
- receiver.
64
- relation_customs.
65
- allow(_contact.sender, 'create', 'activity').
66
- map(&:id)
67
- end
68
- end
69
- end
70
-
71
- def _activity_parent
72
- @_activity_parent ||= Activity.find(_activity_parent_id)
73
- end
74
-
75
- private
76
-
77
- def create_post_activity
78
- create_activity "post"
79
- end
80
-
81
- def create_update_activity
82
- return if _contact_id.blank?
83
-
84
- create_activity "update"
85
- end
86
-
87
- def create_activity(verb)
88
- a = Activity.new :verb => verb,
89
- :channel => channel,
90
- :relation_ids => _relation_ids,
91
- :parent_id => _activity_parent_id
92
-
93
- a.activity_objects << activity_object
94
-
95
- a.save!
96
- end
97
25
  end
98
26
  end
99
27
  end
@@ -22,6 +22,7 @@ module SocialStream
22
22
  subtype_of :actor,
23
23
  :build => { :subject_type => to_s }
24
24
 
25
+ has_one :activity_object, :through => :actor
25
26
  has_one :profile, :through => :actor
26
27
 
27
28
  validates_presence_of :name
@@ -48,7 +49,7 @@ module SocialStream
48
49
 
49
50
  scope :followed, lambda {
50
51
  joins(:actor).
51
- order("actors.follower_count DESC")
52
+ merge(Actor.followed)
52
53
  }
53
54
 
54
55
  scope :liked, lambda {
@@ -53,7 +53,12 @@ module SocialStream #:nodoc:
53
53
  # the subtype. Example: user.foo should raise "foo is not defined in user"
54
54
  # and not "in actor"
55
55
  rescue NameError => supertype_error
56
- raise subtype_error
56
+ if supertype_error.name == subtype_error.name &&
57
+ supertype_error.message =~ /#{ self.class.supertype_name.to_s.classify }/
58
+ raise subtype_error
59
+ else
60
+ raise supertype_error
61
+ end
57
62
  end
58
63
  end
59
64
 
@@ -13,6 +13,12 @@ describe GroupsController do
13
13
  assert_response :success
14
14
  end
15
15
 
16
+ it "should render index with most followed" do
17
+ get :index, :most => 'followed'
18
+
19
+ response.should be_success
20
+ end
21
+
16
22
  it "should render show" do
17
23
  get :show, :id => Factory(:group).to_param
18
24
 
@@ -9,3 +9,9 @@ Factory.define :public_post, :parent => :post do |p|
9
9
  p.owner_id { |q| q.author_id }
10
10
  p._relation_ids { |q| Array(Relation::Public.instance.id) }
11
11
  end
12
+
13
+ Factory.define :self_post, :parent => :post do |p|
14
+ p.author_id { Factory(:user).actor_id }
15
+ p.owner_id { |q| q.author_id }
16
+ p.user_author_id { |q| q.author_id }
17
+ end
@@ -22,5 +22,40 @@ describe ActivityAction do
22
22
 
23
23
  action.reload.should_not be_follow
24
24
  end
25
+
26
+ describe "where posting to other owner" do
27
+ before do
28
+ @post = Factory(:post)
29
+ end
30
+
31
+ it "should not be duplicated" do
32
+ @post.received_actions.count.should == 2
33
+ end
34
+ end
35
+
36
+ describe "where posting to self" do
37
+ before do
38
+ @post = Factory(:self_post)
39
+ end
40
+
41
+ it "should not be duplicated" do
42
+ @post.received_actions.count.should == 1
43
+ end
44
+ end
45
+
46
+ describe "where building the post" do
47
+ before do
48
+ user = Factory(:user)
49
+ @post = Post.new :text => "Testing",
50
+ :author => user,
51
+ :owner => user,
52
+ :user_author => user
53
+ @post.save!
54
+ end
55
+
56
+ it "should not be duplicated" do
57
+ @post.received_actions.count.should == 1
58
+ end
59
+ end
25
60
  end
26
61
  end