Commit 7eb153212ec52864fddce3cc1995af21cfdb9c4e

Authored by Leandro Santos
2 parents 7ec835d6 ae050c75

merging with master

@@ -18,18 +18,18 @@ gem 'exception_notification', '~> 4.0.1' @@ -18,18 +18,18 @@ gem 'exception_notification', '~> 4.0.1'
18 gem 'gettext', '~> 2.2.1', :require => false 18 gem 'gettext', '~> 2.2.1', :require => false
19 gem 'locale', '~> 2.0.5' 19 gem 'locale', '~> 2.0.5'
20 gem 'whenever', :require => false 20 gem 'whenever', :require => false
21 -gem 'grape', '~> 0.11.0' 21 +gem 'eita-jrails', '~> 0.9.5', require: 'jrails'
  22 +
  23 +# API dependencies
  24 +gem 'grape', '~> 0.12'
22 gem 'grape-entity' 25 gem 'grape-entity'
23 -gem 'grape-swagger'  
24 -gem 'grape_logging'  
25 -gem 'api-pagination', '~> 4.1.1' 26 +#FIXME Get the Grape Loggin from master yo solve this issue https://github.com/intridea/grape/issues/1059
  27 +#We have to remove this commit referenve code when update the next release of grape_logging. Actualy we are using (1.1.2)
  28 +gem 'grape_logging', :git => 'https://github.com/aceunreal/grape_logging.git', :ref => '100091b'
26 gem 'rack-cors' 29 gem 'rack-cors'
27 gem 'rack-contrib' 30 gem 'rack-contrib'
28 -#gem 'grape-swagger-rails'  
29 31
30 -# FIXME list here all actual dependencies (i.e. the ones in debian/control),  
31 -# with their GEM names (not the Debian package names)  
32 -gem 'eita-jrails', '~> 0.9.5', require: 'jrails' 32 +gem 'api-pagination', '~> 4.1.1'
33 33
34 # asset pipeline 34 # asset pipeline
35 gem 'uglifier', '>= 1.0.3' 35 gem 'uglifier', '>= 1.0.3'
Gemfile.lock
@@ -1,269 +0,0 @@ @@ -1,269 +0,0 @@
1 -GEM  
2 - remote: https://rubygems.org/  
3 - specs:  
4 - RedCloth (4.2.9)  
5 - actionmailer (3.2.22)  
6 - actionpack (= 3.2.22)  
7 - mail (~> 2.5.4)  
8 - actionpack (3.2.22)  
9 - activemodel (= 3.2.22)  
10 - activesupport (= 3.2.22)  
11 - builder (~> 3.0.0)  
12 - erubis (~> 2.7.0)  
13 - journey (~> 1.0.4)  
14 - rack (~> 1.4.5)  
15 - rack-cache (~> 1.2)  
16 - rack-test (~> 0.6.1)  
17 - sprockets (~> 2.2.1)  
18 - activemodel (3.2.22)  
19 - activesupport (= 3.2.22)  
20 - builder (~> 3.0.0)  
21 - activerecord (3.2.22)  
22 - activemodel (= 3.2.22)  
23 - activesupport (= 3.2.22)  
24 - arel (~> 3.0.2)  
25 - tzinfo (~> 0.3.29)  
26 - activeresource (3.2.22)  
27 - activemodel (= 3.2.22)  
28 - activesupport (= 3.2.22)  
29 - activesupport (3.2.22)  
30 - i18n (~> 0.6, >= 0.6.4)  
31 - multi_json (~> 1.0)  
32 - acts-as-taggable-on (3.4.4)  
33 - activerecord (>= 3.2, < 5)  
34 - api-pagination (4.1.1)  
35 - arel (3.0.3)  
36 - axiom-types (0.1.1)  
37 - descendants_tracker (~> 0.0.4)  
38 - ice_nine (~> 0.11.0)  
39 - thread_safe (~> 0.3, >= 0.3.1)  
40 - builder (3.0.4)  
41 - capybara (2.1.0)  
42 - mime-types (>= 1.16)  
43 - nokogiri (>= 1.3.3)  
44 - rack (>= 1.0.0)  
45 - rack-test (>= 0.5.4)  
46 - xpath (~> 2.0)  
47 - childprocess (0.5.6)  
48 - ffi (~> 1.0, >= 1.0.11)  
49 - chronic (0.10.2)  
50 - coercible (1.0.0)  
51 - descendants_tracker (~> 0.0.1)  
52 - cucumber (1.0.6)  
53 - builder (>= 2.1.2)  
54 - diff-lcs (>= 1.1.2)  
55 - gherkin (~> 2.4.18)  
56 - json (>= 1.4.6)  
57 - term-ansicolor (>= 1.0.6)  
58 - cucumber-rails (1.0.6)  
59 - capybara (>= 1.1.1)  
60 - cucumber (>= 1.0.6)  
61 - nokogiri (>= 1.5.0)  
62 - daemons (1.1.9)  
63 - dalli (2.7.4)  
64 - database_cleaner (1.2.0)  
65 - descendants_tracker (0.0.4)  
66 - thread_safe (~> 0.3, >= 0.3.1)  
67 - diff-lcs (1.2.5)  
68 - eita-jrails (0.9.5)  
69 - actionpack (~> 3.2, >= 3.1.0)  
70 - activesupport (~> 3.2, >= 3.0.0)  
71 - equalizer (0.0.11)  
72 - erubis (2.7.0)  
73 - eventmachine (1.0.7)  
74 - exception_notification (4.0.1)  
75 - actionmailer (>= 3.0.4)  
76 - activesupport (>= 3.0.4)  
77 - execjs (2.5.2)  
78 - fast_gettext (0.6.12)  
79 - ffi (1.9.10)  
80 - gettext (2.2.1)  
81 - locale  
82 - gherkin (2.4.21)  
83 - json (>= 1.4.6)  
84 - git-version-bump (0.15.1)  
85 - grape (0.11.0)  
86 - activesupport  
87 - builder  
88 - hashie (>= 2.1.0)  
89 - multi_json (>= 1.3.2)  
90 - multi_xml (>= 0.5.2)  
91 - rack (>= 1.3.0)  
92 - rack-accept  
93 - rack-mount  
94 - virtus (>= 1.0.0)  
95 - grape-entity (0.4.5)  
96 - activesupport  
97 - multi_json (>= 1.3.2)  
98 - grape-swagger (0.10.1)  
99 - grape (>= 0.8.0)  
100 - grape-entity  
101 - grape_logging (1.1.2)  
102 - grape  
103 - hashie (3.4.2)  
104 - hike (1.2.3)  
105 - i18n (0.7.0)  
106 - ice_nine (0.11.1)  
107 - journey (1.0.4)  
108 - json (1.8.3)  
109 - locale (2.0.9)  
110 - magic (0.2.9)  
111 - ffi (>= 0.6.3)  
112 - mail (2.5.4)  
113 - mime-types (~> 1.16)  
114 - treetop (~> 1.4.8)  
115 - metaclass (0.0.4)  
116 - mime-types (1.25.1)  
117 - mini_portile (0.6.2)  
118 - minitest (3.2.0)  
119 - mocha (1.1.0)  
120 - metaclass (~> 0.0.1)  
121 - multi_json (1.11.2)  
122 - multi_xml (0.5.5)  
123 - nokogiri (1.6.6.2)  
124 - mini_portile (~> 0.6.0)  
125 - pg (0.13.2)  
126 - polyglot (0.3.5)  
127 - rack (1.4.7)  
128 - rack-accept (0.4.5)  
129 - rack (>= 0.4)  
130 - rack-cache (1.2)  
131 - rack (>= 0.4)  
132 - rack-contrib (1.3.0)  
133 - git-version-bump (~> 0.15)  
134 - rack (~> 1.4)  
135 - rack-cors (0.4.0)  
136 - rack-mount (0.8.3)  
137 - rack (>= 1.0.0)  
138 - rack-ssl (1.3.4)  
139 - rack  
140 - rack-test (0.6.3)  
141 - rack (>= 1.0)  
142 - rails (3.2.22)  
143 - actionmailer (= 3.2.22)  
144 - actionpack (= 3.2.22)  
145 - activerecord (= 3.2.22)  
146 - activeresource (= 3.2.22)  
147 - activesupport (= 3.2.22)  
148 - bundler (~> 1.0)  
149 - railties (= 3.2.22)  
150 - rails_autolink (1.1.6)  
151 - rails (> 3.1)  
152 - railties (3.2.22)  
153 - actionpack (= 3.2.22)  
154 - activesupport (= 3.2.22)  
155 - rack-ssl (~> 1.3.2)  
156 - rake (>= 0.8.7)  
157 - rdoc (~> 3.4)  
158 - thor (>= 0.14.6, < 2.0)  
159 - rake (10.4.2)  
160 - rdoc (3.12.2)  
161 - json (~> 1.4)  
162 - rest-client (1.6.9)  
163 - mime-types (~> 1.16)  
164 - rmagick (2.13.4)  
165 - rspec (2.14.1)  
166 - rspec-core (~> 2.14.0)  
167 - rspec-expectations (~> 2.14.0)  
168 - rspec-mocks (~> 2.14.0)  
169 - rspec-core (2.14.8)  
170 - rspec-expectations (2.14.5)  
171 - diff-lcs (>= 1.1.3, < 2.0)  
172 - rspec-mocks (2.14.6)  
173 - rspec-rails (2.14.2)  
174 - actionpack (>= 3.0)  
175 - activemodel (>= 3.0)  
176 - activesupport (>= 3.0)  
177 - railties (>= 3.0)  
178 - rspec-core (~> 2.14.0)  
179 - rspec-expectations (~> 2.14.0)  
180 - rspec-mocks (~> 2.14.0)  
181 - ruby-feedparser (0.9.3)  
182 - magic  
183 - rubyzip (1.1.7)  
184 - sass (3.4.15)  
185 - sass-rails (3.2.6)  
186 - railties (~> 3.2.0)  
187 - sass (>= 3.1.10)  
188 - tilt (~> 1.3)  
189 - selenium-webdriver (2.39.0)  
190 - childprocess (>= 0.2.5)  
191 - multi_json (~> 1.0)  
192 - rubyzip (~> 1.0)  
193 - websocket (~> 1.0.4)  
194 - sprockets (2.2.3)  
195 - hike (~> 1.2)  
196 - multi_json (~> 1.0)  
197 - rack (~> 1.0)  
198 - tilt (~> 1.1, != 1.3.0)  
199 - term-ansicolor (1.3.2)  
200 - tins (~> 1.0)  
201 - thin (1.3.1)  
202 - daemons (>= 1.0.9)  
203 - eventmachine (>= 0.12.6)  
204 - rack (>= 1.0.0)  
205 - thor (0.19.1)  
206 - thread_safe (0.3.5)  
207 - tilt (1.4.1)  
208 - tins (1.5.4)  
209 - treetop (1.4.15)  
210 - polyglot  
211 - polyglot (>= 0.3.1)  
212 - tzinfo (0.3.44)  
213 - uglifier (2.7.1)  
214 - execjs (>= 0.3.0)  
215 - json (>= 1.8.0)  
216 - virtus (1.0.5)  
217 - axiom-types (~> 0.1)  
218 - coercible (~> 1.0)  
219 - descendants_tracker (~> 0.0, >= 0.0.3)  
220 - equalizer (~> 0.0, >= 0.0.9)  
221 - websocket (1.0.7)  
222 - whenever (0.9.4)  
223 - chronic (>= 0.6.3)  
224 - will_paginate (3.0.7)  
225 - xpath (2.0.0)  
226 - nokogiri (~> 1.3)  
227 -  
228 -PLATFORMS  
229 - ruby  
230 -  
231 -DEPENDENCIES  
232 - RedCloth (~> 4.2.9)  
233 - acts-as-taggable-on (~> 3.4.2)  
234 - api-pagination (~> 4.1.1)  
235 - capybara (~> 2.1.0)  
236 - cucumber (~> 1.0.6)  
237 - cucumber-rails (~> 1.0.6)  
238 - daemons (~> 1.1.5)  
239 - dalli (~> 2.7.0)  
240 - database_cleaner (~> 1.2.0)  
241 - eita-jrails (~> 0.9.5)  
242 - exception_notification (~> 4.0.1)  
243 - fast_gettext (~> 0.6.8)  
244 - gettext (~> 2.2.1)  
245 - grape (~> 0.11.0)  
246 - grape-entity  
247 - grape-swagger  
248 - grape_logging  
249 - locale (~> 2.0.5)  
250 - minitest (~> 3.2.0)  
251 - mocha (~> 1.1.0)  
252 - nokogiri (~> 1.6.0)  
253 - pg (~> 0.13.2)  
254 - rack-contrib  
255 - rack-cors  
256 - rails (~> 3.2.22)  
257 - rails_autolink (~> 1.1.5)  
258 - rake  
259 - rest-client (~> 1.6.7)  
260 - rmagick (~> 2.13.1)  
261 - rspec (~> 2.14.0)  
262 - rspec-rails (~> 2.14.1)  
263 - ruby-feedparser (~> 0.7)  
264 - sass-rails  
265 - selenium-webdriver (~> 2.39.0)  
266 - thin (~> 1.3.1)  
267 - uglifier (>= 1.0.3)  
268 - whenever  
269 - will_paginate (~> 3.0.3)  
app/models/add_friend.rb
@@ -14,6 +14,9 @@ class AddFriend &lt; Task @@ -14,6 +14,9 @@ class AddFriend &lt; Task
14 alias :friend :target 14 alias :friend :target
15 alias :friend= :target= 15 alias :friend= :target=
16 16
  17 + validates :requestor, :kind_of => { :kind => Person }
  18 + validates :target, :kind_of => { :kind => Person }
  19 +
17 after_create do |task| 20 after_create do |task|
18 TaskMailer.invitation_notification(task).deliver unless task.friend 21 TaskMailer.invitation_notification(task).deliver unless task.friend
19 remove_from_suggestion_list(task) 22 remove_from_suggestion_list(task)
app/models/add_member.rb
@@ -2,6 +2,9 @@ class AddMember &lt; Task @@ -2,6 +2,9 @@ class AddMember &lt; Task
2 2
3 validates_presence_of :requestor_id, :target_id 3 validates_presence_of :requestor_id, :target_id
4 4
  5 + validates :requestor, kind_of: {kind: Person}
  6 + validates :target, kind_of: {kind: Organization}
  7 +
