social_stream 2.1.1 → 2.2.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 (188) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +5 -2
  3. data/LICENSE +1 -1
  4. data/base/Rakefile +3 -17
  5. data/base/app/assets/images/flags/de.png +0 -0
  6. data/base/app/assets/images/flags/fr.png +0 -0
  7. data/base/app/assets/images/flags/hu.png +0 -0
  8. data/base/app/assets/images/flags/nl.png +0 -0
  9. data/base/app/assets/javascripts/social_stream/actor.js +34 -0
  10. data/base/app/assets/javascripts/social_stream/contact.js +40 -5
  11. data/base/app/assets/javascripts/social_stream/flash.js +6 -1
  12. data/base/app/assets/javascripts/social_stream/group.js +6 -5
  13. data/base/app/assets/javascripts/social_stream/relation_customs.js +0 -1
  14. data/base/app/assets/stylesheets/social_stream/base/adjust/layout/_adjust.css.sass +3 -0
  15. data/base/app/assets/stylesheets/social_stream/base/buttons/_buttons.scss.sass +0 -2
  16. data/base/app/assets/stylesheets/social_stream/base/contacts/_contacts.css.sass +1 -11
  17. data/base/app/assets/stylesheets/social_stream/base/contacts/layouts/_contacts.css.sass +1 -29
  18. data/base/app/assets/stylesheets/social_stream/base/layouts/_header.css.sass +0 -1
  19. data/base/app/assets/stylesheets/social_stream/base/mixins/_buttons.css.sass +5 -0
  20. data/base/app/assets/stylesheets/social_stream/base/mixins/_layout.css.sass +36 -7
  21. data/base/app/controllers/actors_controller.rb +25 -0
  22. data/base/app/controllers/contacts_controller.rb +38 -8
  23. data/base/app/controllers/groups_controller.rb +2 -21
  24. data/base/app/controllers/profiles_controller.rb +4 -0
  25. data/base/app/controllers/settings_controller.rb +12 -2
  26. data/base/app/controllers/users_controller.rb +0 -8
  27. data/base/app/helpers/contacts_helper.rb +8 -0
  28. data/base/app/models/activity.rb +19 -6
  29. data/base/app/models/actor.rb +49 -11
  30. data/base/app/models/contact.rb +12 -5
  31. data/base/app/models/group.rb +13 -11
  32. data/base/app/models/permission.rb +30 -0
  33. data/base/app/models/relation.rb +17 -7
  34. data/base/app/models/relation/custom.rb +2 -40
  35. data/base/app/models/relation/follow.rb +8 -2
  36. data/base/app/models/relation/owner.rb +10 -0
  37. data/base/app/models/relation/single.rb +7 -4
  38. data/base/app/models/site.rb +1 -1
  39. data/base/app/models/tie.rb +8 -4
  40. data/base/app/views/contacts/_add_button.html.erb +9 -0
  41. data/base/app/views/contacts/_button.html.erb +3 -3
  42. data/base/app/views/contacts/_button_multiple.html.erb +4 -0
  43. data/base/app/views/contacts/_button_simple.html.erb +17 -0
  44. data/base/app/views/contacts/_new_modal.html.erb +22 -0
  45. data/base/app/views/contacts/destroy.js.erb +5 -4
  46. data/base/app/views/contacts/update.js.erb +5 -4
  47. data/base/app/views/devise/confirmations/new.html.erb +14 -9
  48. data/base/app/views/frontpage/_presentation.html.erb +2 -2
  49. data/base/app/views/groups/_form.html.erb +20 -20
  50. data/base/app/views/groups/show.html.erb +5 -5
  51. data/base/app/views/layouts/_header_dropdown_menu.html.erb +3 -5
  52. data/base/app/views/layouts/_header_signed_in.erb +3 -3
  53. data/base/app/views/layouts/_logo_in.html.erb +1 -1
  54. data/base/app/views/layouts/application.html.erb +2 -0
  55. data/base/app/views/permissions/_list.html.erb +1 -1
  56. data/base/app/views/profiles/_avatar.html.erb +1 -5
  57. data/base/app/views/profiles/_avatar_edit.html.erb +5 -0
  58. data/base/app/views/profiles/_comunication-info.html.erb +2 -36
  59. data/base/app/views/profiles/_comunication-info_edit.html.erb +27 -0
  60. data/base/app/views/profiles/_edit_icon.html.erb +0 -1
  61. data/base/app/views/profiles/_experience.html.erb +1 -6
  62. data/base/app/views/profiles/_experience_edit.html.erb +5 -0
  63. data/base/app/views/profiles/_personal.html.erb +1 -39
  64. data/base/app/views/profiles/_personal_edit.html.erb +31 -0
  65. data/base/app/views/profiles/_profile_edit.html.erb +7 -0
  66. data/base/app/views/profiles/_tags.html.erb +1 -4
  67. data/base/app/views/profiles/_tags_edit.html.erb +4 -0
  68. data/base/app/views/profiles/edit.html.erb +24 -0
  69. data/base/app/views/settings/_notifications.html.erb +12 -4
  70. data/base/app/views/users/show.html.erb +5 -5
  71. data/base/config/locales/de.yml +654 -0
  72. data/base/config/locales/en.yml +20 -9
  73. data/base/config/locales/es.yml +151 -140
  74. data/base/config/locales/fr.yml +656 -0
  75. data/base/config/locales/hu.yml +653 -0
  76. data/base/config/locales/nl.yml +656 -0
  77. data/base/config/locales/pt.yml +250 -239
  78. data/base/config/locales/rails.de.yml +203 -0
  79. data/base/config/locales/rails.fr.yml +222 -0
  80. data/base/config/locales/rails.hu.yml +199 -0
  81. data/base/config/locales/rails.nl.yml +199 -0
  82. data/base/config/locales/zh.yml +214 -202
  83. data/base/config/routes.rb +22 -30
  84. data/base/db/migrate/20130708152633_set_group_owners.rb +19 -0
  85. data/base/db/migrate/20130723133530_actor_notification_settings.rb +10 -0
  86. data/base/lib/generators/social_stream/base/templates/initializer.rb +13 -7
  87. data/base/lib/rails/social_stream.rb +2 -0
  88. data/base/lib/social_stream/base.rb +27 -7
  89. data/base/lib/social_stream/base/ability.rb +3 -5
  90. data/base/lib/social_stream/base/autoload.rb +1 -0
  91. data/base/lib/social_stream/base/version.rb +1 -1
  92. data/base/lib/social_stream/controllers/authorship.rb +18 -0
  93. data/base/lib/social_stream/controllers/helpers.rb +18 -4
  94. data/base/lib/social_stream/controllers/objects.rb +2 -8
  95. data/base/lib/social_stream/controllers/subjects.rb +9 -2
  96. data/base/lib/social_stream/models/supertype.rb +2 -0
  97. data/base/lib/social_stream/population/activity_object.rb +6 -8
  98. data/base/lib/social_stream/routing/mapper.rb +52 -0
  99. data/base/social_stream-base.gemspec +4 -7
  100. data/base/spec/controllers/groups_controller_spec.rb +19 -8
  101. data/base/spec/controllers/posts_controller_spec.rb +114 -147
  102. data/base/spec/models/post_authorization_spec.rb +190 -204
  103. data/base/spec/models/post_spec.rb +17 -63
  104. data/base/vendor/assets/javascripts/bootstrap-multiselect.js +434 -127
  105. data/documents/Rakefile +1 -6
  106. data/documents/config/locales/de.yml +93 -0
  107. data/documents/config/locales/es.yml +2 -2
  108. data/documents/config/locales/fr.yml +93 -0
  109. data/documents/config/locales/hu.yml +93 -0
  110. data/documents/config/locales/nl.yml +93 -0
  111. data/documents/config/locales/zh.yml +4 -4
  112. data/documents/config/routes.rb +7 -9
  113. data/documents/lib/social_stream/documents/version.rb +1 -1
  114. data/documents/social_stream-documents.gemspec +4 -4
  115. data/events/Rakefile +1 -6
  116. data/events/config/locales/es.yml +3 -3
  117. data/events/config/locales/zh.yml +3 -3
  118. data/events/lib/social_stream/events/models/actor.rb +2 -1
  119. data/events/lib/social_stream/events/version.rb +1 -1
  120. data/events/social_stream-events.gemspec +1 -1
  121. data/lib/generators/social_stream/install_generator.rb +1 -0
  122. data/lib/social_stream.rb +1 -0
  123. data/lib/social_stream/version.rb +1 -1
  124. data/lib/tasks/i18n.rake +22 -2
  125. data/linkser/Rakefile +1 -6
  126. data/linkser/config/locales/de.yml +17 -0
  127. data/linkser/config/locales/es.yml +2 -2
  128. data/linkser/config/locales/fr.yml +17 -0
  129. data/linkser/config/locales/hu.yml +17 -0
  130. data/linkser/config/locales/nl.yml +17 -0
  131. data/linkser/config/locales/zh.yml +2 -2
  132. data/linkser/lib/social_stream/linkser/version.rb +1 -1
  133. data/linkser/social_stream-linkser.gemspec +1 -1
  134. data/oauth2_server/Rakefile +1 -6
  135. data/oauth2_server/app/assets/images/step_1.png +0 -0
  136. data/oauth2_server/app/assets/images/step_2.png +0 -0
  137. data/oauth2_server/app/assets/images/step_3.png +0 -0
  138. data/oauth2_server/app/assets/javascripts/social_stream/site_client.js +27 -0
  139. data/oauth2_server/app/assets/stylesheets/social_stream/oauth2_server/applications/layout/_applications-oauth2server.css.sass +0 -5
  140. data/oauth2_server/app/assets/stylesheets/social_stream/oauth2_server/create/layout/_create-oauth2server.css.sass +3 -5
  141. data/oauth2_server/app/assets/stylesheets/social_stream/oauth2_server/show/layout/_show-oauth2server.css.sass +8 -6
  142. data/oauth2_server/app/controllers/site/clients_controller.rb +17 -41
  143. data/oauth2_server/app/decorators/social_stream/base/relation_decorator.rb +2 -0
  144. data/oauth2_server/app/decorators/social_stream/base/user_decorator.rb +1 -20
  145. data/oauth2_server/app/models/relation/manager.rb +1 -10
  146. data/oauth2_server/app/models/site/client.rb +4 -2
  147. data/oauth2_server/app/views/site/clients/_destroy.html.erb +11 -0
  148. data/oauth2_server/app/views/site/clients/_edit.html.erb +9 -2
  149. data/oauth2_server/app/views/site/clients/_edit_step_2.html.erb +6 -6
  150. data/oauth2_server/app/views/site/clients/_edit_step_3.html.erb +8 -6
  151. data/oauth2_server/app/views/site/clients/_form.html.erb +11 -11
  152. data/oauth2_server/app/views/site/clients/_list.html.erb +23 -11
  153. data/oauth2_server/app/views/site/clients/edit.html.erb +1 -1
  154. data/oauth2_server/app/views/site/clients/index.html.erb +9 -40
  155. data/oauth2_server/app/views/site/clients/show.html.erb +66 -68
  156. data/oauth2_server/config/locales/en.yml +19 -0
  157. data/oauth2_server/config/locales/es.yml +23 -4
  158. data/oauth2_server/config/locales/zh.yml +32 -13
  159. data/oauth2_server/config/routes.rb +3 -1
  160. data/oauth2_server/lib/social_stream/oauth2_server.rb +4 -1
  161. data/oauth2_server/lib/social_stream/oauth2_server/ability.rb +1 -1
  162. data/oauth2_server/lib/social_stream/oauth2_server/models/user.rb +18 -0
  163. data/oauth2_server/lib/social_stream/oauth2_server/version.rb +1 -1
  164. data/oauth2_server/social_stream-oauth2_server.gemspec +1 -1
  165. data/oauth2_server/spec/controllers/site_clients_controller_authorization_spec.rb +7 -0
  166. data/ostatus/Rakefile +1 -6
  167. data/ostatus/config/locales/zh.yml +8 -8
  168. data/ostatus/lib/social_stream-ostatus.rb +3 -0
  169. data/ostatus/lib/social_stream/ostatus/version.rb +1 -1
  170. data/ostatus/social_stream-ostatus.gemspec +1 -1
  171. data/places/config/locales/es.yml +51 -51
  172. data/presence/config/locales/es.yml +48 -48
  173. data/presence/config/locales/zh.yml +48 -48
  174. data/presence/lib/social_stream/presence/version.rb +1 -1
  175. data/presence/social_stream-presence.gemspec +1 -1
  176. data/social_stream.gemspec +8 -7
  177. metadata +60 -29
  178. data/base/app/assets/javascripts/social_stream/follow.js +0 -28
  179. data/base/app/controllers/followers_controller.rb +0 -34
  180. data/base/app/helpers/followers_helper.rb +0 -5
  181. data/base/app/views/contacts/_link_follow.html.erb +0 -16
  182. data/base/app/views/followers/destroy.js.erb +0 -1
  183. data/base/app/views/followers/index.html.erb +0 -30
  184. data/base/app/views/followers/update.js.erb +0 -3
  185. data/base/app/views/frontpage/_characteristics.html.erb +0 -23
  186. data/base/lib/social_stream/routing/constraints/custom.rb +0 -11
  187. data/base/lib/social_stream/routing/constraints/follow.rb +0 -11
  188. data/base/spec/controllers/followers_controller_spec.rb +0 -37
