social_stream-base 0.22.4 → 0.23.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 (47) hide show
  1. data/app/controllers/activities_controller.rb +14 -12
  2. data/app/controllers/api_controller.rb +0 -13
  3. data/app/controllers/frontpage_controller.rb +0 -6
  4. data/app/models/activity.rb +21 -61
  5. data/app/models/actor.rb +4 -8
  6. data/app/models/audience.rb +2 -0
  7. data/app/models/comment.rb +2 -1
  8. data/app/models/group.rb +0 -2
  9. data/app/models/relation.rb +5 -1
  10. data/app/models/relation/custom.rb +17 -4
  11. data/app/models/tie.rb +0 -2
  12. data/app/models/user.rb +0 -2
  13. data/app/views/activities/_options.html.erb +1 -1
  14. data/app/views/activities/index.atom.builder +48 -0
  15. data/app/views/activity_objects/_activity_object.atom.erb +1 -0
  16. data/config/locales/en.yml +8 -0
  17. data/config/locales/es.yml +8 -0
  18. data/config/routes.rb +0 -8
  19. data/lib/rails/social_stream.rb +1 -1
  20. data/lib/social_stream-base.rb +5 -0
  21. data/lib/social_stream/ability/base.rb +4 -16
  22. data/lib/social_stream/activity_streams.rb +39 -0
  23. data/lib/social_stream/activity_streams/subtype.rb +11 -0
  24. data/lib/social_stream/activity_streams/supertype.rb +12 -0
  25. data/lib/social_stream/base/dependencies.rb +2 -0
  26. data/lib/social_stream/base/engine.rb +6 -0
  27. data/lib/social_stream/base/version.rb +1 -1
  28. data/lib/social_stream/models/object.rb +5 -0
  29. data/lib/social_stream/models/subject.rb +1 -1
  30. data/lib/social_stream/models/subtype.rb +2 -0
  31. data/lib/social_stream/models/supertype.rb +2 -0
  32. data/social_stream-base.gemspec +2 -0
  33. data/spec/controllers/activities_controller_spec.rb +18 -0
  34. data/spec/controllers/frontpage_controller_spec.rb +0 -5
  35. data/spec/models/activity_wall_spec.rb +96 -0
  36. data/spec/models/post_authorization_spec.rb +370 -0
  37. data/spec/models/post_spec.rb +0 -2
  38. data/spec/models/relation_spec.rb +22 -0
  39. data/spec/social_stream_activity_streams_spec.rb +16 -0
  40. data/spec/social_stream_spec.rb +1 -1
  41. metadata +27 -8
  42. data/app/assets/images/logos/actor/remote_subject.png +0 -0
  43. data/app/assets/images/logos/actor/remote_user.png +0 -0
  44. data/app/controllers/subjects_controller.rb +0 -7
  45. data/app/views/api/activity_atom_feed.atom.builder +0 -40
  46. data/app/views/frontpage/host_meta.xml.builder +0 -11
  47. data/spec/models/activity_authorization_spec.rb +0 -354