5 alias :person :requestor 8 alias :person :requestor
6 alias :person= :requestor= 9 alias :person= :requestor=
7 10
app/models/approve_article.rb
1 class ApproveArticle < Task 1 class ApproveArticle < Task
2 validates_presence_of :requestor_id, :target_id 2 validates_presence_of :requestor_id, :target_id
3 3
  4 + validates :requestor, kind_of: {kind: Person}
  5 + validate :allowed_requestor
  6 +
  7 + def allowed_requestor
  8 + if target
  9 + if target.person? && requestor != target
  10 + self.errors.add(:requestor, _('You can not post articles to other users.'))
  11 + end
  12 + if target.organization? && !target.members.include?(requestor) && target.environment.portal_community != target
  13 + self.errors.add(:requestor, _('Only members can post articles on communities.'))
  14 + end
  15 + end
  16 + end
  17 +
4 def article_title 18 def article_title
5 article ? article.title : _('(The original text was removed)') 19 article ? article.title : _('(The original text was removed)')
6 end 20 end
7 - 21 +
8 def article 22 def article
9 Article.find_by_id data[:article_id] 23 Article.find_by_id data[:article_id]
10 end 24 end
@@ -124,4 +138,9 @@ class ApproveArticle &lt; Task @@ -124,4 +138,9 @@ class ApproveArticle &lt; Task
124 message 138 message
125 end 139 end
126 140
  141 + def request_is_member_of_target
  142 + unless requestor.is_member_of?(target)
  143 + errors.add(:approve_article, N_('Requestor must be a member of target.'))
  144 + end
  145 + end
127 end 146 end
app/models/change_password.rb
@@ -18,6 +18,8 @@ class ChangePassword &lt; Task @@ -18,6 +18,8 @@ class ChangePassword &lt; Task
18 18
19 validates_presence_of :requestor 19 validates_presence_of :requestor
20 20
  21 + validates :requestor, kind_of: {kind: Person}
  22 +
21 ################################################### 23 ###################################################
22 # validations for updating a ChangePassword task 24 # validations for updating a ChangePassword task
23 25
app/models/create_community.rb
@@ -3,6 +3,9 @@ class CreateCommunity &lt; Task @@ -3,6 +3,9 @@ class CreateCommunity &lt; Task
3 validates_presence_of :requestor_id, :target_id 3 validates_presence_of :requestor_id, :target_id
4 validates_presence_of :name 4 validates_presence_of :name
5 5
  6 + validates :requestor, kind_of: {kind: Person}
  7 + validates :target, kind_of: {kind: Environment}
  8 +
6 alias :environment :target 9 alias :environment :target
7 alias :environment= :target= 10 alias :environment= :target=
8 11
app/models/create_enterprise.rb
@@ -27,6 +27,8 @@ class CreateEnterprise &lt; Task @@ -27,6 +27,8 @@ class CreateEnterprise &lt; Task
27 # checks for actual attributes 27 # checks for actual attributes
28 validates_presence_of :requestor_id, :target_id 28 validates_presence_of :requestor_id, :target_id
29 29
  30 + validates :requestor, kind_of: {kind: Person}
  31 +
30 # checks for admins required attributes 32 # checks for admins required attributes
31 DATA_FIELDS.each do |attribute| 33 DATA_FIELDS.each do |attribute|
32 validates_presence_of attribute, :if => lambda { |obj| obj.environment.required_enterprise_fields.include?(attribute) } 34 validates_presence_of attribute, :if => lambda { |obj| obj.environment.required_enterprise_fields.include?(attribute) }
app/models/email_activation.rb
1 class EmailActivation < Task 1 class EmailActivation < Task
2 2
3 validates_presence_of :requestor_id, :target_id 3 validates_presence_of :requestor_id, :target_id
  4 +
  5 + validates :requestor, kind_of: {kind: Person}
  6 + validates :target, kind_of: {kind: Environment}
  7 +
4 validate :already_requested, :on => :create 8 validate :already_requested, :on => :create
5 9
6 alias :environment :target 10 alias :environment :target
7 alias :person :requestor 11 alias :person :requestor
8 12
9 def already_requested 13 def already_requested
10 - if !self.requestor.nil? && self.requestor.user.email_activation_pending? 14 + if !self.requestor.nil? && self.requestor.person? && self.requestor.user.email_activation_pending?
11 self.errors.add(:base, _('You have already requested activation of your mailbox.')) 15 self.errors.add(:base, _('You have already requested activation of your mailbox.'))
12 end 16 end
13 end 17 end
app/models/enterprise_activation.rb
@@ -8,6 +8,8 @@ class EnterpriseActivation &lt; Task @@ -8,6 +8,8 @@ class EnterpriseActivation &lt; Task
8 8
9 validates_presence_of :enterprise 9 validates_presence_of :enterprise
10 10
  11 + validates :target, kind_of: {kind: Enterprise}
  12 +
11 def perform 13 def perform
12 self.enterprise.enable self.requestor 14 self.enterprise.enable self.requestor
13 end 15 end
app/models/invitation.rb
@@ -6,6 +6,8 @@ class Invitation &lt; Task @@ -6,6 +6,8 @@ class Invitation &lt; Task
6 6
7 validates_presence_of :target_id, :if => Proc.new{|invite| invite.friend_email.blank?} 7 validates_presence_of :target_id, :if => Proc.new{|invite| invite.friend_email.blank?}
8 8
  9 + validates :requestor, kind_of: {kind: Person}
  10 +
9 validates_presence_of :friend_email, :if => Proc.new{|invite| invite.target_id.blank?} 11 validates_presence_of :friend_email, :if => Proc.new{|invite| invite.target_id.blank?}
10 validates_format_of :friend_email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => Proc.new{|invite| invite.target_id.blank?} 12 validates_format_of :friend_email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => Proc.new{|invite| invite.target_id.blank?}
11 13
@@ -34,7 +36,7 @@ class Invitation &lt; Task @@ -34,7 +36,7 @@ class Invitation &lt; Task
34 end 36 end
35 37
36 def not_invite_yourself 38 def not_invite_yourself
37 - email = friend ? friend.user.email : friend_email 39 + email = friend && friend.person? ? friend.user.email : friend_email
38 if person && email && person.user.email == email 40 if person && email && person.user.email == email
39 self.errors.add(:base, _("You can't invite youself")) 41 self.errors.add(:base, _("You can't invite youself"))
40 end 42 end
@@ -136,7 +138,11 @@ class Invitation &lt; Task @@ -136,7 +138,11 @@ class Invitation &lt; Task
136 end 138 end
137 139
138 def environment 140 def environment
139 - self.requestor.environment 141 + if self.requestor
  142 + self.requestor.environment
  143 + else
  144 + nil
  145 + end
140 end 146 end
141 147
142 end 148 end
app/models/moderate_user_registration.rb
@@ -7,6 +7,8 @@ class ModerateUserRegistration &lt; Task @@ -7,6 +7,8 @@ class ModerateUserRegistration &lt; Task
7 7
8 after_create :schedule_spam_checking 8 after_create :schedule_spam_checking
9 9
  10 + validates :target, kind_of: {kind: Environment}
  11 +
10 alias :environment :target 12 alias :environment :target
11 alias :environment= :target= 13 alias :environment= :target=
12 14
app/models/profile.rb
@@ -203,9 +203,9 @@ class Profile &lt; ActiveRecord::Base @@ -203,9 +203,9 @@ class Profile &lt; ActiveRecord::Base
203 Profile.column_names.map{|n| [Profile.table_name, n].join('.')}.join(',') 203 Profile.column_names.map{|n| [Profile.table_name, n].join('.')}.join(',')
204 end 204 end
205 205
206 - scope :visible, :conditions => { :visible => true } 206 + scope :visible, :conditions => { :visible => true, :secret => false }
207 scope :disabled, :conditions => { :visible => false } 207 scope :disabled, :conditions => { :visible => false }
208 - scope :public, :conditions => { :visible => true, :public_profile => true } 208 + scope :public, :conditions => { :visible => true, :public_profile => true, :secret => false }
209 scope :enabled, :conditions => { :enabled => true } 209 scope :enabled, :conditions => { :enabled => true }
210 210
211 # Subclasses must override this method 211 # Subclasses must override this method
app/models/suggest_article.rb
@@ -92,4 +92,5 @@ class SuggestArticle &lt; Task @@ -92,4 +92,5 @@ class SuggestArticle &lt; Task
92 def after_ham! 92 def after_ham!
93 self.delay.marked_as_ham 93 self.delay.marked_as_ham
94 end 94 end
  95 +
95 end 96 end
app/models/task.rb
@@ -117,6 +117,51 @@ class Task &lt; ActiveRecord::Base @@ -117,6 +117,51 @@ class Task &lt; ActiveRecord::Base
117 end 117 end
118 end 118 end
119 119
  120 + class KindOfValidator < ActiveModel::EachValidator
  121 + def validate_each(record, attribute, value)
  122 + environment = record.environment || Environment.default
  123 + klass = options[:kind]
  124 + group = klass.to_s.downcase.pluralize
  125 + id = attribute.to_s + "_id"
  126 + if environment.respond_to?(group)
  127 + attrb = value || environment.send(group).find_by_id(record.send(id))
  128 + else
  129 + attrb = value || klass.find_by_id(record.send(id))
  130 + end
  131 + if attrb.respond_to?(klass.to_s.downcase + "?")
  132 + unless attrb.send(klass.to_s.downcase + "?")
  133 + record.errors[attribute] << (options[:message] || "should be "+ klass.to_s.downcase)
  134 + end
  135 + else
  136 + unless attrb.class == klass
  137 + record.errors[attribute] << (options[:message] || "should be "+ klass.to_s.downcase)
  138 + end
  139 + end
  140 + end
  141 + end
  142 +
  143 + def requestor_is_of_kind(klass, message = nil)
  144 + error_message = message ||= _('Task requestor must be '+klass.to_s.downcase)
  145 + group = klass.to_s.downcase.pluralize
  146 + if environment.respond_to?(group) and requestor_id
  147 + requestor = requestor ||= environment.send(klass.to_s.downcase.pluralize).find_by_id(requestor_id)
  148 + end
  149 + unless requestor.class == klass
  150 + errors.add(error_message)
  151 + end
  152 + end
  153 +
  154 + def target_is_of_kind(klass, message = nil)
  155 + error_message = message ||= _('Task target must be '+klass.to_s.downcase)
  156 + group = klass.to_s.downcase.pluralize
  157 + if environment.respond_to?(group) and target_id
  158 + target = target ||= environment.send(klass.to_s.downcase.pluralize).find_by_id(target_id)
  159 + end
  160 + unless target.class == klass
  161 + errors.add(error_message)
  162 + end
  163 + end
  164 +
120 def close(status, closed_by) 165 def close(status, closed_by)
121 self.status = status 166 self.status = status
122 self.end_date = Time.now 167 self.end_date = Time.now
app/views/api/playground.html.erb
@@ -12,7 +12,11 @@ endpoints.map do |endpoint| @@ -12,7 +12,11 @@ endpoints.map do |endpoint|
12 } 12 }
13 end 13 end
14 end 14 end
15 -end.flatten.compact.sort{|a,b| a[:path]=='/api/v1/login' ? -1:1}.to_json %>; 15 +end.flatten.compact.sort{|a,b|
  16 + a[:path]=='/api/v1/login' ? -1 :
  17 + b[:path]=='/api/v1/login' ? 1 :
  18 + a[:path] <=> b[:path]
  19 +}.to_json %>;