@@ -1,12 +1,9 @@
1
1
  class GroupsController < ApplicationController
2
2
  include SocialStream::Controllers::Subjects
3
+ include SocialStream::Controllers::Authorship
3
4
 
4
5
  before_filter :authenticate_user!, :except => [ :index, :show ]
5
6
 
6
- # Set group founder to current_subject
7
- # Must do before authorization
8
- before_filter :set_founder, :only => [ :new, :create ]
9
-
10
7
  load_and_authorize_resource
11
8
 
12
9
  respond_to :html, :js
@@ -18,7 +15,7 @@ class GroupsController < ApplicationController
18
15
  def create
19
16
  create! do |success, failure|
20
17
  success.html {
21
- self.current_subject = @group
18
+ self.current_subject = resource
22
19
  redirect_to :home
23
20
  }
24
21
  end
@@ -32,20 +29,4 @@ class GroupsController < ApplicationController
32
29
  }
33
30
  end
34
31
  end
35
-
36
- protected
37
-
38
- # Overwrite resource method to support slug
39
- # See InheritedResources::BaseHelpers#resource
40
- def resource
41
- @group ||= end_of_association_chain.find_by_slug!(params[:id])
42
- end
43
-
44
- private
45
-
46
- def set_founder
47
- params[:group] ||= {}
48
- params[:group][:author_id] ||= current_subject.try(:actor_id)
49
- params[:group][:user_author_id] ||= current_user.try(:actor_id)
50
- end
51
32
  end
