social_stream-base 0.13.2 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/activities.js.erb +5 -5
- data/app/assets/javascripts/social_stream-base.js +2 -0
- data/app/assets/stylesheets/cheesecake.css.scss +13 -0
- data/app/controllers/omniauth_callbacks_controller.rb +3 -3
- data/app/helpers/notifications_helper.rb +2 -2
- data/app/models/user.rb +15 -14
- data/app/views/cheesecake/_cheesecake.html.erb +69 -1
- data/app/views/frontpage/_social_networks.html.erb +1 -1
- data/app/views/layouts/application.html.erb +6 -1
- data/lib/acts_as_taggable_on/social_stream.rb +59 -31
- data/lib/i18n-js/social_stream-base.rb +36 -0
- data/lib/social_stream/base/dependencies.rb +6 -2
- data/lib/social_stream/base/version.rb +1 -1
- data/lib/social_stream/controllers/cancan_devise_integration.rb +15 -18
- data/lib/social_stream/controllers/helpers.rb +81 -83
- data/lib/social_stream/controllers/i18n_integration.rb +11 -13
- data/lib/social_stream/controllers/objects.rb +4 -7
- data/lib/social_stream/controllers/subjects.rb +3 -5
- data/lib/social_stream/models/channeled.rb +24 -26
- data/lib/social_stream/models/object.rb +57 -61
- data/lib/social_stream/models/subject.rb +4 -8
- data/lib/social_stream/models/subtype.rb +36 -34
- data/lib/social_stream/models/supertype.rb +17 -21
- data/lib/tasks/db/populate.rake +11 -3
- data/social_stream-base.gemspec +9 -5
- data/spec/dummy/config/initializers/devise.rb +1 -1
- metadata +99 -65
@@ -31,104 +31,102 @@ module SocialStream
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
# Set represented subject
|
44
|
-
def current_subject= instance
|
45
|
-
session[:subject_type] = instance.class.to_s
|
46
|
-
session[:subject_id] = instance.id
|
34
|
+
# Current subject represented by the user. Defaults to the own user
|
35
|
+
def current_subject
|
36
|
+
@current_subject ||=
|
37
|
+
current_subject_from_params ||
|
38
|
+
current_subject_from_session ||
|
39
|
+
current_user
|
40
|
+
end
|
47
41
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
current_subject.actor
|
53
|
-
end
|
42
|
+
# Set represented subject
|
43
|
+
def current_subject= instance
|
44
|
+
session[:subject_type] = instance.class.to_s
|
45
|
+
session[:subject_id] = instance.id
|
54
46
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
# class PostsController < InheritedResources::Base
|
62
|
-
# belongs_to_subjects :optional => true
|
63
|
-
# end
|
64
|
-
#
|
65
|
-
# # /users/demo/posts
|
66
|
-
# profile_subject #=> User demo
|
67
|
-
#
|
68
|
-
# # /groups/test/posts
|
69
|
-
# profile_subject #=> Group test
|
70
|
-
#
|
71
|
-
# # /posts
|
72
|
-
# profile_subject #=> current_subject
|
73
|
-
#
|
74
|
-
#
|
75
|
-
def profile_subject
|
76
|
-
@profile_subject ||= association_chain[-1] || current_subject
|
77
|
-
end
|
47
|
+
@current_subject = instance
|
48
|
+
end
|
49
|
+
|
50
|
+
def current_actor
|
51
|
+
current_subject.actor
|
52
|
+
end
|
78
53
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
54
|
+
# Returns the {SocialStream::Models::Subject subject} that is in the path, or
|
55
|
+
# the {#current_subject} if some {User} is logged in.
|
56
|
+
#
|
57
|
+
# Requirements: the controller must inherit from +InheritedResources::Base+ and the method
|
58
|
+
# {ClassMethods#belongs_to_subjects} must be called
|
59
|
+
#
|
60
|
+
# class PostsController < InheritedResources::Base
|
61
|
+
# belongs_to_subjects :optional => true
|
62
|
+
# end
|
63
|
+
#
|
64
|
+
# # /users/demo/posts
|
65
|
+
# profile_subject #=> User demo
|
66
|
+
#
|
67
|
+
# # /groups/test/posts
|
68
|
+
# profile_subject #=> Group test
|
69
|
+
#
|
70
|
+
# # /posts
|
71
|
+
# profile_subject #=> current_subject
|
72
|
+
#
|
73
|
+
#
|
74
|
+
def profile_subject
|
75
|
+
@profile_subject ||= association_chain[-1] || current_subject
|
76
|
+
end
|
83
77
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
def profile_or_current_subject
|
89
|
-
profile_subject || current_subject
|
90
|
-
rescue
|
91
|
-
current_subject
|
92
|
-
end
|
78
|
+
# Go to sign in page if {#profile_subject} is blank
|
79
|
+
def profile_subject!
|
80
|
+
@profile_subject ||= association_chain[-1] || warden.authenticate!
|
81
|
+
end
|
93
82
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
83
|
+
# Profile subject is suitable for paths like:
|
84
|
+
# /users/demo/posts
|
85
|
+
#
|
86
|
+
# This method tries {#profile_subject} first and then {#current_subject}
|
87
|
+
def profile_or_current_subject
|
88
|
+
profile_subject || current_subject
|
89
|
+
rescue
|
90
|
+
current_subject
|
91
|
+
end
|
98
92
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
end
|
93
|
+
# A {User} must be logged in and is equal to {#profile_subject}
|
94
|
+
def profile_subject_is_current?
|
95
|
+
user_signed_in? && profile_subject == current_subject
|
96
|
+
end
|
104
97
|
|
105
|
-
|
98
|
+
# Override Cancan#current_ability method to use {#current_subject}
|
99
|
+
def current_ability
|
100
|
+
@current_ability ||=
|
101
|
+
Ability.new(current_subject)
|
102
|
+
end
|
106
103
|
|
107
|
-
|
108
|
-
def current_subject_from_params
|
109
|
-
return unless params[:s].present?
|
104
|
+
private
|
110
105
|
|
111
|
-
|
106
|
+
# Get represented subject from params[:s]
|
107
|
+
def current_subject_from_params
|
108
|
+
return unless params[:s].present?
|
112
109
|
|
113
|
-
|
114
|
-
raise CanCan::AccessDenied.new("Not authorized!", :represent, subject.name)
|
115
|
-
end
|
110
|
+
subject = Actor.find_by_slug!(params[:s]).subject
|
116
111
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
:subject => subject.name)
|
121
|
-
end
|
112
|
+
unless subject.represented_by?(current_user)
|
113
|
+
raise CanCan::AccessDenied.new("Not authorized!", :represent, subject.name)
|
114
|
+
end
|
122
115
|
|
123
|
-
|
116
|
+
if subject != current_user
|
117
|
+
flash[:notice] ||= ""
|
118
|
+
flash[:notice] += t('representation.notice',
|
119
|
+
:subject => subject.name)
|
124
120
|
end
|
125
121
|
|
126
|
-
|
127
|
-
|
128
|
-
return unless session[:subject_type].present? && session[:subject_id].present?
|
122
|
+
self.current_subject = subject
|
123
|
+
end
|
129
124
|
|
130
|
-
|
131
|
-
|
125
|
+
# Get represented subject from session
|
126
|
+
def current_subject_from_session
|
127
|
+
return unless session[:subject_type].present? && session[:subject_id].present?
|
128
|
+
|
129
|
+
session[:subject_type].constantize.find session[:subject_id]
|
132
130
|
end
|
133
131
|
end
|
134
132
|
end
|
@@ -8,21 +8,19 @@ module SocialStream
|
|
8
8
|
before_filter :set_locale
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
11
|
+
# Set locale as per params, user preference or default
|
12
|
+
def set_locale
|
13
|
+
I18n.locale = params[:locale] || user_preferred_locale || extract_locale_from_accept_language_header || I18n.default_locale
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
private
|
17
|
+
def extract_locale_from_accept_language_header
|
18
|
+
return nil if request.env['HTTP_ACCEPT_LANGUAGE'].nil?
|
19
|
+
(request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).map{|l| l.to_sym} & I18n.available_locales).first
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
end
|
22
|
+
def user_preferred_locale
|
23
|
+
current_user.language if user_signed_in?
|
26
24
|
end
|
27
25
|
end
|
28
26
|
end
|
@@ -25,14 +25,11 @@ module SocialStream
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
|
28
|
+
protected
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
resource_params.first[:author_id] = current_subject.try(:actor_id)
|
34
|
-
resource_params.first[:user_author_id] = current_user.try(:actor_id)
|
35
|
-
end
|
30
|
+
def set_author_ids
|
31
|
+
resource_params.first[:author_id] = current_subject.try(:actor_id)
|
32
|
+
resource_params.first[:user_author_id] = current_user.try(:actor_id)
|
36
33
|
end
|
37
34
|
end
|
38
35
|
end
|
@@ -7,11 +7,9 @@ module SocialStream
|
|
7
7
|
inherit_resources
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
!resource.new_record? && resource || current_subject
|
14
|
-
end
|
10
|
+
# Overwrite {SocialStream::Controllers::Helpers::InstanceMethods#profile_subject}
|
11
|
+
def profile_subject
|
12
|
+
!resource.new_record? && resource || current_subject
|
15
13
|
end
|
16
14
|
end
|
17
15
|
end
|
@@ -3,6 +3,18 @@ module SocialStream
|
|
3
3
|
# Models that have author, user_author and owner, properties saved in {Channel}.
|
4
4
|
# Currently {Activity} and {ActivityObject}
|
5
5
|
module Channeled
|
6
|
+
# Add the method {#channeled} to ActiveRecord
|
7
|
+
module ActiveRecord
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
# This class is channeled. See {Channel}
|
12
|
+
def channeled
|
13
|
+
include SocialStream::Models::Channeled
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
6
18
|
extend ActiveSupport::Concern
|
7
19
|
|
8
20
|
included do
|
@@ -14,36 +26,22 @@ module SocialStream
|
|
14
26
|
before_validation :check_existing_channel
|
15
27
|
end
|
16
28
|
|
17
|
-
|
18
|
-
|
19
|
-
protected
|
29
|
+
protected
|
20
30
|
|
21
|
-
|
22
|
-
|
23
|
-
|
31
|
+
# Use existing channel, do not create a new one
|
32
|
+
def check_existing_channel
|
33
|
+
return unless channel!.new_record?
|
24
34
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
35
|
+
existing_channel =
|
36
|
+
Channel.
|
37
|
+
where(:author_id => author_id,
|
38
|
+
:owner_id => owner_id,
|
39
|
+
:user_author_id => user_author_id).
|
40
|
+
first
|
31
41
|
|
32
|
-
|
42
|
+
return if existing_channel.blank?
|
33
43
|
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
module ActiveRecord
|
39
|
-
extend ActiveSupport::Concern
|
40
|
-
|
41
|
-
module ClassMethods
|
42
|
-
# This class is channeled. See {Channel}
|
43
|
-
def channeled
|
44
|
-
include SocialStream::Models::Channeled
|
45
|
-
end
|
46
|
-
end
|
44
|
+
self.channel = existing_channel
|
47
45
|
end
|
48
46
|
end
|
49
47
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
|
3
1
|
module SocialStream
|
4
2
|
module Models
|
5
3
|
# Additional features for models that are Activity Objects
|
@@ -31,79 +29,77 @@ module SocialStream
|
|
31
29
|
}
|
32
30
|
end
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
32
|
+
# Was the author represented with this {SocialStream::Models::Object object} was created?
|
33
|
+
def represented_author?
|
34
|
+
author_id == user_author_id
|
35
|
+
end
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
37
|
+
# All the activities with this object
|
38
|
+
def activities
|
39
|
+
Activity.
|
40
|
+
includes(:activity_objects => self.class.to_s.underscore).
|
41
|
+
where("#{ self.class.quoted_table_name }.id" => self.id)
|
42
|
+
end
|
46
43
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
44
|
+
# Build the post activity when this object is not saved
|
45
|
+
def build_post_activity
|
46
|
+
Activity.new :author => author,
|
47
|
+
:user_author => user_author,
|
48
|
+
:owner => owner,
|
49
|
+
:relation_ids => Array(_relation_ids)
|
50
|
+
end
|
54
51
|
|
55
|
-
|
56
|
-
|
57
|
-
|
52
|
+
def _contact
|
53
|
+
@_contact ||= author && owner && author.contact_to!(owner)
|
54
|
+
end
|
58
55
|
|
59
|
-
|
60
|
-
|
61
|
-
|
56
|
+
def _contact_id
|
57
|
+
_contact.try(:id)
|
58
|
+
end
|
62
59
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
60
|
+
def _relation_ids
|
61
|
+
@_relation_ids ||=
|
62
|
+
if _contact_id.nil?
|
63
|
+
nil
|
64
|
+
else
|
65
|
+
# FIXME: repeated in Activity#fill_relations
|
66
|
+
if _contact.reflexive?
|
67
|
+
_contact.sender.relation_customs.map(&:id)
|
67
68
|
else
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
receiver.
|
74
|
-
relation_customs.
|
75
|
-
allow(_contact.sender, 'create', 'activity').
|
76
|
-
map(&:id)
|
77
|
-
end
|
69
|
+
_contact.
|
70
|
+
receiver.
|
71
|
+
relation_customs.
|
72
|
+
allow(_contact.sender, 'create', 'activity').
|
73
|
+
map(&:id)
|
78
74
|
end
|
79
|
-
|
75
|
+
end
|
76
|
+
end
|
80
77
|
|
81
|
-
|
82
|
-
|
83
|
-
|
78
|
+
def _activity_parent
|
79
|
+
@_activity_parent ||= Activity.find(_activity_parent_id)
|
80
|
+
end
|
84
81
|
|
85
|
-
|
82
|
+
private
|
86
83
|
|
87
|
-
|
88
|
-
|
89
|
-
|
84
|
+
def create_post_activity
|
85
|
+
create_activity "post"
|
86
|
+
end
|
90
87
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
88
|
+
def create_update_activity
|
89
|
+
return if _contact_id.blank?
|
90
|
+
|
91
|
+
create_activity "update"
|
92
|
+
end
|
96
93
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
94
|
+
def create_activity(verb)
|
95
|
+
a = Activity.new :verb => verb,
|
96
|
+
:channel => channel,
|
97
|
+
:relation_ids => _relation_ids,
|
98
|
+
:parent_id => _activity_parent_id
|
102
99
|
|
103
|
-
|
100
|
+
a.activity_objects << activity_object
|
104
101
|
|
105
|
-
|
106
|
-
end
|
102
|
+
a.save!
|
107
103
|
end
|
108
104
|
end
|
109
105
|
end
|