16 </script> 20 </script>
17 21
18 <form id="api-form"> 22 <form id="api-form">
@@ -6,6 +6,13 @@ require ::File.expand_path(&#39;../config/environment&#39;, __FILE__) @@ -6,6 +6,13 @@ require ::File.expand_path(&#39;../config/environment&#39;, __FILE__)
6 #use Rails::Rack::Static 6 #use Rails::Rack::Static
7 #run ActionController::Dispatcher.new 7 #run ActionController::Dispatcher.new
8 8
  9 +use Rack::Cors do
  10 + allow do
  11 + origins '*'
  12 + resource '/api/*', :headers => :any, :methods => [:get, :post]
  13 + end
  14 +end
  15 +
9 rails_app = Rack::Builder.new do 16 rails_app = Rack::Builder.new do
10 run Noosfero::Application 17 run Noosfero::Application
11 end 18 end
config/application.rb
@@ -135,12 +135,5 @@ module Noosfero @@ -135,12 +135,5 @@ module Noosfero
135 135
136 Noosfero::Plugin.setup(config) 136 Noosfero::Plugin.setup(config)
137 137
138 - config.middleware.use Rack::Cors do  
139 - allow do  
140 - origins '*'  
141 - resource '/api/*', :headers => :any, :methods => [:get, :post]  
142 - end  
143 - end  
144 -  
145 end 138 end
146 end 139 end
config/initializers/eager_load.rb 0 → 100644
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +Rails.application.eager_load!
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 # 11 #
12 # It's strongly recommended to check this file into your version control system. 12 # It's strongly recommended to check this file into your version control system.
13 13
14 -ActiveRecord::Schema.define(:version => 20150603182105) do 14 +ActiveRecord::Schema.define(:version => 20150712194411) do
15 15
16 create_table "abuse_reports", :force => true do |t| 16 create_table "abuse_reports", :force => true do |t|
17 t.integer "reporter_id" 17 t.integer "reporter_id"
@@ -48,6 +48,18 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do @@ -48,6 +48,18 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do
48 add_index "action_tracker_notifications", ["profile_id", "action_tracker_id"], :name => "index_action_tracker_notif_on_prof_id_act_tracker_id", :unique => true 48 add_index "action_tracker_notifications", ["profile_id", "action_tracker_id"], :name => "index_action_tracker_notif_on_prof_id_act_tracker_id", :unique => true
49 add_index "action_tracker_notifications", ["profile_id"], :name => "index_action_tracker_notifications_on_profile_id" 49 add_index "action_tracker_notifications", ["profile_id"], :name => "index_action_tracker_notifications_on_profile_id"
50 50
  51 + create_table "article_followers", :force => true do |t|
  52 + t.integer "person_id", :null => false
  53 + t.integer "article_id", :null => false
  54 + t.datetime "since"
  55 + t.datetime "created_at", :null => false
  56 + t.datetime "updated_at", :null => false
  57 + end
  58 +
  59 + add_index "article_followers", ["article_id"], :name => "index_article_followers_on_article_id"
  60 + add_index "article_followers", ["person_id", "article_id"], :name => "index_article_followers_on_person_id_and_article_id", :unique => true
  61 + add_index "article_followers", ["person_id"], :name => "index_article_followers_on_person_id"
  62 +
51 create_table "article_privacy_exceptions", :id => false, :force => true do |t| 63 create_table "article_privacy_exceptions", :id => false, :force => true do |t|
52 t.integer "article_id" 64 t.integer "article_id"
53 t.integer "person_id" 65 t.integer "person_id"
@@ -75,8 +87,8 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do @@ -75,8 +87,8 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do
75 t.integer "comments_count" 87 t.integer "comments_count"
76 t.boolean "advertise", :default => true 88 t.boolean "advertise", :default => true
77 t.boolean "published", :default => true 89 t.boolean "published", :default => true
78 - t.date "start_date"  
79 - t.date "end_date" 90 + t.datetime "start_date"
  91 + t.datetime "end_date"
80 t.integer "children_count", :default => 0 92 t.integer "children_count", :default => 0
81 t.boolean "accept_comments", :default => true 93 t.boolean "accept_comments", :default => true
82 t.integer "reference_article_id" 94 t.integer "reference_article_id"
@@ -127,8 +139,8 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do @@ -127,8 +139,8 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do
127 t.integer "comments_count", :default => 0 139 t.integer "comments_count", :default => 0
128 t.boolean "advertise", :default => true 140 t.boolean "advertise", :default => true
129 t.boolean "published", :default => true 141 t.boolean "published", :default => true
130 - t.date "start_date"  
131 - t.date "end_date" 142 + t.datetime "start_date"
  143 + t.datetime "end_date"
132 t.integer "children_count", :default => 0 144 t.integer "children_count", :default => 0
133 t.boolean "accept_comments", :default => true 145 t.boolean "accept_comments", :default => true
134 t.integer "reference_article_id" 146 t.integer "reference_article_id"
@@ -151,6 +163,8 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do @@ -151,6 +163,8 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do
151 t.integer "author_id" 163 t.integer "author_id"
152 t.integer "created_by_id" 164 t.integer "created_by_id"
153 t.boolean "show_to_followers", :default => true 165 t.boolean "show_to_followers", :default => true
  166 + t.integer "sash_id"
  167 + t.integer "level", :default => 0
154 end 168 end
155 169
156 add_index "articles", ["comments_count"], :name => "index_articles_on_comments_count" 170 add_index "articles", ["comments_count"], :name => "index_articles_on_comments_count"
@@ -177,6 +191,17 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do @@ -177,6 +191,17 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do
177 add_index "articles_categories", ["article_id"], :name => "index_articles_categories_on_article_id" 191 add_index "articles_categories", ["article_id"], :name => "index_articles_categories_on_article_id"
178 add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id" 192 add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id"
179 193
  194 + create_table "badges_sashes", :force => true do |t|
  195 + t.integer "badge_id"
  196 + t.integer "sash_id"
  197 + t.boolean "notified_user", :default => false
  198 + t.datetime "created_at"
  199 + end
  200 +
  201 + add_index "badges_sashes", ["badge_id", "sash_id"], :name => "index_badges_sashes_on_badge_id_and_sash_id"
  202 + add_index "badges_sashes", ["badge_id"], :name => "index_badges_sashes_on_badge_id"
  203 + add_index "badges_sashes", ["sash_id"], :name => "index_badges_sashes_on_sash_id"
  204 +
180 create_table "blocks", :force => true do |t| 205 create_table "blocks", :force => true do |t|
181 t.string "title" 206 t.string "title"
182 t.integer "box_id" 207 t.integer "box_id"
@@ -272,8 +297,10 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do @@ -272,8 +297,10 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do
272 t.string "referrer" 297 t.string "referrer"
273 t.text "settings" 298 t.text "settings"
274 t.integer "paragraph_id" 299 t.integer "paragraph_id"
  300 + t.string "paragraph_uuid"
275 end 301 end
276 302
  303 + add_index "comments", ["paragraph_uuid"], :name => "index_comments_on_paragraph_uuid"
277 add_index "comments", ["source_id", "spam"], :name => "index_comments_on_source_id_and_spam" 304 add_index "comments", ["source_id", "spam"], :name => "index_comments_on_source_id_and_spam"
278 305
279 create_table "contact_lists", :force => true do |t| 306 create_table "contact_lists", :force => true do |t|
@@ -313,6 +340,17 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do @@ -313,6 +340,17 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do
313 add_index "domains", ["owner_id", "owner_type", "is_default"], :name => "index_domains_on_owner_id_and_owner_type_and_is_default" 340 add_index "domains", ["owner_id", "owner_type", "is_default"], :name => "index_domains_on_owner_id_and_owner_type_and_is_default"
314 add_index "domains", ["owner_id", "owner_type"], :name => "index_domains_on_owner_id_and_owner_type" 341 add_index "domains", ["owner_id", "owner_type"], :name => "index_domains_on_owner_id_and_owner_type"
315 342
  343 + create_table "email_templates", :force => true do |t|
  344 + t.string "name"
  345 + t.string "template_type"
  346 + t.string "subject"
  347 + t.text "body"
  348 + t.integer "owner_id"
  349 + t.string "owner_type"
  350 + t.datetime "created_at", :null => false
  351 + t.datetime "updated_at", :null => false
  352 + end
  353 +
316 create_table "environments", :force => true do |t| 354 create_table "environments", :force => true do |t|
317 t.string "name" 355 t.string "name"
318 t.string "contact_email" 356 t.string "contact_email"
@@ -332,6 +370,7 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do @@ -332,6 +370,7 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do
332 t.string "default_language" 370 t.string "default_language"
333 t.string "noreply_email" 371 t.string "noreply_email"
334 t.string "redirection_after_signup", :default => "keep_on_same_page" 372 t.string "redirection_after_signup", :default => "keep_on_same_page"
  373 + t.text "send_email_plugin_allow_to"
335 t.string "date_format", :default => "month_name_with_year" 374 t.string "date_format", :default => "month_name_with_year"
336 end 375 end
337 376
@@ -368,6 +407,17 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do @@ -368,6 +407,17 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do
368 add_index "friendships", ["person_id", "friend_id"], :name => "index_friendships_on_person_id_and_friend_id" 407 add_index "friendships", ["person_id", "friend_id"], :name => "index_friendships_on_person_id_and_friend_id"
369 add_index "friendships", ["person_id"], :name => "index_friendships_on_person_id" 408 add_index "friendships", ["person_id"], :name => "index_friendships_on_person_id"
370 409
  410 + create_table "gamification_plugin_badges", :force => true do |t|
  411 + t.string "name"
  412 + t.integer "level"
  413 + t.string "description"
  414 + t.string "custom_fields"
  415 + t.integer "owner_id"
  416 + t.string "owner_type"
  417 + t.datetime "created_at", :null => false
  418 + t.datetime "updated_at", :null => false
  419 + end
  420 +
371 create_table "images", :force => true do |t| 421 create_table "images", :force => true do |t|
372 t.integer "parent_id" 422 t.integer "parent_id"
373 t.string "content_type" 423 t.string "content_type"
@@ -424,6 +474,46 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do @@ -424,6 +474,46 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do
424 t.datetime "updated_at" 474 t.datetime "updated_at"
425 end 475 end
426 476
  477 + create_table "mark_comment_as_read_plugin", :force => true do |t|
  478 + t.integer "comment_id"
  479 + t.integer "person_id"
  480 + end
  481 +
  482 + add_index "mark_comment_as_read_plugin", ["comment_id", "person_id"], :name => "index_mark_comment_as_read_plugin_on_comment_id_and_person_id", :unique => true
  483 +
  484 + create_table "merit_actions", :force => true do |t|
  485 + t.integer "user_id"
  486 + t.string "action_method"
  487 + t.integer "action_value"
  488 + t.boolean "had_errors", :default => false
  489 + t.string "target_model"
  490 + t.integer "target_id"
  491 + t.text "target_data"
  492 + t.boolean "processed", :default => false
  493 + t.datetime "created_at", :null => false
  494 + t.datetime "updated_at", :null => false
  495 + end
  496 +
  497 + create_table "merit_activity_logs", :force => true do |t|
  498 + t.integer "action_id"
  499 + t.string "related_change_type"
  500 + t.integer "related_change_id"
  501 + t.string "description"
  502 + t.datetime "created_at"
  503 + end
  504 +
  505 + create_table "merit_score_points", :force => true do |t|
  506 + t.integer "score_id"
  507 + t.integer "num_points", :default => 0
  508 + t.string "log"
  509 + t.datetime "created_at"
  510 + end
  511 +
  512 + create_table "merit_scores", :force => true do |t|
  513 + t.integer "sash_id"
  514 + t.string "category", :default => "default"
  515 + end
  516 +
427 create_table "national_region_types", :force => true do |t| 517 create_table "national_region_types", :force => true do |t|
428 t.string "name" 518 t.string "name"
429 end 519 end
@@ -440,6 +530,15 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do @@ -440,6 +530,15 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do
440 add_index "national_regions", ["name"], :name => "name_index" 530 add_index "national_regions", ["name"], :name => "name_index"
441 add_index "national_regions", ["national_region_code"], :name => "code_index" 531 add_index "national_regions", ["national_region_code"], :name => "code_index"
442 532
  533 + create_table "pairwise_plugin_choices_related", :force => true do |t|
  534 + t.integer "choice_id"
  535 + t.integer "parent_choice_id"
  536 + t.integer "question_id"
  537 + t.integer "user_id"
  538 + t.datetime "created_at", :null => false
  539 + t.datetime "updated_at", :null => false
  540 + end
  541 +
443 create_table "price_details", :force => true do |t| 542 create_table "price_details", :force => true do |t|
444 t.decimal "price", :default => 0.0 543 t.decimal "price", :default => 0.0
445 t.integer "product_id" 544 t.integer "product_id"
@@ -547,15 +646,37 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do @@ -547,15 +646,37 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do
547 t.boolean "allow_members_to_invite", :default => true 646 t.boolean "allow_members_to_invite", :default => true
548 t.boolean "invite_friends_only", :default => false 647 t.boolean "invite_friends_only", :default => false
549 t.boolean "secret", :default => false 648 t.boolean "secret", :default => false
  649 + t.integer "sash_id"
  650 + t.integer "level", :default => 0
550 end 651 end
551 652
552 add_index "profiles", ["activities_count"], :name => "index_profiles_on_activities_count" 653 add_index "profiles", ["activities_count"], :name => "index_profiles_on_activities_count"
553 add_index "profiles", ["created_at"], :name => "index_profiles_on_created_at" 654 add_index "profiles", ["created_at"], :name => "index_profiles_on_created_at"
  655 + add_index "profiles", ["enabled"], :name => "index_profiles_on_enabled"
554 add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id" 656 add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id"
555 add_index "profiles", ["friends_count"], :name => "index_profiles_on_friends_count" 657 add_index "profiles", ["friends_count"], :name => "index_profiles_on_friends_count"
556 add_index "profiles", ["identifier"], :name => "index_profiles_on_identifier" 658 add_index "profiles", ["identifier"], :name => "index_profiles_on_identifier"
557 add_index "profiles", ["members_count"], :name => "index_profiles_on_members_count" 659 add_index "profiles", ["members_count"], :name => "index_profiles_on_members_count"
558 add_index "profiles", ["region_id"], :name => "index_profiles_on_region_id" 660 add_index "profiles", ["region_id"], :name => "index_profiles_on_region_id"
  661 + add_index "profiles", ["type"], :name => "index_profiles_on_type"
  662 + add_index "profiles", ["validated"], :name => "index_profiles_on_validated"
  663 + add_index "profiles", ["visible"], :name => "index_profiles_on_visible"
  664 +
  665 + create_table "proposals_discussion_plugin_proposal_evaluations", :force => true do |t|
  666 + t.integer "proposal_task_id"
  667 + t.integer "evaluator_id"
  668 + t.integer "flagged_status"
  669 + t.datetime "created_at", :null => false
  670 + t.datetime "updated_at", :null => false
  671 + end
  672 +
  673 + add_index "proposals_discussion_plugin_proposal_evaluations", ["evaluator_id"], :name => "index_proposals_discussion_plugin_proposal_evaluator_id"
  674 + add_index "proposals_discussion_plugin_proposal_evaluations", ["proposal_task_id"], :name => "index_proposals_discussion_plugin_proposal_task_id"
  675 +
  676 + create_table "proposals_discussion_plugin_task_categories", :id => false, :force => true do |t|
  677 + t.integer "task_id"
  678 + t.integer "category_id"
  679 + end
559 680
560 create_table "qualifier_certifiers", :force => true do |t| 681 create_table "qualifier_certifiers", :force => true do |t|
561 t.integer "qualifier_id" 682 t.integer "qualifier_id"
@@ -597,6 +718,12 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do @@ -597,6 +718,12 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do
597 t.boolean "is_global" 718 t.boolean "is_global"
598 end 719 end
599 720
  721 + add_index "role_assignments", ["accessor_id", "accessor_type", "resource_id", "resource_type"], :name => "index_on_role_assigments_accessor_resource_role"
  722 + add_index "role_assignments", ["accessor_id", "accessor_type", "role_id"], :name => "index_on_role_assigments_accessor_role"
  723 + add_index "role_assignments", ["accessor_id", "accessor_type"], :name => "index_role_assignments_on_accessor_id_and_accessor_type"
  724 + add_index "role_assignments", ["resource_id", "resource_type", "role_id"], :name => "index_on_role_assigments_resource_role"
  725 + add_index "role_assignments", ["resource_id", "resource_type"], :name => "index_role_assignments_on_resource_id_and_resource_type"
  726 +
600 create_table "roles", :force => true do |t| 727 create_table "roles", :force => true do |t|
601 t.string "name" 728 t.string "name"
602 t.string "key" 729 t.string "key"
@@ -606,6 +733,11 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do @@ -606,6 +733,11 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do
606 t.integer "profile_id" 733 t.integer "profile_id"
607 end 734 end
608 735
  736 + create_table "sashes", :force => true do |t|
  737 + t.datetime "created_at", :null => false
  738 + t.datetime "updated_at", :null => false
  739 + end
  740 +
609 create_table "scraps", :force => true do |t| 741 create_table "scraps", :force => true do |t|
610 t.text "content" 742 t.text "content"
611 t.integer "sender_id" 743 t.integer "sender_id"
@@ -684,7 +816,7 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do @@ -684,7 +816,7 @@ ActiveRecord::Schema.define(:version =&gt; 20150603182105) do
684 create_table "tasks", :force => true do |t| 816 create_table "tasks", :force => true do |t|
685 t.text "data" 817 t.text "data"
686 t.integer "status" 818 t.integer "status"
687 - t.date "end_date" 819 + t.datetime "end_date"
688 t.integer "requestor_id" 820 t.integer "requestor_id"
689 t.integer "target_id" 821 t.integer "target_id"
690 t.string "code", :limit => 40 822 t.string "code", :limit => 40
lib/noosfero/api/helpers.rb
@@ -59,7 +59,8 @@ @@ -59,7 +59,8 @@
59 end 59 end
60 end 60 end
61 61
62 - ARTICLE_TYPES = Article.descendants.map{|a| a.to_s} 62 + ARTICLE_TYPES = ['Article'] + Article.descendants.map{|a| a.to_s}
  63 + TASK_TYPES = ['Task'] + Task.descendants.map{|a| a.to_s}
63 64
64 def find_article(articles, id) 65 def find_article(articles, id)
65 article = articles.find(id) 66 article = articles.find(id)
@@ -107,9 +108,36 @@ @@ -107,9 +108,36 @@
107 articles 108 articles
108 end 109 end
109 110
110 - def find_task(tasks, id)  
111 - task = tasks.find(id)  
112 - task.display_to?(current_user.person) ? task : forbidden! 111 + def find_task(asset, id)
  112 + task = asset.tasks.find(id)
  113 + current_person.has_permission?(task.permission, asset) ? task : forbidden!
  114 + end
  115 +
  116 + def post_task(asset, params)
  117 + klass_type= params[:content_type].nil? ? 'Task' : params[:content_type]
  118 + return forbidden! unless TASK_TYPES.include?(klass_type)
  119 +
  120 + task = klass_type.constantize.new(params[:task])
  121 + task.requestor_id = current_person.id
  122 + task.target_id = asset.id
  123 + task.target_type = 'Profile'
  124 +
  125 + if !task.save
  126 + render_api_errors!(task.errors.full_messages)
  127 + end
  128 + present task, :with => Entities::Task, :fields => params[:fields]
  129 + end
  130 +
  131 + def present_task(asset)
  132 + task = find_task(asset, params[:id])
  133 + present task, :with => Entities::Task, :fields => params[:fields]
  134 + end
  135 +
  136 + def present_tasks(asset)
  137 + tasks = select_filtered_collection_of(asset, 'tasks', params)
  138 + tasks = tasks.select {|t| current_person.has_permission?(t.permission, asset)}
  139 + return forbidden! if tasks.empty? && !current_person.has_permission?(:perform_task, asset)
  140 + present tasks, :with => Entities::Task, :fields => params[:fields]
113 end 141 end
114 142
115 def make_conditions_with_parameter(params = {}) 143 def make_conditions_with_parameter(params = {})
@@ -131,12 +159,13 @@ @@ -131,12 +159,13 @@
131 end 159 end
132 160
133 def by_reference(scope, params) 161 def by_reference(scope, params)
134 - if params[:reference_id]  
135 - created_at = scope.find(params[:reference_id]).created_at  
136 - scope.send("#{params.key?(:oldest) ? 'older_than' : 'younger_than'}", created_at)  
137 - else 162 + reference_id = params[:reference_id].to_i == 0 ? nil : params[:reference_id].to_i
  163 + if reference_id.nil?
138 scope 164 scope
139 - end 165 + else
  166 + created_at = scope.find(reference_id).created_at
  167 + scope.send("#{params.key?(:oldest) ? 'older_than' : 'younger_than'}", created_at)
  168 + end
140 end 169 end
141 170
142 def select_filtered_collection_of(object, method, params) 171 def select_filtered_collection_of(object, method, params)
lib/noosfero/api/v1/tasks.rb
@@ -18,146 +18,41 @@ module Noosfero @@ -18,146 +18,41 @@ module Noosfero
18 # Example Request: 18 # Example Request:
19 # GET host/api/v1/tasks?from=2013-04-04-14:41:43&until=2015-04-04-14:41:43&limit=10&private_token=e96fff37c2238fdab074d1dcea8e6317 19 # GET host/api/v1/tasks?from=2013-04-04-14:41:43&until=2015-04-04-14:41:43&limit=10&private_token=e96fff37c2238fdab074d1dcea8e6317
20 get do 20 get do
21 - #FIXME check for permission  
22 tasks = select_filtered_collection_of(environment, 'tasks', params) 21 tasks = select_filtered_collection_of(environment, 'tasks', params)
  22 + tasks = tasks.select {|t| current_person.has_permission?(t.permission, environment)}
23 present tasks, :with => Entities::Task, :fields => params[:fields] 23 present tasks, :with => Entities::Task, :fields => params[:fields]
24 end 24 end
25 25
26 desc "Return the task id" 26 desc "Return the task id"
27 get ':id' do 27 get ':id' do
28 - task = find_task(environment.tasks, params[:id]) 28 + task = find_task(environment, params[:id])
29 present task, :with => Entities::Task, :fields => params[:fields] 29 present task, :with => Entities::Task, :fields => params[:fields]
30 end 30 end
31 -  
32 -  
33 end 31 end
34 32
35 - resource :communities do  
36 - segment '/:community_id' do  
37 - resource :tasks do  
38 - get do  
39 - #FIXME check for permission  
40 - community = environment.communities.find(params[:community_id])  
41 - tasks = select_filtered_collection_of(community, 'tasks', params)  
42 - present tasks, :with => Entities::Task, :fields => params[:fields]  
43 - end  
44 -  
45 - get ':id' do  
46 - community = environment.communities.find(params[:community_id])  
47 - task = find_task(community.tasks, params[:id])  
48 - present task, :with => Entities::Task, :fields => params[:fields]  
49 - end  
50 -  
51 - # Example Request:  
52 - # POST api/v1/communites/:community_id/articles?private_token=234298743290432&article[name]=title&article[body]=body  
53 - post do  
54 - community = environment.communities.find(params[:community_id])  
55 -#FIXME see the correct permission  
56 - return forbidden! unless current_person.can_post_content?(community)  
57 -#FIXME check the task type before create  
58 - klass_type= params[:content_type].nil? ? 'Task' : params[:content_type]  
59 -# return forbidden! unless ARTICLE_TYPES.include?(klass_type)  
60 -#  
61 - task = klass_type.constantize.new(params[:task])  
62 - task.requestor = current_person  
63 - task.target = community  
64 -  
65 - if !task.save  
66 - render_api_errors!(task.errors.full_messages) 33 + kinds = %w[community person enterprise]
  34 + kinds.each do |kind|
  35 + resource kind.pluralize.to_sym do
  36 + segment "/:#{kind}_id" do
  37 + resource :tasks do
  38 + get do
  39 + profile = environment.send(kind.pluralize).find(params["#{kind}_id"])
  40 + present_tasks(profile)
67 end 41 end
68 - present task, :with => Entities::Task, :fields => params[:fields]  
69 - end  
70 -  
71 - end  
72 - end  
73 -  
74 - end  
75 -  
76 - resource :people do  
77 - segment '/:person_id' do  
78 - resource :tasks do  
79 - get do  
80 -# person = environment.people.find(params[:person_id])  
81 -# articles = select_filtered_collection_of(person, 'articles', params)  
82 -# articles = articles.display_filter(current_person, person)  
83 -tasks = Task.all  
84 - present tasks, :with => Entities::Task, :fields => params[:fields]  
85 - end  
86 -  
87 - get ':id' do  
88 -# person = environment.people.find(params[:person_id])  
89 -# article = find_article(person.articles, params[:id])  
90 -task = Task.first  
91 - present task, :with => Entities::Task, :fields => params[:fields]  
92 - end  
93 42
94 - post do  
95 -# person = environment.people.find(params[:person_id])  
96 -# return forbidden! unless current_person.can_post_content?(person)  
97 -#  
98 -# klass_type= params[:content_type].nil? ? 'TinyMceArticle' : params[:content_type]  
99 -# return forbidden! unless ARTICLE_TYPES.include?(klass_type)  
100 -#  
101 -# article = klass_type.constantize.new(params[:article])  
102 -# article.last_changed_by = current_person  
103 -# article.created_by= current_person  
104 -# article.profile = person  
105 -#  
106 -# if !article.save  
107 -# render_api_errors!(article.errors.full_messages)  
108 -# end  
109 -task = Task.first  
110 - present task, :with => Entities::Task, :fields => params[:fields]  
111 - end  
112 -  
113 - end  
114 - end  
115 -  
116 - end  
117 -  
118 - resource :enterprises do  
119 - segment '/:enterprise_id' do  
120 - resource :tasks do  
121 - get do  
122 -# enterprise = environment.enterprises.find(params[:enterprise_id])  
123 -# articles = select_filtered_collection_of(enterprise, 'articles', params)  
124 -# articles = articles.display_filter(current_person, enterprise)  
125 -tasks = Task.all  
126 - present tasks, :with => Entities::Task, :fields => params[:fields]  
127 - end  
128 -  
129 - get ':id' do  
130 -# enterprise = environment.enterprises.find(params[:enterprise_id])  
131 -# article = find_article(enterprise.articles, params[:id])  
132 -task = Task.first  
133 - present task, :with => Entities::Task, :fields => params[:fields]  
134 - end 43 + get ':id' do
  44 + profile = environment.send(kind.pluralize).find(params["#{kind}_id"])
  45 + present_task(profile)
  46 + end
135 47
136 - post do  
137 -# enterprise = environment.enterprises.find(params[:enterprise_id])  
138 -# return forbidden! unless current_person.can_post_content?(enterprise)  
139 -#  
140 -# klass_type= params[:content_type].nil? ? 'TinyMceArticle' : params[:content_type]  
141 -# return forbidden! unless ARTICLE_TYPES.include?(klass_type)  
142 -#  
143 -# article = klass_type.constantize.new(params[:article])  
144 -# article.last_changed_by = current_person  
145 -# article.created_by= current_person  
146 -# article.profile = enterprise  
147 -#  
148 -# if !article.save  
149 -# render_api_errors!(article.errors.full_messages)  
150 -# end  
151 -task = Task.first  
152 - present task, :with => Entities::Task, :fields => params[:fields] 48 + post do
  49 + profile = environment.send(kind.pluralize).find(params["#{kind}_id"])
  50 + post_task(profile, params)
  51 + end
153 end 52 end
154 -  
155 end 53 end
156 end 54 end
157 -  
158 end 55 end
159 -  
160 -  
161 end 56 end
162 end 57 end
163 end 58 end
test/functional/categories_controller_test.rb
@@ -32,12 +32,10 @@ class CategoriesControllerTest &lt; ActionController::TestCase @@ -32,12 +32,10 @@ class CategoriesControllerTest &lt; ActionController::TestCase
32 end 32 end
33 33
34 def test_edit 34 def test_edit
35 - cat = Category.new  
36 - env.categories.expects(:find).with('1').returns(cat)  
37 - get :edit, :id => '1' 35 + get :edit, :id => cat1
38 assert_response :success 36 assert_response :success
39 assert_template 'edit' 37 assert_template 'edit'
40 - assert_equal cat, assigns(:category) 38 + assert_equal cat1, assigns(:category)
41 end 39 end
42 40
43 def test_edit_save 41 def test_edit_save
test/functional/tasks_controller_test.rb
@@ -145,15 +145,23 @@ class TasksControllerTest &lt; ActionController::TestCase @@ -145,15 +145,23 @@ class TasksControllerTest &lt; ActionController::TestCase
145 end 145 end
146 146
147 should 'affiliate roles to user after finish add member task' do 147 should 'affiliate roles to user after finish add member task' do
148 - community = fast_create(Community)  
149 - community.add_member(person)  
150 - another_person = fast_create(Person)  
151 - t = AddMember.create!(:person => another_person, :organization => community)  
152 - count = community.members.size  
153 - @controller.stubs(:profile).returns(community) 148 + c = fast_create(Community)
  149 + p = create_user('member').person
  150 +
  151 + @controller.stubs(:profile).returns(c)
  152 + c.affiliate(profile, Profile::Roles.all_roles(profile.environment.id))
  153 +
  154 + t = AddMember.create!(:person => p, :organization => c)
  155 +
  156 + count = c.members.size
  157 +
154 post :close, :tasks => {t.id => {:decision => 'finish', :task => {}}} 158 post :close, :tasks => {t.id => {:decision => 'finish', :task => {}}}
155 - community = Profile.find(community.id)  
156 - assert_equal count + 1, community.members.size 159 + t.reload
  160 +
  161 + ok('task should be finished') { t.status == Task::Status::FINISHED }
  162 +
  163 + c.reload
  164 + assert_equal count + 1, c.members.size
157 end 165 end
158 166
159 should 'display a create ticket form' do 167 should 'display a create ticket form' do
@@ -269,6 +277,7 @@ class TasksControllerTest &lt; ActionController::TestCase @@ -269,6 +277,7 @@ class TasksControllerTest &lt; ActionController::TestCase
269 @controller.stubs(:profile).returns(c) 277 @controller.stubs(:profile).returns(c)
270 c.affiliate(person, Profile::Roles.all_roles(c.environment)) 278 c.affiliate(person, Profile::Roles.all_roles(c.environment))
271 person = create_user('test_user').person 279 person = create_user('test_user').person
  280 + c.add_member(person)
272 p_blog = Blog.create!(:profile => person, :name => 'Blog') 281 p_blog = Blog.create!(:profile => person, :name => 'Blog')
273 c_blog1 = Blog.create!(:profile => c, :name => 'Blog') 282 c_blog1 = Blog.create!(:profile => c, :name => 'Blog')
274 c_blog2 = Blog.new(:profile => c); c_blog2.name = 'blog2'; c_blog2.save! 283 c_blog2 = Blog.new(:profile => c); c_blog2.name = 'blog2'; c_blog2.save!
test/unit/api/articles_test.rb
@@ -31,7 +31,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -31,7 +31,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
31 end 31 end
32 32
33 should 'not return article if user has no permission to view it' do 33 should 'not return article if user has no permission to view it' do
34 - person = fast_create(Person) 34 + person = fast_create(Person, :environment_id => environment.id)
35 article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) 35 article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false)
36 assert !article.published? 36 assert !article.published?
37 37
@@ -58,7 +58,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -58,7 +58,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
58 end 58 end
59 59
60 should 'not list children of forbidden article' do 60 should 'not list children of forbidden article' do
61 - person = fast_create(Person) 61 + person = fast_create(Person, :environment_id => environment.id)
62 article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) 62 article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false)
63 child1 = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing") 63 child1 = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing")
64 child2 = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing") 64 child2 = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing")
@@ -67,7 +67,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -67,7 +67,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
67 end 67 end
68 68
69 should 'not return child of forbidden article' do 69 should 'not return child of forbidden article' do
70 - person = fast_create(Person) 70 + person = fast_create(Person, :environment_id => environment.id)
71 article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) 71 article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false)
72 child = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing") 72 child = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing")
73 get "/api/v1/articles/#{article.id}/children/#{child.id}?#{params.to_query}" 73 get "/api/v1/articles/#{article.id}/children/#{child.id}?#{params.to_query}"
@@ -75,7 +75,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -75,7 +75,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
75 end 75 end
76 76
77 should 'not return private child' do 77 should 'not return private child' do
78 - person = fast_create(Person) 78 + person = fast_create(Person, :environment_id => environment.id)
79 article = fast_create(Article, :profile_id => person.id, :name => "Some thing") 79 article = fast_create(Article, :profile_id => person.id, :name => "Some thing")
80 child = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing", :published => false) 80 child = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing", :published => false)
81 get "/api/v1/articles/#{article.id}/children/#{child.id}?#{params.to_query}" 81 get "/api/v1/articles/#{article.id}/children/#{child.id}?#{params.to_query}"
@@ -83,7 +83,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -83,7 +83,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
83 end 83 end
84 84
85 should 'not list private child' do 85 should 'not list private child' do
86 - person = fast_create(Person) 86 + person = fast_create(Person, :environment_id => environment.id)
87 article = fast_create(Article, :profile_id => person.id, :name => "Some thing") 87 article = fast_create(Article, :profile_id => person.id, :name => "Some thing")
88 child = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing", :published => false) 88 child = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing", :published => false)
89 get "/api/v1/articles/#{article.id}/children?#{params.to_query}" 89 get "/api/v1/articles/#{article.id}/children?#{params.to_query}"
@@ -98,7 +98,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -98,7 +98,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
98 profile_kinds = %w(community person enterprise) 98 profile_kinds = %w(community person enterprise)
99 profile_kinds.each do |kind| 99 profile_kinds.each do |kind|
100 should "return article by #{kind}" do 100 should "return article by #{kind}" do
101 - profile = fast_create(kind.camelcase.constantize) 101 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
102 article = fast_create(Article, :profile_id => profile.id, :name => "Some thing") 102 article = fast_create(Article, :profile_id => profile.id, :name => "Some thing")
103 get "/api/v1/#{kind.pluralize}/#{profile.id}/articles/#{article.id}?#{params.to_query}" 103 get "/api/v1/#{kind.pluralize}/#{profile.id}/articles/#{article.id}?#{params.to_query}"
104 json = JSON.parse(last_response.body) 104 json = JSON.parse(last_response.body)
@@ -106,7 +106,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -106,7 +106,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
106 end 106 end
107 107
108 should "not return article by #{kind} if user has no permission to view it" do 108 should "not return article by #{kind} if user has no permission to view it" do
109 - profile = fast_create(kind.camelcase.constantize) 109 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
110 article = fast_create(Article, :profile_id => profile.id, :name => "Some thing", :published => false) 110 article = fast_create(Article, :profile_id => profile.id, :name => "Some thing", :published => false)
111 assert !article.published? 111 assert !article.published?
112 112
@@ -115,7 +115,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -115,7 +115,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
115 end 115 end
116 116
117 should "not list forbidden article when listing articles by #{kind}" do 117 should "not list forbidden article when listing articles by #{kind}" do
118 - profile = fast_create(kind.camelcase.constantize) 118 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
119 article = fast_create(Article, :profile_id => profile.id, :name => "Some thing", :published => false) 119 article = fast_create(Article, :profile_id => profile.id, :name => "Some thing", :published => false)
120 assert !article.published? 120 assert !article.published?
121 121
@@ -132,7 +132,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -132,7 +132,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
132 group_kinds = %w(community enterprise) 132 group_kinds = %w(community enterprise)
133 group_kinds.each do |kind| 133 group_kinds.each do |kind|
134 should "#{kind}: create article" do 134 should "#{kind}: create article" do
135 - profile = fast_create(kind.camelcase.constantize) 135 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
136 give_permission(user.person, 'post_content', profile) 136 give_permission(user.person, 'post_content', profile)
137 params[:article] = {:name => "Title"} 137 params[:article] = {:name => "Title"}
138 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" 138 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}"
@@ -141,16 +141,16 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -141,16 +141,16 @@ class ArticlesTest &lt; ActiveSupport::TestCase
141 end 141 end
142 142
143 should "#{kind}: do not create article if user has no permission to post content" do 143 should "#{kind}: do not create article if user has no permission to post content" do
144 - profile = fast_create(kind.camelcase.constantize) 144 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
145 give_permission(user.person, 'invite_members', profile) 145 give_permission(user.person, 'invite_members', profile)
146 params[:article] = {:name => "Title"} 146 params[:article] = {:name => "Title"}
147 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" 147 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}"
148 assert_equal 403, last_response.status 148 assert_equal 403, last_response.status
149 end 149 end
150 150
151 - should "#{kind}: create article with parent" do  
152 - profile = fast_create(kind.camelcase.constantize)  
153 - profile.add_member(user.person) 151 + should "#{kind} create article with parent" do
  152 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
  153 + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true)
