social_stream 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. data/.gitignore +1 -0
  2. data/README.rdoc +2 -3
  3. data/app/controllers/likes_controller.rb +2 -2
  4. data/app/controllers/messages_controller.rb +3 -0
  5. data/app/controllers/representations_controller.rb +8 -0
  6. data/app/controllers/ties_controller.rb +1 -1
  7. data/app/helpers/activities_helper.rb +2 -2
  8. data/app/helpers/ties_helper.rb +19 -16
  9. data/app/models/activity.rb +42 -7
  10. data/app/models/activity_object.rb +1 -0
  11. data/app/models/activity_verb.rb +5 -1
  12. data/app/models/actor.rb +113 -68
  13. data/app/models/group.rb +15 -1
  14. data/app/models/message.rb +2 -0
  15. data/app/models/permission.rb +20 -41
  16. data/app/models/profile.rb +1 -1
  17. data/app/models/relation.rb +34 -26
  18. data/app/models/representation.rb +35 -0
  19. data/app/models/tie.rb +47 -100
  20. data/app/models/user.rb +12 -17
  21. data/app/views/activities/_activities.html.erb +2 -2
  22. data/app/views/activities/_new.html.erb +6 -3
  23. data/app/views/activities/_options.html.erb +1 -1
  24. data/app/views/comments/_new.html.erb +2 -2
  25. data/app/views/frontpage/index.html.erb +0 -2
  26. data/app/views/groups/_group.html.erb +3 -3
  27. data/app/views/groups/_index.html.erb +3 -4
  28. data/app/views/groups/_middle_show.html.erb +7 -4
  29. data/app/views/groups/_new.html.erb +25 -0
  30. data/app/views/groups/_right_show.html.erb +4 -2
  31. data/app/views/groups/new.html.erb +1 -0
  32. data/app/views/groups/show.html.erb +1 -1
  33. data/app/views/home/_groups.html.erb +7 -5
  34. data/app/views/home/_location.html.erb +1 -1
  35. data/app/views/home/_options.html.erb +2 -2
  36. data/app/views/home/_right.html.erb +2 -2
  37. data/app/views/home/index.html.erb +6 -2
  38. data/app/views/layouts/_footer.html.erb +1 -1
  39. data/app/views/layouts/_header.erb +4 -1
  40. data/app/views/layouts/_representation.html.erb +20 -0
  41. data/app/views/{private_messages → messages}/_form.html.erb +4 -4
  42. data/app/views/{private_messages → messages}/_index.html.erb +1 -1
  43. data/app/views/{private_messages → messages}/_location.html.erb +1 -1
  44. data/app/views/messages/_message.html.erb +17 -0
  45. data/app/views/messages/_messages.html.erb +2 -0
  46. data/app/views/messages/edit.html.erb +6 -0
  47. data/app/views/{private_messages → messages}/index.html.erb +0 -0
  48. data/app/views/{private_messages → messages}/index.js.erb +0 -0
  49. data/app/views/{private_messages → messages}/new.html.erb +2 -2
  50. data/app/views/messages/show.html.erb +21 -0
  51. data/app/views/subjects/_contacts.html.erb +20 -0
  52. data/app/views/ties/_new.html.erb +6 -6
  53. data/app/views/ties/_pendings.html.erb +3 -3
  54. data/app/views/ties/_suggestions.html.erb +3 -3
  55. data/app/views/ties/_tie.html.erb +1 -1
  56. data/app/views/ties/create.js.erb +4 -5
  57. data/app/views/ties/new.js.erb +1 -1
  58. data/app/views/users/_groups.html.erb +5 -5
  59. data/app/views/users/_index.html.erb +3 -1
  60. data/app/views/users/_options.html.erb +1 -1
  61. data/app/views/users/_right_show.html.erb +3 -3
  62. data/app/views/users/show.html.erb +5 -3
  63. data/config/locales/en.yml +13 -19
  64. data/config/routes.rb +11 -4
  65. data/lib/generators/social_stream/install_generator.rb +2 -10
  66. data/lib/generators/social_stream/templates/initializer.rb +1 -1
  67. data/lib/generators/social_stream/templates/migration.rb +19 -24
  68. data/lib/generators/social_stream/templates/public/javascripts/jquery.js +6883 -0
  69. data/lib/generators/social_stream/templates/public/javascripts/rails.js +146 -0
  70. data/lib/generators/social_stream/templates/public/javascripts/ui.dropdownchecklist.js +3 -13
  71. data/lib/generators/social_stream/templates/public/stylesheets/header.css +5 -1
  72. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  73. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-bg_flat_75_ffffff_40x100.png +0 -0
  74. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  75. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-bg_glass_65_ffffff_1x400.png +0 -0
  76. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-bg_glass_75_dadada_1x400.png +0 -0
  77. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  78. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  79. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  80. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-icons_222222_256x240.png +0 -0
  81. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-icons_2e83ff_256x240.png +0 -0
  82. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-icons_454545_256x240.png +0 -0
  83. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-icons_888888_256x240.png +0 -0
  84. data/lib/generators/social_stream/templates/public/{images → stylesheets/images}/ui-icons_cd0a0a_256x240.png +0 -0
  85. data/lib/generators/social_stream/templates/relations.yml +42 -0
  86. data/lib/social_stream/ability.rb +7 -6
  87. data/lib/social_stream/controllers/helpers.rb +35 -0
  88. data/lib/social_stream/models/{activity_object.rb → object.rb} +1 -1
  89. data/lib/social_stream/models/{actor.rb → subject.rb} +10 -30
  90. data/lib/social_stream/models/supertype.rb +5 -2
  91. data/lib/social_stream/rails.rb +25 -6
  92. data/lib/social_stream/relations.rb +46 -0
  93. data/lib/social_stream/version.rb +1 -1
  94. data/lib/social_stream.rb +13 -13
  95. data/lib/tasks/db/populate.rake +23 -29
  96. data/spec/controllers/groups_controller_spec.rb +2 -6
  97. data/spec/controllers/ties_controller_spec.rb +19 -0
  98. data/spec/controllers/users_controller_spec.rb +0 -2
  99. data/spec/dummy/config/application.rb +0 -1
  100. data/spec/dummy/config/initializers/social_stream.rb +14 -2
  101. data/spec/dummy/config/relations.yml +42 -0
  102. data/spec/dummy/db/schema.rb +9 -0
  103. data/spec/dummy/db/seeds.rb +0 -1
  104. data/spec/factories/activity.rb +2 -2
  105. data/spec/factories/actor.rb +2 -1
  106. data/spec/factories/group.rb +1 -0
  107. data/spec/factories/post.rb +1 -1
  108. data/spec/factories/tie.rb +16 -22
  109. data/spec/models/activity_spec.rb +27 -24
  110. data/spec/models/actor_spec.rb +3 -0
  111. data/spec/models/representation_spec.rb +16 -0
  112. data/spec/models/tie_spec.rb +49 -57
  113. data/spec/models/user_spec.rb +22 -0
  114. data/spec/support/db.rb +1 -1
  115. metadata +47 -45
  116. data/Gemfile.lock +0 -171
  117. data/app/controllers/private_messages_controller.rb +0 -3
  118. data/app/models/private_message.rb +0 -6
  119. data/app/views/groups/_follow.html.erb +0 -9
  120. data/app/views/groups/_followers.html.erb +0 -16
  121. data/app/views/home/_contacts.html.erb +0 -17
  122. data/app/views/private_messages/_messages.html.erb +0 -2
  123. data/app/views/private_messages/_private_message.html.erb +0 -17
  124. data/app/views/private_messages/edit.html.erb +0 -6
  125. data/app/views/private_messages/show.html.erb +0 -21
  126. data/app/views/ties/_pending.html.erb +0 -21
  127. data/app/views/users/_contacts.html.erb +0 -19
  128. data/init.rb +0 -3
  129. data/lib/generators/social_stream/templates/seeds.yml +0 -64
  130. data/lib/social_stream/rails/common.rb +0 -36
  131. data/lib/social_stream/rails/engine.rb +0 -9
  132. data/lib/social_stream/rails/railtie.rb +0 -9
  133. data/lib/social_stream/seed.rb +0 -49
  134. data/spec/dummy/db/seeds/social_stream.yml +0 -64
  135. data/spec/models/user_space.rb +0 -10