@@ -13,6 +13,10 @@ class ProfilesController < ApplicationController
13
13
  end
14
14
  end
15
15
 
16
+ def edit
17
+ current_profile
18
+ end
19
+
16
20
  def update
17
21
  current_profile.update_attributes profile_params
18
22
 
@@ -1,7 +1,7 @@
1
1
  class SettingsController < ApplicationController
2
-
2
+
3
3
  before_filter :authenticate_user!
4
-
4
+
5
5
  def index
6
6
  end
7
7
 
@@ -20,6 +20,16 @@ class SettingsController < ApplicationController
20
20
  current_subject.notify_by_email = false if notify_by_email.eql? "never"
21
21
  current_subject.notify_by_email = true if notify_by_email.eql? "always"
22
22
  end
23
+
24
+ # Custom notification settings
25
+ if params[:notification_settings].present?
26
+ notification_settings = {}
27
+ params[:notification_settings].each_pair do |key, setting|
28
+ notification_settings[key.to_sym] = false if setting.eql? "never"
29
+ notification_settings[key.to_sym] = true if setting.eql? "always"
30
+ end
31
+ current_subject.update_attribute(:notification_settings, notification_settings)
32
+ end
23
33
  end
24
34
 
25
35
  #Updating language
@@ -21,12 +21,4 @@ class UsersController < ApplicationController
21
21
  def new; end; def create; end