154 article = fast_create(Article) 154 article = fast_create(Article)
155 155
156 params[:article] = {:name => "Title", :parent_id => article.id} 156 params[:article] = {:name => "Title", :parent_id => article.id}
@@ -159,9 +159,9 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -159,9 +159,9 @@ class ArticlesTest &lt; ActiveSupport::TestCase
159 assert_equal article.id, json["article"]["parent"]["id"] 159 assert_equal article.id, json["article"]["parent"]["id"]
160 end 160 end
161 161
162 - should "#{kind}: create article with content type passed as parameter" do  
163 - profile = fast_create(kind.camelcase.constantize)  
164 - profile.add_member(user.person) 162 + should "#{kind} create article with content type passed as parameter" do
  163 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
  164 + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true)
165 165
166 Article.delete_all 166 Article.delete_all
167 params[:article] = {:name => "Title"} 167 params[:article] = {:name => "Title"}
@@ -173,8 +173,8 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -173,8 +173,8 @@ class ArticlesTest &lt; ActiveSupport::TestCase
173 end 173 end
174 174
175 should "#{kind}: create article of TinyMceArticle type if no content type is passed as parameter" do 175 should "#{kind}: create article of TinyMceArticle type if no content type is passed as parameter" do
176 - profile = fast_create(kind.camelcase.constantize)  
177 - profile.add_member(user.person) 176 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
  177 + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true)