@@ -0,0 +1,39 @@
1
+ module SocialStream
2
+ # Maintains a list of the equivalences between SocialStream's models
3
+ # and ActivityStreams' object types
4
+ #
5
+ # http://activitystrea.ms/specs/json/schema/activity-schema.html#object-types
6
+ module ActivityStreams
7
+ DEFAULT_TYPE = :note
8
+
9
+ class << self
10
+ @@register = {}
11
+
12
+ # Register a new ActivityStreams type along with the model
13
+ def register(object_type, klass = nil)
14
+ klass ||= object_type
15
+
16
+ @@register[object_type] = klass
17
+ end
18
+
19
+ # Get the SocialStream's model, given a ActivityStreams' object type
20
+ def model(type)
21
+ model = @@register[type]
22
+ model && model.to_s.classify.constantize
23
+ end
24
+
25
+ # Get the SocialStream's model, given a ActivityStreams' object type
26
+ # or the default model
27
+ def model!(type)
28
+ model(type) || model(SocialStream::ActivityStreams::DEFAULT_TYPE)
29
+ end
30
+
31
+ # Get the ActivityStreams' object type, given a SocialStream's model
32
+ def type(klass)
33
+ klass = klass.to_s.underscore.to_sym unless klass.is_a?(Symbol)
34
+
35
+ @@register.invert[klass]
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,11 @@
1
+ module SocialStream
2
+ module ActivityStreams
3
+ module Subtype
4
+ # The {ActivityStreams}[http://activitystrea.ms/specs/atom/1.0/] object type for
5
+ # this subtype
6
+ def as_object_type
7
+ SocialStream::ActivityStreams.type(self.class)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module SocialStream
2
+ module ActivityStreams
3
+ module Supertype
4
+ # The {ActivityStreams}[http://activitystrea.ms/specs/atom/1.0/] object type for
5
+ # this object
6
+ def as_object_type
7
+ subtype_instance.as_object_type
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -2,6 +2,8 @@
2
2
  require 'deep_merge'
3
3
  # Monkey patch Ruby on Rails
4
4
  require 'rails/social_stream'
5
+ # Rails Engine Decorators
6
+ require 'rails_engine_decorators'
5
7
  # Database foreign keys
6
8
  require 'foreigner'
7
9
  # jQuery
@@ -29,6 +29,12 @@ module SocialStream
29
29
  SocialStream.single_relations.each{ |r| "Relation::#{ r.to_s.classify }".constantize }
30
30
  end
31
31
 
32
+ initializer "social_stream-base.model.register_activity_streams" do
33
+ SocialStream::ActivityStreams.register :person, :user
34
+ SocialStream::ActivityStreams.register :group
35
+ SocialStream::ActivityStreams.register :note, :post
36
+ end
37
+
32
38
  initializer "social_stream-base.controller.helpers" do
33
39
  ActiveSupport.on_load(:action_controller) do
34
40
  include SocialStream::Controllers::Helpers
@@ -1,5 +1,5 @@
1
1
  module SocialStream
2
2
  module Base
3
- VERSION = "0.22.4".freeze
3
+ VERSION = "0.23.0".freeze
4
4
  end
5
5
  end
@@ -48,6 +48,11 @@ module SocialStream
48
48
  merge(ActivityObject.followed_by(subject))
49
49
  }
50
50
  end
51
+
52
+ module ClassMethods
53
+ # Nothing here by the moment, but methods are added by other
54
+ # SocialStream's components, such as Ostatus
55
+ end
51
56
  end
52
57
  end
53
58
  end
@@ -17,7 +17,7 @@ module SocialStream
17
17
  #
18
18
  module Subject
19
19
  extend ActiveSupport::Concern
20
-
20
+
21
21
  included do
22
22
  subtype_of :actor,
23
23
  :build => { :subject_type => to_s }
@@ -9,6 +9,8 @@ module SocialStream #:nodoc:
9
9
  module Subtype
10
10
  extend ActiveSupport::Concern
11
11
 
12
+ include SocialStream::ActivityStreams::Subtype
13
+
12
14
  included do
13
15
  class << self
14
16
  attr_reader :supertype_name, :supertype_options
@@ -11,6 +11,8 @@ module SocialStream #:nodoc:
11
11
  module Supertype
12
12
  extend ActiveSupport::Concern
13
13
 
14
+ include SocialStream::ActivityStreams::Supertype
15
+
14
16
  included do
15
17
  subtypes.each do |s| # [ :user, :group ].each do |s|
16
18
  has_one s, :dependent => :destroy # has_one s, :dependent => :destroy
@@ -19,6 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.add_runtime_dependency('deep_merge')
20
20
  # Rails
21
21
  s.add_runtime_dependency('rails', '>= 3.1.0')
