Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of git@github.com:ging/social_stream-base

  • Loading branch information...
commit 5e4b057f46ea4e9f7a4325d46cc081330bf2440c 2 parents 32bee21 + 7416bbd
ebarra authored
Showing with 532 additions and 940 deletions.
  1. +2 −1  app/assets/stylesheets/contacts.css
  2. 0  app/assets/stylesheets/{spheres.css → relation_customs.css}
  3. +1 −11 app/controllers/relation/customs_controller.rb
  4. +0 −12 app/controllers/spheres_controller.rb
  5. +1 −2  app/helpers/activities_helper.rb
  6. +5 −5 app/helpers/permissions_helper.rb
  7. +19 −13 app/models/activity.rb
  8. +30 −71 app/models/actor.rb
  9. +15 −0 app/models/contact.rb
  10. +1 −3 app/models/group.rb
  11. +9 −72 app/models/permission.rb
  12. +14 −38 app/models/relation.rb
  13. +6 −33 app/models/relation/custom.rb
  14. +0 −9 app/models/sphere.rb
  15. +5 −1 app/models/user.rb
  16. +5 −2 app/views/activities/_new.html.erb
  17. +1 −1  app/views/activities/_options.html.erb
  18. +14 −20 app/views/contacts/_form.html.erb
  19. +1 −1  app/views/contacts/edit.html.erb
  20. +1 −1  app/views/groups/_group.html.erb
  21. +1 −1  app/views/layouts/_settings.html.erb
  22. +0 −6 app/views/objects/_new.html.erb
  23. +2 −2 app/views/relation/customs/_form.html.erb
  24. +0 −28 app/views/relation/customs/_index.html.erb
  25. +0 −58 app/views/{spheres → relation/customs}/_jquery.erb
  26. +9 −26 app/views/relation/customs/_list.html.erb
  27. +2 −3 app/views/relation/customs/create.js.erb
  28. +67 −0 app/views/relation/customs/index.html.erb
  29. +0 −2  app/views/relation/customs/index.js.erb
  30. +0 −28 app/views/spheres/_form.html.erb
  31. +0 −19 app/views/spheres/_list.html.erb
  32. +0 −20 app/views/spheres/create.js.erb
  33. +0 −74 app/views/spheres/index.html.erb
  34. +15 −40 config/locales/en.yml
  35. +0 −1  config/routes.rb
  36. +30 −0 db/migrate/20110712090343_remove_spheres.rb
  37. +26 −0 db/migrate/20110712142140_remove_permission_function.rb
  38. +14 −20 lib/generators/social_stream/base/templates/relations.yml
  39. +1 −2  lib/social_stream/ability.rb
  40. +6 −0 lib/social_stream/base.rb
  41. +1 −1  lib/social_stream/base/version.rb
  42. +19 −0 lib/social_stream/migration_finder.rb
  43. +93 −95 lib/social_stream/toolbar_config.rb
  44. +1 −1  social_stream-base.gemspec
  45. +1 −1  spec/controllers/contacts_controller_spec.rb
  46. +1 −2  spec/controllers/permissions_controller_spec.rb
  47. +2 −2 spec/controllers/posts_controller_spec.rb
  48. +69 −62 spec/controllers/relation_customs_controller_spec.rb
  49. +0 −116 spec/controllers/spheres_controller_spec.rb
  50. +1 −1  spec/factories/relation_custom.rb
  51. +0 −5 spec/factories/sphere.rb
  52. +4 −0 spec/factories/tie.rb
  53. +11 −2 spec/models/activity_spec.rb
  54. +0 −14 spec/models/relation_custom_spec.rb
  55. +23 −0 spec/models/user_spec.rb
  56. +3 −12 spec/support/migrations.rb