@@ -8,24 +8,6 @@
8
8
  # two actors are stronger than others.
9
9
  # When a strong tie is established, ties with weaker relations are establised as well
10
10
  #
11
- # == Reflexive relations
12
- # Some relations are set by default for actors with theirselves. This sets some ties
13
- # for posting in self wall at several visibility levels: only for friends, public and
14
- # so on
15
- #
16
- # == Inverse relations
17
- # A Relation can have its inverse. When a tie is established, an inverse tie will be
18
- # established if an inverse relation exists. An example is a relation of friendship,
19
- # whose inverse relation is itself. When A is friend of B, the inverse tie B is friend of A
20
- # is establised as well.
21
- #
22
- # == Granted relations
23
- # There are cases when relations need previous invitation or request to be granted.
24
- # This is the case of friendship requests. When A wants to become friend of B, A
25
- # sends a friendship_request to B. A is granting the friend relation with B, that is,
26
- # friendship_request grants friend relation.
27
- #
28
-
29
11
  class Relation < ActiveRecord::Base
30
12
  acts_as_nested_set
31
13
 
@@ -33,20 +15,46 @@ class Relation < ActiveRecord::Base
33
15
  where(:sender_type => st, :receiver_type => rt)
34
16
  }
35
17
 
36
- belongs_to :inverse,
37
- :class_name => "Relation"
38
- belongs_to :granted,
39
- :class_name => "Relation"
40
-
41
- scope :reflexive, where(:reflexive => true)
42
- scope :request, where('relations.granted_id IS NOT NULL')
43
-
44
18
  has_many :relation_permissions, :dependent => :destroy