178 178
179 params[:article] = {:name => "Title"} 179 params[:article] = {:name => "Title"}
180 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" 180 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}"
@@ -184,7 +184,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -184,7 +184,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
184 end 184 end
185 185
186 should "#{kind}: not create article with invalid article content type" do 186 should "#{kind}: not create article with invalid article content type" do
187 - profile = fast_create(kind.camelcase.constantize) 187 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
188 profile.add_member(user.person) 188 profile.add_member(user.person)
189 189
190 params[:article] = {:name => "Title"} 190 params[:article] = {:name => "Title"}
@@ -195,20 +195,20 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -195,20 +195,20 @@ class ArticlesTest &lt; ActiveSupport::TestCase
195 assert_equal 403, last_response.status 195 assert_equal 403, last_response.status
196 end 196 end
197 197
198 - should "#{kind}: create article defining the correct profile" do  
199 - profile = fast_create(kind.camelcase.constantize)  
200 - profile.add_member(user.person) 198 + should "#{kind} create article defining the correct profile" do
  199 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
  200 + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true)
201 201
202 params[:article] = {:name => "Title"} 202 params[:article] = {:name => "Title"}
203 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" 203 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}"
204 json = JSON.parse(last_response.body) 204 json = JSON.parse(last_response.body)
205 205
206 - assert_equal profile, Article.last.profile 206 + assert_equal profile.id, json['article']['profile']['id']
207 end 207 end
208 208
209 should "#{kind}: create article defining the created_by" do 209 should "#{kind}: create article defining the created_by" do
210 - profile = fast_create(kind.camelcase.constantize)  
211 - profile.add_member(user.person) 210 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
  211 + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true)
212 212
213 params[:article] = {:name => "Title"} 213 params[:article] = {:name => "Title"}
214 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" 214 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}"
@@ -218,8 +218,8 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -218,8 +218,8 @@ class ArticlesTest &lt; ActiveSupport::TestCase
218 end 218 end
219 219
220 should "#{kind}: create article defining the last_changed_by" do 220 should "#{kind}: create article defining the last_changed_by" do
221 - profile = fast_create(kind.camelcase.constantize)  
222 - profile.add_member(user.person) 221 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
  222 + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true)
223 223
224 params[:article] = {:name => "Title"} 224 params[:article] = {:name => "Title"}
225 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" 225 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}"
@@ -241,7 +241,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -241,7 +241,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
241 end 241 end
242 242
243 should 'person do not create article if user has no permission to post content' do 243 should 'person do not create article if user has no permission to post content' do
244 - person = fast_create(Person) 244 + person = fast_create(Person, :environment_id => environment.id)
245 params[:article] = {:name => "Title"} 245 params[:article] = {:name => "Title"}
246 post "/api/v1/people/#{person.id}/articles?#{params.to_query}" 246 post "/api/v1/people/#{person.id}/articles?#{params.to_query}"
247 assert_equal 403, last_response.status 247 assert_equal 403, last_response.status
test/unit/api/categories_test.rb
@@ -7,25 +7,25 @@ class CategoriesTest &lt; ActiveSupport::TestCase @@ -7,25 +7,25 @@ class CategoriesTest &lt; ActiveSupport::TestCase
7 end 7 end
8 8
9 should 'list categories' do 9 should 'list categories' do
10 - category = fast_create(Category) 10 + category = fast_create(Category, :environment_id => environment.id)
11 get "/api/v1/categories/?#{params.to_query}" 11 get "/api/v1/categories/?#{params.to_query}"
12 json = JSON.parse(last_response.body) 12 json = JSON.parse(last_response.body)
13 assert_includes json["categories"].map { |c| c["name"] }, category.name 13 assert_includes json["categories"].map { |c| c["name"] }, category.name
14 end 14 end
15 15
16 should 'get category by id' do 16 should 'get category by id' do
17 - category = fast_create(Category) 17 + category = fast_create(Category, :environment_id => environment.id)
18 get "/api/v1/categories/#{category.id}/?#{params.to_query}" 18 get "/api/v1/categories/#{category.id}/?#{params.to_query}"
19 json = JSON.parse(last_response.body) 19 json = JSON.parse(last_response.body)
20 assert_equal category.name, json["category"]["name"] 20 assert_equal category.name, json["category"]["name"]
21 end 21 end
22 22
23 should 'list parent and children when get category by id' do 23 should 'list parent and children when get category by id' do
24 - parent = fast_create(Category)  
25 - child_1 = fast_create(Category)  
26 - child_2 = fast_create(Category) 24 + parent = fast_create(Category, :environment_id => environment.id)
  25 + child_1 = fast_create(Category, :environment_id => environment.id)
  26 + child_2 = fast_create(Category, :environment_id => environment.id)
27 27
28 - category = fast_create(Category) 28 + category = fast_create(Category, :environment_id => environment.id)
29 category.parent = parent 29 category.parent = parent
30 category.children << child_1 30 category.children << child_1
31 category.children << child_2 31 category.children << child_2
@@ -38,11 +38,11 @@ class CategoriesTest &lt; ActiveSupport::TestCase @@ -38,11 +38,11 @@ class CategoriesTest &lt; ActiveSupport::TestCase
38 end 38 end
39 39
40 should 'include parent in categories list if params is true' do 40 should 'include parent in categories list if params is true' do
41 - parent_1 = fast_create(Category) # parent_1 has no parent category  
42 - child_1 = fast_create(Category)  
43 - child_2 = fast_create(Category) 41 + parent_1 = fast_create(Category, :environment_id => environment.id) # parent_1 has no parent category
  42 + child_1 = fast_create(Category, :environment_id => environment.id)
  43 + child_2 = fast_create(Category, :environment_id => environment.id)
44 44
45 - parent_2 = fast_create(Category) 45 + parent_2 = fast_create(Category, :environment_id => environment.id)
46 parent_2.parent = parent_1 46 parent_2.parent = parent_1
47 parent_2.children << child_1 47 parent_2.children << child_1
48 parent_2.children << child_2 48 parent_2.children << child_2
@@ -60,10 +60,10 @@ class CategoriesTest &lt; ActiveSupport::TestCase @@ -60,10 +60,10 @@ class CategoriesTest &lt; ActiveSupport::TestCase
60 end 60 end
61 61
62 should 'include children in categories list if params is true' do 62 should 'include children in categories list if params is true' do
63 - category = fast_create(Category)  
64 - child_1 = fast_create(Category)  
65 - child_2 = fast_create(Category)  
66 - child_3 = fast_create(Category) 63 + category = fast_create(Category, :environment_id => environment.id)
  64 + child_1 = fast_create(Category, :environment_id => environment.id)
  65 + child_2 = fast_create(Category, :environment_id => environment.id)
  66 + child_3 = fast_create(Category, :environment_id => environment.id)
67 67
68 category.children << child_1 68 category.children << child_1
69 category.children << child_2 69 category.children << child_2
test/unit/api/communities_test.rb
@@ -8,8 +8,8 @@ class CommunitiesTest &lt; ActiveSupport::TestCase @@ -8,8 +8,8 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
8 end 8 end
9 9
10 should 'list only communities' do 10 should 'list only communities' do
11 - community = fast_create(Community)  
12 - enterprise = fast_create(Enterprise) # should not list this enterprise 11 + community = fast_create(Community, :environment_id => environment.id)
  12 + enterprise = fast_create(Enterprise, :environment_id => environment.id) # should not list this enterprise
13 get "/api/v1/communities?#{params.to_query}" 13 get "/api/v1/communities?#{params.to_query}"
14 json = JSON.parse(last_response.body) 14 json = JSON.parse(last_response.body)
15 assert_not_includes json['communities'].map {|c| c['id']}, enterprise.id 15 assert_not_includes json['communities'].map {|c| c['id']}, enterprise.id
@@ -17,16 +17,16 @@ class CommunitiesTest &lt; ActiveSupport::TestCase @@ -17,16 +17,16 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
17 end 17 end
18 18
19 should 'list all communities' do 19 should 'list all communities' do
20 - community1 = fast_create(Community, :public_profile => true)  
21 - community2 = fast_create(Community) 20 + community1 = fast_create(Community, :environment_id => environment.id, :public_profile => true)
  21 + community2 = fast_create(Community, :environment_id => environment.id)
22 get "/api/v1/communities?#{params.to_query}" 22 get "/api/v1/communities?#{params.to_query}"
23 json = JSON.parse(last_response.body) 23 json = JSON.parse(last_response.body)
24 assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']} 24 assert_equivalent [community1.id, community2.id], json['communities'].map {|c| c['id']}
25 end 25 end
26 26
27 should 'not list invisible communities' do 27 should 'not list invisible communities' do
28 - community1 = fast_create(Community)  
29 - fast_create(Community, :visible => false) 28 + community1 = fast_create(Community, :environment_id => environment.id)
  29 + fast_create(Community, :environment_id => environment.id, :visible => false)
30 30
31 get "/api/v1/communities?#{params.to_query}" 31 get "/api/v1/communities?#{params.to_query}"
32 json = JSON.parse(last_response.body) 32 json = JSON.parse(last_response.body)
@@ -34,8 +34,8 @@ class CommunitiesTest &lt; ActiveSupport::TestCase @@ -34,8 +34,8 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
34 end 34 end
35 35
36 should 'not list private communities without permission' do 36 should 'not list private communities without permission' do
37 - community1 = fast_create(Community)  
38 - fast_create(Community, :public_profile => false) 37 + community1 = fast_create(Community, :environment_id => environment.id)
  38 + fast_create(Community, :environment_id => environment.id, :public_profile => false)