22
22
  # Not supported yet
23
23
  def destroy; end
24
-
25
- protected
26
-
27
- # Overwrite resource method to support slug
28
- # See InheritedResources::BaseHelpers#resource
29
- def resource
30
- @user ||= end_of_association_chain.find_by_slug!(params[:id])
31
- end
32
24
  end
@@ -43,4 +43,12 @@ module ContactsHelper
43
43
  def current_contact_section? section
44
44
  params[:type] == section.to_s
45
45
  end
46
+
47
+ def contact_select_options options
48
+ if !options.empty? && options.first.respond_to?(:last) && Array === options.first.last
49
+ grouped_options_for_select(options)
50
+ else
51
+ options_for_select(options)
52
+ end
53
+ end
46
54
  end
@@ -260,12 +260,25 @@ class Activity < ActiveRecord::Base
260
260
  return true unless notificable?
261
261
  #Avaible verbs: follow, like, make-friend, post, update, join
262
262
 
263
- if direct_object.is_a? Comment
264
- participants.each do |p|
265
- p.notify(notification_subject, "Youre not supposed to see this", self) unless p == sender
266
- end
267
- elsif ['like','follow','make-friend','post','update', 'join'].include? verb and !reflexive?
268
- receiver.notify(notification_subject, "Youre not supposed to see this", self)
263
+ case
264
+ when direct_object.is_a?(Comment)
265
+ participants.each do |p|
266
+ send_mail = p.subject.notification_settings[:someone_comments_on_my_post]
267
+ p.notify(notification_subject, "Youre not supposed to see this", self, true, nil, send_mail) unless p == sender
268
+ end
269
+ when reflexive?
270
+ return true
271
+ when ['like'].include?(verb)
272
+ send_mail = receiver.subject.notification_settings[:someone_likes_my_post]
273
+ receiver.notify(notification_subject, "Youre not supposed to see this", self, true, nil, send_mail)
274
+ when ['follow'].include?(verb)
275
+ send_mail = receiver.subject.notification_settings[:someone_adds_me_as_a_contact]
276
+ receiver.notify(notification_subject, "Youre not supposed to see this", self, true, nil, send_mail)
277
+ when ['make-friend'].include?(verb)
278
+ send_mail = receiver.subject.notification_settings[:someone_confirms_my_contact_request]
279
+ receiver.notify(notification_subject, "Youre not supposed to see this", self, true, nil, send_mail)
280
+ when ['post', 'update', 'join'].include?(verb)
281
+ receiver.notify(notification_subject, "Youre not supposed to see this", self)
269
282
  end