45
19
  has_many :permissions, :through => :relation_permissions
46
20
 
47
21
  has_many :ties, :dependent => :destroy
48
22
 
49
23
  class << self
24
+ # Get relation from object, if possible
25
+ #
26
+ # Options::
27
+ # sender:: The sender of the tie
28
+ def normalize(r, options = {})
29
+ case r
30
+ when Relation
31
+ r
32
+ when String
33
+ if options[:sender]
34
+ options[:sender].relation(r)
35
+ else
36
+ raise "Must provide a sender when looking up relations from name: #{ options[:sender] }"
37
+ end
38
+ when Integer
39
+ Relation.find r
40
+ when Array
41
+ r.map{ |e| Relation.normalize(e, options) }
42
+ else
43
+ raise "Unable to normalize relation #{ r.inspect }"
44
+ end
45
+ end
46
+
47
+ def normalize_id(r, options = {})
48
+ case r
49
+ when Integer
50
+ r
51
+ when Array
52
+ r.map{ |e| Relation.normalize_id(e, options) }
53
+ else
54
+ normalize(r, options).id
55
+ end
56
+ end
57
+
50
58
  # A relation in the top of a strength hierarchy
51
59
  def strongest
52
60
  root
@@ -0,0 +1,35 @@
1
+ # Users can represent other subjects in the application, acting as them
2
+ # through the browser, posting new activities, establishing new ties, etc.
3
+ class Representation
4
+ extend ActiveModel::Naming
5
+ include ActionController::RecordIdentifier
6
+
7
+ attr_reader :subject
8
+
9
+ # Sets up new representation
10
+ #
11
+ # params[:subject] must contain the dom_id of the represented subject
12
+ def initialize arg
13
+ @subject =
14
+ case arg
15
+ when Hash
16
+ arg[:subject_dom_id] =~ /(.*)_(\d*)$/
17
+
18
+ subject_type = $1.classify.constantize
19
+ subject_id = $2.to_i
20
+
21
+ subject_type.find subject_id
22
+ else
23
+ arg
24
+ end
25
+ end
26
+
27
+ def subject_dom_id
28
+ dom_id(subject)
29
+ end
30
+
31
+ # ActiveRecord compatibility
32
+ def to_key #:nodoc:
33
+ nil
34
+ end
35
+ end
data/app/models/tie.rb CHANGED
@@ -4,16 +4,17 @@
4
4
  #
5
5
  # == Ties and Activities
6
6
  # Activities are attached to ties.
7
- # * The sender actor is the author of the Activity. It is the user that uploads
7
+ # * The sender of the tie is the target of the Activity. The wall-profile of an actor is
8
+ # composed by the resources assigned to the ties in which the actor is the sender.
9
+ # * The receiver actor of the tie is the author of the Activity. It is the user that uploads
8
10
  # a resource to the website or the social entity that originates the activity.
9
- # * The receiver is the target of the Activity. The wall-profile of an actor is
10
- # composed by the resources assigned to the ties in which the actor is the receiver.
11
11
  # * The Relation sets up the mode in which the Activity is shared. It sets the rules,
12
12
  # or permissions, by which actors have access to the Activity.
13
- #
14
- # == Inverse ties
15
- # Relations can have its inverse. When a tie is establised, an inverse tie is establised
16
- # as well.
13
+ #
14
+ # == Authorization
15
+ # When an actor establishes a tie with other, she is granting a set of permissions to them
16
+ # (posting to her wall, reading her posts, etc..) The set of permissions granted are
17
+ # associated with the relation of the tie.
17
18
  #