39 39
40 get "/api/v1/communities?#{params.to_query}" 40 get "/api/v1/communities?#{params.to_query}"
41 json = JSON.parse(last_response.body) 41 json = JSON.parse(last_response.body)
@@ -43,8 +43,8 @@ class CommunitiesTest &lt; ActiveSupport::TestCase @@ -43,8 +43,8 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
43 end 43 end
44 44
45 should 'list private community for members' do 45 should 'list private community for members' do
46 - c1 = fast_create(Community)  
47 - c2 = fast_create(Community, :public_profile => false) 46 + c1 = fast_create(Community, :environment_id => environment.id)
  47 + c2 = fast_create(Community, :environment_id => environment.id, :public_profile => false)
48 c2.add_member(person) 48 c2.add_member(person)
49 49
50 get "/api/v1/communities?#{params.to_query}" 50 get "/api/v1/communities?#{params.to_query}"
@@ -66,7 +66,7 @@ class CommunitiesTest &lt; ActiveSupport::TestCase @@ -66,7 +66,7 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
66 end 66 end
67 67
68 should 'get community' do 68 should 'get community' do
69 - community = fast_create(Community) 69 + community = fast_create(Community, :environment_id => environment.id)
70 70
71 get "/api/v1/communities/#{community.id}?#{params.to_query}" 71 get "/api/v1/communities/#{community.id}?#{params.to_query}"
72 json = JSON.parse(last_response.body) 72 json = JSON.parse(last_response.body)
@@ -74,7 +74,7 @@ class CommunitiesTest &lt; ActiveSupport::TestCase @@ -74,7 +74,7 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
74 end 74 end
75 75
76 should 'not get invisible community' do 76 should 'not get invisible community' do
77 - community = fast_create(Community, :visible => false) 77 + community = fast_create(Community, :environment_id => environment.id, :visible => false)
78 78
79 get "/api/v1/communities/#{community.id}?#{params.to_query}" 79 get "/api/v1/communities/#{community.id}?#{params.to_query}"
80 json = JSON.parse(last_response.body) 80 json = JSON.parse(last_response.body)
@@ -82,8 +82,8 @@ class CommunitiesTest &lt; ActiveSupport::TestCase @@ -82,8 +82,8 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
82 end 82 end
83 83
84 should 'not get private communities without permission' do 84 should 'not get private communities without permission' do
85 - community = fast_create(Community)  
86 - fast_create(Community, :public_profile => false) 85 + community = fast_create(Community, :environment_id => environment.id)
  86 + fast_create(Community, :environment_id => environment.id, :public_profile => false)
87 87
88 get "/api/v1/communities/#{community.id}?#{params.to_query}" 88 get "/api/v1/communities/#{community.id}?#{params.to_query}"
89 json = JSON.parse(last_response.body) 89 json = JSON.parse(last_response.body)
@@ -91,17 +91,18 @@ class CommunitiesTest &lt; ActiveSupport::TestCase @@ -91,17 +91,18 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
91 end 91 end
92 92
93 should 'get private community for members' do 93 should 'get private community for members' do
94 - community = fast_create(Community, :public_profile => false) 94 + community = fast_create(Community, :environment_id => environment.id, :public_profile => false, :visible => true)
95 community.add_member(person) 95 community.add_member(person)
96 96
  97 +
97 get "/api/v1/communities/#{community.id}?#{params.to_query}" 98 get "/api/v1/communities/#{community.id}?#{params.to_query}"
98 json = JSON.parse(last_response.body) 99 json = JSON.parse(last_response.body)
99 assert_equal community.id, json['community']['id'] 100 assert_equal community.id, json['community']['id']
100 end 101 end
101 102
102 should 'list person communities' do 103 should 'list person communities' do
103 - community = fast_create(Community)  
104 - fast_create(Community) 104 + community = fast_create(Community, :environment_id => environment.id)
  105 + fast_create(Community, :environment_id => environment.id)
105 community.add_member(person) 106 community.add_member(person)
106 107
107 get "/api/v1/people/#{person.id}/communities?#{params.to_query}" 108 get "/api/v1/people/#{person.id}/communities?#{params.to_query}"
@@ -110,8 +111,8 @@ class CommunitiesTest &lt; ActiveSupport::TestCase @@ -110,8 +111,8 @@ class CommunitiesTest &lt; ActiveSupport::TestCase
110 end 111 end
111 112
112 should 'not list person communities invisible' do 113 should 'not list person communities invisible' do
113 - c1 = fast_create(Community)  
114 - c2 = fast_create(Community, :visible => false) 114 + c1 = fast_create(Community, :environment_id => environment.id)
  115 + c2 = fast_create(Community, :environment_id => environment.id, :visible => false)
115 c1.add_member(person) 116 c1.add_member(person)
116 c2.add_member(person) 117 c2.add_member(person)
117 118
test/unit/api/enterprises_test.rb
@@ -8,8 +8,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase @@ -8,8 +8,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase
8 end 8 end
9 9
10 should 'list only enterprises' do 10 should 'list only enterprises' do
11 - community = fast_create(Community) # should not list this community  
12 - enterprise = fast_create(Enterprise, :public_profile => true) 11 + community = fast_create(Community, :environment_id => environment.id) # should not list this community
  12 + enterprise = fast_create(Enterprise, :environment_id => environment.id, :public_profile => true)
13 get "/api/v1/enterprises?#{params.to_query}" 13 get "/api/v1/enterprises?#{params.to_query}"
14 json = JSON.parse(last_response.body) 14 json = JSON.parse(last_response.body)
15 assert_includes json['enterprises'].map {|c| c['id']}, enterprise.id 15 assert_includes json['enterprises'].map {|c| c['id']}, enterprise.id
@@ -17,15 +17,15 @@ class EnterprisesTest &lt; ActiveSupport::TestCase @@ -17,15 +17,15 @@ class EnterprisesTest &lt; ActiveSupport::TestCase
17 end 17 end
18 18
19 should 'list all enterprises' do 19 should 'list all enterprises' do
20 - enterprise1 = fast_create(Enterprise, :public_profile => true)  
21 - enterprise2 = fast_create(Enterprise) 20 + enterprise1 = fast_create(Enterprise, :environment_id => environment.id, :public_profile => true)
  21 + enterprise2 = fast_create(Enterprise, :environment_id => environment.id)
22 get "/api/v1/enterprises?#{params.to_query}" 22 get "/api/v1/enterprises?#{params.to_query}"
23 json = JSON.parse(last_response.body) 23 json = JSON.parse(last_response.body)
24 assert_equivalent [enterprise1.id, enterprise2.id], json['enterprises'].map {|c| c['id']} 24 assert_equivalent [enterprise1.id, enterprise2.id], json['enterprises'].map {|c| c['id']}
25 end 25 end
26 26
27 should 'not list invisible enterprises' do 27 should 'not list invisible enterprises' do
28 - enterprise1 = fast_create(Enterprise) 28 + enterprise1 = fast_create(Enterprise, :environment_id => environment.id)
29 fast_create(Enterprise, :visible => false) 29 fast_create(Enterprise, :visible => false)
30 30
31 get "/api/v1/enterprises?#{params.to_query}" 31 get "/api/v1/enterprises?#{params.to_query}"
@@ -34,8 +34,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase @@ -34,8 +34,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase
34 end 34 end
35 35
36 should 'not list private enterprises without permission' do 36 should 'not list private enterprises without permission' do
37 - enterprise1 = fast_create(Enterprise)  
38 - fast_create(Enterprise, :public_profile => false) 37 + enterprise1 = fast_create(Enterprise, :environment_id => environment.id)
  38 + fast_create(Enterprise, :environment_id => environment.id, :public_profile => false)
39 39
40 get "/api/v1/enterprises?#{params.to_query}" 40 get "/api/v1/enterprises?#{params.to_query}"
41 json = JSON.parse(last_response.body) 41 json = JSON.parse(last_response.body)
@@ -43,8 +43,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase @@ -43,8 +43,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase
43 end 43 end
44 44
45 should 'list private enterprise for members' do 45 should 'list private enterprise for members' do
46 - c1 = fast_create(Enterprise)  
47 - c2 = fast_create(Enterprise, :public_profile => false) 46 + c1 = fast_create(Enterprise, :environment_id => environment.id)
  47 + c2 = fast_create(Enterprise, :environment_id => environment.id, :public_profile => false)
48 c2.add_member(person) 48 c2.add_member(person)
49 49
50 get "/api/v1/enterprises?#{params.to_query}" 50 get "/api/v1/enterprises?#{params.to_query}"
@@ -53,7 +53,7 @@ class EnterprisesTest &lt; ActiveSupport::TestCase @@ -53,7 +53,7 @@ class EnterprisesTest &lt; ActiveSupport::TestCase
53 end 53 end
54 54
55 should 'get enterprise' do 55 should 'get enterprise' do
56 - enterprise = fast_create(Enterprise) 56 + enterprise = fast_create(Enterprise, :environment_id => environment.id)
57 57
58 get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}" 58 get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}"
59 json = JSON.parse(last_response.body) 59 json = JSON.parse(last_response.body)
@@ -69,8 +69,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase @@ -69,8 +69,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase
69 end 69 end
70 70
71 should 'not get private enterprises without permission' do 71 should 'not get private enterprises without permission' do
72 - enterprise = fast_create(Enterprise)  
73 - fast_create(Enterprise, :public_profile => false) 72 + enterprise = fast_create(Enterprise, :environment_id => environment.id)
  73 + fast_create(Enterprise, :environment_id => environment.id, :public_profile => false)
74 74
75 get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}" 75 get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}"
76 json = JSON.parse(last_response.body) 76 json = JSON.parse(last_response.body)
@@ -87,8 +87,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase @@ -87,8 +87,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase
87 end 87 end
88 88
89 should 'list person enterprises' do 89 should 'list person enterprises' do
90 - enterprise = fast_create(Enterprise)  
91 - fast_create(Enterprise) 90 + enterprise = fast_create(Enterprise, :environment_id => environment.id)
  91 + fast_create(Enterprise, :environment_id => environment.id)
92 enterprise.add_member(person) 92 enterprise.add_member(person)
93 93
94 get "/api/v1/people/#{person.id}/enterprises?#{params.to_query}" 94 get "/api/v1/people/#{person.id}/enterprises?#{params.to_query}"
@@ -97,8 +97,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase @@ -97,8 +97,8 @@ class EnterprisesTest &lt; ActiveSupport::TestCase
97 end 97 end
98 98
99 should 'not list person enterprises invisible' do 99 should 'not list person enterprises invisible' do
100 - c1 = fast_create(Enterprise)  
101 - c2 = fast_create(Enterprise, :visible => false) 100 + c1 = fast_create(Enterprise, :environment_id => environment.id)
  101 + c2 = fast_create(Enterprise, :environment_id => environment.id, :visible => false)
102 c1.add_member(person) 102 c1.add_member(person)
103 c2.add_member(person) 103 c2.add_member(person)
104 104
test/unit/api/task_test.rb
@@ -12,6 +12,7 @@ class TasksTest &lt; ActiveSupport::TestCase @@ -12,6 +12,7 @@ class TasksTest &lt; ActiveSupport::TestCase
12 attr_accessor :person, :community, :environment 12 attr_accessor :person, :community, :environment
13 13
14 should 'list tasks of environment' do 14 should 'list tasks of environment' do
  15 + environment.add_admin(person)