270
283
  true
271
284
  end
@@ -28,7 +28,9 @@ class Actor < ActiveRecord::Base
28
28
  acts_as_messageable
29
29
 
30
30
  acts_as_url :name, :url_attribute => :slug
31
-
31
+
32
+ serialize :notification_settings
33
+
32
34
  has_one :profile,
33
35
  dependent: :destroy,
34
36
  inverse_of: :actor
@@ -132,6 +134,12 @@ class Actor < ActiveRecord::Base
132
134
  joins(:received_contacts).merge(Contact.active.sent_by(a))
133
135
  }
134
136
 
137
+ scope :not_contacted_from, lambda { |a|
138
+ if a.present?
139
+ where(arel_table[:id].not_in(a.sent_active_contact_ids + [a.id]))
140
+ end
141
+ }
142
+
135
143
  scope :followed, joins(:activity_object).merge(ActivityObject.followed)
136
144
 
137
145
  scope :followed_by, lambda { |a|
@@ -143,7 +151,7 @@ class Actor < ActiveRecord::Base
143
151
 
144
152
  scope :subject_type, lambda { |t|
145
153
  if t.present?
146
- where(subject_type: t.classify)
154
+ where(subject_type: t.split(',').map(&:classify))
147
155
  end
148
156
  }
149
157
 
@@ -217,15 +225,30 @@ class Actor < ActiveRecord::Base
217
225
  # They usually include {Relation::Custom} but may also include other system-defined
218
226
  # relations that are not editable but appear in add contact buttons
219
227
  def relations_list
220
- Relation.extra_list(subject) + relation_customs
228
+ Relation.system_list(subject) + relation_customs
221
229
  end
222
230
 
223
231
  # The relations offered in the "Add contact" button when subjects
224
232
  # add new contacts
225
- def relations_for_button
233
+ def relations_for_select
226
234
  relations_list
227
235
  end
228
236
 
237
+ # Return an object of choices suitable for the contact add button or modal
238
+ def options_for_contact_select
239
+ relations_for_select.map{ |r| [ r.name, r.id ] }
240
+ end
241
+
242
+ # Options for contact select are simple
243
+ def options_for_contact_select_simple?
244
+ relations_list.count == 1
245
+ end
246
+
247
+ # Returns the type for contact select, :simple or :multiple
248
+ def options_for_contact_select_type
249
+ options_for_contact_select_simple? ? :simple : :multiple
250
+ end
251
+
229
252
  # All the {Actor Actors} this one has ties with:
230
253
  #
231
254
  # actor.contact_actors #=> array of actors that sent and receive ties from actor
@@ -293,7 +316,7 @@ class Actor < ActiveRecord::Base
293
316
  if options[:relations].present?
294
317
  as = as.merge(Tie.related_by(options[:relations]))
295
318
  else
296
- as = as.merge(Relation.where(:type => ['Relation::Custom', 'Relation::Public']))
319
+ as = as.merge(Relation.positive)
297
320
  end
298
321
 
299
322
  as
@@ -328,7 +351,7 @@ class Actor < ActiveRecord::Base
328
351
  # Return a contact to subject. Create it if it does not exist
329
352
  def contact_to!(subject)
330
353
  contact_to(subject) ||
331
- sent_contacts.create!(:receiver => Actor.normalize(subject))
354
+ sent_contacts.create!(receiver_id: Actor.normalize_id(subject))
332
355
  end
333
356
 
334
357
  # The {Contact} of this {Actor} to self (totally close!)
@@ -434,11 +457,21 @@ class Actor < ActiveRecord::Base
434
457
 
435
458
  # The default {Relation Relations} for sharing an {Activity} owned
436
459
  # by this {Actor}
460
+ #
461
+ # Activities are shared with all the contacts by default.
462
+ #
463
+ # You can change this behaviour with a decorator, overwriting this method.
464
+ # For example, if you want the activities shared publicly by default, create
465
+ # a decorator in app/decorators/actor_decorator.rb with
466
+ # Actor.class_eval do
467
+ # def activity_relations
468
+ # [ Relation::Public.instance ]
469
+ # end
470
+ # end
471
+ #
437
472
  def activity_relations
438
- SocialStream.relation_model == :custom ?
439
- relations.
440
- allowing('read', 'activity') :
441
- [ Relation::Public.instance ]
473
+ relations.
474
+ allowing('read', 'activity')
442
475
  end
443
476
 
444
477
  # The ids of the default {Relation Relations} for sharing an {Activity}
@@ -516,7 +549,12 @@ class Actor < ActiveRecord::Base
516
549
  }