18
19
  # == Scopes
19
20
  # There are several scopes defined:
@@ -21,23 +22,20 @@
21
22
  # * received_by(actor), ties whose receiver is actor
22
23
  # * sent_or_received_by(actor), the union of the former
23
24
  # * related_by(relation), ties with this relation. Accepts relation, relation_name, integer, array
24
- # * pending, ties whose relation grant other relations, like friendship requests.
25
- # * inverse(tie), the inverse of tie
25
+ # * replied, ties having at least another tie in the other way, a tie from a to b is replied if there is a tie from b to a
26
26
  #
27
27
  class Tie < ActiveRecord::Base
28
+ attr_accessor :message
29
+
28
30
  # Facilitates relation assigment along with find_relation callback
29
31
  attr_writer :relation_name
30
32
 
31
- # Avoids loops at create_inverse after save callback
32
- attr_accessor :_without_inverse
33
- attr_protected :_without_inverse
34
-
35
33
  belongs_to :sender,
36
34
  :class_name => "Actor",
37
- :include => SocialStream.actors
35
+ :include => SocialStream.subjects
38
36
  belongs_to :receiver,
39
37
  :class_name => "Actor",
40
- :include => SocialStream.actors
38
+ :include => SocialStream.subjects
41
39
 
42
40
  belongs_to :relation
43
41
 
@@ -47,36 +45,34 @@ class Tie < ActiveRecord::Base
47
45
  scope :recent, order("#{ quoted_table_name }.created_at DESC")
48
46
 
49
47
  scope :sent_by, lambda { |a|
50
- where(:sender_id => Actor_id(a))
48
+ where(:sender_id => Actor.normalize_id(a))
51
49
  }
52
50
 
53
51
  scope :received_by, lambda { |a|
54
- where(:receiver_id => Actor_id(a))
52
+ where(:receiver_id => Actor.normalize_id(a))
55
53
  }
56
54
 
57
55
  scope :sent_or_received_by, lambda { |a|
58
- where(arel_table[:sender_id].eq(Actor_id(a)).
59
- or(arel_table[:receiver_id].eq(Actor_id(a))))
56
+ where(arel_table[:sender_id].eq(Actor.normalize_id(a)).
57
+ or(arel_table[:receiver_id].eq(Actor.normalize_id(a))))
60
58
 
61
59
  }
62
60
 
63
61
  scope :related_by, lambda { |r|
64
- where(:relation_id => Relation(r))
62
+ where(:relation_id => Relation.normalize_id(r))
65
63
  }
66
64
 