22
+ # Rails Engine Decorators
23
+ s.add_runtime_dependency('rails_engine_decorators')
22
24
  # Activity and Relation hierarchies
23
25
  s.add_runtime_dependency('ancestry', '~> 1.2.3')
24
26
  # SQL foreign keys
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActivitiesController do
4
+ describe "show" do
5
+ it "should redirecto to activity object" do
6
+ id = 3
7
+ activity = double("activity")
8
+ post = Factory(:post)
9
+
10
+ activity.should_receive(:direct_object) { post }
11
+
12
+ Activity.should_receive(:find).with(id.to_s) { activity }
13
+
14
+ get :show, id: id
15
+ end
16
+ end
17
+ end
18
+
@@ -7,10 +7,5 @@ describe FrontpageController do
7
7
  get :index
8
8
  assert_response :success
9
9
  end
10
-
11
- it "should render host_meta" do
12
- get :host_meta, :format => :all
13
- assert_response :success
14
- end
15
10
  end
16
11
 
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+
3
+ describe Activity do
4
+
5
+ context "user" do
6
+ before(:all) do
7
+ @subject = @user = Factory(:user)
8
+ end
9
+
10
+ context "with public activity" do
11
+ before do
12
+ @activity = Factory(:self_activity, :relation_ids => [Relation::Public.instance.id])
13
+ end
14
+
15
+ describe "sender home" do
16
+ it "should include activity" do
17
+ @activity.sender.wall(:home).should include(@activity)
18
+ end
19
+ end
20
+
21
+ describe "sender profile" do
22
+ context "accessed by alien" do
23
+ it "should include activity" do
24
+ @activity.sender.wall(:profile,
25
+ :for => Factory(:user)).should include(@activity)
26
+ end
27
+ end
28
+
29
+ context "accessed by anonymous" do
30
+ it "should include activity" do
31
+ @activity.sender.wall(:profile,
32
+ :for => nil).should include(@activity)
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ describe "belonging to friend" do
39
+ before do
40
+ @activity = Factory(:activity)
41
+ end
42
+
43
+ describe "sender home" do
44
+ it "should include activity" do
45
+ @activity.sender.wall(:home).should include(@activity)
46
+ end
47
+ end
48
+
49
+ describe "sender profile" do
50
+ context "accessed by friend" do
51
+ it "should include activity" do
52
+ @activity.sender.wall(:profile,
53
+ :for => @activity.receiver).should include(@activity)
54
+ end
55
+ end
56
+
57
+ context "accessed by alien" do
58
+ it "should not include activity" do
59
+ @activity.sender.wall(:profile,
60
+ :for => Factory(:user)).should_not include(@activity)
61
+ end
62
+ end
63
+
64
+ context "accessed by anonymous" do
65
+ it "should not include activity" do
66
+ @activity.sender.wall(:profile,
67
+ :for => nil).should_not include(@activity)
68
+ end
69
+ end
70
+ end
71
+
72
+ describe "receiver profile" do
73
+ context "accessed by receiver" do
74
+ it "should include activity" do
75
+ @activity.receiver.wall(:profile,
76
+ :for => @activity.receiver).should include(@activity)
77
+ end
78
+ end
79
+
80
+ context "accessed by alien" do
81
+ it "should not include activity" do
82
+ @activity.receiver.wall(:profile,
83
+ :for => Factory(:user)).should_not include(@activity)
84
+ end
85
+ end
86
+
87
+ context "accessed by anonymous" do
88
+ it "should not include activity" do
89
+ @activity.receiver.wall(:profile,
90
+ :for => nil).should_not include(@activity)
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,370 @@
1
+ require 'spec_helper'
2
+
3
+ module PostAuthorizationTestHelper
4
+ def create_ability_accessed_by(subject)
5
+ @ability = Ability.new(subject)
6
+ end
7
+
8
+ def create_ability_accessed_by_related(tie_type)
9
+ @tie = create_related_tie(tie_type)
10
+ @related = @tie.receiver_subject
11
+ @ability = Ability.new(@related)
12
+ end
13
+
14
+ def create_ability_accessed_publicly
15
+ u = Factory(:user)
16
+ @ability = Ability.new(u)
17
+ end
18
+
19
+ def create_related_tie(tie_type)
20
+ Factory(tie_type, :contact => Factory(:contact, :sender => Actor.normalize(@subject)))
21
+ end
22
+
23
+ shared_examples_for "Allows Creating" do
24
+ it "should allow create" do
25
+ @ability.should be_able_to(:create, @post)
26
+ end
27
+ end
28
+
29
+ shared_examples_for "Allows Reading" do
30
+ it "should allow read" do
31
+ @ability.should be_able_to(:read, @post)
32
+ end
33
+ end
34
+
35
+ shared_examples_for "Allows Updating" do
36
+ it "should allow update" do
37
+ @ability.should be_able_to(:update, @post)
38
+ end
39
+ end
40
+
41
+ shared_examples_for "Allows Destroying" do
42
+ it "should allow destroy" do
43
+ @ability.should be_able_to(:destroy, @post)
44
+ end
45
+ end
46
+
47
+ shared_examples_for "Denies Creating" do
48
+ it "should deny create" do
49
+ @ability.should_not be_able_to(:create, @post)
50
+ end
51
+ end
52
+
53
+ shared_examples_for "Denies Reading" do
54
+ it "should deny read" do
55
+ @ability.should_not be_able_to(:read, @post)
56
+ end
57
+ end
58
+
59
+ shared_examples_for "Denies Updating" do
60
+ it "should deny update" do
61
+ @ability.should_not be_able_to(:update, @post)
62
+ end
63
+ end
64
+
65
+ shared_examples_for "Denies Destroying" do
66
+ it "should deny destroy" do
67
+ @ability.should_not be_able_to(:destroy, @post)
68
+ end
69
+ end
70
+ end
71
+
72
+ describe Post do
73
+ include PostAuthorizationTestHelper
74
+
75
+ before :all do
76
+ @ss_relation_model = SocialStream.relation_model
77
+ end
78
+
79
+ after :all do
80
+ SocialStream.relation_model = @ss_relation_model
81
+ end
82
+
83
+ context "in custom relation model" do
84
+ before :all do
85
+ SocialStream.relation_model = :custom
86
+ end
87
+
88
+ before :all do
89
+ @subject = @user = Factory(:user)
90
+ end
91
+
92
+ context "with friend tie" do
93
+ before :all do
94
+ @tie = create_related_tie(:friend)
95
+ end
96
+
97
+ describe "posting for all contacts" do
98
+ before :all do
99
+ @post = Factory(:post,
100
+ :author => @tie.receiver,
101
+ :owner => @tie.sender)
102
+ end
103
+
104
+ describe "accesed by author" do
105
+ before do
106
+ create_ability_accessed_by(@post.author_subject)
107
+ end
108
+
109
+ it_should_behave_like "Allows Creating"
110
+ it_should_behave_like "Allows Reading"
111
+ it_should_behave_like "Allows Updating"
112
+ it_should_behave_like "Allows Destroying"
113
+ end
114
+
115
+ describe "accesed by owner" do
116
+ before do
117
+ create_ability_accessed_by(@post.owner_subject)
118
+ end
119
+
120
+ it_should_behave_like "Denies Creating"
121
+ it_should_behave_like "Allows Reading"
122
+ it_should_behave_like "Allows Updating"
123
+ it_should_behave_like "Allows Destroying"
124
+ end
125
+
126
+ describe "accessed by different friend" do
127
+ before do
128
+ create_ability_accessed_by_related :friend
129
+ end
130
+
131
+ it_should_behave_like "Denies Creating"
132
+ it_should_behave_like "Allows Reading"
133
+ it_should_behave_like "Denies Updating"
134
+ it_should_behave_like "Denies Destroying"
135
+ end
136
+
137
+ describe "accessed by acquaintance" do
138
+ before do
139
+ create_ability_accessed_by_related :acquaintance
140
+ end
141
+ it_should_behave_like "Denies Creating"
142
+ it_should_behave_like "Allows Reading"
143
+ it_should_behave_like "Denies Updating"
144
+ it_should_behave_like "Denies Destroying"
145
+ end
146
+
147
+ describe "accessed publicly" do
148
+ before do
149
+ create_ability_accessed_publicly
150
+ end
151
+
152
+ it_should_behave_like "Denies Creating"
153
+ it_should_behave_like "Denies Reading"
154
+ it_should_behave_like "Denies Updating"
155
+ it_should_behave_like "Denies Destroying"
156
+ end
157
+ end
158
+
159
+ describe "posting only to friends" do
160
+ before :all do
161
+ @post = Factory(:post,
162
+ :author => @tie.receiver,
163
+ :owner => @tie.sender,
164
+ :relation_ids => [@tie.relation_id])
165
+
166
+ end
167
+
168
+ describe "accessed by author" do
169
+ before do
170
+ create_ability_accessed_by(@post.author_subject)
171
+ end
172
+
173
+ it_should_behave_like "Allows Creating"
174
+ it_should_behave_like "Allows Reading"
175
+ it_should_behave_like "Allows Updating"
176
+ it_should_behave_like "Allows Destroying"
177
+ end
178
+
179
+ describe "accesed by owner" do
180
+ before do
181
+ create_ability_accessed_by(@post.owner_subject)
182
+ end
183
+
184
+ it_should_behave_like "Denies Creating"
185
+ it_should_behave_like "Allows Reading"
186
+ it_should_behave_like "Allows Updating"
187
+ it_should_behave_like "Allows Destroying"
188
+ end
189
+
190
+ describe "accessed by a friend" do
191
+ before do
192
+ create_ability_accessed_by_related :friend
193
+ end
194
+
195
+ it_should_behave_like "Denies Creating"
196
+ it_should_behave_like "Allows Reading"
197
+ it_should_behave_like "Denies Updating"
198
+ it_should_behave_like "Denies Destroying"
199
+ end
200
+
201
+ describe "accessed by acquaintance" do
202
+ before do
203
+ create_ability_accessed_by_related :acquaintance
204
+ end
205
+
206
+ it_should_behave_like "Denies Creating"
207
+ it_should_behave_like "Denies Reading"
208
+ it_should_behave_like "Denies Updating"
209
+ it_should_behave_like "Denies Destroying"
210
+ end
211
+
212
+ describe "accessed publicly" do
213
+ before do
214
+ create_ability_accessed_publicly
215
+ end
216
+
217
+ it_should_behave_like "Denies Creating"
218
+ it_should_behave_like "Denies Reading"
219
+ it_should_behave_like "Denies Updating"
220
+ it_should_behave_like "Denies Destroying"
221
+ end
222
+ end
223
+
224
+ describe "posting to public relation" do
225
+
226
+ before do
227
+ @post = Factory(:post,
228
+ :author => @tie.receiver,
229
+ :owner => @tie.sender,
230
+ :relation_ids => [Relation::Public.instance.id])
231
+ end
232
+
233
+ describe "accessed by author" do
234
+ before do
235
+ create_ability_accessed_by(@post.author_subject)
236
+ end
237
+
238
+ it_should_behave_like "Allows Creating"
239
+ it_should_behave_like "Allows Reading"
240
+ it_should_behave_like "Allows Updating"
241
+ it_should_behave_like "Allows Destroying"
242
+ end
243
+
244
+ describe "accessed by owner" do
245
+ before do
246
+ create_ability_accessed_by(@post.owner_subject)
247
+ end
248
+
249
+ it_should_behave_like "Denies Creating"
250
+ it_should_behave_like "Allows Reading"
251
+ it_should_behave_like "Allows Updating"
252
+ it_should_behave_like "Allows Destroying"
253
+ end
254
+
255
+ describe "accessed by a friend" do
256
+ before do
257
+ create_ability_accessed_by_related :friend
258
+ end
259
+
260
+ it_should_behave_like "Denies Creating"
261
+ it_should_behave_like "Allows Reading"
262
+ it_should_behave_like "Denies Updating"
263
+ it_should_behave_like "Denies Destroying"
264
+ end
265
+
266
+ describe "accessed by acquaintance" do
267
+ before do
268
+ create_ability_accessed_by_related :acquaintance
269
+ end
270
+
271
+ it_should_behave_like "Denies Creating"
272
+ it_should_behave_like "Allows Reading"
273
+ it_should_behave_like "Denies Updating"
274
+ it_should_behave_like "Denies Destroying"
275
+ end
276
+
277
+ describe "accessed publicly" do
278
+ before do
279
+ create_ability_accessed_publicly
280
+ end
281
+
282
+ it_should_behave_like "Denies Creating"
283
+ it_should_behave_like "Allows Reading"
284
+ it_should_behave_like "Denies Updating"
285
+ it_should_behave_like "Denies Destroying"
286
+ end
287
+ end
288
+
289
+ describe "posting by not replied" do
290
+ before :all do
291
+ @post = Factory(:post,
292
+ :author => @tie.sender,
293
+ :owner => @tie.receiver)
294
+ end
295
+
296
+ describe "accessed by author" do
297
+ before do
298
+ create_ability_accessed_by(@post.author_subject)
299
+ end
300
+
301
+ it_should_behave_like "Denies Creating"
302
+ end
303
+ end
304
+ end
305
+
306
+ context "group" do
307
+ before(:all) do
308
+ @subject = @group = Factory(:group)
309
+ end
310
+
311
+ describe "with member tie" do
312
+ before :all do
313
+ @tie = create_related_tie(:member)
314
+ end
315
+
316
+ describe "posting from member all contacts" do
317
+ before :all do
318
+ @post = Factory(:post,
319
+ :author => @tie.receiver,
320
+ :owner => @tie.sender)
321
+ end
322
+
323
+ describe "accessed by author" do
324
+ before do
325
+ create_ability_accessed_by @post.author_subject
326
+ end
327
+
328
+ it_should_behave_like "Allows Creating"
329
+ it_should_behave_like "Allows Reading"
330
+ it_should_behave_like "Allows Updating"
331
+ it_should_behave_like "Allows Destroying"
332
+ end
333
+
334
+ describe "accessed by different member" do
335
+ before do
336
+ create_ability_accessed_by_related :member
337
+ end
338
+
339
+ it_should_behave_like "Denies Creating"
340
+ it_should_behave_like "Allows Reading"
341
+ it_should_behave_like "Denies Updating"
342
+ it_should_behave_like "Denies Destroying"
343
+ end
344
+
345
+ describe "accessed by partner" do
346
+ before do
347
+ create_ability_accessed_by_related :partner
348
+ end
349
+
350
+ it_should_behave_like "Denies Creating"
351
+ it_should_behave_like "Allows Reading"
352
+ it_should_behave_like "Denies Updating"
353
+ it_should_behave_like "Denies Destroying"
354
+ end
355
+
356
+ describe "accessed publicly" do
357
+ before do
358
+ create_ability_accessed_publicly
359
+ end
360
+
361
+ it_should_behave_like "Denies Creating"
362
+ it_should_behave_like "Denies Reading"
363
+ it_should_behave_like "Denies Updating"
364
+ it_should_behave_like "Denies Destroying"
365
+ end
366
+ end
367
+ end
368
+ end
369
+ end
370
+ end