517
550
  }
518
551
  end
519
-
552
+
553
+ def notification_settings
554
+ self.update_attribute(:notification_settings, SocialStream.default_notification_settings) unless super
555
+ super
556
+ end
557
+
520
558
  private
521
559
 
522
560
  # After create callback
@@ -49,10 +49,10 @@ class Contact < ActiveRecord::Base
49
49
  }
50
50
 
51
51
  scope :in_direction_with, lambda { |subject, d = 'sent'|
52
- if d == 'sent'
53
- sent_by(subject).joins(:receiver)
54
- else
52
+ if d == 'received'
55
53
  received_by(subject).joins(:sender)
54
+ else
55
+ sent_by(subject).joins(:receiver)
56
56
  end
57
57
  }
58
58
 
@@ -180,9 +180,16 @@ class Contact < ActiveRecord::Base
180
180
  end
181
181
  end
182
182
 
183
- # Return an array of options suitable for the contact add button
183
+ # Return an object of choices suitable for the contact add button
184
+ #
184
185
  def options_for_select
185
- sender.relations_for_button.map{ |r| [ r.name, r.id ] }
186
+ sender.options_for_contact_select
187
+ end
188
+
189
+ # Options for select are simple or multiple
190
+ #
191
+ def options_for_select_type
192
+ sender.options_for_contact_select_type
186
193
  end