67
- scope :pending, includes(:relation) & Relation.request
68
-
69
- scope :inverse, lambda { |t|
70
- sent_by(t.receiver).
71
- received_by(t.sender).
72
- where(:relation_id => t.relation.inverse.try(:id))
65
+ scope :replied, lambda {
66
+ select("DISTINCT ties.*").
67
+ from("ties, ties as ties_2").
68
+ where("ties.sender_id = ties_2.receiver_id AND ties.receiver_id = ties_2.sender_id")
73
69
  }
74
70
 
75
71
  validates_presence_of :sender_id, :receiver_id, :relation_id
76
72
 
77
73
  before_validation :find_relation
78
74
 
79
- after_create :complete_weak_set, :create_inverse
75
+ after_create :complete_weak_set
80
76
 
81
77
  def relation_name
82
78
  @relation_name || relation.try(:name)
@@ -95,6 +91,11 @@ class Tie < ActiveRecord::Base
95
91
  receiver.try(:subject)
96
92
  end
97
93
 
94
+ # Does this tie have the same sender and receiver?
95
+ def reflexive?
96
+ sender_id == receiver_id
97
+ end
98
+
98
99
  # The set of ties between sender and receiver
99
100
  #
100
101
  # Options::
@@ -105,8 +106,8 @@ class Tie < ActiveRecord::Base
105
106
 
106
107
  if options.key?(:relations)
107
108
  set =
108
- set.related_by self.class.Relation(options[:relations],
109
- :mode => relation.mode)
109
+ set.related_by Relation.normalize_id(options[:relations],
110
+ :sender => sender)
110
111
  end
111
112
 
112
113
  set
@@ -117,13 +118,9 @@ class Tie < ActiveRecord::Base
117
118
  relation_set(:relations => r).first
118
119
  end
119
120
 
120
- # The inverse tie
121
- def inverse
122
- Tie.inverse(self).first
123
- end
124
-
125
121
  def activity_receivers
126
- Array(inverse)
122
+ # TODO
123
+ Array.new
127
124
  end
128
125
 
129
126
  # = Access Control
@@ -151,7 +148,7 @@ class Tie < ActiveRecord::Base
151
148
  # ------------------ ------------------
152
149
  #
153
150
  # Because we want to find ties, an additional join table (ties_as) is needed for applying access set conditions
154
- # We get the set of ties that are allowed to certain condition
151
+ # We get the set of ties that are allowing certain permission
155
152
  #
156
153
 
157
154
  scope :with_permissions, lambda { |action, object|
@@ -166,10 +163,10 @@ class Tie < ActiveRecord::Base
166
163
  where(Permission.parameter_conditions(tie))
167
164
  }
168
165
 
169
- scope :allowed_set, lambda { |action, object|
166
+ scope :allowing_set, lambda { |action, object|
170
167
  query =
171
168
  select("DISTINCT ties.*").
172
- from("ties INNER JOIN relations ON relations.id = ties.relation_id, ties as ties_as INNER JOIN relations AS relations_as ON relations_as.id = ties_as.relation_id INNER JOIN relation_permissions ON relations_as.id = relation_permissions.relation_id INNER JOIN permissions ON permissions.id = relation_permissions.permission_id, relations as relations_inverse").
169
+ from("ties INNER JOIN relations ON relations.id = ties.relation_id, ties as ties_as INNER JOIN relations AS relations_as ON relations_as.id = ties_as.relation_id INNER JOIN relation_permissions ON relations_as.id = relation_permissions.relation_id INNER JOIN permissions ON permissions.id = relation_permissions.permission_id").
173
170
  where("permissions.action = ?", action).
174
171
  where("permissions.object = ?", object)
175
172
 
@@ -182,21 +179,21 @@ class Tie < ActiveRecord::Base
182
179
  query.where(conds)
183
180
  }
184
181
 
185
- scope :allowed, lambda { |actor, action, object|
186
- allowed_set(action, object).
187
- where("ties_as.receiver_id" => Actor_id(actor))
182
+ scope :allowing, lambda { |actor, action, object|
183
+ allowing_set(action, object).
184
+ where("ties_as.receiver_id" => Actor.normalize_id(actor))
188
185
  }
189
186
 
190
187
  def access_set(action, object)
191
188
  self.class.access_set(self, action, object)
192
189
  end
193
190
 
194
- def permissions(user, action, object)
191
+ def allowing(user, action, object)
195
192
  access_set(action, object).received_by(user)
196
193
  end
197
194
 
198
- def permission?(user, action, object)
199
- permissions(user, action, object).any?
195
+ def allows?(user, action, object)
196
+ allowing(user, action, object).any?
200
197
  end
201
198
 
202
199
  private
@@ -204,73 +201,23 @@ class Tie < ActiveRecord::Base
204
201
  # Before validation callback
205
202
  # Infers relation from its name and the type of the actors
206
203
  def find_relation
207
- if relation_name.present? && relation_name != relation.try(:name)
208
- self.relation = Relation.mode(sender_subject.class.to_s,
209
- receiver_subject.class.to_s).
210
- find_by_name(relation_name)
204
+ if relation_name.present? &&
205
+ relation_name != relation.try(:name) &&
206
+ sender.present?
207
+ self.relation = sender.relation(relation_name)
211
208
  end
212
209
  end
213
210
 
214
211
  # After create callback
215
212
  # Creates ties with a weaker relations in the strength hierarchy of this tie
216
213
  def complete_weak_set
214
+ return if reflexive?
215
+
217
216
  relation.weaker.each do |r|
218
217
  if relation_set(:relations => r).blank?
219
218
  t = relation_set.build :relation => r
220
- t._without_inverse = true
221
219
  t.save!
222
220
  end
223
221
  end
224
222
  end
225
-
226
- # After create callback
227
- # Creates a the inverse of this tie
228
- def create_inverse
229
- if !_without_inverse &&
230
- relation.inverse.present? &&
231
- Tie.inverse(self).blank?
232
- t = Tie.inverse(self).build
233
- t._without_inverse = true
234
- t.save!
235
- end
236
- end
237
-
238
- class << self
239
- def Actor_id(a)
240
- case a
241
- when Integer
242
- a
243
- when Actor
244
- a.id
245
- else
246
- a.actor.id
247
- end
248
- end
249
-
250
- # Normalize a relation for ActiveRecord query from relation_name, id or Array
251
- #
252
- # Options::
253
- # mode:: Relation mode
254
- def Relation(r, options = {})
255
- case r
256
- when Relation
257
- r
258
- when String
259
- case options[:mode]
260
- when Array
261
- Relation.mode(*options[:mode]).find_by_name(r)
262
- when ActiveRecord::Relation
263
- options[:mode].find_by_name(r)
264
- else
265
- raise "Must provide a mode when looking up relations from name: #{ options[:mode] }"
266
- end
267
- when Integer
268
- r
269
- when Array
270
- r.map{ |e| Relation(e, options) }
271
- else
272
- raise "Unable to normalize relation #{ r.inspect }"
273
- end
274
- end
275
- end
276
223
  end
data/app/models/user.rb CHANGED
@@ -3,11 +3,8 @@ require 'devise/orm/active_record'
3
3
  class User < ActiveRecord::Base
4
4
  devise *SocialStream.devise_modules
5
5
 
6
- has_one :profile, :dependent => :destroy
7
- accepts_nested_attributes_for :profile
8
-
9
6
  # Setup accessible (or protected) attributes for your model
10
- attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :profile_attributes, :birthday
7
+ attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :profile_attributes
11
8
 
12
9
  validates_presence_of :email
13
10
 
@@ -20,25 +17,25 @@ class User < ActiveRecord::Base
20
17
  v.validates_length_of :password, :within => Devise.password_length, :allow_blank => true
21
18
  end
22
19
 
23
- def recent_groups
24
- receiver_subjects(:group, :relations => 'follower') & Tie.recent
25
- end
26
-
27
-
28
-
29
20
  def age
30
21
  return nil if profile.birthday.blank?
31
22
  now = Time.now.utc.to_date
32
23
  now.year - profile.birthday.year - (profile.birthday.to_date.change(:year => now.year) > now ? 1 : 0)
33
24
  end
34
-
35
- after_create :create_profile
36
-
37
25
 
38
- def friends
39
- receiver_subjects(:user, :relations => 'friend')
26
+ def recent_groups
27
+ subjects(:subject_type => :group, :direction => :receivers) do |q|
28
+ q & Tie.recent
29
+ end
40
30
  end
41
31
 
32
+ # Subjects this user can acts as
33
+ def represented
34
+ subjects(:direction => :senders) do |q|
35
+ q.joins(:sent_ties => { :relation => :permissions }) & Permission.represent
36
+ end
37
+ end
38
+
42
39
  protected
43
40
 
44
41
  # From devise
@@ -101,6 +98,4 @@ class User < ActiveRecord::Base
101
98
  record
102
99
  end
103
100
  end
104
-
105
-
106
101
  end
@@ -1,5 +1,5 @@
1
- <%= content_for :head, stylesheet_link_tag("activities", :media => "screen, projection") %>
2
- <%= content_for :javascript do %>
1
+ <% content_for :head, stylesheet_link_tag("activities", :media => "screen, projection") %>
2
+ <% content_for :javascript do %>
3
3
  <%= render :partial => 'activities/jquery' %>
4
4
  <% end -%>
5
5
 
@@ -1,5 +1,8 @@
1
- <% if current_user.active_ties_to(receiver).any? %>
1
+ <% if receiver.sent_ties_allowing(current_subject, 'create', 'activity').any? %>
2
2
  <% content_for :javascript do %>
3
+ securityImage = "<%= escape_javascript(image_tag('btn/btn_security.png', :id => 'security_image', :alt => 'security')) %>";
4
+ downImage = "<%= escape_javascript(image_tag('btn/btn_down.png')) %>";
5
+
3
6
  $("#security").dropdownchecklist( { closeRadioOnClick: true } );
4
7
  $("#security_image").parent().width(28);
5
8
  $("#security_image").parent().parent().width(28);
@@ -7,13 +10,13 @@
7
10
 
8
11
  <div id="activities_header" class="content_size">
9
12
  <%= form_for Post.new(:text => t('activity.input'),
10
- :_activity_tie_id => current_user.active_ties_to(receiver).first.id),
13
+ :_activity_tie_id => receiver.sent_ties_allowing(current_subject, 'create', 'activity').first.id),
11
14
  :remote => true do |f| %>
12
15
  <%= f.hidden_field :_activity_tie_id %>
13
16
  <%= f.text_field :text, :id => "input_activities", :size => 85 %>
14
17
  <div id="activities_share_btn">
15
18
  <div id="securities">
16
- <%= f.select :_activity_tie_id, current_user.active_ties_to(receiver).map{ |t| [ t(t.relation_name, :count => :other), t.id ] }, {}, :id => 'security' %>
19
+ <%= f.select :_activity_tie_id, receiver.sent_ties_allowing(current_subject, 'create', 'activity').map{ |t| [ t.relation_name, t.id ] }, {}, :id => 'security' %>
17
20
  </div>
18
21
  <%= image_submit_tag "btn/btn_share.png" %>
19
22
  </div>
@@ -1,7 +1,7 @@
1
1
  <div class="activity_options">
2
2
  <ul class="activity_options" >
3
3
  <li><div class="post_time_ago"><%= t('time.ago', :time => time_ago_in_words(activity.created_at)) %></div></li>
4
- <% if activity.is_root? && current_user.active_ties_to(activity.receiver).any? %>
4
+ <% if activity.is_root? && activity.receiver.sent_ties_allowing(current_subject, 'create', 'activity').any? %>
5
5
  <li><div class="verb_comment"> · <%= link_to t('activity.to_comment'), "#", :class => "to_comment" %> </div></li>
6
6
  <% end %>
7
7
  <li><div class="verb_like" id="like_<%= dom_id(activity) %>"> · <%= link_like(activity)%></div></li>
@@ -1,8 +1,8 @@
1
- <% if current_user.active_ties_to(activity.receiver).any? %>
1
+ <% if activity.receiver.sent_ties_allowing(current_subject, 'create', 'activity').any? %>
2
2
  <div class="activity_new_comment">
3
3
  <%= form_for Comment.new(:text => t('comment.input'),
4
4
  :_activity_tie_id =>
5
- current_user.active_ties_to(activity.receiver).first.id,
5
+ activity.receiver.sent_ties_allowing(current_subject, 'create', 'activity').first.id,
6
6
  :_activity_parent_id => activity.id),
7
7
  :remote => true do |f| %>
8
8
  <%= f.hidden_field :_activity_tie_id %>
@@ -1,5 +1,3 @@
1
- <%= content_for :search do %>
2
- <%end %>
3
1
  <div class="left column span-11 borde">
4
2
  <div id="left_espacio">
5
3
  </div>
@@ -1,4 +1,4 @@
1
- <% if (current_user.recent_groups.count)>10 %>
1
+ <% if (current_subject.recent_groups.count)>10 %>
2
2
  <li>
3
3
  <% end %>
4
4
  <%= div_for group do %>
@@ -9,6 +9,6 @@
9
9
  <%=link_to(group.name, group)%>
10
10
  </div>
11
11
  <% end %>
12
- <% if (current_user.recent_groups.count)>10 %>
12
+ <% if (current_subject.recent_groups.count)>10 %>
13
13
  </li>
14
- <% end %>
14
+ <% end %>
@@ -8,15 +8,14 @@
8
8
  <% end %>
9
9
 
10
10
  <div class="post_browse">
11
- <div class="post_picture"><%= link_to (image_tag(group.logo.url , :size => "50x50", :alt => group.name )),home_path %></div>
11
+ <div class="post_picture"><%= link_to (image_tag(group.logo.url , :size => "50x50", :alt => group.name )), group %></div>
12
12
  <div class="post_browse_content_people content_size">
13
13
  <div class="post_browse_title content_size" >
14
14
  <%= link_to group.name, group %>
15
15
  </div>
16
+
16
17
  <div class="content_size">
17
- <%= tie_link(current_user.sent_ties.build(:receiver => group.actor,
18
- :relation => Relation.mode(current_user.class,
19
- group.class).find_by_name("follower"))) %>
18
+ <%= ties_to(group) %>
20
19
  </div>
21
20
  </div>
22
21
  </div>
@@ -1,7 +1,10 @@
1
1
  <div class="space_center">
2
2
  </div>
3
- <%= render :partial => "ties/suggestions" %>
4
- <div class="space_center">
5
- </div>
6
- <%= render :partial => 'ties/pendings' %>
3
+
4
+ <% if user_signed_in? %>
5
+ <%= render :partial => "ties/suggestions" %>
6
+ <div class="space_center">
7
+ </div>
8
+ <%= render :partial => 'ties/pendings' %>
9
+ <% end %>
7
10
 
@@ -0,0 +1,25 @@
1
+ <%= form_for @group do |f| %>
2
+ <% f.object._founder = current_subject.permalink %>
3
+ <%= f.hidden_field :_founder %>
4
+
5
+ <% if @group.errors.any? %>
6
+ <div id="error_explanation">
7
+ <h2><%= pluralize(@group.errors.count, "error") %> prohibited this group from being saved:</h2>
8
+
9
+ <ul>
10
+ <% @group.errors.full_messages.each do |msg| %>
11
+ <li><%= msg %></li>
12
+ <% end %>
13
+ </ul>
14
+ </div>
15
+ <% end %>
16
+
17
+ <div class="field">
18
+ <%= f.label :name %><br />
19
+ <%= f.text_field :name %>
20
+ </div>
21
+
22
+ <div class="actions">
23
+ <%= f.submit %>
24
+ </div>
25
+ <% end %>
@@ -1,6 +1,8 @@
1
- <%= render :partial => 'follow' %>
1
+ <%= ties_to(@group) %>
2
+
2
3
  <%= render :partial => 'logo' %>
3
4
  <%= render :partial => 'tabs' %>
4
5
  <div class="space_center">
5
6
  </div>
6
- <%= render :partial => 'followers' %>
7
+
8
+ <%= render :partial => 'subjects/contacts', :locals => { :subject => @group } %>
@@ -0,0 +1 @@
1
+ <%= render :partial => 'new' %>
@@ -17,5 +17,5 @@
17
17
  </div>
18
18
 
19
19
  <%= render :partial => "activities/activities",
20
- :locals => { :activities => @group.wall_profile(current_user).paginate,
20
+ :locals => { :activities => @group.profile_wall(current_subject).paginate,
21
21
  :owner => @group } %>
@@ -1,9 +1,10 @@
1
- <% if current_user.recent_groups.any? %>
1
+ <% if (groups = current_subject.recent_groups).any? %>
2
2
  <div id="groups_title" class="content_size">
3
- <%=t('group.last') %> (<span id="group_count"><%=current_user.recent_groups.count%></span>)
3
+ <%=t('group.last') %> (<span id="group_count"><%= groups.count %></span>)
4
4
  </div>
5
+
5
6
  <div id="groups_list" class="content_size">
6
- <% if (current_user.recent_groups.count) > 10 %>
7
+ <% if (groups.count) > 10 %>
7
8
  <div id='carousel_container'>
8
9
  <div id='left_scroll'><%=image_tag("btn/group_left.png")%></div>
9
10
  <div id='carousel_inner'>
@@ -12,8 +13,9 @@
12
13
  <div class="space_center"></div>
13
14
  <%end%>
14
15
 
15
- <%= render current_user.recent_groups %>
16
- <% if (current_user.recent_groups.count) > 10 %>
16
+ <%= render groups %>
17
+
18
+ <% if (groups.count) > 10 %>
17
19
  </ul>
18
20
  </div>
19
21
  <div id='right_scroll'><%=image_tag("btn/group_right.png")%></div>
@@ -1,3 +1,3 @@
1
1
  <div id="map_location" class="content_size">
2
- <%= t('location.message', :location => "#{ image_tag('btn/btn_home.png' , :class => 'btn_config') } #{ t('home') }: <span class=\"name_group\">#{ sanitize current_user.name }</span>").html_safe %>
2
+ <%= t('location.message', :location => "#{ image_tag('btn/btn_home.png' , :class => 'btn_config') } #{ t('home') }: <span class=\"name_group\">#{ sanitize current_subject.name }</span>").html_safe %>
3
3
  </div>
@@ -1,8 +1,8 @@
1
1
  <ul class="menu noaccordion">
2
2
  <li>
3
- <%= link_to( image_tag("btn/btn_inbox.png", :class => "menu_icon")+t('inbox.one'), private_messages_path, :remote => true) %>
3
+ <%= link_to( image_tag("btn/btn_inbox.png", :class => "menu_icon")+t('inbox.one'), messages_path, :remote => true) %>
4
4
  </li>
5
5
  <li>
6
- <%= link_to( image_tag("btn/btn_group.png", :class => "menu_icon")+t('group.new'), "#", :remote => true) %>
6
+ <%= link_to( image_tag("btn/btn_group.png", :class => "menu_icon")+t('group.new'), new_group_path, :remote => true) %>
7
7
  </li>
8
8
  </ul>
@@ -1,6 +1,6 @@
1
1
  <div id="logo">
2
- <b><%= link_to(current_user.name, current_user)%></b><br/>
3
- <%= link_to(image_tag(current_user.logo.url(:profile) , :alt => current_user.name ), current_user ) %>
2
+ <b><%= link_to(current_subject.name, current_subject)%></b><br/>
3
+ <%= link_to(image_tag(current_subject.logo.url(:profile) , :alt => current_subject.name ), current_subject ) %>
4
4
  </div>
5
5
  <div class="space_center">
6
6
  </div>