15 task = create(Task, :requestor => person, :target => environment) 16 task = create(Task, :requestor => person, :target => environment)
16 get "/api/v1/tasks?#{params.to_query}" 17 get "/api/v1/tasks?#{params.to_query}"
17 json = JSON.parse(last_response.body) 18 json = JSON.parse(last_response.body)
@@ -26,364 +27,147 @@ class TasksTest &lt; ActiveSupport::TestCase @@ -26,364 +27,147 @@ class TasksTest &lt; ActiveSupport::TestCase
26 assert_equal task.id, json["task"]["id"] 27 assert_equal task.id, json["task"]["id"]
27 end 28 end
28 29
29 -# should 'not return environmet task if user has no permission to view it' do  
30 -# person = fast_create(Person)  
31 -# task = create(Task, :requestor => person, :target => environment)  
32 -#  
33 -# get "/api/v1/tasks/#{task.id}?#{params.to_query}"  
34 -# assert_equal 403, last_response.status  
35 -# end  
36 -#  
37 -# #############################  
38 -# # Community Tasks #  
39 -# #############################  
40 -#  
41 -# should 'return task by community' do  
42 -# community = fast_create(Community)  
43 -# task = create(Task, :requestor => person, :target => community)  
44 -# get "/api/v1/communities/#{community.id}/tasks/#{task.id}?#{params.to_query}"  
45 -# json = JSON.parse(last_response.body)  
46 -# assert_equal task.id, json["task"]["id"]  
47 -# end  
48 -#  
49 -# should 'not return task by community if user has no permission to view it' do  
50 -# community = fast_create(Community)  
51 -# task = create(Task, :requestor => person, :target => community)  
52 -# assert !person.is_member_of?(community)  
53 -#  
54 -# get "/api/v1/communities/#{community.id}/tasks/#{task.id}?#{params.to_query}"  
55 -# assert_equal 403, last_response.status  
56 -# end  
57 -#  
58 -## should 'not list forbidden article when listing articles by community' do  
59 -## community = fast_create(Community)  
60 -## article = fast_create(Article, :profile_id => community.id, :name => "Some thing", :published => false)  
61 -## assert !article.published?  
62 -##  
63 -## get "/api/v1/communities/#{community.id}/articles?#{params.to_query}"  
64 -## json = JSON.parse(last_response.body)  
65 -## assert_not_includes json['articles'].map {|a| a['id']}, article.id  
66 -## end  
67 -#  
68 -# should 'create task in a community' do  
69 -# community = fast_create(Community)  
70 -# give_permission(person, 'post_content', community)  
71 -# post "/api/v1/communities/#{community.id}/tasks?#{params.to_query}"  
72 -# json = JSON.parse(last_response.body)  
73 -# assert_not_nil json["task"]["id"]  
74 -# end  
75 -#  
76 -# should 'do not create article if user has no permission to post content' do  
77 -#assert false  
78 -## community = fast_create(Community)  
79 -## give_permission(user.person, 'invite_members', community)  
80 -## params[:article] = {:name => "Title"}  
81 -## post "/api/v1/communities/#{community.id}/articles?#{params.to_query}"  
82 -## assert_equal 403, last_response.status  
83 -# end  
84 -#  
85 -## should 'create article with parent' do  
86 -## community = fast_create(Community)  
87 -## community.add_member(user.person)  
88 -## article = fast_create(Article)  
89 -##  
90 -## params[:article] = {:name => "Title", :parent_id => article.id}  
91 -## post "/api/v1/communities/#{community.id}/articles?#{params.to_query}"  
92 -## json = JSON.parse(last_response.body)  
93 -## assert_equal article.id, json["article"]["parent"]["id"]  
94 -## end  
95 -#  
96 -# should 'create task defining the requestor as current profile logged in' do  
97 -# community = fast_create(Community)  
98 -# community.add_member(person)  
99 -#  
100 -# post "/api/v1/communities/#{community.id}/tasks?#{params.to_query}"  
101 -# json = JSON.parse(last_response.body)  
102 -#  
103 -# assert_equal person, Task.last.requestor  
104 -# end  
105 -#  
106 -# should 'create task defining the target as the community' do  
107 -# community = fast_create(Community)  
108 -# community.add_member(person)  
109 -#  
110 -# post "/api/v1/communities/#{community.id}/tasks?#{params.to_query}"  
111 -# json = JSON.parse(last_response.body)  
112 -#  
113 -# assert_equal community, Task.last.target  
114 -# end  
115 -#  
116 -## #############################  
117 -## # Person Articles #  
118 -## #############################  
119 -##  
120 -## should 'return article by person' do  
121 -## person = fast_create(Person)  
122 -## article = fast_create(Article, :profile_id => person.id, :name => "Some thing")  
123 -## get "/api/v1/people/#{person.id}/articles/#{article.id}?#{params.to_query}"  
124 -## json = JSON.parse(last_response.body)  
125 -## assert_equal article.id, json["article"]["id"]  
126 -## end  
127 -##  
128 -## should 'not return article by person if user has no permission to view it' do  
129 -## person = fast_create(Person)  
130 -## article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false)  
131 -## assert !article.published?  
132 -##  
133 -## get "/api/v1/people/#{person.id}/articles/#{article.id}?#{params.to_query}"  
134 -## assert_equal 403, last_response.status  
135 -## end  
136 -##  
137 -## should 'not list forbidden article when listing articles by person' do  
138 -## person = fast_create(Person)  
139 -## article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false)  
140 -## assert !article.published?  
141 -## get "/api/v1/people/#{person.id}/articles?#{params.to_query}"  
142 -## json = JSON.parse(last_response.body)  
143 -## assert_not_includes json['articles'].map {|a| a['id']}, article.id  
144 -## end  
145 -##  
146 -## should 'create article in a person' do  
147 -## params[:article] = {:name => "Title"}  
148 -## post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"  
149 -## json = JSON.parse(last_response.body)  
150 -## assert_equal "Title", json["article"]["title"]  
151 -## end  
152 -##  
153 -## should 'person do not create article if user has no permission to post content' do  
154 -## person = fast_create(Person)  
155 -## params[:article] = {:name => "Title"}  
156 -## post "/api/v1/people/#{person.id}/articles?#{params.to_query}"  
157 -## assert_equal 403, last_response.status  
158 -## end  
159 -##  
160 -## should 'person create article with parent' do  
161 -## article = fast_create(Article)  
162 -##  
163 -## params[:article] = {:name => "Title", :parent_id => article.id}  
164 -## post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"  
165 -## json = JSON.parse(last_response.body)  
166 -## assert_equal article.id, json["article"]["parent"]["id"]  
167 -## end  
168 -##  
169 -## should 'person create article with content type passed as parameter' do  
170 -## Article.delete_all  
171 -## params[:article] = {:name => "Title"}  
172 -## params[:content_type] = 'TextArticle'  
173 -## post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"  
174 -## json = JSON.parse(last_response.body)  
175 -##  
176 -## assert_kind_of TextArticle, Article.last  
177 -## end  
178 -##  
179 -## should 'person create article of TinyMceArticle type if no content type is passed as parameter' do  
180 -## params[:article] = {:name => "Title"}  
181 -## post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"  
182 -## json = JSON.parse(last_response.body)  
183 -##  
184 -## assert_kind_of TinyMceArticle, Article.last  
185 -## end  
186 -##  
187 -## should 'person not create article with invalid article content type' do  
188 -## params[:article] = {:name => "Title"}  
189 -## params[:content_type] = 'Person'  
190 -## post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"  
191 -## json = JSON.parse(last_response.body)  
192 -##  
193 -## assert_equal 403, last_response.status  
194 -## end  
195 -##  
196 -## should 'person create article defining the correct profile' do  
197 -## params[:article] = {:name => "Title"}  
198 -## post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"  
199 -## json = JSON.parse(last_response.body)  
200 -##  
201 -## assert_equal user.person, Article.last.profile  
202 -## end  
203 -##  
204 -## should 'person create article defining the created_by' do  
205 -## params[:article] = {:name => "Title"}  
206 -## post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"  
207 -## json = JSON.parse(last_response.body)  
208 -##  
209 -## assert_equal user.person, Article.last.created_by  
210 -## end  
211 -##  
212 -## should 'person create article defining the last_changed_by' do  
213 -## params[:article] = {:name => "Title"}  
214 -## post "/api/v1/people/#{user.person.id}/articles?#{params.to_query}"  
215 -## json = JSON.parse(last_response.body)  
216 -##  
217 -## assert_equal user.person, Article.last.last_changed_by  
218 -## end  
219 -##  
220 -## #############################  
221 -## # Enterprise Articles #  
222 -## #############################  
223 -##  
224 -## should 'return article by enterprise' do  
225 -## enterprise = fast_create(Enterprise)  
226 -## article = fast_create(Article, :profile_id => enterprise.id, :name => "Some thing")  
227 -## get "/api/v1/enterprises/#{enterprise.id}/articles/#{article.id}?#{params.to_query}"  
228 -## json = JSON.parse(last_response.body)  
229 -## assert_equal article.id, json["article"]["id"]  
230 -## end  
231 -##  
232 -## should 'not return article by enterprise if user has no permission to view it' do  
233 -## enterprise = fast_create(Enterprise)  
234 -## article = fast_create(Article, :profile_id => enterprise.id, :name => "Some thing", :published => false)  
235 -## assert !article.published?  
236 -##  
237 -## get "/api/v1/enterprises/#{enterprise.id}/articles/#{article.id}?#{params.to_query}"  
238 -## assert_equal 403, last_response.status  
239 -## end  
240 -##  
241 -## should 'not list forbidden article when listing articles by enterprise' do  
242 -## enterprise = fast_create(Enterprise)  
243 -## article = fast_create(Article, :profile_id => enterprise.id, :name => "Some thing", :published => false)  
244 -## assert !article.published?  
245 -##  
246 -## get "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"  
247 -## json = JSON.parse(last_response.body)  
248 -## assert_not_includes json['articles'].map {|a| a['id']}, article.id  
249 -## end  
250 -##  
251 -## should 'create article in a enterprise' do  
252 -## enterprise = fast_create(Enterprise)  
253 -## give_permission(user.person, 'post_content', enterprise)  
254 -## params[:article] = {:name => "Title"}  
255 -## post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"  
256 -## json = JSON.parse(last_response.body)  
257 -## assert_equal "Title", json["article"]["title"]  
258 -## end  
259 -##  
260 -## should 'enterprise: do not create article if user has no permission to post content' do  
261 -## enterprise = fast_create(Enterprise)  
262 -## give_permission(user.person, 'invite_members', enterprise)  
263 -## params[:article] = {:name => "Title"}  
264 -## post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"  
265 -## assert_equal 403, last_response.status  
266 -## end  
267 -##  
268 -## should 'enterprise: create article with parent' do  
269 -## enterprise = fast_create(Enterprise)  
270 -## enterprise.add_member(user.person)  
271 -## article = fast_create(Article)  
272 -##  
273 -## params[:article] = {:name => "Title", :parent_id => article.id}  
274 -## post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"  
275 -## json = JSON.parse(last_response.body)  
276 -## assert_equal article.id, json["article"]["parent"]["id"]  
277 -## end  
278 -##  
279 -## should 'enterprise: create article with content type passed as parameter' do  
280 -## enterprise = fast_create(Enterprise)  
281 -## enterprise.add_member(user.person)  
282 -##  
283 -## Article.delete_all  
284 -## params[:article] = {:name => "Title"}  
285 -## params[:content_type] = 'TextArticle'  
286 -## post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"  
287 -## json = JSON.parse(last_response.body)  
288 -##  
289 -## assert_kind_of TextArticle, Article.last  
290 -## end  
291 -##  
292 -## should 'enterprise: create article of TinyMceArticle type if no content type is passed as parameter' do  
293 -## enterprise = fast_create(Enterprise)  
294 -## enterprise.add_member(user.person)  
295 -##  
296 -## params[:article] = {:name => "Title"}  
297 -## post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"  
298 -## json = JSON.parse(last_response.body)  
299 -##  
300 -## assert_kind_of TinyMceArticle, Article.last  
301 -## end  
302 -##  
303 -## should 'enterprise: not create article with invalid article content type' do  
304 -## enterprise = fast_create(Enterprise)  
305 -## enterprise.add_member(user.person)  
306 -##  
307 -## params[:article] = {:name => "Title"}  
308 -## params[:content_type] = 'Person'  
309 -## post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"  
310 -## json = JSON.parse(last_response.body)  
311 -##  
312 -## assert_equal 403, last_response.status  
313 -## end  
314 -##  
315 -## should 'enterprise: create article defining the correct profile' do  
316 -## enterprise = fast_create(Enterprise)  
317 -## enterprise.add_member(user.person)  
318 -##  
319 -## params[:article] = {:name => "Title"}  
320 -## post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"  
321 -## json = JSON.parse(last_response.body)  
322 -##  
323 -## assert_equal enterprise, Article.last.profile  
324 -## end  
325 -##  
326 -## should 'enterprise: create article defining the created_by' do  
327 -## enterprise = fast_create(Enterprise)  
328 -## enterprise.add_member(user.person)  
329 -##  
330 -## params[:article] = {:name => "Title"}  
331 -## post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"  
332 -## json = JSON.parse(last_response.body)  
333 -##  
334 -## assert_equal user.person, Article.last.created_by  
335 -## end  
336 -##  
337 -## should 'enterprise: create article defining the last_changed_by' do  
338 -## enterprise = fast_create(Enterprise)  
339 -## enterprise.add_member(user.person)  
340 -##  
341 -## params[:article] = {:name => "Title"}  
342 -## post "/api/v1/enterprises/#{enterprise.id}/articles?#{params.to_query}"  
343 -## json = JSON.parse(last_response.body)  
344 -##  
345 -## assert_equal user.person, Article.last.last_changed_by  
346 -## end  
347 -##  
348 -## should 'list article children with partial fields' do  
349 -## article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")  
350 -## child1 = fast_create(Article, :parent_id => article.id, :profile_id => user.person.id, :name => "Some thing")  
351 -## params[:fields] = [:title]  
352 -## get "/api/v1/articles/#{article.id}/children?#{params.to_query}"  
353 -## json = JSON.parse(last_response.body)  
354 -## assert_equal ['title'], json['articles'].first.keys  
355 -## end  
356 -##  
357 -## should 'suggest article children' do  
358 -## article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")  
359 -## params[:target_id] = user.person.id  
360 -## params[:article] = {:name => "Article name", :body => "Article body"}  
361 -## assert_difference "SuggestArticle.count" do  
362 -## post "/api/v1/articles/#{article.id}/children/suggest?#{params.to_query}"  
363 -## end  
364 -## json = JSON.parse(last_response.body)  
365 -## assert_equal 'SuggestArticle', json['type']  
366 -## end  
367 -##  
368 -## should 'suggest event children' do  
369 -## article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")  
370 -## params[:target_id] = user.person.id  
371 -## params[:article] = {:name => "Article name", :body => "Article body", :type => "Event"}  
372 -## assert_difference "SuggestArticle.count" do  
373 -## post "/api/v1/articles/#{article.id}/children/suggest?#{params.to_query}"  
374 -## end  
375 -## json = JSON.parse(last_response.body)  
376 -## assert_equal 'SuggestArticle', json['type']  
377 -## end  
378 -##  
379 -## should 'update hit attribute of article children' do  
380 -## a1 = fast_create(Article, :profile_id => user.person.id)  
381 -## a2 = fast_create(Article, :parent_id => a1.id, :profile_id => user.person.id)  
382 -## a3 = fast_create(Article, :parent_id => a1.id, :profile_id => user.person.id)  
383 -## get "/api/v1/articles/#{a1.id}/children?#{params.to_query}"  
384 -## json = JSON.parse(last_response.body)  
385 -## assert_equal [1, 1], json['articles'].map { |a| a['hits']}  
386 -## assert_equal [0, 1, 1], [a1.reload.hits, a2.reload.hits, a3.reload.hits]  
387 -## end  
388 -## 30 + should 'not return environmet task if user has no permission to view it' do
  31 + person = fast_create(Person)
  32 + task = create(Task, :requestor => person, :target => environment)
  33 +
  34 + get "/api/v1/tasks/#{task.id}?#{params.to_query}"
  35 + assert_equal 403, last_response.status
  36 + end
  37 +
  38 + #############################
  39 + # Community Tasks #
  40 + #############################
  41 +
  42 + should 'return task by community' do
  43 + community = fast_create(Community)
  44 + community.add_admin(person)
  45 +
  46 + task = create(Task, :requestor => person, :target => community)
  47 + assert person.is_member_of?(community)
  48 +
  49 + get "/api/v1/communities/#{community.id}/tasks/#{task.id}?#{params.to_query}"
  50 + json = JSON.parse(last_response.body)
  51 + assert_equal task.id, json["task"]["id"]
  52 + end
  53 +
  54 + should 'not return task by community if user has no permission to view it' do
  55 + community = fast_create(Community)
  56 + task = create(Task, :requestor => person, :target => community)
  57 + assert !person.is_member_of?(community)
  58 +
  59 + get "/api/v1/communities/#{community.id}/tasks/#{task.id}?#{params.to_query}"
  60 + assert_equal 403, last_response.status
  61 + end
  62 +
  63 + should 'create task in a community' do
  64 + community = fast_create(Community)
  65 + give_permission(person, 'perform_task', community)
  66 + post "/api/v1/communities/#{community.id}/tasks?#{params.to_query}"
  67 + json = JSON.parse(last_response.body)
  68 + assert_not_nil json["task"]["id"]
  69 + end
  70 +
  71 + should 'create task defining the requestor as current profile logged in' do
  72 + community = fast_create(Community)
  73 + community.add_member(person)
  74 +
  75 + post "/api/v1/communities/#{community.id}/tasks?#{params.to_query}"
  76 + json = JSON.parse(last_response.body)
  77 +
  78 + assert_equal person, Task.last.requestor
  79 + end
  80 +
  81 + should 'create task defining the target as the community' do
  82 + community = fast_create(Community)
  83 + community.add_member(person)
  84 +
  85 + post "/api/v1/communities/#{community.id}/tasks?#{params.to_query}"
  86 + json = JSON.parse(last_response.body)
  87 +
  88 + assert_equal community, Task.last.target
  89 + end
  90 +
  91 + #############################
  92 + # Person Tasks #
  93 + #############################
  94 +
  95 + should 'return task by person' do
  96 + task = create(Task, :requestor => person, :target => person)
  97 + get "/api/v1/people/#{person.id}/tasks/#{task.id}?#{params.to_query}"
  98 + json = JSON.parse(last_response.body)
  99 + assert_equal task.id, json["task"]["id"]
  100 + end
  101 +
  102 + should 'not return task by person if user has no permission to view it' do
  103 + some_person = fast_create(Person)
  104 + task = create(Task, :requestor => person, :target => some_person)
  105 +
  106 + get "/api/v1/people/#{some_person.id}/tasks/#{task.id}?#{params.to_query}"
  107 + assert_equal 403, last_response.status
  108 + end
  109 +
  110 + should 'create task for person' do
  111 + post "/api/v1/people/#{person.id}/tasks?#{params.to_query}"
  112 + json = JSON.parse(last_response.body)
  113 + assert_not_nil json["task"]["id"]
  114 + end
  115 +
  116 + should 'create task for another person' do
  117 + some_person = fast_create(Person)
  118 + post "/api/v1/people/#{some_person.id}/tasks?#{params.to_query}"
  119 + json = JSON.parse(last_response.body)
  120 +
  121 + assert_equal some_person, Task.last.target
  122 + end
  123 +
  124 + should 'create task defining the target as a person' do
  125 + post "/api/v1/people/#{person.id}/tasks?#{params.to_query}"
  126 + json = JSON.parse(last_response.body)
  127 +
  128 + assert_equal person, Task.last.target
  129 + end
  130 +
  131 + #############################
  132 + # Enterprise Tasks #
  133 + #############################
  134 +
  135 + should 'return task by enterprise' do
  136 + enterprise = fast_create(Enterprise)
  137 + enterprise.add_admin(person)
  138 +
  139 + task = create(Task, :requestor => person, :target => enterprise)
  140 + assert person.is_member_of?(enterprise)
  141 +
  142 + get "/api/v1/enterprises/#{enterprise.id}/tasks/#{task.id}?#{params.to_query}"
  143 + json = JSON.parse(last_response.body)
  144 + assert_equal task.id, json["task"]["id"]
  145 + end
  146 +
  147 + should 'not return task by enterprise if user has no permission to view it' do
  148 + enterprise = fast_create(Enterprise)
  149 + task = create(Task, :requestor => person, :target => enterprise)
  150 + assert !person.is_member_of?(enterprise)
  151 +
  152 + get "/api/v1/enterprises/#{enterprise.id}/tasks/#{task.id}?#{params.to_query}"
  153 + assert_equal 403, last_response.status
  154 + end
  155 +
  156 + should 'create task in a enterprise' do
  157 + enterprise = fast_create(Enterprise)
  158 + give_permission(person, 'perform_task', enterprise)
  159 + post "/api/v1/enterprises/#{enterprise.id}/tasks?#{params.to_query}"
  160 + json = JSON.parse(last_response.body)
  161 + assert_not_nil json["task"]["id"]
  162 + end
  163 +
  164 + should 'create task defining the target as the enterprise' do
  165 + enterprise = fast_create(Enterprise)
  166 + enterprise.add_member(person)
  167 +
  168 + post "/api/v1/enterprises/#{enterprise.id}/tasks?#{params.to_query}"
  169 + json = JSON.parse(last_response.body)
  170 +
  171 + assert_equal enterprise, Task.last.target
  172 + end