187
194
 
188
195
  private
@@ -6,7 +6,7 @@
6
6
  class Group < ActiveRecord::Base
7
7
  include SocialStream::Models::Subject
8
8
 
9
- attr_accessor :_participants
9
+ attr_accessor :owners
10
10
 
11
11
  delegate :description, :description=, :to => :profile!
12
12
 
@@ -19,14 +19,14 @@ class Group < ActiveRecord::Base
19
19
  private
20
20
 
21
21
  # Creates ties from founder to the group, based on _relation_ids,
22
- # and ties from the group to founder and participants.
22
+ # and ties from the group to founder and owners.
23
23
  def create_ties
24
- create_ties_from_founder
25
- create_ties_to_participants
24
+ create_ties_from_author
25
+ create_ties_to_owners
26
26
  end
27
27
 
28
28
  # Creates the ties from the founder to the group
29
- def create_ties_from_founder
29
+ def create_ties_from_author
30
30
  =begin
31
31
  # FIXME: need to define a proper relation for this case. Maybe a system defined relation
32
32
  author.sent_contacts.create! :receiver_id => actor_id,
@@ -39,18 +39,20 @@ class Group < ActiveRecord::Base
39
39
  =end
40
40
  end
41
41
 
42
- # Creates the ties from the group to the participants
43
- def create_ties_to_participants
44
- @_participants ||= ""
42
+ # Creates the ties from the group to the owners added in the group creation form
43
+ #
44
+ # The system-defined Relation::Owner is used for the ties
45
+ def create_ties_to_owners
46
+ @owners ||= ""
45
47
 
46
- participant_ids = ([ author_id, user_author_id ] | @_participants.split(',').map(&:to_i)).uniq
48
+ owner_ids = ([ author_id, user_author_id ] | @owners.split(',').map(&:to_i)).uniq
47
49
 
48
- participant_ids.each do |a|
50
+ owner_ids.each do |a|
49
51
  c =
50
52
  sent_contacts.create! :receiver_id => a,
51
53
  :user_author => user_author
52
54
 
53
- c.relation_ids = Array.wrap(relation_customs.sort.first.id)
55
+ c.relation_ids = Array.wrap(::Relation::Owner.instance.id)
54
56
  end
55
57
  end
56
58
  end
@@ -44,6 +44,36 @@ class Permission < ActiveRecord::Base
44
44
  end
45
45
 
46
46
  class << self
47
+ # Obtains the available permissions for subject, as they are configured
48
+ # in config.available_permissions entry in config/initializers/social_stream.rb
49
+ #
50
+ # It takes STI into account, so it will try to load the permissions of the base_class
51
+ # if the class is not found
52
+ def available(subject)
53
+ class_name = subject.class.to_s.underscore
54
+ base_class_name = subject.class.base_class.to_s.underscore
55
+
56
+ candidates = [ class_name, class_name.to_sym ]
57
+
58
+ if class_name != base_class_name
59
+ candidates += [ base_class_name, base_class_name.to_sym ]
60
+ end
61
+
62
+ list = nil
63
+
64
+ candidates.each do |n|
65
+ list = SocialStream.available_permissions[n]
66
+
67
+ break if list.present?
68
+ end
69
+
70
+ if list.blank?
71
+ raise "You need to configure SocialStream.available_permissions[:#{ class_name }] in config/initializers/social_stream.rb"
72
+ end
73
+
74
+ instances list
75
+ end
76
+
47
77
  # Finds or creates in the database the instances of the permissions described in
48
78
  # {ary} by arrays of [ action, object ]
49
79
  def instances ary