View
3  app/assets/stylesheets/contacts.css
@@ -18,7 +18,8 @@ div.sphere-name {
color: #1F4A75;
}
-#contact-new {
+#relation-new {
+ margin-left: 20px;
font-weight: bold;
}
View
0  app/assets/stylesheets/spheres.css → app/assets/stylesheets/relation_customs.css
File renamed without changes
View
12 app/controllers/relation/customs_controller.rb
@@ -2,15 +2,5 @@ class Relation::CustomsController < InheritedResources::Base
before_filter :authenticate_user!
load_and_authorize_resource :class => Relation::Custom
- respond_to :js
-
- belongs_to :sphere, :optional => true
-
- def index
- # Must authorize index, because Cancan does not filter collection with conditions.
- # See https://github.com/ryanb/cancan/wiki/checking-abilities
- authorize! :read, parent.customs.new
-
- index!
- end
+ respond_to :html, :js
end
View
12 app/controllers/spheres_controller.rb
@@ -1,12 +0,0 @@
-class SpheresController < InheritedResources::Base
- before_filter :authenticate_user!
- load_and_authorize_resource
-
- respond_to :html, :js
-
- protected
-
- def begin_of_association_chain
- current_subject
- end
-end
View
3  app/helpers/activities_helper.rb
@@ -31,7 +31,6 @@ def link_like_params(object)
def new_activity(receiver)
return Activity.new unless user_signed_in?
- Activity.new :contact_id => current_subject.contact_to!(receiver).id,
- :relation_ids => current_subject.activity_relations(receiver, :from => :receiver).map(&:id)
+ Activity.new :contact_id => current_subject.contact_to!(receiver).id
end
end
View
10 app/helpers/permissions_helper.rb
@@ -1,16 +1,16 @@
module PermissionsHelper
DEFAULT_PERMISSIONS =
[
- [ "read", "activity", "same_and_lower_levels" ],
- [ "create", "activity", "same_level" ],
- [ "follow", nil, nil],
- [ "represent", nil, nil]
+ [ "read", "activity" ],
+ [ "create", "activity" ],
+ [ "follow", nil ],
+ [ "represent", nil ]
]
def default_permissions
@default_permissions ||=
DEFAULT_PERMISSIONS.map{ |p|
- Permission.find_or_create_by_action_and_object_and_function *p
+ Permission.find_or_create_by_action_and_object *p
}
end
end
View
32 app/models/activity.rb
@@ -204,22 +204,30 @@ def notify
def allow?(subject, action)
return false if contact.blank?
- # We do not support private activities by now
- return false if relation_ids.blank?
-
case action
when 'create'
return false if contact.sender_id != Actor.normalize_id(subject)
- rels = Relation.normalize(relation_ids)
+ if relation_ids.present?
+ rels = Relation.normalize(relation_ids)
+
+ foreign_rels = rels.select{ |r| r.actor_id != contact.sender_id }
- foreign_rels = rels.select{ |r| r.actor_id != contact.sender_id }
+ # Only posting to own relations
+ return true if foreign_rels.blank?
- # Only posting to own relations
- return true if foreign_rels.blank?
+ return Relation.
+ allow(subject, action, 'activity', :in => foreign_rels).all.size == foreign_rels.size
+ else
+ if contact.reflexive?
+ return true
+ else
+ relation_ids = receiver.relation_customs.allow(sender, 'create', 'activity')
+
+ return relation_ids.present?
+ end
+ end
- return Relation.
- allow(subject, action, 'activity', :in => foreign_rels).all.size == foreign_rels.size
when 'read'
return true if [contact.sender_id, contact.receiver_id].include?(Actor.normalize_id(subject)) || relations.select{ |r| r.is_a?(Relation::Public) }.any?
when 'update'
@@ -230,9 +238,7 @@ def allow?(subject, action)
end
Relation.
- allow(subject, action, 'activity').
- where('relations.id' => relation_ids).
- any?
+ allow?(subject, action, 'activity', :in => self.relation_ids, :public => false)
end
# Can subject delete the object of this activity?
@@ -272,7 +278,7 @@ def decrement_like_count
#
# Destroy any Notification linked with the activity
def delete_notifications
- Notification.find_by_object(self).each do |notification|
+ Notification.with_object(self).each do |notification|
notification.destroy
end
end
View
101 app/models/actor.rb
@@ -56,11 +56,6 @@ class Actor < ActiveRecord::Base
:uniq => true
has_many :relations
- has_many :spheres
-
- has_many :relation_customs,
- :through => :spheres,
- :source => :customs
scope :alphabetic, order('actors.name')
@@ -140,12 +135,31 @@ def find_by_webfinger!(link)
end
end
+ # Returns the email used for Mailboxer
+ def mailboxer_email
+ return email if email.present?
+ if (group = self.subject).is_a? Group
+ relation = group.relation_customs.sort.first
+ receivers = group.contact_actors(:direction => :sent, :relations => relation)
+ emails = Array.new
+ receivers.each do |receiver|
+ emails << receiver.mailboxer_email
+ end
+ return emails
+ end
+ end
+
# The subject instance for this actor
def subject
subtype_instance ||
activity_object.try(:object)
end
+ # All the {Relation relations} defined by this {Actor}
+ def relation_customs
+ relations.where(:type => 'Relation::Custom')
+ end
+
# A given relation defined and managed by this actor
def relation_custom(name)
relation_customs.find_by_name(name)
@@ -161,25 +175,23 @@ def relation_public
# Options:
# * type: Filter by the class of the contacts.
# * direction: sent or received
- # * relations: Restrict the relations of considered ties. Defaults to {Relation::Custom subject's custom relations}
+ # * relations: Restrict the relations of considered ties. Defaults to {Relation::Custom relations of custom type}
# * include_self: False by default, don't include this actor as subject even they have ties with themselves.
#
def contact_actors(options = {})
- options[:relations] ||= relation_customs.to_a
-
subject_types = Array(options[:type] || self.class.subtypes)
subject_classes = subject_types.map{ |s| s.to_s.classify }
as = Actor.select("DISTINCT actors.*").
- where('actors.subject_type' => subject_classes).
- includes(subject_types)
+ where('actors.subject_type' => subject_classes).
+ includes(subject_types)
case options[:direction]
when :sent
- as = as.contacted_from(self)
+ as = as.joins(:received_ties => :relation).merge(Contact.sent_by(self))
when :received
- as = as.contacted_to(self)
+ as = as.joins(:sent_ties => :relation).merge(Contact.received_by(self))
else
raise "contact actors in both directions are not supported yet"
end
@@ -188,7 +200,11 @@ def contact_actors(options = {})
as = as.where("actors.id != ?", self.id)
end
- as = as.joins(:received_ties).merge(Tie.related_by(options[:relations]))
+ if options[:relations].present?
+ as = as.merge(Tie.related_by(options[:relations]))
+ else
+ as = as.merge(Relation.where(:type => 'Relation::Custom'))
+ end
as
end
@@ -279,30 +295,15 @@ def represented_by?(subject)
any?
end
- # The relations that allow attaching an activity to them. This method is used for caching
- def active_relations
- @active_relations ||= { :sender => {}, :receiver => {} }
- end
-
# An {Activity} can be shared with multiple {audicences Audience}, which corresponds to a {Relation}.
#
# This method returns all the {relations Relation} that this actor can use to broadcast an Activity
#
- # Options:
- # from:: limit the relations to one side, from the :sender or the :receiver of the activity
#
def activity_relations(subject, options = {})
return relations if Actor.normalize(subject) == self
- case options[:from]
- when :sender
- sender_activity_relations(subject)
- when :receiver
- receiver_activity_relations(subject)
- else
- sender_activity_relations(subject) +
- receiver_activity_relations(subject)
- end
+ Array.new
end
# Are there any activity_relations present?
@@ -310,48 +311,6 @@ def activity_relations?(*args)
activity_relations(*args).any?
end
- # Relations from this actor that can be read by subject
- def sender_activity_relations(subject)
- active_relations[:sender][subject] ||=
- Relation.allow(subject, 'read', 'activity', :owner => self)
- end
-
- def receiver_activity_relations(subject)
- active_relations[:receiver][subject] ||=
- Relation.allow(self, 'create', 'activity', :owner => subject)
- end
-
- # Builds a hash of options their spheres as keys
- def grouped_activity_relations(subject)
- rels = activity_relations(subject)
-
- spheres =
- rels.map{ |r| r.respond_to?(:sphere) ? r.sphere : I18n.t('relation_public.name') }.uniq
-
- spheres.sort!{ |x, y|
- case x
- when Sphere
- case y
- when Sphere
- x.id <=> y.id
- else
- -1
- end
- else
- 1
- end
- }
-
- spheres.map{ |s|
- case s
- when Sphere
- [ s.name, rels.select{ |r| r.respond_to?(:sphere) && r.sphere == s }.sort.map{ |u| [ u.name, u.id ] } ]
- else
- [ s, rels.select{ |r| r.is_a?(Relation::Public) }.map{ |u| [ u.name, u.id ] } ]
- end
- }
- end
-
# Is this {Actor} allowed to create a comment on activity?
#
# We are allowing comments from everyone signed in by now
View
15 app/models/contact.rb
@@ -100,6 +100,21 @@ def relation_ids=(ids)
association(:relations).ids_writer(ids)
end
+ # Is this {Contact} +new+ or +edit+ for {SocialStream::Models::Subject subject} ?
+ #
+ # action is +new+ when, despite of being created, it has not {Tie ties} or it has a {Tie} with a
+ # {Relation::Public public relation}.
+ #
+ # The contact's action is +edit+ when it has any {Tie} with a {Relation::Custom custom relation}
+ #
+ def action
+ if ties_count > 0 && relations.where(:type => 'Relation::Custom').any?
+ 'edit'
+ else
+ 'new'
+ end
+ end
+
private
def remove_follower(ids)
View
4 app/models/group.rb
@@ -23,9 +23,7 @@ def recent_groups
merge(Contact.recent)
end
end
-
- private
-
+
# Creates the ties between the group and the founder
def create_founder
founder =
View
81 app/models/permission.rb
@@ -1,5 +1,5 @@
-# SocialStream provides a sophisticated and powerful system of permissions based on the {Relation relations}
-# of the social network.
+# SocialStream provides a system of permissions based on the {Relation relations}
+# of the social network as roles.
#
# = Permissions and Relations
#
@@ -13,9 +13,9 @@
#
# = Permissions description
#
-# Permissions are composed by *action*, *objective* and *function*. Action and objective
+# Permissions are composed by *action* and *object*. Action and object
# are typical in content management systems, e.g. <tt>create activity</tt>,
-# <tt>update tie</tt>, <tt>read post</tt>. *function* is a new parameter for social networks
+# <tt>update tie</tt>, <tt>read post</tt>.
#
# == Actions
#
@@ -32,33 +32,8 @@
#
# +activity+:: all the objects in a wall: posts, comments
#
-# Other objectives currently not implemented could be +tie+, +post+, +comment+ or +message+
+# Other objects currently not implemented could be +tie+, +post+, +comment+ or +message+
#
-# == Functions
-#
-# Function is a novel feature. It supports applying the permission to other related relations and ties.
-# It is required because the set of ties changes while {SocialStream::Models::Subject subjects } build their network.
-# Besides {SocialStream::Models::Subject subjects} can describe and
-# customize their own relations and permissions.
-#
-# Available functions are:
-#
-# +same_level+:: the permission applies to all the objects in same relation
-#
-# Example: the _friend_ relation has the permission
-# <tt>read tie same_level</tt>. If _Alice_ has a _friend_ tie with
-# _Bob_, she is granting him access to read all the contacts of type _friend_
-##
-# +same_and_lower_levels+:: apply the permission to all the related objects attached to a relation weaker
-# or equal than this.#
-#
-# Example: if the _member_ relation of a group has the permission
-# <tt>create activity same_and_lower_levels</tt>, its members
-# can also create activities attached to the weaker relations of
-# _acquaintance_ and _public_.
-# This means than a group _member_ can create activities at different
-# levels of the sphere, and therefore, with different levels of
-# access.
#
class Permission < ActiveRecord::Base
has_many :relation_permissions, :dependent => :destroy
@@ -68,51 +43,13 @@ class Permission < ActiveRecord::Base
scope p, where(:action => p) # scope :represent, where(:action => 'represent')
end
- RelationConditions = {
- 'same_level' =>
- "relations.id = relations_as.id",
- 'same_and_lower_levels' =>
- "(relations.id = relations_as.id OR relations.ancestry = relations_as.id || '' OR relations.ancestry = (relations_as.ancestry || '/' || relations_as.id) OR relations.ancestry LIKE (relations_as.id || '/%') OR relations.ancestry LIKE (relations_as.ancestry || '/' || relations_as.id || '/%')) OR (relations.actor_id = relations_as.actor_id AND relations.type = 'Relation::Public')"
- }
-
- class << self
- # Builds SQL conditions based on {RelationConditions}
- def relation_conditions
- RelationConditions.inject([]){ |result, pc|
- result <<
- "(#{ pc.last }) AND #{ sanitize_sql('permissions_as.function' => pc.first) }"
- }.join(" OR ")
- end
- end
-
# An explanation of the permissions. Type can be brief or detailed.
- # If detailed, description includes details about the relation
+ # If detailed, description includes more information about the relation
def description(type, relation = nil)
- options = ( relation.present? ? description_options(relation) : {} )
+ options = {}
+ options[:relation] = relation.name if relation.present?
- I18n.t "permission.description.#{ type }.#{ action }.#{ object || "nil" }.#{ function || "nil" }",
+ I18n.t "permission.description.#{ type }.#{ action }.#{ object || "nil" }",
options
end
-
- private
-
- def description_options(relation)
- {
- :sphere => relation.sphere.name,
- :public => I18n.t('relation_public.name')
- }.tap do |h|
- case function
- when NilClass, "same_level"
- h[:relation] = relation.name
- when "same_and_lower_levels"
- h[:relations] = relation.
- weaker_or_equal.
- sort.
- map(&:name).
- join(", ")
-
- end
- end
-
- end
end
View
52 app/models/relation.rb
@@ -30,6 +30,7 @@ class Relation < ActiveRecord::Base
has_many :permissions, :through => :relation_permissions
has_many :ties, :dependent => :destroy
+ has_many :contacts, :through => :ties
scope :mode, lambda { |st, rt|
where(:sender_type => st, :receiver_type => rt)
@@ -76,59 +77,34 @@ def normalize_id(r, options = {})
#
# Options:
# in:: Limit possible relations to a set
- # owner:: The owner of the relations
# public_relations:: include also {Relation::Public} whose activities can always be read
def allow(subject, action, object, options = {})
- # The case when the owner == subject is special,
- # all the permissions are granted to the owner of the relations
- if options[:owner].present? && Actor.normalize(options[:owner]) == Actor.normalize(subject)
- rels = subject.relations
+ q =
+ select("DISTINCT relations.*").
+ joins(:contacts).
+ joins(:permissions)
- if options[:in].present?
- rels = rels & options[:in]
- end
-
- rels
- end
-
- # Relation conditions
- # Some relations can have permissions that grant permissions to other relations
- # through Relation#function
- conds = Permission.relation_conditions
-
- # Permission conditions
- # Set the permission conditions
- conds = "( #{ conds } ) AND #{ sanitize_sql('permissions_as.action' => action) } AND #{ sanitize_sql('permissions_as.object' => object) }"
+ conds =
+ Permission.arel_table[:action].eq(action).and(Permission.arel_table[:object].eq(object))
# Relation::Public permissions cannot be customized yet
if action == 'read' && object == 'activity' && (options[:public].nil? || options[:public])
- conds =
- "( #{ conds } ) OR #{ sanitize_sql('relations.type' => 'Relation::Public') }"
- end
-
- # subject conditions
- #
- # Relation permissions are granted to the contact receiver.
- # However, relation owners have all the permissions
- conds = "( ( #{ conds } ) AND #{ sanitize_sql('contacts_as.receiver_id' => Actor.normalize_id(subject)) } ) OR #{ sanitize_sql('relations.actor_id' => Actor.normalize_id(subject)) }"
-
- # Add owner condition
- if options[:owner].present?
- conds = "( #{ conds } ) AND #{ sanitize_sql('relations.actor_id' => Actor.normalize_id(options[:owner])) }"
+ conds = conds.or(Relation.arel_table[:type].eq('Relation::Public'))
end
# Add in condition
if options[:in].present?
- conds = "( #{ conds } ) AND #{ sanitize_sql('relations.id' => Relation.normalize_id(Array(options[:in]))) }"
+ conds = conds.and(Relation.arel_table[:id].in(Relation.normalize_id(Array(options[:in]))))
end
- select("DISTINCT relations.*").
- from("relations, contacts AS contacts_as INNER JOIN ties AS ties_as ON contacts_as.id = ties_as.contact_id INNER JOIN relations AS relations_as ON relations_as.id = ties_as.relation_id INNER JOIN relation_permissions AS relation_permissions_as ON relations_as.id = relation_permissions_as.relation_id INNER JOIN permissions AS permissions_as ON permissions_as.id = relation_permissions_as.permission_id").
- where(conds)
+ # subject conditions
+ conds = conds.and(Contact.arel_table[:receiver_id].eq(Actor.normalize_id(subject)))
+
+ q.where(conds)
end
def allow?(*args)
- allow(*args).any?
+ allow(*args).to_a.any?
end
end
View
39 app/models/relation/custom.rb
@@ -13,16 +13,10 @@ class Relation::Custom < Relation
inspect
has_ancestry
- attr_protected :actor_id
-
- belongs_to :sphere
belongs_to :actor
- validates_presence_of :name, :sphere_id, :actor_id
- validates_uniqueness_of :name, :scope => :sphere_id
-
- before_validation :assign_parent, :on => :create
- before_validation :assign_actor, :on => :create
+ validates_presence_of :name, :actor_id
+ validates_uniqueness_of :name, :scope => :actor_id
class << self
# Relations configuration
@@ -40,18 +34,15 @@ def defaults_for(actor)
rels = {}
cfg_rels.each_pair do |name, cfg_rel|
- raise("Must associatiate relation #{ cfg_rel['name'] } to a sphere") if cfg_rel['sphere'].blank?
- sphere = actor.spheres.find_or_create_by_name(cfg_rel['sphere'])
-
rels[name] =
- create! :sphere => sphere,
- :receiver_type => cfg_rel['receiver_type'],
- :name => cfg_rel['name']
+ create! :actor => actor,
+ :name => cfg_rel['name'],
+ :receiver_type => cfg_rel['receiver_type']
if (ps = cfg_rel['permissions']).present?
ps.each do |p|
rels[name].permissions <<
- Permission.find_or_create_by_action_and_object_and_function(*p)
+ Permission.find_or_create_by_action_and_object(*p)
end
end
end
@@ -103,22 +94,4 @@ def stronger
def stronger_or_equal
path
end
-
- private
-
- # Before create callback
- #
- # Assign the last relation as parent if there are other custom relations in the sphere
- def assign_parent
- return if parent.present? || sphere.customs.blank?
-
- self.parent = sphere.customs.sort.last
- end
-
- # Before create callback
- #
- # Assign the sphere's actor
- def assign_actor
- self.actor = sphere.actor
- end
end
View
9 app/models/sphere.rb
@@ -1,9 +0,0 @@
-class Sphere < ActiveRecord::Base
- belongs_to :actor
-
- has_many :customs, :class_name => "Relation::Custom"
-
- validates_presence_of :name
- validates_uniqueness_of :name, :scope => :actor_id
-
-end
View
6 app/models/user.rb
@@ -29,8 +29,12 @@ def recent_groups
# Subjects this user can acts as
def represented
+ candidates = contact_actors(:direction => :sent).map(&:id)
+
contact_subjects(:direction => :received) do |q|
- q.joins(:sent_ties => { :relation => :permissions }).merge(Permission.represent)
+ q.joins(:sent_ties => { :relation => :permissions }).
+ merge(Permission.represent).
+ where(:id => candidates)
end
end
View
7 app/views/activities/_new.html.erb
@@ -19,7 +19,10 @@
</div>
<div id="activities_share_btn">
-<div id="securities"><%= select_tag :_relation_ids, grouped_options_for_select(current_subject.grouped_activity_relations(receiver)), :id => 'security', :multiple => nil %></div>
-<%= submit_tag(t('share'), :class => "myButtonBlue", :id => "masterSubmitButton") %>
+<% if current_subject == receiver %>
+ <div id="securities"><%= select_tag :_relation_ids, options_for_select(current_subject.activity_relations(receiver).sort.map{ |r| [ r.name, r.id ] }), :id => 'security', :multiple => nil %></div>
+<% end %>
+
+ <%= submit_tag(t('share'), :class => "myButtonBlue", :id => "masterSubmitButton") %>
</div>
<% end %>
View
2  app/views/activities/_options.html.erb
@@ -1,7 +1,7 @@
<div class="activity_options">
<ul class="activity_options" >
<li><div class="post_time_ago"><%= t('time.ago', :time => time_ago_in_words(activity.created_at)) %></div></li>
- <% if activity.is_root? && user_signed_in? && current_subject.activity_relations?(activity.receiver, :in => activity.relations) %>
+ <% if activity.is_root? && user_signed_in? %>
<li><div class="verb_comment"> · <%= link_to t('activity.to_comment'), "#", :class => "to_comment" %> </div></li>
<% end %>
<li><div class="verb_like" id="like_<%= dom_id(activity) %>"> · <%= link_like(activity)%></div></li>
View
34 app/views/contacts/_form.html.erb
@@ -10,9 +10,6 @@
function checkBoxEnable(id) {
$('div[contain$=' + id + ']').addClass("checked-option");
-
- var sphere = $("#"+id).attr("optionOf");
- $(':checkbox[optionOf$='+sphere+']:checked:not(#'+id+')').checkBox('changeCheckStatus', false);
}
function checkBoxDisable(id) {
@@ -24,24 +21,21 @@
<%= form_for @contact do |f| %>
<%= hidden_field_tag "contact[relation_ids][]", "gotcha" %>
- <% current_subject.spheres.each do |sphere| %>
- <div class="sphere-name"><%= sphere.name %></div>
- <ul>
- <% sphere.customs.sort.each do |relation| %>
- <li>
- <div contain="<%= dom_id relation %>">
- <input id="<%= dom_id relation %>" name="contact[relation_ids][]" value="<%= relation.id %>" type="checkbox" optionOf="<%= sphere.name %>" <%= raw('checked="checked"') if @contact.relation_ids.include?(relation.id) %> />
- <label for="<%= dom_id relation %>">
- <%= relation.name %>
- </label>
- </div>
- </li>
- <% end %>
- </ul>
+ <ul>
+ <% current_subject.relation_customs.each do |relation| %>
+ <li>
+ <div contain="<%= dom_id relation %>">
+ <input id="<%= dom_id relation %>" name="contact[relation_ids][]" value="<%= relation.id %>" type="checkbox" <%= raw('checked="checked"') if @contact.relation_ids.include?(relation.id) %> />
+ <label for="<%= dom_id relation %>">
+ <%= relation.name %>
+ </label>
+ </div>
+ </li>
<% end %>
+ </ul>
- <div id="contact-new">
- <%= link_to t('contact.type.new'), spheres_path %>
+ <div id="relation-new">
+ <%= link_to t('contact.type.new'), relation_customs_path %>
</div>
<div id="contact-message">
@@ -50,7 +44,7 @@
</div>
<div id="contact-submit">
- <%= submit_tag t("contact.#{ controller.action_name }.submit"), :class => "button" %>
+ <%= submit_tag t("contact.#{ f.object.action }.submit"), :class => "button" %>
</div>
<% end %>
</div>
View
2  app/views/contacts/edit.html.erb
@@ -1,6 +1,6 @@
<% toolbar :profile => @contact.receiver_subject, :option => 'contacts' %>
<% location link_to(image_tag("btn/btn_friend.png", :class => "menu_icon") +
- t('contact.edit.title', :name => @contact.receiver.name), edit_contact_path(@contact.to_param)) %>
+ t("contact.#{ @contact.action }.title", :name => @contact.receiver.name), edit_contact_path(@contact.to_param)) %>
<%= render :partial => 'form' %>
View
2  app/views/groups/_group.html.erb
@@ -4,7 +4,7 @@
<%=link_to(image_tag(group.logo.url(:actor), :class => 'btn_group', :alt => group.name, :title => group.name), group) %>
</div>
<div class="group_title">
- <%=link_to(group.name, group)%>
+ <%=link_to(truncate_name(group.name), group)%>
</div>
<% end %>
</li>
View
2  app/views/layouts/_settings.html.erb
@@ -10,7 +10,7 @@
<%= link_to t('settings.main'), settings_path, :id => "btn_menu_settings" %>
</li>
<li class="current">
- <%= link_to t('account.privacy'), spheres_path %>
+ <%= link_to t('account.privacy'), relation_customs_path %>
</li>
</ul>
</li>
View
6 app/views/objects/_new.html.erb
@@ -5,10 +5,4 @@
<%= f.hidden_field :_contact_id %>
<%= render :partial => object.class.to_s.tableize+'/fields' , :locals => {:f => f} %>
-
- <% if current_subject != receiver %>
- <% current_subject.activity_relations(receiver, :from => :receiver).each do |r| %>
- <%= f.hidden_field "_relation_ids][", :value => r.id %>
- <% end %>
- <% end %>
<% end %>
View
4 app/views/relation/customs/_form.html.erb
@@ -1,7 +1,7 @@
-<% @custom ||= @sphere.customs.build %>
+<% @custom ||= Relation::Custom.new(:actor_id => current_subject.actor_id) %>
<%= form_for @custom, :remote => true do |f| %>
- <%= f.hidden_field :sphere_id %>
+ <%= f.hidden_field :actor_id %>
<% if @custom.errors.any? %>
<div id="error_explanation">
View
28 app/views/relation/customs/_index.html.erb
@@ -1,28 +0,0 @@
-<%= javascript_include_tag 'jquery-ui'%>
-
-<p class="sectionTitle"><%= raw t('relation_custom.in_sphere.choose', :name => h(@sphere.name)) %> </p>
-
-
-<div class="privacy_add_element">
- <div id="new_relation_custom_title_block">
- <a href="#"><span id="new_relation_custom_title" class="privacy_span_new"><%= t 'relation_custom.new' %></span></a>
- </div>
- <div id="new_relation_custom_input_block">
- <%= render :partial => 'relation/customs/form' %>
- </div>
-</div>
-
-<div id="relation_custom_list">
- <%= render :partial => 'relation/customs/list', :object => @customs %>
-</div>
-
-<%= javascript_tag do %>
- $(function() {
- $("#new_relation_custom_input_block").hide();
-
- $("#new_relation_custom_title").click(function() {
- $("#new_relation_custom_title_block").hide();
- $("#new_relation_custom_input_block").show();
- });
- })
-<% end %>
View
58 app/views/spheres/_jquery.erb → app/views/relation/customs/_jquery.erb
@@ -26,28 +26,9 @@ function checkBoxEnable(id) {
switch (checkBoxType(id)) {
- case "sphere":
- $(':checkbox[id^="sphere"]:checked:not(#' + id + ')').checkBox('changeCheckStatus', false);
-
- var sphereSelected = checkBoxId(id);
-
- $.ajax({
- url: "<%= relation_customs_path %>",
- context: document.body,
- data: { sphere_id: sphereSelected },
- dataType: "script"
- });
-
- break;
-
case "relation_custom":
$(':checkbox[id^="relation_custom"]:checked:not(#' + id + ')').checkBox('changeCheckStatus', false);
- var value = relations.length - checkBoxOrder(id) - 2;
- $("#slider-range").slider("value", value);
-
- $( "#relation" ).val(checkBoxValue(id));
-
$.ajax({
url: "<%= permissions_path %>",
context: document.body,
@@ -73,19 +54,10 @@ function checkBoxDisable(id) {
switch (checkBoxType(id)) {
- case "sphere":
- $("#permissions").html("");
- $("#permissions").hide();
- $("#relations").hide();
-
- break;
-
case "relation_custom":
$("#permissions").html("");
$("#permissions").hide();
- $("#slider-range").slider("value", relations.length - 1);
-
break;
case "permission":
@@ -98,33 +70,3 @@ function checkBoxDisable(id) {
}
}
-
-
-function initSlider() {
- /* TODO: get relations from checkboxOptions */
- relations.unshift("<%= t 'relation_public.name' %>");
- relations.push("<%= current_subject.name %>");
-
- $("#relation").val(relations[relations.length - 1]);
-
- $("#slider-range").slider({
- orientation: "vertical",
- range: "min",
- min: 0,
- max: relations.length - 1,
- step: 1,
- value: relations.length - 1,
- slide: function(event, ui) {
- $('#relation').val(relations[ui.value]);
- },
- stop: function(event, ui) {
- var order = relations.length - ui.value - 2;
- if (order >= 0 && order < relations.length - 2) {
- var id = '#' + checkBoxIdByOrder(order);
- $(id).checkBox('changeCheckStatus', true);
- } else {
- $(':checkbox[id^="relation_custom"]:checked').checkBox('changeCheckStatus', false);
- }
- }
- });
-};
View
35 app/views/relation/customs/_list.html.erb
@@ -1,36 +1,19 @@
-<table class="tableCheckBoxOptions">
-
- <tr><td colspan="2"><div class="slider-header"><%= current_subject.name %></div></td></tr>
-
- <tr><td rowspan="<%= list.size + 1 %>">
- <div class="slider-div">
- <p>
- <div id="slider-range"></div>
- </p>
- </div>
- </td>
- </tr>
-
- <% order = 0 %>
- <% list.sort.each do |r| %>
- <tr><td>
- <div contain=<%= dom_id r %> class="checkboxOptionLeft">
- <input id=<%= dom_id r %> type="checkbox"/>
- <label for="<%= dom_id r %>" order="<%= order %>"><%= r.name %></label>
+<table class="tableCheckBoxOptions">
+ <% list.each do |r| %>
+ <%= raw cycle("<tr><td>", "<td>", :name => "begin_cell") %>
+ <div contain="<%= dom_id(r) %>" class="checkboxOptionLeft">
+ <input id=<%= dom_id(r) %> type="checkbox"/>
+ <label for=<%= dom_id(r) %>><%=r.name%></label>
</div>
- </td></tr>
- <% order += 1 %>
+ <%= raw cycle("</td>", "</td></tr>", :name => "end_cell") %>
<% end %>
- <tr><td colspan="2"><div class="slider-footer"><%= t 'relation_public.name' %></div></td><tr>
+ <%= raw("</tr>") if list.size.odd? %>
+
</table>
<%= javascript_tag do %>
$(function() {
- relations = <%= list.sort.reverse.map{ |r| h(r.name) }.to_json.html_safe %>;
-
$('input[id^="relation_custom"]').checkBox();
-
- initSlider();
})
<% end %>
View
5 app/views/relation/customs/create.js.erb
@@ -1,7 +1,7 @@
<% if @custom.errors.present? %>
$('#new_relation_custom_input_block').html("<%= escape_javascript render(:partial => 'relation/customs/form') %>");
<% else %>
- // Hide #permissions
+ // Hide #relations and #permissions
$('#permissions').html("");
$('#permissions').hide();
@@ -10,9 +10,8 @@
$('#new_relation_custom_input_block').hide();
$('#new_relation_custom_title_block').show();
-
// Refresh list
- $('#relation_custom_list').html("<%= escape_javascript render(:partial => 'relation/customs/list', :object => @custom.sphere.customs.reload) %>");
+ $('#relation_customs_list').html("<%= escape_javascript render(:partial => 'relation/customs/list', :object => current_subject.relation_customs) %>");
// Select relation_custom
$('#' + '<%= dom_id @custom %>').checkBox('changeCheckStatus', true);
View
67 app/views/relation/customs/index.html.erb
@@ -0,0 +1,67 @@
+<% content_for :headers do %>
+ <%= stylesheet_link_tag "relation_customs.css", :media => "screen, projection" %>
+ <%= javascript_include_tag 'ui.checkbox'%>
+<% end %>
+
+<% toolbar :profile => current_subject, :option => 'contacts' %>
+
+<%= javascript_tag do %>
+ <%= render :partial => 'relation/customs/jquery' %>
+<% end %>
+
+<div id="wrapper_section">
+
+ <p class="pageTitle"><%= t 'relation_custom.title' %></p>
+
+ <div id="relation_customs" class="privacy_block_section first_block_section">
+ <p class="sectionTitle"><%= t 'relation_custom.choose' %></p>
+
+ <div class="privacy_add_element">
+ <div id="new_relation_custom_title_block">
+ <a href="#"><span id="new_relation_custom_title" class="privacy_span_new"><%= t('relation_custom.new') %></span></a>
+ </div>
+ <div id="new_relation_custom_input_block">
+ <%= render :partial => 'relation/customs/form' %>
+ </div>
+ </div>
+
+ <%= javascript_tag do %>
+ $(function() {
+ $("#new_relation_custom_input_block").hide();
+
+ $("#new_relation_custom_title").click(function() {
+ $("#new_relation_custom_title_block").hide();
+ $("#new_relation_custom_input_block").show();
+ });
+
+ $("#loading").hide();
+
+ $("#loading").ajaxStart(function(){
+ $(this).show();
+ });
+
+ $("#loading").ajaxStop(function(){
+ $(this).hide();
+ });
+
+ })
+ <% end %>
+
+ <div id="relation_customs_list">
+ <%= render :partial => 'relation/customs/list', :object => @customs %>
+ </div>
+
+</div>
+
+
+ <div id="permissions" class="privacy_block_section">
+ </div>
+
+ <div id="loading"></div>
+
+ <%= javascript_tag do %>
+ $(function() {
+ $("#permissions").hide();
+ })
+ <% end %>
+</div>
View
2  app/views/relation/customs/index.js.erb
@@ -1,2 +0,0 @@
-$('#relations').html("<%= escape_javascript render(:partial => 'index') %>");
-$('#relations').show();
View
28 app/views/spheres/_form.html.erb
@@ -1,28 +0,0 @@
-<% @sphere ||= Sphere.new %>
-
-<%= form_for @sphere, :remote => true do |f| %>
-
- <% if @sphere.errors.any? %>
- <div id="error_explanation">
- <h2><%= pluralize(@sphere.errors.count, "error") %> prohibited this sphere from being saved:</h2>
-
- <ul>
- <% @sphere.errors.full_messages.each do |msg| %>
- <li><%= msg %></li>
- <% end %>
- </ul>
- </div>
- <% end %>
-
- <p><%= f.text_field :name, :class => "privacy_input_new", :size => 20 %></p>
- <%= f.submit nil, :class => "button" %>
- <button class="button" id="cancel_new_sphere" ><%= t('button.cancel') %></button>
-<% end %>
-
-<%= javascript_tag do %>
- $("#cancel_new_sphere").click(function() {
- $("#new_sphere_input_block").hide();
- $("#new_sphere_title_block").show();
- return false;
- });
-<% end %>
View
19 app/views/spheres/_list.html.erb
@@ -1,19 +0,0 @@
-<table class="tableCheckBoxOptions">
- <% list.each do |sphere| %>
- <%= raw cycle("<tr><td>", "<td>", :name => "begin_cell") %>
- <div contain="<%= dom_id(sphere) %>" class="checkboxOptionLeft">
- <input id=<%= dom_id(sphere) %> type="checkbox"/>
- <label for=<%= dom_id(sphere) %>><%=sphere.name%></label>
- </div>
- <%= raw cycle("</td>", "</td></tr>", :name => "end_cell") %>
- <% end %>
-
- <%= raw("</tr>") if list.size.odd? %>
-
-</table>
-
-<%= javascript_tag do %>
- $(function() {
- $('input[id^="sphere"]').checkBox();
- })
-<% end %>
View
20 app/views/spheres/create.js.erb
@@ -1,20 +0,0 @@
-<% if @sphere.errors.present? %>
- $('#new_sphere_input_block').html("<%= escape_javascript render(:partial => 'spheres/form') %>");
-<% else %>
- // Hide #relations and #permissions
- $('#permissions').html("");
- $('#permissions').hide();
- $('#relations').hide();
-
- // Restore form
- $('#sphere_name').val('');
- $('#new_sphere_input_block').hide();
- $('#new_sphere_title_block').show();
-
- // Refresh list
- $('#spheres_list').html("<%= escape_javascript render(:partial => 'spheres/list', :object => current_subject.spheres) %>");
-
- // Select sphere
- $('#' + '<%= dom_id @sphere %>').checkBox('changeCheckStatus', true);
-<% end %>
-
View
74 app/views/spheres/index.html.erb
@@ -1,74 +0,0 @@
-<% content_for :headers do %>
- <%= stylesheet_link_tag "spheres.css", :media => "screen, projection" %>
- <%= stylesheet_link_tag "jquery.ui.slider.css", :media => "screen, projection" %>
- <%= stylesheet_link_tag "jquery.ui.slidertheme.css", :media => "screen, projection" %>
- <%= javascript_include_tag 'ui.checkbox'%>
-<% end %>
-
-<% toolbar :profile => current_subject, :option => 'contacts' %>
-
-<%= javascript_tag do %>
- <%= render :partial => 'spheres/jquery' %>
-<% end %>
-
-<div id="wrapper_section">
-
- <p class="pageTitle"><%= t 'sphere.title' %></p>
-
- <div id="spheres" class="privacy_block_section first_block_section">
- <p class="sectionTitle"><%= t 'sphere.choose' %></p>
-
- <div class="privacy_add_element">
- <div id="new_sphere_title_block">
- <a href="#"><span id="new_sphere_title" class="privacy_span_new"><%= t('sphere.new') %></span></a>
- </div>
- <div id="new_sphere_input_block">
- <%= render :partial => 'spheres/form' %>
- </div>
- </div>
-
- <%= javascript_tag do %>
- $(function() {
- $("#new_sphere_input_block").hide();
-
- $("#new_sphere_title").click(function() {
- $("#new_sphere_title_block").hide();
- $("#new_sphere_input_block").show();
- });
-
- $("#loading").hide();
-
- $("#loading").ajaxStart(function(){
- $(this).show();
- });
-
- $("#loading").ajaxStop(function(){
- $(this).hide();
- });
-
- })
- <% end %>
-
- <div id="spheres_list">
- <%= render :partial => 'spheres/list', :object => @spheres %>
- </div>
-
-</div>
-
-
- <div id="relations" class="privacy_block_section">
- </div>
-
-
- <div id="permissions" class="privacy_block_section">
- </div>
-
- <div id="loading"></div>
-
- <%= javascript_tag do %>
- $(function() {
- $("#relations").hide();
- $("#permissions").hide();
- })
- <% end %>
-</div>
View
55 config/locales/en.yml
@@ -73,6 +73,7 @@ en:
confirm_delete: "Delete comment?"
contact:
all_n: "All contacts (%{count})"
+ addressbook: "Addressbook"
edit:
title: "Edit contact to %{name}"
submit: "Edit Contact"
@@ -150,8 +151,6 @@ en:
help: "Help"
helpers:
submit:
- sphere:
- create: "Save"
relation_custom:
create: "Save"
home: "Home"
@@ -165,6 +164,7 @@ en:
join_me: "Join me at SocialStream!"
one: "Invitation"
other: "Invitations"
+ toolbar: "Invite"
success: "Your invitations have successfully been sent"
text: "Write your own message"
like:
@@ -246,46 +246,25 @@ en:
description:
brief:
create:
- activity:
- same_level: "Post to wall"
- destroy:
- activity:
- nil: "Delete activities in wall"
+ activity: "Post to wall"
follow:
- nil:
- nil: "Follow their activity"
+ nil: "Follow their activity"
read:
- activity:
- same_and_lower_levels: "Read wall"
+ activity: "Read wall"
represent:
- nil:
- nil: "Represent"
+ nil: "Represent"
detailed:
create:
- activity:
- same_level: "Post to \"%{sphere}\" wall at %{relation} level"
- same_and_lower_levels: "Post to \"%{sphere}\" wall as %{relations} and %{public}"
- destroy:
- activity:
- nil: "Delete the activities posted to \"%{sphere}\" wall by this %{relation}"
+ activity: "Post to \"%{relation}\" wall"
follow:
- nil:
- nil: "Activities of the contacts at %{relation} level will appear in our home wall"
+ nil: "Activities of the contacts at %{relation} will appear in our home wall"
read:
- activity:
- same_and_lower_levels: "Read posts in \"%{sphere}\" wall at levels %{relations} and %{public}"
- tie:
- same_and_lower_levels:
- "See contacts in levels: %{relations} and %{public}"
+ activity: "Read posts in \"%{relation}\" wall"
+ tie: "See contacts in levels: %{relations} and %{public}"
represent:
- nil:
- nil: "Represent me/us in the website"
- update:
- activity:
- nil: "Update the wall activities posted by %{relation}"
- weak_star_ties: "Update the wall activities posted in levels %{relations} and %{public}"
+ nil: "Represent me/us in the website"
of_relation:
- choose: "3. Permissions in <strong>%{name}</strong> level"
+ choose: "2. Permissions in <strong>%{name}</strong> level"
privacy:
intro: "Contacts at <strong>%{relation}</strong> level are only allowed to:"
rule:
@@ -296,9 +275,9 @@ en:
one: "Product"
other: "Products"
relation_custom:
- in_sphere:
- choose: "2. Levels in <strong>%{name}</strong> sphere"
- new: "+ New level"
+ title: "Privacy & context"
+ choose: "1. Choose stream"
+ new: "+ New stream"
relation_public:
name: "Public"
required: "* These fields are required"
@@ -327,10 +306,6 @@ en:
sign_out: "Sign out"
sign_up: "Sign up"
socialstream: "SocialStream"
- sphere:
- title: "Privacy & context"
- choose: "1. Choose sphere"
- new: '+ New sphere'
sure: "Are you sure?"
time:
ago: "%{time} ago"
View
1  config/routes.rb
@@ -29,7 +29,6 @@
resources :contacts
- resources :spheres
namespace "relation" do
resources :customs
end
View
30 db/migrate/20110712090343_remove_spheres.rb
@@ -0,0 +1,30 @@
+class RemoveSpheres < ActiveRecord::Migration
+ def up
+ remove_foreign_key "relations", :name => "relations_on_sphere_id"
+
+ remove_foreign_key "spheres", :name => "spheres_on_actor_id"
+
+ remove_column :relations, :sphere_id
+
+ drop_table :spheres
+ end
+
+ def down
+ add_column :relations, :sphere_id, :integer
+
+ add_index "relations", "sphere_id"
+
+ create_table "spheres", :force => true do |t|
+ t.string "name"
+ t.integer "actor_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "spheres", "actor_id"
+
+ add_foreign_key "relations", "spheres", :name => "relations_on_sphere_id"
+
+ add_foreign_key "spheres", "actors", :name => "spheres_on_actor_id"
+ end
+end
View
26 db/migrate/20110712142140_remove_permission_function.rb
@@ -0,0 +1,26 @@
+class RemovePermissionFunction < ActiveRecord::Migration
+ def up
+ remove_column :permissions, :function
+
+ ts = RelationPermission.record_timestamps
+ RelationPermission.record_timestamps = false
+
+ Permission.all.each do |p|
+ q = Permission.find_by_action_and_object p.action, p.object
+
+ next if p == q
+
+ p.relation_permissions.each do |rp|
+ rp.update_attribute :permission_id, q.id
+ end
+
+ p.reload.destroy
+ end
+
+ RelationPermission.record_timestamps = ts
+ end
+
+ def down
+ add_column :permissions, :function, :string
+ end
+end
View
34 lib/generators/social_stream/base/templates/relations.yml
@@ -11,35 +11,29 @@ user:
friend:
name: friend
permissions:
- - [ follow ] # follow the activities of the friend
- - [ create, activity, same_level ] # let the friend create activities
- - [ read, activity, same_and_lower_levels ] # friend can read activities from the other friends and below
- sphere: personal
+ - [ follow ]
+ - [ create, activity ]
+ - [ read, activity ]
acquaintance:
name: acquaintance
- parent: friend # friend relation is stronger than acquaintance
permissions:
- - [ read, activity, same_and_lower_levels ]
- sphere: personal
- partner:
- name: partner
+ - [ read, activity ]
+ colleague:
+ name: colleague
permissions:
- - [ read, activity, same_and_lower_levels ]
- sphere: work
+ - [ follow ]
+ - [ create, activity ]
+ - [ read, activity ]
group:
member:
name: member
permissions:
- - [ represent ] # let the member act as the group
- - [ create, activity, same_and_lower_levels ] # let them member create activities
- - [ read, activity, same_and_lower_levels ] # read activities from other members
- - [ read, tie, same_and_lower_levels ]
- sphere: organization
+ - [ represent ]
+ - [ create, activity ]
+ - [ read, activity ]
+ - [ read, tie ]
partner:
name: partner
- parent: member # member is stronger than partner
permissions:
- - [ read, activity, same_and_lower_levels ]
- sphere: external_relations
-
+ - [ read, activity ]
View
3  lib/social_stream/ability.rb
@@ -93,8 +93,7 @@ def initialize(subject)
end
# Privacy
- can [:create, :read, :update, :destroy], Sphere, :actor_id => subject.try(:actor_id)
- can [:create, :read, :update, :destroy], Relation::Custom, :sphere => { :actor_id => subject.try(:actor_id) }
+ can [:create, :read, :update, :destroy], Relation::Custom, :actor_id => subject.try(:actor_id)
end
end
end
View
6 lib/social_stream/base.rb
@@ -35,6 +35,12 @@ class Engine < ::Rails::Engine #:nodoc:
:profile => '119x119'}
end
end
+
+ initializer "social_stream-base.mailboxer", :before => :load_config_initializers do
+ Mailboxer.setup do |config|
+ config.email_method = :mailboxer_email
+ end
+ end
end
end
end
View
2  lib/social_stream/base/version.rb
@@ -1,5 +1,5 @@
module SocialStream
module Base
- VERSION = "0.6.3".freeze
+ VERSION = "0.6.5".freeze
end
end
View
19 lib/social_stream/migration_finder.rb
@@ -0,0 +1,19 @@
+module SocialStream
+ # Searches for migrations in a gem and requires them.
+ # Example:
+ #
+ # MigrationFinder.new 'acts-as-taggable-on',
+ # ["generators", "acts_as_taggable_on", "migration", "templates", "active_record", "migration"]
+ # ActsAsTaggableOnMigration.up
+class MigrationFinder
+ def initialize gem, path
+ finder = Gem::GemPathSearcher.new
+ taggable_spec = finder.find(gem)
+ taggable_migration = finder.matching_files(taggable_spec,
+ File.join(*path)).first
+
+ require taggable_migration
+ end
+end
+
+end
View
188 lib/social_stream/toolbar_config.rb
@@ -1,113 +1,111 @@
module SocialStream
module ToolbarConfig
#Prints the default home toolbar menu
- def default_home_toolbar_menu
- items = Array.new
- #Notifications
- items << {:key => :notifications,
- :name => image_tag("btn/btn_notification.png")+t('notification.other')+' ('+ current_subject.mailbox.notifications.not_trashed.unread.count.to_s+')',
- :url => notifications_path,
- :options => {:link => {:id => "notifications_menu"}}}
+ def default_home_toolbar_menu
+ items = Array.new
+ #Notifications
+ items << {:key => :notifications,
+ :name => image_tag("btn/btn_notification.png")+t('notification.other')+' ('+ current_subject.mailbox.notifications.not_trashed.unread.count.to_s+')',
+ :url => notifications_path,
+ :options => {:link => {:id => "notifications_menu"}}}
- #Messages
- items << {:key => :messages,
- :name => image_tag("btn/new.png")+t('message.other')+' (' + current_subject.mailbox.inbox(:unread => true).count.to_s + ')',
- :url => "#",
- :options => {:link => {:id => "messages_menu"}},
- :items => [
- {:key => :message_new, :name => image_tag("btn/message_new.png")+ t('message.new'), :url => new_message_path},
- {:key => :message_inbox, :name => image_tag("btn/message_inbox.png")+t('message.inbox')+' (' + current_subject.mailbox.inbox(:unread => true).count.to_s + ')',
- :url => conversations_path, :options => {:link =>{:remote=> true}}},
- {:key => :message_sentbox, :name => image_tag("btn/message_sentbox.png")+t('message.sentbox'), :url => conversations_path(:box => :sentbox), :remote=> true},
- {:key => :message_trash, :name => image_tag("btn/message_trash.png")+t('message.trash'), :url => conversations_path(:box => :trash)}
- ]}
+ #Messages
+ items << {:key => :messages,
+ :name => image_tag("btn/new.png")+t('message.other')+' (' + current_subject.mailbox.inbox(:unread => true).count.to_s + ')',
+ :url => "#",
+ :options => {:link => {:id => "messages_menu"}},
+ :items => [
+ {:key => :message_new, :name => image_tag("btn/message_new.png")+ t('message.new'), :url => new_message_path},
+ {:key => :message_inbox, :name => image_tag("btn/message_inbox.png")+t('message.inbox')+' (' + current_subject.mailbox.inbox(:unread => true).count.to_s + ')',
+ :url => conversations_path, :options => {:link =>{:remote=> true}}},
+ {:key => :message_sentbox, :name => image_tag("btn/message_sentbox.png")+t('message.sentbox'), :url => conversations_path(:box => :sentbox), :remote=> true},
+ {:key => :message_trash, :name => image_tag("btn/message_trash.png")+t('message.trash'), :url => conversations_path(:box => :trash)}
+ ]}
+
+ #Documents if present
+ if SocialStream.activity_forms.include? :document
+ items << {:key => :resources,
+ :name => image_tag("btn/btn_resource.png",:class =>"menu_icon")+t('resource.mine'),
+ :url => "#",
+ :options => {:link => {:id => "resources_menu"}},
+ :items => [
+ {:key => :resources_documents,:name => image_tag("btn/btn_documents.png")+t('document.title'),:url => documents_path},
+ {:key => :resources_pictures,:name => image_tag("btn/btn_gallery.png")+t('picture.title'),:url => pictures_path},
+ {:key => :resources_videos,:name => image_tag("btn/btn_video.png")+t('video.title'),:url => videos_path},
+ {:key => :resources_audios,:name => image_tag("btn/btn_audio.png")+t('audio.title'),:url => audios_path}
+ ]}
+ end
- #Documents if present
- if SocialStream.activity_forms.include? :document
- items << {:key => :resources,
- :name => image_tag("btn/btn_resource.png",:class =>"menu_icon")+t('resource.mine'),
+ #Contacts
+ items << {:key => :contacts,
+ :name => image_tag("btn/btn_friend.png")+t('contact.other'),
:url => "#",
- :options => {:link => {:id => "resources_menu"}},
+ :options => {:link => {:id => "contacts_menu"}},
:items => [
- {:key => :resources_documents,:name => image_tag("btn/btn_documents.png")+t('document.title'),:url => documents_path},
- {:key => :resources_pictures,:name => image_tag("btn/btn_gallery.png")+t('picture.title'),:url => pictures_path},
- {:key => :resources_videos,:name => image_tag("btn/btn_video.png")+t('video.title'),:url => videos_path},
- {:key => :resources_audios,:name => image_tag("btn/btn_audio.png")+t('audio.title'),:url => audios_path}
+ {:key => :invitations, :name => image_tag("btn/btn_friend.png")+t('contact.addresbook'), :url => contacts_path},
+ {:key => :invitations, :name => image_tag("btn/btn_invitation.png")+t('invitation.toolbar'), :url => new_invitation_path},
+ {:key => :invitations, :name => image_tag("btn/btn_friend.png")+t('contact.pending.other'), :url => contacts_path(:pending=>true)}
]}
- end
- #Contacts
- relation_items = [{:key => :invitations, :name => image_tag("btn/btn_invitation.png")+t('invitation.other'), :url => new_invitation_path}]
- current_subject.relation_customs.sort.each do |r|
- relation_items << {:key => r.name + "_menu",
- :name => image_tag("btn/btn_friend.png") + r.name,
- :url => contacts_path(:relation => r.id)}
- end
- items << {:key => :contacts,
- :name => image_tag("btn/btn_friend.png")+t('contact.other'),
- :url => "#",
- :options => {:link => {:id => "contacts_menu"}},
- :items => relation_items}
+ #Subjects
+ items << {:key => :groups,
+ :name => image_tag("btn/btn_group.png")+t('group.other'),
+ :url => "#",
+ :options => {:link => {:id => "groups_menu"}},
+ :items => [{:key => :new_group ,:name => image_tag("btn/btn_group.png")+t('group.new.action'),:url => new_group_path('group' => { '_founder' => current_subject.slug })}]
+ }
- #Subjects
- items << {:key => :groups,
- :name => image_tag("btn/btn_group.png")+t('group.other'),
- :url => "#",
- :options => {:link => {:id => "groups_menu"}},
- :items => [{:key => :new_group ,:name => image_tag("btn/btn_group.png")+t('group.new.action'),:url => new_group_path('group' => { '_founder' => current_subject.slug })}]
- }
+ render_items items
+ end
- render_items items
- end
+ #Prints the default profile toolbar menu
+ def default_profile_toolbar_menu(subject = current_subject)
+ items = Array.new
+ #Information button
+ items << {:key => :subject_info,
+ :name => image_tag("btn/btn_edit.png")+t('menu.information'),
+ :url => [subject, :profile]
+ }
- #Prints the default profile toolbar menu
- def default_profile_toolbar_menu(subject = current_subject)
- items = Array.new
- #Information button
- items << {:key => :subject_info,
- :name => image_tag("btn/btn_edit.png")+t('menu.information'),
- :url => [subject, :profile]
- }
+ if subject!=current_subject
+ #Like button
+ items << {:key => :like_button,
+ :name => link_like_params(subject)[0],
+ :url => link_like_params(subject)[1],
+ :options => {:link => link_like_params(subject)[2]}}
- if subject!=current_subject
- #Like button
- items << {:key => :like_button,
- :name => link_like_params(subject)[0],
- :url => link_like_params(subject)[1],
- :options => {:link => link_like_params(subject)[2]}}
-
- if user_signed_in?
- #Relation button
- items << {:key => :subject_relation,
- :name => image_tag("btn/btn_friend.png") + contact_status(subject),
- :url => edit_contact_path(current_subject.contact_to!(subject))
- }
- #Send message button
- items << {:key => :send_message,
- :name => image_tag("btn/btn_send.png")+t('message.send'),
- :url => new_message_path(:receiver => subject.slug)
- }
+ if user_signed_in?
+ #Relation button
+ items << {:key => :subject_relation,
+ :name => image_tag("btn/btn_friend.png") + contact_status(subject),
+ :url => edit_contact_path(current_subject.contact_to!(subject))
+ }
+ #Send message button
+ items << {:key => :send_message,
+ :name => image_tag("btn/btn_send.png")+t('message.send'),
+ :url => new_message_path(:receiver => subject.slug)
+ }
+ end
end
- end
- #Documents if present
- if SocialStream.activity_forms.include? :document
- if subject == current_subject
- resources_label = t('resource.mine')
- else
- resources_label = t('resource.title')
+ #Documents if present
+ if SocialStream.activity_forms.include? :document
+ if subject == current_subject
+ resources_label = t('resource.mine')
+ else
+ resources_label = t('resource.title')
+ end
+ items << {:key => :resources,
+ :name => image_tag("btn/btn_resource.png",:class =>"menu_icon")+resources_label,
+ :url => "#",
+ :options => {:link => {:id => "resources_menu"}},
+ :items => [
+ {:key => :resources_documents,:name => image_tag("btn/btn_documents.png")+t('document.title'),:url => documents_path},
+ {:key => :resources_pictures,:name => image_tag("btn/btn_gallery.png")+t('picture.title'),:url => pictures_path},
+ {:key => :resources_videos,:name => image_tag("btn/btn_video.png")+t('video.title'),:url => videos_path},
+ {:key => :resources_audios,:name => image_tag("btn/btn_audio.png")+t('audio.title'),:url => audios_path}
+ ]}
end
- items << {:key => :resources,
- :name => image_tag("btn/btn_resource.png",:class =>"menu_icon")+resources_label,
- :url => "#",
- :options => {:link => {:id => "resources_menu"}},
- :items => [
- {:key => :resources_documents,:name => image_tag("btn/btn_documents.png")+t('document.title'),:url => documents_path},
- {:key => :resources_pictures,:name => image_tag("btn/btn_gallery.png")+t('picture.title'),:url => pictures_path},
- {:key => :resources_videos,:name => image_tag("btn/btn_video.png")+t('video.title'),:url => videos_path},
- {:key => :resources_audios,:name => image_tag("btn/btn_audio.png")+t('audio.title'),:url => audios_path}
- ]}
+ render_items items
end
- render_items items
- end
end
end
View
2  social_stream-base.gemspec
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
# OAuth provider
s.add_runtime_dependency('oauth-plugin','~> 0.4.0.pre1')
# Messages
- s.add_runtime_dependency('mailboxer','~> 0.2.5')
+ s.add_runtime_dependency('mailboxer','~> 0.3.2')
# Avatar manipulation
s.add_runtime_dependency('rmagick','~> 2.13.1')
# Tagging
View
2  spec/controllers/contacts_controller_spec.rb
@@ -63,7 +63,7 @@
contact = @user.contact_to!(group)
# Initialize inverse contact
contact.inverse!
- relations = [ @user.relation_custom('friend'), @user.relation_custom('partner') ]
+ relations = [ @user.relation_custom('friend'), @user.relation_custom('colleague') ]
put :update, :id => contact.id,
View
3  spec/controllers/permissions_controller_spec.rb
@@ -14,8 +14,7 @@
context "with an existing relation" do
before do
- @sphere = Factory(:sphere, :actor_id => @user.actor_id)
- @relation = Factory(:relation_custom, :sphere_id => @sphere.id)
+ @relation = Factory(:relation_custom, :actor_id => @user.actor_id)
end
it "should render index" do
View
4 spec/controllers/posts_controller_spec.rb
@@ -76,10 +76,10 @@
@group = Factory(:member, :contact => Factory(:group_contact, :receiver => @user.actor)).sender_subject
end
- describe "with public relation" do
+ describe "with member relation" do
before do
contact = @user.contact_to!(@group)
- relation = @group.relation_public
+ relation = @group.relation_custom('member')
model_assigned_to contact, relation
@current_model = Factory(:post, :_contact_id => contact.id, :_relation_ids => Array(relation.id))
View
131 spec/controllers/relation_customs_controller_spec.rb
@@ -1,103 +1,112 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Relation::CustomsController do
- include SocialStream::TestHelpers::Controllers
-
render_views
- describe "when authenticated" do
- before do
- @user = Factory(:user)
+ describe "when Anonymous" do
+ context "faking a new relation" do
+ it "should not create" do
+ post :create, :custom => Factory.attributes_for(:relation_custom)
- sign_in @user
+ response.should redirect_to(:new_user_session)
+ end
end
- context "with an existing sphere" do
+ context "an existing relation" do
before do
- @sphere = Factory(:sphere, :actor_id => @user.actor_id)
+ @relation = Factory(:relation_custom)
end
- it "should render index" do
- get :index, :sphere_id => @sphere.id, :format => "js"
+ it "should not update" do
+ put :update, :id => @relation.to_param, :custom => { :name => 'Testing' }
- response.should be_success
+ assigns(:custom).should be_blank
+ response.should redirect_to(:new_user_session)
end
- context "a new relation" do
- it "should be created" do
- count = Relation::Custom.count
+ it "should not destroy" do
+ count = Relation.count
+ begin
+ delete :destroy, :id => @relation.to_param
+ rescue CanCan::AccessDenied
+ end
- post :create, :custom => { :name => "Test create", :sphere_id => @sphere.id }, :format => 'js'
+ relation = assigns(:custom)
- relation = assigns(:custom)
+ Relation.count.should eq(count)
+ end
- Relation::Custom.count.should eq(count + 1)
- relation.should be_valid
- response.should be_success
- end
+ end
+ end
- end
- context "a existing own relation" do
- before do
- @relation = Factory(:relation_custom, :sphere_id => @sphere.id)
- @relation.reload
- end
+ describe "when authenticated" do
+ before do
+ @user = Factory(:user)
+
+ sign_in @user
+ end
- it "should allow updating" do
- attrs = { :name => "Updating own" }
+ it "should render index" do
+ get :index
- put :update, :id => @relation.to_param, :relation_custom => attrs, :format => 'js'
+ response.should be_success
+ end
- relation = assigns(:custom)
+ context "a new own relation" do
+ it "should be created" do
+ count = Relation::Custom.count
-# relation.should_receive(:update_attributes).with(attrs)
- relation.should be_valid
- response.should be_success
- end
+ post :create, :custom => { :name => "Test create", :actor_id => @user.actor_id }, :format => 'js'
+
+ relation = assigns(:custom)
- it "should allow destroying" do
- pending "Delete relations"
+ Relation::Custom.count.should eq(count + 1)
+ relation.should be_valid
+ response.should be_success
+ end
+ end
- count = Relation::Custom.count
+ context "a new fake relation" do
+ it "should not be created" do
+ count = Relation.count
+ begin
+ post :create, :custom => Factory.attributes_for(:relation_custom)
- delete :destroy, :id => @relation.to_param, :format => :js
+ assert false
+ rescue CanCan::AccessDenied
+ assigns(:custom).should be_new_record
- Relation::Custom.count.should eq(count - 1)
+ Relation.count.should eq(count)
end
end
-
end
- context "with a fake sphere" do
+ context "a existing own relation" do
before do
- @sphere = Factory(:sphere)
+ @relation = Factory(:relation_custom, :actor => @user.actor)
end
- it "should not render index" do
- begin
- get :index, :sphere_id => @sphere.id, :format => "js"
+ it "should allow updating" do
+ attrs = { :name => "Updating own" }
- # Should not get here
- assert false
- rescue CanCan::AccessDenied
- assigns(:customs).should be_blank
- end
+ put :update, :id => @relation.to_param, :relation_custom => attrs, :format => 'js'
+
+ relation = assigns(:custom)
+
+# relation.should_receive(:update_attributes).with(attrs)
+ relation.should be_valid
+ response.should be_success
end
- context "a new relation" do
- it "should belong to user" do
- count = Relation::Custom.count
+ it "should allow destroying" do
+ pending "Delete relations"
- begin
- post :create, :relation_custom => { :name => "Test create", :sphere_id => @sphere.id }, :format => 'js'
+ count = Relation::Custom.count
- assert false
- rescue CanCan::AccessDenied
+ delete :destroy, :id => @relation.to_param, :format => :js
- Relation::Custom.count.should eq(count)
- end
- end
+ Relation::Custom.count.should eq(count - 1)
end
end
@@ -126,8 +135,6 @@
end
end
end
-
-
end
end
View
116 spec/controllers/spheres_controller_spec.rb
@@ -1,116 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-
-describe SpheresController do
- include SocialStream::TestHelpers::Controllers
-
- render_views
-
- describe "when Anonymous" do
- context "faking a new sphere" do
- before do
- model_attributes[:actor_id] = Factory(:user).actor_id
- end
-
- it "should not create" do
- post :create, attributes
-
- response.should redirect_to(:new_user_session)
- end
- end
-
- context "an existing sphere" do
- before do
- @current_model = Factory(:sphere)
- end
-
- it "should not update" do
- put :update, updating_attributes
-
- assigns(:sphere).should be_blank
- response.should redirect_to(:new_user_session)
- end
-
- it_should_behave_like "Deny Destroying"
- end
- end
-