social_stream-base 0.6.3 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. data/app/assets/stylesheets/base.css +1 -0
  2. data/app/assets/stylesheets/contacts.css +2 -1
  3. data/app/assets/stylesheets/fcbkComplete.css +1 -1
  4. data/app/assets/stylesheets/header.css +2 -2
  5. data/app/assets/stylesheets/messages.css +3 -3
  6. data/app/assets/stylesheets/{spheres.css → relation_customs.css} +0 -0
  7. data/app/controllers/contacts_controller.rb +9 -4
  8. data/app/controllers/messages_controller.rb +69 -68
  9. data/app/controllers/relation/customs_controller.rb +1 -11
  10. data/app/helpers/activities_helper.rb +1 -2
  11. data/app/helpers/notifications_helper.rb +3 -2
  12. data/app/helpers/permissions_helper.rb +5 -5
  13. data/app/helpers/subjects_helper.rb +9 -0
  14. data/app/helpers/toolbar_helper.rb +10 -89
  15. data/app/models/activity.rb +39 -15
  16. data/app/models/actor.rb +30 -71
  17. data/app/models/contact.rb +15 -0
  18. data/app/models/group.rb +1 -3
  19. data/app/models/permission.rb +9 -72
  20. data/app/models/profile.rb +7 -2
  21. data/app/models/relation/custom.rb +6 -33
  22. data/app/models/relation.rb +15 -39
  23. data/app/models/user.rb +5 -1
  24. data/app/views/activities/_new.html.erb +5 -2
  25. data/app/views/activities/_options.html.erb +2 -2
  26. data/app/views/activities/_walls.html.erb +1 -1
  27. data/app/views/contacts/_contact.html.erb +3 -3
  28. data/app/views/contacts/_form.html.erb +14 -20
  29. data/app/views/contacts/_index.html.erb +1 -1
  30. data/app/views/contacts/_suggestions.html.erb +1 -13
  31. data/app/views/contacts/destroy.js.erb +6 -0
  32. data/app/views/contacts/edit.html.erb +1 -1
  33. data/app/views/conversations/_conversation.html.erb +1 -1
  34. data/app/views/groups/_group.html.erb +1 -1
  35. data/app/views/groups/_index.html.erb +1 -1
  36. data/app/views/groups/show.html.erb +1 -1
  37. data/app/views/invitation_mailer/send_invitation.html.erb +17 -6
  38. data/app/views/invitation_mailer/send_invitation.text.erb +7 -2
  39. data/app/views/layouts/_representation.html.erb +10 -6
  40. data/app/views/layouts/_settings.html.erb +1 -1
  41. data/app/views/messages/_message.html.erb +1 -1
  42. data/app/views/messages/new.html.erb +1 -1
  43. data/app/views/notifications/_notification.html.erb +7 -3
  44. data/app/views/objects/_new.html.erb +0 -6
  45. data/app/views/profiles/edit.html.erb +5 -9
  46. data/app/views/relation/customs/_form.html.erb +2 -2
  47. data/app/views/{spheres → relation/customs}/_jquery.erb +0 -58
  48. data/app/views/relation/customs/_list.html.erb +9 -26
  49. data/app/views/relation/customs/create.js.erb +2 -3
  50. data/app/views/relation/customs/index.html.erb +67 -0
  51. data/app/views/users/_index.html.erb +1 -1
  52. data/app/views/users/show.html.erb +1 -1
  53. data/config/locales/en.yml +16 -41
  54. data/config/routes.rb +1 -6
  55. data/db/migrate/20110705103202_empty_ties_count.rb +4 -0
  56. data/db/migrate/20110712090343_remove_spheres.rb +30 -0
  57. data/db/migrate/20110712142140_remove_permission_function.rb +26 -0
  58. data/lib/generators/social_stream/base/install_generator.rb +4 -0
  59. data/lib/generators/social_stream/base/templates/mailboxer_custom.rb +13 -0
  60. data/lib/generators/social_stream/base/templates/navigation.rb +4 -0
  61. data/lib/generators/social_stream/base/templates/relations.yml +14 -20
  62. data/lib/social_stream/ability.rb +1 -2
  63. data/lib/social_stream/base/version.rb +1 -1
  64. data/lib/social_stream/migration_finder.rb +19 -0
  65. data/lib/social_stream/toolbar_config.rb +113 -0
  66. data/lib/social_stream-base.rb +1 -0
  67. data/lib/tasks/db/populate.rake +1 -1
  68. data/social_stream-base.gemspec +4 -2
  69. data/spec/controllers/contacts_controller_spec.rb +1 -1
  70. data/spec/controllers/permissions_controller_spec.rb +1 -2
  71. data/spec/controllers/posts_controller_spec.rb +2 -2
  72. data/spec/controllers/relation_customs_controller_spec.rb +69 -62
  73. data/spec/dummy/config/database.yml +7 -0
  74. data/spec/dummy/config/relations.yml +14 -20
  75. data/spec/factories/relation_custom.rb +1 -1
  76. data/spec/factories/tie.rb +4 -0
  77. data/spec/models/activity_spec.rb +11 -2
  78. data/spec/models/user_spec.rb +68 -9
  79. data/spec/spec_helper.rb +0 -3
  80. data/spec/support/db.rb +9 -0
  81. data/spec/support/migrations.rb +3 -12
  82. metadata +19 -25
  83. data/app/controllers/spheres_controller.rb +0 -12
  84. data/app/models/sphere.rb +0 -9
  85. data/app/views/relation/customs/_index.html.erb +0 -28
  86. data/app/views/relation/customs/index.js.erb +0 -2
  87. data/app/views/spheres/_form.html.erb +0 -28
  88. data/app/views/spheres/_list.html.erb +0 -19
  89. data/app/views/spheres/create.js.erb +0 -20
  90. data/app/views/spheres/index.html.erb +0 -74
  91. data/spec/controllers/spheres_controller_spec.rb +0 -116
  92. data/spec/factories/sphere.rb +0 -5
  93. data/spec/models/relation_custom_spec.rb +0 -14