@@ -41,7 +41,7 @@
41
41
  # It sets the {Audience} that has access to it, and the {Permission Permissions} that rule that access.
42
42
  #
43
43
  class Relation < ActiveRecord::Base
44
- Positive = %w{ custom public follow }
44
+ Positive = %w{ custom public follow owner }
45
45
  Negative = %w{ reject }
46
46
 
47
47
  has_many :relation_permissions, :dependent => :destroy
@@ -152,7 +152,7 @@ class Relation < ActiveRecord::Base
152
152
  def ids_shared_with(subject)
153
153
  ids = [Relation::Public.instance.id]
154
154
 
155
- if SocialStream.relation_model == :custom && subject.present?
155
+ if subject.present?
156
156
  # Subject own defined custom relations
157
157
  ids += subject.relation_ids
158
158
  # From Ties sent by other subject
@@ -168,11 +168,14 @@ class Relation < ActiveRecord::Base
168
168
 
169
169
  # Default extra relations that are displayed in {Actor}'s relation list,
170
170
  # typically in /relation/customs
171
- def extra_list subject
172
- l = SocialStream.list_relations[subject.class.to_s.underscore]
173
- return [] if l.blank?
174
-
175
- l.map{ |r| "Relation::#{ r.to_s.classify }".constantize.instance }
171
+ def system_list subject
172
+ name = subject.class.to_s.underscore
173
+ list = SocialStream.system_relations[name] ||
174
+ SocialStream.system_relations[name.to_sym]
175
+
176
+ return [] if list.blank?
177
+
178
+ list.map{ |r| "Relation::#{ r.to_s.classify }".constantize.instance }
176
179
  end
177
180
  end
178
181
 
@@ -181,6 +184,13 @@ class Relation < ActiveRecord::Base
181
184
  Relation.mode(sender_type, receiver_type)
182
185
  end
183
186
 
187
+ # Compare two relations
188
+ def <=> rel
189
+ return -1 if rel.is_a?(Public)
190
+
191
+ permissions.count <=> rel.permissions.count
192
+ end
193
+
184
194
  # Is this {Relation} a Positive one?
185
195
  def positive?
186
196
  self.class.positive_names.include?(self.class.to_s)
@@ -2,7 +2,7 @@
2
2
  # of relations is created for him. Afterwards, the {SocialStream::Models::Subject subject}
3
3
  # can customize them and adapt them to his own preferences.
4
4
  #
5
- # Default relations are defined at config/relations.yml
5
+ # Default relations are defined at config/initializers/social_stream.rb
6
6
  #
7
7
  class Relation::Custom < Relation
8
8
  # This is weird. We must call #inspect before has_ancestry for Relation::Custom
@@ -57,11 +57,6 @@ class Relation::Custom < Relation
57
57
 
58
58
  rels.values
59
59
  end
60
-
61
- # A relation in the top of a strength hierarchy
62
- def strongest
63
- roots
64
- end
65
60
  end
66
61
 
67
62
  # The subject who defined of this relation
@@ -69,41 +64,8 @@ class Relation::Custom < Relation
69
64
  actor.subject
70
65
  end
71
66
 
72
- # Compare two relations
73
- def <=> rel
74
- return -1 if rel.is_a?(Public)
75
-
76
- if ancestor_ids.include?(rel.id)
77
- 1
78
- elsif rel.ancestor_ids.include?(id)
79
- -1
80
- else
81
- 0
82
- end
83
- end
84
-
85
- # Other relations below in the same hierarchy that this relation
86
- def weaker
87
- descendants
88
- end
89
-
90
- # Relations below or at the same level of this relation
91
- def weaker_or_equal
92
- subtree
93
- end
94
-
95
- # Other relations above in the same hierarchy that this relation
96
- def stronger
97
- ancestors
98
- end
99
-
100
- # Relations above or at the same level of this relation
101
- def stronger_or_equal
102
- path
103
- end
104
-
105
67
  def available_permissions
106
- Permission.instances SocialStream.available_permissions[subject.class.to_s.underscore]
68
+ Permission.available(subject)
107
69
  end
108
70
 
109
71
  private