389 end 173 end
test/unit/api/test_helper.rb
@@ -9,7 +9,8 @@ class ActiveSupport::TestCase @@ -9,7 +9,8 @@ class ActiveSupport::TestCase
9 end 9 end
10 10
11 def login_api 11 def login_api
12 - @user = User.create!(:login => 'testapi', :password => 'testapi', :password_confirmation => 'testapi', :email => 'test@test.org', :environment => Environment.default) 12 + @environment = Environment.default
  13 + @user = User.create!(:login => 'testapi', :password => 'testapi', :password_confirmation => 'testapi', :email => 'test@test.org', :environment => @environment)
13 @user.activate 14 @user.activate
14 @person = @user.person 15 @person = @user.person
15 16
@@ -18,7 +19,7 @@ class ActiveSupport::TestCase @@ -18,7 +19,7 @@ class ActiveSupport::TestCase
18 @private_token = json["private_token"] 19 @private_token = json["private_token"]
19 @params = {:private_token => @private_token} 20 @params = {:private_token => @private_token}
20 end 21 end
21 - attr_accessor :private_token, :user, :person, :params 22 + attr_accessor :private_token, :user, :person, :params, :environment
22 23
23 private 24 private
24 25
test/unit/approve_article_test.rb
@@ -9,6 +9,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -9,6 +9,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
9 @profile = create_user('test_user').person 9 @profile = create_user('test_user').person
10 @article = fast_create(TextileArticle, :profile_id => @profile.id, :name => 'test name', :abstract => 'Lead of article', :body => 'This is my article') 10 @article = fast_create(TextileArticle, :profile_id => @profile.id, :name => 'test name', :abstract => 'Lead of article', :body => 'This is my article')
11 @community = fast_create(Community) 11 @community = fast_create(Community)
  12 + @community.add_member(@profile)
12 end 13 end
13 attr_reader :profile, :article, :community 14 attr_reader :profile, :article, :community
14 15
@@ -251,6 +252,8 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -251,6 +252,8 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
251 end 252 end
252 253
253 should 'not group trackers activity of article\'s creation' do 254 should 'not group trackers activity of article\'s creation' do
  255 + other_community = fast_create(Community)
  256 + other_community.add_member(profile)
254 ActionTracker::Record.delete_all 257 ActionTracker::Record.delete_all
255 258
256 article = fast_create(TextileArticle) 259 article = fast_create(TextileArticle)
@@ -262,20 +265,20 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -262,20 +265,20 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
262 a.finish 265 a.finish
263 266
264 article = fast_create(TextileArticle) 267 article = fast_create(TextileArticle)
265 - other_community = fast_create(Community)  
266 a = create(ApproveArticle, :name => 'another bar', :article => article, :target => other_community, :requestor => profile) 268 a = create(ApproveArticle, :name => 'another bar', :article => article, :target => other_community, :requestor => profile)
267 a.finish 269 a.finish
268 assert_equal 3, ActionTracker::Record.count 270 assert_equal 3, ActionTracker::Record.count
269 end 271 end
270 272
271 should 'not create trackers activity when updating articles' do 273 should 'not create trackers activity when updating articles' do
  274 + other_community = fast_create(Community)
  275 + other_community.add_member(profile)
272 ActionTracker::Record.delete_all 276 ActionTracker::Record.delete_all
273 article1 = fast_create(TextileArticle) 277 article1 = fast_create(TextileArticle)
274 a = create(ApproveArticle, :name => 'bar', :article => article1, :target => community, :requestor => profile) 278 a = create(ApproveArticle, :name => 'bar', :article => article1, :target => community, :requestor => profile)
275 a.finish 279 a.finish
276 280
277 article2 = fast_create(TinyMceArticle) 281 article2 = fast_create(TinyMceArticle)
278 - other_community = fast_create(Community)  
279 a = create(ApproveArticle, :name => 'another bar', :article => article2, :target => other_community, :requestor => profile) 282 a = create(ApproveArticle, :name => 'another bar', :article => article2, :target => other_community, :requestor => profile)
280 a.finish 283 a.finish
281 assert_equal 2, ActionTracker::Record.count 284 assert_equal 2, ActionTracker::Record.count
@@ -283,7 +286,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -283,7 +286,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
283 assert_no_difference 'ActionTracker::Record.count' do 286 assert_no_difference 'ActionTracker::Record.count' do
284 published = article1.class.last 287 published = article1.class.last
285 published.name = 'foo';published.save! 288 published.name = 'foo';published.save!
286 - 289 +
287 published = article2.class.last 290 published = article2.class.last
288 published.name = 'another foo';published.save! 291 published.name = 'another foo';published.save!
289 end 292 end
@@ -307,7 +310,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -307,7 +310,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
307 person = fast_create(Person) 310 person = fast_create(Person)
308 person.stubs(:notification_emails).returns(['target@example.org']) 311 person.stubs(:notification_emails).returns(['target@example.org'])
309 312
310 - a = create(ApproveArticle, :article => article, :target => person, :requestor => profile) 313 + a = create(ApproveArticle, :article => article, :target => person, :requestor => person)
311 a.finish 314 a.finish
312 315
313 approved_article = person.articles.find_by_name(article.name) 316 approved_article = person.articles.find_by_name(article.name)
@@ -427,7 +430,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -427,7 +430,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
427 article = fast_create(Article) 430 article = fast_create(Article)
428 profile.domains << create(Domain, :name => 'example.org') 431 profile.domains << create(Domain, :name => 'example.org')
429 assert_nothing_raised do 432 assert_nothing_raised do
430 - create(ApproveArticle, :article => article, :target => profile, :requestor => community) 433 + create(ApproveArticle, :article => article, :target => profile, :requestor => profile)
431 end 434 end
432 end 435 end
433 436
@@ -440,4 +443,47 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -440,4 +443,47 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
440 assert_equal article, LinkArticle.last.reference_article 443 assert_equal article, LinkArticle.last.reference_article
441 end 444 end
442 445
  446 + should 'not allow non-person requestor' do
  447 + task = ApproveArticle.new(:requestor => Community.new)
  448 + task.valid?
  449 + assert task.invalid?(:requestor)
  450 + end
  451 +
  452 + should 'allow only self requestors when the target is a person' do
  453 + person = fast_create(Person)
  454 + another_person = fast_create(Person)
  455 +
  456 + t1 = ApproveArticle.new(:requestor => person, :target => person)
  457 + t2 = ApproveArticle.new(:requestor => another_person, :target => person)
  458 +
  459 + assert t1.valid?
  460 + assert !t2.valid?
  461 + assert t2.invalid?(:requestor)
  462 + end
  463 +
  464 + should 'allow only members to be requestors when target is a community' do
  465 + community = fast_create(Community)
  466 + member = fast_create(Person)
  467 + community.add_member(member)
  468 + non_member = fast_create(Person)
  469 +
  470 + t1 = ApproveArticle.new(:requestor => member, :target => community)
  471 + t2 = ApproveArticle.new(:requestor => non_member, :target => community)
  472 +
  473 + assert t1.valid?
  474 + assert !t2.valid?
  475 + assert t2.invalid?(:requestor)
  476 + end
  477 +
  478 + should 'allow any user to be requestor whe the target is the portal community' do
  479 + community = fast_create(Community)
  480 + environment = community.environment
  481 + environment.portal_community = community
  482 + environment.save!
  483 + person = fast_create(Person)
  484 +
  485 + task = ApproveArticle.new(:requestor => person, :target => community)
  486 +
  487 + assert task.valid?
  488 + end
443 end 489 end
test/unit/article_test.rb
@@ -913,6 +913,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -913,6 +913,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
913 should 'not doubly escape quotes in the name' do 913 should 'not doubly escape quotes in the name' do
914 person = fast_create(Person) 914 person = fast_create(Person)
915 community = fast_create(Community) 915 community = fast_create(Community)
  916 + community.add_member(profile)
916 article = fast_create(Article, :name => 'article name', :profile_id => person.id) 917 article = fast_create(Article, :name => 'article name', :profile_id => person.id)
917 a = create(ApproveArticle, :article => article, :target => community, :requestor => profile) 918 a = create(ApproveArticle, :article => article, :target => community, :requestor => profile)
918 a.finish 919 a.finish
test/unit/folder_test.rb
@@ -93,6 +93,7 @@ class FolderTest &lt; ActiveSupport::TestCase @@ -93,6 +93,7 @@ class FolderTest &lt; ActiveSupport::TestCase
93 image = UploadedFile.create!(:profile => person, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) 93 image = UploadedFile.create!(:profile => person, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
94 94
95 community = fast_create(Community) 95 community = fast_create(Community)
  96 + community.add_member(person)
96 folder = fast_create(Folder, :profile_id => community.id) 97 folder = fast_create(Folder, :profile_id => community.id)
97 a = create(ApproveArticle, :article => image, :target => community, :requestor => person, :article_parent => folder) 98 a = create(ApproveArticle, :article => image, :target => community, :requestor => person, :article_parent => folder)
98 a.finish 99 a.finish
test/unit/gallery_test.rb
@@ -101,6 +101,7 @@ class GalleryTest &lt; ActiveSupport::TestCase @@ -101,6 +101,7 @@ class GalleryTest &lt; ActiveSupport::TestCase
101 i = UploadedFile.create!(:profile => p, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) 101 i = UploadedFile.create!(:profile => p, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
102 102
103 c = fast_create(Community) 103 c = fast_create(Community)
  104 + c.add_member(p)
104 gallery = fast_create(Gallery, :profile_id => c.id) 105 gallery = fast_create(Gallery, :profile_id => c.id)
105 106
106 a = create(ApproveArticle, :article => i, :target => c, :requestor => p, :article_parent => gallery) 107 a = create(ApproveArticle, :article => i, :target => c, :requestor => p, :article_parent => gallery)
test/unit/scrap_test.rb
@@ -218,7 +218,7 @@ class ScrapTest &lt; ActiveSupport::TestCase @@ -218,7 +218,7 @@ class ScrapTest &lt; ActiveSupport::TestCase
218 should "update the scrap on reply creation" do 218 should "update the scrap on reply creation" do
219 person = create_user.person 219 person = create_user.person
220 s = fast_create(Scrap, :updated_at => DateTime.parse('2010-01-01')) 220 s = fast_create(Scrap, :updated_at => DateTime.parse('2010-01-01'))
221 - assert_equal DateTime.parse('2010-01-01'), s.updated_at.strftime('%Y-%m-%d') 221 + assert_equal DateTime.parse('2010-01-01'), s.updated_at
222 DateTime.stubs(:now).returns(DateTime.parse('2010-09-07')) 222 DateTime.stubs(:now).returns(DateTime.parse('2010-09-07'))
223 s1 = create(Scrap, :content => 'some content', :sender => person, :receiver => person, :scrap_id => s.id) 223 s1 = create(Scrap, :content => 'some content', :sender => person, :receiver => person, :scrap_id => s.id)
224 s.reload 224 s.reload