@@ -48,6 +48,7 @@ input.other_blue{ background:#497FC1; border:0px; cursor:pointer; font-size:1.0
48
48
  margin-right:4px; color:white; padding:1px;}
49
49
  textarea.new_contact_text_area{ width:100%; height: 100px; color: #2A3890;}
50
50
  .colum_field_title{ text-align: center; }
51
+ .needed{color:#D8000C;font-weight: normal;}
51
52
  .select_relations select{ font-size: 12px; color: white; background-color:#1F4A75;}
52
53
 
53
54
  /************ Forms - Buttons SECTION ***************************/
@@ -18,7 +18,8 @@ div.sphere-name {
18
18
  color: #1F4A75;
19
19
  }
20
20
 
21
- #contact-new {
21
+ #relation-new {
22
+ margin-left: 20px;
22
23
  font-weight: bold;
23
24
  }
24
25
 
@@ -1,5 +1,5 @@
1
1
  /* TextboxList sample CSS */
2
- ul.holder { margin: 0; border: 1px solid #BDC7D8; overflow: hidden; height: auto !important; height: 1%; padding: 4px 5px 0; }
2
+ ul.holder { margin: 0; border: 1px solid #BDC7D8; overflow: hidden; height: auto !important; height: 1%; padding: 5px; }
3
3
  *:first-child+html ul.holder { padding-bottom: 2px; } * html ul.holder { padding-bottom: 2px; } /* ie7 and below */
4
4
  ul.holder li { float: left; list-style-type: none; /*margin: 0 5px 4px 0;*/ white-space:nowrap;}
5
5
  ul.holder li.bit-box, ul.holder li.bit-input input { font: 11px "Lucida Grande", "Verdana"; }
@@ -52,7 +52,7 @@ li.btn_menu_browse{background: transparent url("btn/btn_browse.png") no-repeat l
52
52
 
53
53
  #account, #representation_li,#current_user_info, #representations_menu, #account_menu, #settings_menu {display:inline-block;vertical-align: top; height:22px; color:#FFF;}
54
54
  #representation_li{margin-left:10px;}
55
-
55
+ #representation_text{display:inline;margin-left:2px;color:#FFF;}
56
56
  li.btn_menu_representation{}
57
57
  #menu_home ul li.pipe,#menu_account ul li.pipe{padding:0px 3px 0px 3px; margin:0px;}
58
58
  .menu_white{display:inline-block; color:#fff;}
@@ -79,7 +79,7 @@ li.btn_menu_representation{}
79
79
  .sf-menu ul {
80
80
  position: absolute;
81
81
  top: -999em;
82
- width: 10em; /* left offset of submenus need to match (see below) */
82
+ width: 17em; /* left offset of submenus need to match (see below) */
83
83
  }
84
84
  .sf-menu ul li {
85
85
  width: 100%;
@@ -91,13 +91,13 @@
91
91
  }
92
92
  .conversations .conversation .content_left {
93
93
  float:left;
94
- width:20%;
95
- padding: 7px 0px 0px 0px;
94
+ width:25%;
95
+ padding: 0px;
96
96
  }
97
97
  .conversations .conversation .content_right {
98
98
  float:left;
99
99
  width:55%;
100
- padding: 7px 0px 0px 0px;
100
+ padding: 0px;
101
101
  }
102
102
  .conversations .conversation .sender_photo {
103
103
  float:left;
@@ -13,7 +13,7 @@ class ContactsController < ApplicationController
13
13
  respond_to do |format|
14
14
  format.html { @contacts = Kaminari.paginate_array(@contacts).page(params[:page]).per(10) }
15
15
  format.js { @contacts = Kaminari.paginate_array(@contacts).page(params[:page]).per(10) }
16
- format.json { render :text => @contacts.map{ |c| { 'key' => c.actor_id.to_s, 'value' => c.name } }.to_json }
16
+ format.json { render :text => @contacts.map{ |c| { 'key' => c.actor_id.to_s, 'value' => self.class.helpers.truncate_name(c.name) } }.to_json }
17
17
  end
18
18
  end
19
19
 
@@ -36,8 +36,13 @@ class ContactsController < ApplicationController
36
36
  end
37
37
  end
38
38
 
39
- def suggestion
40
- @contact = current_subject.suggestion
41
- render :layout => false
39
+ def destroy
40
+ @contact = current_subject.sent_contacts.find params[:id]
41
+
42
+ @contact.relation_ids = [current_subject.relation_public.id]
43
+
44
+ respond_to do |format|
45
+ format.js
46
+ end
42
47
  end
43
48
  end
@@ -1,86 +1,87 @@
1
1
  class MessagesController < ApplicationController
2
2
 
3
3
  before_filter :authenticate_user!
4
- before_filter :get_mailbox, :get_box, :get_actor
5
-
6
- def index
7
- redirect_to conversations_path(:box => @box)
8
- end
9
- # GET /messages/1
10
- # GET /messages/1.xml
11
- def show
12
- if @message = Message.find_by_id(params[:id]) and @conversation = @message.conversation
13
- if @conversation.is_participant?(@actor)
14
- redirect_to conversation_path(@conversation, :box => @box, :anchor => "message_" + @message.id.to_s)
15
- return
16
- end
17
- end
18
- end
4
+ before_filter :get_mailbox, :get_box, :get_actor
5
+ def index
6
+ redirect_to conversations_path(:box => @box)
7
+ end
19
8
 
20
- # GET /messages/new
21
- # GET /messages/new.xml
22
- def new
23
- if params[:receiver].present?
24
- @recipient = Actor.find_by_slug(params[:receiver])
25
- return if @recipient.nil?
26
- @recipient = nil if Actor.normalize(@recipient)==Actor.normalize(current_subject)
27
- end
28
- end
9
+ # GET /messages/1
10
+ # GET /messages/1.xml
11
+ def show
12
+ if @message = Message.find_by_id(params[:id]) and @conversation = @message.conversation
13
+ if @conversation.is_participant?(@actor)
14
+ redirect_to conversation_path(@conversation, :box => @box, :anchor => "message_" + @message.id.to_s)
15
+ return
16
+ end
17
+ end
18
+ redirect_to conversations_path(:box => @box)
19
+ end
29
20
 
30
- # GET /messages/1/edit
31
- def edit
21
+ # GET /messages/new
22
+ # GET /messages/new.xml
23
+ def new
24
+ if params[:receiver].present?
25
+ @recipient = Actor.find_by_slug(params[:receiver])
26
+ return if @recipient.nil?
27
+ @recipient = nil if Actor.normalize(@recipient)==Actor.normalize(current_subject)
28
+ end
29
+ end
32
30
 
33
- end
31
+ # GET /messages/1/edit
32
+ def edit
34
33
 
35
- # POST /messages
36
- # POST /messages.xml
37
- def create
38
- @recipients = Array.new
39
- if params[:_recipients].present?
40
- params[:_recipients].each do |recp_id|
41
- recp = Actor.find_by_id(recp_id)
42
- next if recp.nil?
43
- @recipients << recp
44
- end
45
- end
46
- @receipt = @actor.send_message(@recipients, params[:body], params[:subject])
47
- if (@receipt.errors.blank?)
48
- @conversation = @receipt.conversation
34
+ end
35
+
36
+ # POST /messages
37
+ # POST /messages.xml
38
+ def create
39
+ @recipients = Array.new
40
+ if params[:_recipients].present?
41
+ params[:_recipients].each do |recp_id|
42
+ recp = Actor.find_by_id(recp_id)
43
+ next if recp.nil?
44
+ @recipients << recp
45
+ end
46
+ end
47
+ @receipt = @actor.send_message(@recipients, params[:body], params[:subject])
48
+ if (@receipt.errors.blank?)
49
+ @conversation = @receipt.conversation
49
50
  flash[:success]="Your message was sent"
50
- redirect_to conversation_path(@conversation, :box => :sentbox)
51
- else
52
- render :action => :new
53
- end
54
- end
51
+ redirect_to conversation_path(@conversation, :box => :sentbox)
52
+ else
53
+ render :action => :new
54
+ end
55
+ end
55
56
 
56
- # PUT /messages/1
57
- # PUT /messages/1.xml
58
- def update
57
+ # PUT /messages/1
58
+ # PUT /messages/1.xml
59
+ def update
59
60
 
60
- end
61
+ end
61
62
 
62
- # DELETE /messages/1
63
- # DELETE /messages/1.xml
64
- def destroy
63
+ # DELETE /messages/1
64
+ # DELETE /messages/1.xml
65
+ def destroy
65
66
 
66
- end
67
+ end
67
68
 
68
- private
69
+ private
69
70
 
70
- def get_mailbox
71
- @mailbox = current_subject.mailbox
72
- end
71
+ def get_mailbox
72
+ @mailbox = current_subject.mailbox
73
+ end
73
74
 
74
- def get_actor
75
- @actor = Actor.normalize(current_subject)
76
- end
75
+ def get_actor
76
+ @actor = Actor.normalize(current_subject)
77
+ end
77
78
 
78
- def get_box
79
- if params[:box].blank? or !["inbox","sentbox","trash"].include?params[:box]
80
- @box = "inbox"
81
- return
82
- end
83
- @box = params[:box]
84
- end
79
+ def get_box
80
+ if params[:box].blank? or !["inbox","sentbox","trash"].include?params[:box]
81
+ @box = "inbox"
82
+ return
83
+ end
84
+ @box = params[:box]
85
+ end
85
86
 
86
87
  end
@@ -2,15 +2,5 @@ class Relation::CustomsController < InheritedResources::Base
2
2
  before_filter :authenticate_user!
3
3
  load_and_authorize_resource :class => Relation::Custom
4
4
 
5
- respond_to :js
6
-
7
- belongs_to :sphere, :optional => true
8
-
9
- def index
10
- # Must authorize index, because Cancan does not filter collection with conditions.
11
- # See https://github.com/ryanb/cancan/wiki/checking-abilities
12
- authorize! :read, parent.customs.new
13
-
14
- index!
15
- end
5
+ respond_to :html, :js
16
6
  end
@@ -31,7 +31,6 @@ module ActivitiesHelper
31
31
  def new_activity(receiver)
32
32
  return Activity.new unless user_signed_in?
33
33
 
34
- Activity.new :contact_id => current_subject.contact_to!(receiver).id,
35
- :relation_ids => current_subject.activity_relations(receiver, :from => :receiver).map(&:id)
34
+ Activity.new :contact_id => current_subject.contact_to!(receiver).id
36
35
  end
37
36
  end
@@ -1,8 +1,9 @@
1
1
  module NotificationsHelper
2
+ include SubjectsHelper, ActionView::Helpers::TextHelper
2
3
  def decode_notification notification_text, activity
3
4
  return if activity.nil?
4
- notification_text = notification_text.gsub(/\%\{sender\}/, link_to(activity.sender.name, activity.sender.subject))
5
- notification_text = notification_text.gsub(/\%\{sender.name\}/,activity.sender.name)
5
+ notification_text = notification_text.gsub(/\%\{sender\}/, link_to(truncate_name(activity.sender.name), activity.sender.subject))
6
+ notification_text = notification_text.gsub(/\%\{sender.name\}/,truncate_name(activity.sender.name))
6
7
 
7
8
  if activity.direct_object.present?
8
9
  object = activity.direct_object
@@ -1,16 +1,16 @@
1
1
  module PermissionsHelper
2
2
  DEFAULT_PERMISSIONS =
3
3
  [
4
- [ "read", "activity", "same_and_lower_levels" ],
5
- [ "create", "activity", "same_level" ],
6
- [ "follow", nil, nil],
7
- [ "represent", nil, nil]
4
+ [ "read", "activity" ],
5
+ [ "create", "activity" ],
6
+ [ "follow", nil ],
7
+ [ "represent", nil ]
8
8
  ]
9
9
 
10
10
  def default_permissions
11
11
  @default_permissions ||=
12
12
  DEFAULT_PERMISSIONS.map{ |p|
13
- Permission.find_or_create_by_action_and_object_and_function *p
13
+ Permission.find_or_create_by_action_and_object *p
14
14
  }
15
15
  end
16
16
  end
@@ -1,6 +1,15 @@
1
1
  module SubjectsHelper
2
+
3
+ NAME_MAX_LENGHT = 30
4
+
2
5
  # Return a link to this subject with the name
3
6
  def link_name(subject, options = {})
4
7
  link_to subject.name, subject, options
5
8
  end
9
+
10
+ # Return the truncated name
11
+ def truncate_name(name, options={})
12
+ options = {:length => NAME_MAX_LENGHT, :separator => ' '}.merge options
13
+ truncate(name,options)
14
+ end
6
15
  end
@@ -80,102 +80,23 @@ module ToolbarHelper
80
80
  @menu_options ||= {}
81
81
  end
82
82
 
83
- def default_toolbar_menu
84
- home_toolbar_menu
85
- end
86
-
83
+ #Prints the home toolbar menu.
87
84
  def home_toolbar_menu
88
- items = Array.new
89
- #Notifications
90
- items << {:key => :notifications,
91
- :name => image_tag("btn/btn_notification.png")+t('notification.other')+' ('+ current_subject.mailbox.notifications.not_trashed.unread.count.to_s+')',
92
- :url => notifications_path,
93
- :options => {:link => {:id => "notifications_menu"}}}
94
-
95
- #Messages
96
- items << {:key => :messages,
97
- :name => image_tag("btn/new.png")+t('message.other')+' (' + current_subject.mailbox.inbox(:unread => true).count.to_s + ')',
98
- :url => "#",
99
- :options => {:link => {:id => "messages_menu"}},
100
- :items => [
101
- {:key => :message_new, :name => image_tag("btn/message_new.png")+ t('message.new'), :url => new_message_path},
102
- {:key => :message_inbox, :name => image_tag("btn/message_inbox.png")+t('message.inbox')+' (' + current_subject.mailbox.inbox(:unread => true).count.to_s + ')',
103
- :url => conversations_path, :options => {:link =>{:remote=> true}}},
104
- {:key => :message_sentbox, :name => image_tag("btn/message_sentbox.png")+t('message.sentbox'), :url => conversations_path(:box => :sentbox), :remote=> true},
105
- {:key => :message_trash, :name => image_tag("btn/message_trash.png")+t('message.trash'), :url => conversations_path(:box => :trash)}
106
- ]}
107
-
108
- #Documents if present
109
- if SocialStream.activity_forms.include? :document
110
- items << {:key => :resources,
111
- :name => image_tag("btn/btn_resource.png",:class =>"menu_icon")+t('resource.title'),
112
- :url => "#",
113
- :options => {:link => {:id => "resources_menu"}},
114
- :items => [
115
- {:key => :resources_documents,:name => image_tag("btn/btn_documents.png")+t('document.title'),:url => documents_path},
116
- {:key => :resources_pictores,:name => image_tag("btn/btn_gallery.png")+t('picture.title'),:url => pictures_path},
117
- {:key => :resources_videos,:name => image_tag("btn/btn_video.png")+t('video.title'),:url => videos_path},
118
- {:key => :resources_audios,:name => image_tag("btn/btn_audio.png")+t('audio.title'),:url => audios_path}
119
- ]}
120
- end
121
-
122
- #Contacts
123
- relation_items = [{:key => :invitations, :name => image_tag("btn/btn_invitation.png")+t('invitation.other'), :url => new_invitation_path}]
124
- current_subject.relation_customs.sort.each do |r|
125
- relation_items << {:key => r.name + "_menu",
126
- :name => image_tag("btn/btn_friend.png") + r.name,
127
- :url => contacts_path(:relation => r.id)}
128
- end
129
- items << {:key => :contacts,
130
- :name => image_tag("btn/btn_friend.png")+t('contact.other'),
131
- :url => "#",
132
- :options => {:link => {:id => "contacts_menu"}},
133
- :items => relation_items}
134
-
135
- #Subjects
136
- items << {:key => :groups,
137
- :name => image_tag("btn/btn_group.png")+t('group.other'),
138
- :url => "#",
139
- :options => {:link => {:id => "groups_menu"}},
140
- :items => [{:key => :new_group ,:name => image_tag("btn/btn_group.png")+t('group.new.action'),:url => new_group_path('group' => { '_founder' => current_subject.slug })}]
141
- }
142
-
143
- return render_items items
85
+ default_home_toolbar_menu
144
86
  end
145
87
 
146
- def profile_toolbar_menu(subject = current_subject)
147
- items = Array.new
148
-
149
- if subject!=current_subject
150
- #Like button
151
- items << {:key => :like_button,
152
- :name => link_like_params(subject)[0],
153
- :url => link_like_params(subject)[1],
154
- :options => {:link => link_like_params(subject)[2]}}
155
-
156
- if user_signed_in?
157
- #Relation button
158
- items << {:key => :subject_relation,
159
- :name => image_tag("btn/btn_friend.png") + contact_status(subject),
160
- :url => edit_contact_path(current_subject.contact_to!(subject))
161
- }
162
- #Send message button
163
- items << {:key => :send_message,
164
- :name => image_tag("btn/btn_send.png")+t('message.send'),
165
- :url => new_message_path(:receiver => subject.slug)
166
- }
167
- end
168
- end
169
- #Information button
170
- items << {:key => :subject_info,
171
- :name => image_tag("btn/btn_edit.png")+t('menu.information'),
172
- :url => [subject, :profile]
173
- }
174
- return render_items items
88
+ #Prints the home profile menu.
89
+ def profile_toolbar_menu(subject=current_subject)
90
+ default_profile_toolbar_menu(subject)
175
91
  end
92
+
176
93
 
94
+ #Renders array of navigation items with simple_navigation
177
95
  def render_items(items)
178
96
  menu = render_navigation :items => items
179
97
  return raw menu
180
98
  end
99
+
100
+
101
+ include SocialStream::ToolbarConfig
181
102
  end
@@ -80,7 +80,7 @@ class Activity < ActiveRecord::Base
80
80
  }
81
81
 
82
82
  after_create :increment_like_count
83
- after_destroy :decrement_like_count
83
+ after_destroy :decrement_like_count, :delete_notifications
84
84
 
85
85
 
86
86
  #For now, it should be the last one
@@ -204,35 +204,50 @@ class Activity < ActiveRecord::Base
204
204
  def allow?(subject, action)
205
205
  return false if contact.blank?
206
206
 
207
- # We do not support private activities by now
208
- return false if relation_ids.blank?
209
-
210
207
  case action
211
208
  when 'create'
212
209
  return false if contact.sender_id != Actor.normalize_id(subject)
213
210
 
214
- rels = Relation.normalize(relation_ids)
211
+ if relation_ids.present?
212
+ rels = Relation.normalize(relation_ids)
213
+
214
+ foreign_rels = rels.select{ |r| r.actor_id != contact.sender_id }
215
215
 
216
- foreign_rels = rels.select{ |r| r.actor_id != contact.sender_id }
216
+ # Only posting to own relations
217
+ return true if foreign_rels.blank?
217
218
 
218
- # Only posting to own relations
219
- return true if foreign_rels.blank?
219
+ return Relation.
220
+ allow(subject, action, 'activity', :in => foreign_rels).all.size == foreign_rels.size
221
+ else
222
+ if contact.reflexive?
223
+ return true
224
+ else
225
+ relation_ids = receiver.relation_customs.allow(sender, 'create', 'activity')
226
+
227
+ return relation_ids.present?
228
+ end
229
+ end
220
230
 
221
- return Relation.
222
- allow(subject, action, 'activity', :in => foreign_rels).all.size == foreign_rels.size
223
231
  when 'read'
224
232
  return true if [contact.sender_id, contact.receiver_id].include?(Actor.normalize_id(subject)) || relations.select{ |r| r.is_a?(Relation::Public) }.any?
225
233
  when 'update'
226
234
  return true if contact.sender_id == Actor.normalize_id(subject)
227
235
  when 'destroy'
228
- return true if [contact.sender_id, contact.receiver_id].include?(Actor.normalize_id(subject))
236
+ # We only allow destroying to sender and receiver by now
237
+ return [contact.sender_id, contact.receiver_id].include?(Actor.normalize_id(subject))
229
238
  end
230
239
 
231
240
  Relation.
232
- allow(subject, action, 'activity').
233
- where('relations.id' => relation_ids).
234
- any?
235
- end
241
+ allow?(subject, action, 'activity', :in => self.relation_ids, :public => false)
242
+ end
243
+
244
+ # Can subject delete the object of this activity?
245
+ def delete_object_by?(subject)
246
+ subject.present? &&
247
+ direct_object.present? &&
248
+ ! direct_object.is_a?(Actor) &&
249
+ allow?(subject, 'destroy')
250
+ end
236
251
 
237
252
  private
238
253
 
@@ -258,4 +273,13 @@ class Activity < ActiveRecord::Base
258
273
 
259
274
  direct_activity_object.decrement!(:like_count)
260
275
  end
276
+
277
+ # after_destroy callback
278
+ #
279
+ # Destroy any Notification linked with the activity
280
+ def delete_notifications
281
+ Notification.with_object(self).each do |notification|
282
+ notification.destroy
283
+ end
284
+ end
261
285
  end