Commit d1300777121421c513974b14f6ff8fc1c190c4fa

Authored by Leandro Santos
2 parents 2066e859 5fc16fc4

fixing conflit with api branch

@@ -83,6 +83,9 @@ Carlos Morais + Eduardo Morais <carlos88morais@gmail.com> @@ -83,6 +83,9 @@ Carlos Morais + Eduardo Morais <carlos88morais@gmail.com>
83 Carlos Morais + Paulo Meirelles <carlos88morais@gmail.com> 83 Carlos Morais + Paulo Meirelles <carlos88morais@gmail.com>
84 Carlos Morais + Pedro Leal <carlos88morais@gmail.com> 84 Carlos Morais + Pedro Leal <carlos88morais@gmail.com>
85 Carlos Morais <carlos88morais@gmail.com> 85 Carlos Morais <carlos88morais@gmail.com>
  86 +Christophe DANIEL <papaeng@gmail.com>
  87 +Daniel Alves + Diego Araújo <danpaulalves@gmail.com>
  88 +Daniel Alves + Diego Araújo <diegoamc90@gmail.com>
86 Daniel Alves + Diego Araújo + Guilherme Rojas <danpaulalves@gmail.com> 89 Daniel Alves + Diego Araújo + Guilherme Rojas <danpaulalves@gmail.com>
87 Daniel Alves + Diego Araújo + Guilherme Rojas <diegoamc90@gmail.com> 90 Daniel Alves + Diego Araújo + Guilherme Rojas <diegoamc90@gmail.com>
88 Daniel Alves + Diego Araújo + Guilherme Rojas <guilhermehrojas@gmail.com> 91 Daniel Alves + Diego Araújo + Guilherme Rojas <guilhermehrojas@gmail.com>
@@ -128,6 +131,7 @@ Eduardo Vital &lt;vitaldu@gmail.com&gt; @@ -128,6 +131,7 @@ Eduardo Vital &lt;vitaldu@gmail.com&gt;
128 Evandro Jr <evandrojr@gmail.com> 131 Evandro Jr <evandrojr@gmail.com>
129 Evandro Junior <evandrojr@gmail.com> 132 Evandro Junior <evandrojr@gmail.com>
130 Evandro Magalhaes Leite Junior <evandro.leite@serpro.gov.br> 133 Evandro Magalhaes Leite Junior <evandro.leite@serpro.gov.br>
  134 +Fabio Teixeira <fabio1079@gmail.com>
131 FAMMA TV NOTICIAS MEDIOS DE CO <revistafammatvmusic.oficial@gmail.com> 135 FAMMA TV NOTICIAS MEDIOS DE CO <revistafammatvmusic.oficial@gmail.com>
132 Fabio Teixeira <fabio1079@gmail.com> 136 Fabio Teixeira <fabio1079@gmail.com>
133 Fernanda Lopes <nanda.listas+psl@gmail.com> 137 Fernanda Lopes <nanda.listas+psl@gmail.com>
@@ -18,6 +18,7 @@ gem &#39;exception_notification&#39;, &#39;~&gt; 4.0.1&#39; @@ -18,6 +18,7 @@ gem &#39;exception_notification&#39;, &#39;~&gt; 4.0.1&#39;
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 'eita-jrails', '~> 0.9.5', require: 'jrails'
21 gem 'grape', '~> 0.11.0' 22 gem 'grape', '~> 0.11.0'
22 gem 'grape-entity' 23 gem 'grape-entity'
23 gem 'grape-swagger' 24 gem 'grape-swagger'
@@ -30,7 +31,9 @@ gem &#39;liquid&#39;, &#39;~&gt; 3.0.3&#39; @@ -30,7 +31,9 @@ gem &#39;liquid&#39;, &#39;~&gt; 3.0.3&#39;
30 31
31 # FIXME list here all actual dependencies (i.e. the ones in debian/control), 32 # FIXME list here all actual dependencies (i.e. the ones in debian/control),
32 # with their GEM names (not the Debian package names) 33 # with their GEM names (not the Debian package names)
33 -gem 'eita-jrails', '~> 0.9.5', require: 'jrails' 34 +
  35 +# FIXME list here all actual dependencies (i.e. the ones in debian/control),
  36 +# with their GEM names (not the Debian package names)
34 37
35 # asset pipeline 38 # asset pipeline
36 gem 'uglifier', '>= 1.0.3' 39 gem 'uglifier', '>= 1.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
@@ -204,9 +204,9 @@ class Profile &lt; ActiveRecord::Base @@ -204,9 +204,9 @@ class Profile &lt; ActiveRecord::Base
204 Profile.column_names.map{|n| [Profile.table_name, n].join('.')}.join(',') 204 Profile.column_names.map{|n| [Profile.table_name, n].join('.')}.join(',')
205 end 205 end
206 206
207 - scope :visible, :conditions => { :visible => true } 207 + scope :visible, :conditions => { :visible => true, :secret => false }
208 scope :disabled, :conditions => { :visible => false } 208 scope :disabled, :conditions => { :visible => false }
209 - scope :public, :conditions => { :visible => true, :public_profile => true } 209 + scope :public, :conditions => { :visible => true, :public_profile => true, :secret => false }
210 scope :enabled, :conditions => { :enabled => true } 210 scope :enabled, :conditions => { :enabled => true }
211 211
212 # Subclasses must override this method 212 # 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
@@ -133,6 +133,51 @@ class Task &lt; ActiveRecord::Base @@ -133,6 +133,51 @@ class Task &lt; ActiveRecord::Base
133 end 133 end
134 end 134 end
135 135
  136 + class KindOfValidator < ActiveModel::EachValidator
  137 + def validate_each(record, attribute, value)
  138 + environment = record.environment || Environment.default
  139 + klass = options[:kind]
  140 + group = klass.to_s.downcase.pluralize
  141 + id = attribute.to_s + "_id"
  142 + if environment.respond_to?(group)
  143 + attrb = value || environment.send(group).find_by_id(record.send(id))
  144 + else
  145 + attrb = value || klass.find_by_id(record.send(id))
  146 + end
  147 + if attrb.respond_to?(klass.to_s.downcase + "?")
  148 + unless attrb.send(klass.to_s.downcase + "?")
  149 + record.errors[attribute] << (options[:message] || "should be "+ klass.to_s.downcase)
  150 + end
  151 + else
  152 + unless attrb.class == klass
  153 + record.errors[attribute] << (options[:message] || "should be "+ klass.to_s.downcase)
  154 + end
  155 + end
  156 + end
  157 + end
  158 +
  159 + def requestor_is_of_kind(klass, message = nil)
  160 + error_message = message ||= _('Task requestor must be '+klass.to_s.downcase)
  161 + group = klass.to_s.downcase.pluralize
  162 + if environment.respond_to?(group) and requestor_id
  163 + requestor = requestor ||= environment.send(klass.to_s.downcase.pluralize).find_by_id(requestor_id)
  164 + end
  165 + unless requestor.class == klass
  166 + errors.add(error_message)
  167 + end
  168 + end
  169 +
  170 + def target_is_of_kind(klass, message = nil)
  171 + error_message = message ||= _('Task target must be '+klass.to_s.downcase)
  172 + group = klass.to_s.downcase.pluralize
  173 + if environment.respond_to?(group) and target_id
  174 + target = target ||= environment.send(klass.to_s.downcase.pluralize).find_by_id(target_id)
  175 + end
  176 + unless target.class == klass
  177 + errors.add(error_message)
  178 + end
  179 + end
  180 +
136 def close(status, closed_by) 181 def close(status, closed_by)
137 self.status = status 182 self.status = status
138 self.end_date = Time.now 183 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!
debian/changelog
1 -noosfero (1.2~1) UNRELEASED; urgency=medium  
2 -  
3 - [ Antonio Terceiro ]  
4 - * Temporary version in heavy development 1 +noosfero (1.2~rc1) wheezy; urgency=medium
5 2
6 [ Joenio Costa ] 3 [ Joenio Costa ]
7 * Build noosfero-chat package 4 * Build noosfero-chat package
8 5
9 - [ root ]  
10 - * Api test 6 + [ Antonio Terceiro ]
  7 + * Noosfero 1.2 RC1
11 8
12 - -- root <root@17edebf1ae91> Mon, 06 Jul 2015 14:39:06 +0000 9 + -- Antonio Terceiro <terceiro@colivre.coop.br> Mon, 13 Jul 2015 15:44:17 -0300
13 10
14 noosfero (1.1) wheezy; urgency=low 11 noosfero (1.1) wheezy; urgency=low
15 12
lib/noosfero/api/helpers.rb
@@ -52,7 +52,8 @@ @@ -52,7 +52,8 @@
52 end 52 end
53 end 53 end
54 54
55 - ARTICLE_TYPES = Article.descendants.map{|a| a.to_s} 55 + ARTICLE_TYPES = ['Article'] + Article.descendants.map{|a| a.to_s}
  56 + TASK_TYPES = ['Task'] + Task.descendants.map{|a| a.to_s}
56 57
57 def find_article(articles, id) 58 def find_article(articles, id)
58 article = articles.find(id) 59 article = articles.find(id)
@@ -97,11 +98,39 @@ @@ -97,11 +98,39 @@
97 if params[:categories_ids] 98 if params[:categories_ids]
98 articles = articles.joins(:categories).where('category_id in (?)', params[:categories_ids]) 99 articles = articles.joins(:categories).where('category_id in (?)', params[:categories_ids])
99 end 100 end
  101 + articles
100 end 102 end
101 103
102 - def find_task(tasks, id)  
103 - task = tasks.find(id)  
104 - task.display_to?(current_user.person) ? task : forbidden! 104 + def find_task(asset, id)
  105 + task = asset.tasks.find(id)
  106 + current_person.has_permission?(task.permission, asset) ? task : forbidden!
  107 + end
  108 +
  109 + def post_task(asset, params)
  110 + klass_type= params[:content_type].nil? ? 'Task' : params[:content_type]
  111 + return forbidden! unless TASK_TYPES.include?(klass_type)
  112 +
  113 + task = klass_type.constantize.new(params[:task])
  114 + task.requestor_id = current_person.id
  115 + task.target_id = asset.id
  116 + task.target_type = 'Profile'
  117 +
  118 + if !task.save
  119 + render_api_errors!(task.errors.full_messages)
  120 + end
  121 + present task, :with => Entities::Task, :fields => params[:fields]
  122 + end
  123 +
  124 + def present_task(asset)
  125 + task = find_task(asset, params[:id])
  126 + present task, :with => Entities::Task, :fields => params[:fields]
  127 + end
  128 +
  129 + def present_tasks(asset)
  130 + tasks = select_filtered_collection_of(asset, 'tasks', params)
  131 + tasks = tasks.select {|t| current_person.has_permission?(t.permission, asset)}
  132 + return forbidden! if tasks.empty? && !current_person.has_permission?(:perform_task, asset)
  133 + present tasks, :with => Entities::Task, :fields => params[:fields]
105 end 134 end
106 135
107 def make_conditions_with_parameter(params = {}) 136 def make_conditions_with_parameter(params = {})
@@ -318,7 +347,13 @@ @@ -318,7 +347,13 @@
318 https.use_ssl = true 347 https.use_ssl = true
319 request = Net::HTTP::Post.new(uri.path) 348 request = Net::HTTP::Post.new(uri.path)
320 request.set_form_data(verify_hash) 349 request.set_form_data(verify_hash)
321 - body = https.request(request).body 350 + begin
  351 + body = https.request(request).body
  352 + rescue Exception => e
  353 + logger.error e
  354 + return _("Google recaptcha error: #{e.message}")
  355 + end
  356 + body = JSON.parse(body)
322 body == "true\nsuccess" ? true : body 357 body == "true\nsuccess" ? true : body
323 end 358 end
324 359
@@ -337,20 +372,36 @@ @@ -337,20 +372,36 @@
337 https.use_ssl = true 372 https.use_ssl = true
338 request = Net::HTTP::Post.new(uri.path) 373 request = Net::HTTP::Post.new(uri.path)
339 request.set_form_data(verify_hash) 374 request.set_form_data(verify_hash)
340 - captcha_result = JSON.parse(https.request(request).body) 375 + begin
  376 + body = https.request(request).body
  377 + rescue Exception => e
  378 + logger.error e
  379 + return _("Google recaptcha error: #{e.message}")
  380 + end
  381 + captcha_result = JSON.parse(body)
341 captcha_result["success"] ? true : captcha_result 382 captcha_result["success"] ? true : captcha_result
342 end 383 end
343 384
344 def verify_serpro_captcha(client_id, token, captcha_text, verify_uri) 385 def verify_serpro_captcha(client_id, token, captcha_text, verify_uri)
345 - if token == nil || captcha_text == nil  
346 - return _('Missing captcha data')  
347 - end 386 + return _('Missing Serpro Captcha token') if token == nil
  387 + return _('Captcha text has not been filled') if captcha_text == nil
348 uri = URI(verify_uri) 388 uri = URI(verify_uri)
349 http = Net::HTTP.new(uri.host, uri.port) 389 http = Net::HTTP.new(uri.host, uri.port)
350 request = Net::HTTP::Post.new(uri.path) 390 request = Net::HTTP::Post.new(uri.path)
351 verify_string = "#{client_id}&#{token}&#{captcha_text}" 391 verify_string = "#{client_id}&#{token}&#{captcha_text}"
352 request.body = verify_string 392 request.body = verify_string
  393 +<<<<<<< HEAD
353 body = http.request(request).body 394 body = http.request(request).body
  395 +=======
  396 + begin
  397 + body = http.request(request).body
  398 + rescue Exception => e
  399 + logger.error e
  400 + return _("Serpro captcha error: #{e.message}")
  401 + end
  402 + return _("Wrong captcha text, please try again") if body == 0
  403 + return _("Token not found") if body == 2
  404 +>>>>>>> serpro_api
354 body == '1' ? true : body 405 body == '1' ? true : body
355 end 406 end
356 407
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
lib/noosfero/version.rb
1 module Noosfero 1 module Noosfero
2 PROJECT = 'noosfero' 2 PROJECT = 'noosfero'
3 - VERSION = '1.2~1' 3 + VERSION = '1.2~rc1'
4 end 4 end
5 5
6 root = File.expand_path(File.dirname(__FILE__) + '/../..') 6 root = File.expand_path(File.dirname(__FILE__) + '/../..')
plugins/gamification
1 -Subproject commit a8aed5d9befec360868155eba1be426cee015a18 1 +Subproject commit 1f2171520eb4719fefc5a32f26ef2a002cd61f0d
plugins/proposals_discussion
1 -Subproject commit b50fd52ad1e3a1178757ea61d26e96628f7d59ae 1 +Subproject commit e6cd995bbde179a2b941d80ae5c1a05a4bf7ffa5
po/fr/noosfero.po
@@ -6,11 +6,11 @@ msgid &quot;&quot; @@ -6,11 +6,11 @@ msgid &quot;&quot;
6 msgstr "" 6 msgstr ""
7 "Project-Id-Version: 1.1-2519-g5b6a4ea\n" 7 "Project-Id-Version: 1.1-2519-g5b6a4ea\n"
8 "Report-Msgid-Bugs-To: \n" 8 "Report-Msgid-Bugs-To: \n"
9 -"POT-Creation-Date: 2015-07-07 15:26-0300\n"  
10 -"PO-Revision-Date: 2015-03-12 16:11+0200\n"  
11 -"Last-Translator: Tuux <tuxa@galaxie.eu.org>\n"  
12 -"Language-Team: French <https://hosted.weblate.org/projects/noosfero/noosfero/"  
13 -"fr/>\n" 9 +"POT-Creation-Date: 2015-06-01 17:26-0300\n"
  10 +"PO-Revision-Date: 2015-07-13 10:39+0200\n"
  11 +"Last-Translator: Christophe DANIEL <papaeng@gmail.com>\n"
  12 +"Language-Team: French "
  13 +"<https://hosted.weblate.org/projects/noosfero/noosfero/fr/>\n"
14 "Language: fr\n" 14 "Language: fr\n"
15 "MIME-Version: 1.0\n" 15 "MIME-Version: 1.0\n"
16 "Content-Type: text/plain; charset=UTF-8\n" 16 "Content-Type: text/plain; charset=UTF-8\n"
@@ -7744,31 +7744,22 @@ msgstr &quot;Type&quot; @@ -7744,31 +7744,22 @@ msgstr &quot;Type&quot;
7744 msgid "Last update" 7744 msgid "Last update"
7745 msgstr "Dernière mise à jour" 7745 msgstr "Dernière mise à jour"
7746 7746
7747 -#: app/views/cms/view.html.erb:48 app/views/cms/view.html.erb:50  
7748 -#, fuzzy  
7749 -msgid "parent folder"  
7750 -msgstr "Catégorie courante :" 7747 +#: app/views/profile_roles/destroy.html.erb:13
  7748 +msgid "To which role do you want to change them?"
  7749 +msgstr "Pour quel rôle voulez-vous les changer ?"
7751 7750
7752 -#: app/views/cms/_media_new_folder.html.erb:1  
7753 -#, fuzzy  
7754 -msgid "Create new folder"  
7755 -msgstr "Créer un nouveau groupe" 7751 +#: app/views/profile_roles/destroy.html.erb:20
  7752 +msgid "Delete role"
  7753 +msgstr "Supprimer le rôle"
7756 7754
7757 #: app/views/cms/_media_new_folder.html.erb:3 7755 #: app/views/cms/_media_new_folder.html.erb:3
7758 #, fuzzy 7756 #, fuzzy
7759 msgid "Choose parent folder:" 7757 msgid "Choose parent folder:"
7760 msgstr "Catégorie courante :" 7758 msgstr "Catégorie courante :"
7761 7759
7762 -#: app/views/cms/_media_new_folder.html.erb:13  
7763 -#: app/views/memberships/new_community.html.erb:52  
7764 -#: app/views/profile_themes/new.html.erb:8  
7765 -msgid "Create"  
7766 -msgstr "Créer"  
7767 -  
7768 -#: app/views/cms/_link_article.html.erb:3  
7769 -#, fuzzy  
7770 -msgid "Reference"  
7771 -msgstr "Adresse :" 7760 +#: app/views/profile_roles/index.html.erb:5 app/views/role/index.html.erb:5
  7761 +msgid "Role"
  7762 +msgstr "Rôle"
7772 7763
7773 #: app/views/cms/upload_files.html.erb:3 7764 #: app/views/cms/upload_files.html.erb:3
7774 msgid "This file couldn't be saved" 7765 msgid "This file couldn't be saved"
@@ -7806,9 +7797,9 @@ msgstr &quot;Catégorie courante :&quot; @@ -7806,9 +7797,9 @@ msgstr &quot;Catégorie courante :&quot;
7806 msgid "License" 7797 msgid "License"
7807 msgstr "" 7798 msgstr ""
7808 7799
7809 -#: app/views/cms/_blog.html.erb:3  
7810 -msgid "My Blog"  
7811 -msgstr "Mon blog" 7800 +#: app/views/comment_notifier/mail_to_followers.html.erb:1
  7801 +msgid "Hi!"
  7802 +msgstr "Bonjour !"
7812 7803
7813 #: app/views/cms/_blog.html.erb:42 7804 #: app/views/cms/_blog.html.erb:42
7814 #: app/views/profile_editor/_organization.html.erb:48 7805 #: app/views/profile_editor/_organization.html.erb:48
@@ -7825,10 +7816,10 @@ msgstr &quot;&quot; @@ -7825,10 +7816,10 @@ msgstr &quot;&quot;
7825 "les liens extérieurs menant à la page d'accueil ou le contenu du site lui-" 7816 "les liens extérieurs menant à la page d'accueil ou le contenu du site lui-"
7826 "même. Voulez-vous vraiment la modifier ?" 7817 "même. Voulez-vous vraiment la modifier ?"
7827 7818
7828 -#: app/views/cms/_blog.html.erb:59  
7829 -#, fuzzy  
7830 -msgid "Cover image:"  
7831 -msgstr "image" 7819 +#: app/views/comment_notifier/mail_to_followers.html.erb:5
  7820 +#: app/views/comment_notifier/notification.text.erb:5
  7821 +msgid "Title: %s"
  7822 +msgstr "Titre : %s"
7832 7823
7833 #: app/views/cms/_blog.html.erb:64 7824 #: app/views/cms/_blog.html.erb:64
7834 #, fuzzy 7825 #, fuzzy
@@ -7918,18 +7909,17 @@ msgstr &quot;Plus de documents&quot; @@ -7918,18 +7909,17 @@ msgstr &quot;Plus de documents&quot;
7918 msgid "Upload" 7909 msgid "Upload"
7919 msgstr "Téléverser" 7910 msgstr "Téléverser"
7920 7911
7921 -#: app/views/cms/_text_fields.html.erb:1  
7922 -#, fuzzy  
7923 -msgid "Publish date"  
7924 -msgstr "Publier le média" 7912 +#: app/views/templates/index.html.erb:31
  7913 +msgid "Edit settings"
  7914 +msgstr "Modifier les paramètres"
7925 7915
7926 #: app/views/cms/_enterprise_homepage.html.erb:3 7916 #: app/views/cms/_enterprise_homepage.html.erb:3
7927 msgid "Text" 7917 msgid "Text"
7928 msgstr "Texte" 7918 msgstr "Texte"
7929 7919
7930 -#: app/views/cms/why_categorize.html.erb:1 app/views/cms/edit.html.erb:31  
7931 -msgid "Why categorize?"  
7932 -msgstr "Pourquoi catégoriser ?" 7920 +#: app/views/templates/index.html.erb:35
  7921 +msgid "Edit header/footer"
  7922 +msgstr "Modifier en-tête/pied de page"
7933 7923
7934 #: app/views/cms/why_categorize.html.erb:4 7924 #: app/views/cms/why_categorize.html.erb:4
7935 msgid "" 7925 msgid ""
@@ -7948,10 +7938,13 @@ msgstr &quot;&quot; @@ -7948,10 +7938,13 @@ msgstr &quot;&quot;
7948 msgid "Start date and time" 7938 msgid "Start date and time"
7949 msgstr "Date de début" 7939 msgstr "Date de début"
7950 7940
7951 -#: app/views/cms/_event.html.erb:13  
7952 -#, fuzzy  
7953 -msgid "End date and time"  
7954 -msgstr "Date de fin" 7941 +#: app/views/home/terms.html.erb:1
  7942 +msgid "Terms of use - %s"
  7943 +msgstr "Conditions d'utilisation - %s"
  7944 +
  7945 +#: app/views/home/welcome.html.erb:4
  7946 +msgid "Welcome to %s!"
  7947 +msgstr "Bienvenue sur %s !"
7955 7948
7956 #: app/views/cms/_event.html.erb:15 7949 #: app/views/cms/_event.html.erb:15
7957 msgid "Presenter:" 7950 msgid "Presenter:"
@@ -7961,10 +7954,9 @@ msgstr &quot;&quot; @@ -7961,10 +7954,9 @@ msgstr &quot;&quot;
7961 msgid "Event website:" 7954 msgid "Event website:"
7962 msgstr "Site web de l'événement :" 7955 msgstr "Site web de l'événement :"
7963 7956
7964 -#: app/views/cms/select_article_type.html.erb:3  
7965 -#, fuzzy  
7966 -msgid "Choose the type of content:"  
7967 -msgstr "Choisissez le type de l'article :" 7957 +#: app/views/home/welcome.html.erb:11
  7958 +msgid "Confirm your account!"
  7959 +msgstr "Confirmer votre compte !"
7968 7960
7969 #: app/views/cms/_drag_and_drop_note.html.erb:3 7961 #: app/views/cms/_drag_and_drop_note.html.erb:3
7970 msgid "Drag images to add them to the text." 7962 msgid "Drag images to add them to the text."
@@ -8038,10 +8030,9 @@ msgid &quot;&quot; @@ -8038,10 +8030,9 @@ msgid &quot;&quot;
8038 "just search for the community below." 8030 "just search for the community below."
8039 msgstr "" 8031 msgstr ""
8040 8032
8041 -#: app/views/cms/publish.html.erb:42  
8042 -#, fuzzy  
8043 -msgid "Type in a search for your community"  
8044 -msgstr "Désactiver la recherche d'entreprises" 8033 +#: app/views/home/welcome.html.erb:25
  8034 +msgid "Invite and find"
  8035 +msgstr "Inviter et trouver"
8045 8036
8046 #: app/views/cms/publish.html.erb:55 8037 #: app/views/cms/publish.html.erb:55
8047 msgid "" 8038 msgid ""
@@ -8053,15 +8044,15 @@ msgstr &quot;&quot; @@ -8053,15 +8044,15 @@ msgstr &quot;&quot;
8053 msgid "Textile markup quick reference" 8044 msgid "Textile markup quick reference"
8054 msgstr "" 8045 msgstr ""
8055 8046
8056 -#: app/views/cms/_textile_quick_reference.html.erb:4  
8057 -#, fuzzy  
8058 -msgid "(show)"  
8059 -msgstr "Voir le diaporama" 8047 +#: app/views/home/index.html.erb:2
  8048 +msgid "News"
  8049 +msgstr "Nouveautés"
8060 8050
8061 -#: app/views/cms/_textile_quick_reference.html.erb:5  
8062 -#, fuzzy  
8063 -msgid "(hide)"  
8064 -msgstr "Cacher" 8051 +#: app/views/home/index.html.erb:45
  8052 +#: app/views/profile/_profile_activities_list.html.erb:14
  8053 +#: app/views/profile/_profile_network_activities.html.erb:6
  8054 +msgid "View more"
  8055 +msgstr "Voir plus"
8065 8056
8066 #: app/views/cms/_textile_quick_reference.html.erb:8 8057 #: app/views/cms/_textile_quick_reference.html.erb:8
8067 #, fuzzy 8058 #, fuzzy
@@ -8072,15 +8063,15 @@ msgstr &quot;Informations fournies&quot; @@ -8072,15 +8063,15 @@ msgstr &quot;Informations fournies&quot;
8072 msgid "italics" 8063 msgid "italics"
8073 msgstr "" 8064 msgstr ""
8074 8065
8075 -#: app/views/cms/_textile_quick_reference.html.erb:8  
8076 -#, fuzzy  
8077 -msgid "bold"  
8078 -msgstr "travail" 8066 +#: app/views/features/_manage_enterprise_fields.html.erb:8
  8067 +msgid "Display on registration?"
  8068 +msgstr "Afficher à l'inscription ?"
8079 8069
8080 -#: app/views/cms/_textile_quick_reference.html.erb:8  
8081 -#, fuzzy  
8082 -msgid "striked"  
8083 -msgstr "Contact" 8070 +#: app/views/features/_manage_enterprise_fields.html.erb:13
  8071 +#: app/views/features/_manage_community_fields.html.erb:13
  8072 +#: app/views/features/_manage_person_fields.html.erb:13
  8073 +msgid "Check/Uncheck All"
  8074 +msgstr "Tout cocher/décocher"
8084 8075
8085 #: app/views/cms/_textile_quick_reference.html.erb:9 8076 #: app/views/cms/_textile_quick_reference.html.erb:9
8086 #, fuzzy 8077 #, fuzzy
@@ -8125,20 +8116,17 @@ msgstr &quot;&quot; @@ -8125,20 +8116,17 @@ msgstr &quot;&quot;
8125 msgid "Insert media" 8116 msgid "Insert media"
8126 msgstr "" 8117 msgstr ""
8127 8118
8128 -#: app/views/cms/_text_editor_sidebar.html.erb:8  
8129 -#, fuzzy  
8130 -msgid "Show/Hide"  
8131 -msgstr "Voir le diaporama" 8119 +#: app/views/features/index.html.erb:15
  8120 +msgid "Feature"
  8121 +msgstr "Fonctionnalité"
8132 8122
8133 -#: app/views/cms/_text_editor_sidebar.html.erb:21  
8134 -#, fuzzy  
8135 -msgid "New folder"  
8136 -msgstr "Catégorie courante :" 8123 +#: app/views/features/index.html.erb:16
  8124 +msgid "Enabled?"
  8125 +msgstr "Activé ?"
8137 8126
8138 -#: app/views/cms/_text_editor_sidebar.html.erb:26  
8139 -#, fuzzy  
8140 -msgid "Hide all uploads"  
8141 -msgstr "Voir tous les produits" 8127 +#: app/views/features/index.html.erb:27
  8128 +msgid "Configure features"
  8129 +msgstr "Editer les fonctionnalités"
8142 8130
8143 #: app/views/cms/_text_editor_sidebar.html.erb:27 8131 #: app/views/cms/_text_editor_sidebar.html.erb:27
8144 #, fuzzy 8132 #, fuzzy
@@ -8167,14 +8155,9 @@ msgstr &quot;Ma page d&#39;accueil&quot; @@ -8167,14 +8155,9 @@ msgstr &quot;Ma page d&#39;accueil&quot;
8167 msgid "My groups" 8155 msgid "My groups"
8168 msgstr "Mes groupes" 8156 msgstr "Mes groupes"
8169 8157
8170 -#: app/views/shared/user_menu.html.erb:32  
8171 -msgid "Webmail"  
8172 -msgstr "Webmail"  
8173 -  
8174 -#: app/views/shared/_profile_suggestions_list.html.erb:6  
8175 -#, fuzzy  
8176 -msgid "You have no more suggestions :("  
8177 -msgstr "Vous avez des requêtes en attente" 8158 +#: app/views/chat/start_session_error.html.erb:3
  8159 +msgid "Could not connect to chat"
  8160 +msgstr "Impossible de se connecter au chat"
8178 8161
8179 #: app/views/shared/_profile_suggestions_list.html.erb:19 8162 #: app/views/shared/_profile_suggestions_list.html.erb:19
8180 #: app/views/shared/_profile_suggestions_list.html.erb:26 8163 #: app/views/shared/_profile_suggestions_list.html.erb:26
@@ -8205,46 +8188,65 @@ msgstr &quot;Contenu principal&quot; @@ -8205,46 +8188,65 @@ msgstr &quot;Contenu principal&quot;
8205 msgid "This link might be unavailable if the content is removed" 8188 msgid "This link might be unavailable if the content is removed"
8206 msgstr "" 8189 msgstr ""
8207 8190
8208 -#: app/views/shared/reported_versions/profile/_folder.html.erb:1  
8209 -#, fuzzy  
8210 -msgid "Reported folder"  
8211 -msgstr "Catégorie courante :" 8191 +#: app/views/themes/_select_theme.html.erb:5
  8192 +msgid "Use the default theme"
  8193 +msgstr "Utiliser le thème par défaut"
8212 8194
8213 -#: app/views/shared/reported_versions/profile/_comment.html.erb:3  
8214 -#, fuzzy  
8215 -msgid "Comment"  
8216 -msgstr "Commentaires" 8195 +#: app/views/themes/_select_theme.html.erb:5
  8196 +msgid "Are you sure you want to use the environment default theme?"
  8197 +msgstr "Etes-vous sûr que vous voulez utiliser le thème par défaut ?"
8217 8198
8218 -#: app/views/shared/_organization_custom_fields.html.erb:12  
8219 -#: app/views/maps/edit_location.html.erb:13  
8220 -#: app/views/profile_editor/_person_form.html.erb:25  
8221 -msgid "Address (street and number)"  
8222 -msgstr "Adresse (n° et rue)" 8199 +#: app/views/file_presenter/_image.html.erb:7
  8200 +#: app/views/file_presenter/_image.html.erb:9
  8201 +msgid "&laquo; Previous"
  8202 +msgstr "&laquo; Précédent"
8223 8203
8224 -#: app/views/shared/_profile_connections.html.erb:2  
8225 -#, fuzzy  
8226 -msgid "Profiles in common:"  
8227 -msgstr "Informations fournies" 8204 +#: app/views/file_presenter/_image.html.erb:13
  8205 +#: app/views/file_presenter/_image.html.erb:15
  8206 +msgid "Next &raquo;"
  8207 +msgstr "Suivant &raquo;"
8228 8208
8229 #: app/views/shared/_profile_connections.html.erb:17 8209 #: app/views/shared/_profile_connections.html.erb:17
8230 msgid "Tags in common:" 8210 msgid "Tags in common:"
8231 msgstr "" 8211 msgstr ""
8232 8212
8233 -#: app/views/shared/logged_in/xmpp_chat.html.erb:10  
8234 -msgid ""  
8235 -"The user is not online now. He/She will receive these messages as soon as he/"  
8236 -"she gets online." 8213 +#: app/views/profile_members/unassociate.html.erb:2
  8214 +#: app/views/profile_members/remove_admin.html.erb:2
  8215 +#: app/views/profile_members/_members_list.html.erb:2
  8216 +#: app/views/profile_members/add_member.html.erb:2
  8217 +#: app/views/profile_members/add_admin.html.erb:2
  8218 +msgid "Current members"
  8219 +msgstr "Les membres actuels"
  8220 +
  8221 +#: app/views/profile_members/_manage_roles.html.erb:21
  8222 +msgid "Type in a search term for users"
8237 msgstr "" 8223 msgstr ""
8238 8224
8239 -#: app/views/shared/logged_in/xmpp_chat.html.erb:25  
8240 -#, fuzzy  
8241 -msgid "Offline"  
8242 -msgstr "Uniquement dans %s" 8225 +#: app/views/profile_members/_add_admins.html.erb:1
  8226 +msgid "Add admins to %s"
  8227 +msgstr "Ajouter un admin à %s"
8243 8228
8244 -#: app/views/shared/logged_in/xmpp_chat.html.erb:60  
8245 -#, fuzzy  
8246 -msgid "Join room"  
8247 -msgstr "Se joindre" 8229 +#: app/views/profile_members/affiliate.html.erb:7
  8230 +#: app/views/environment_role_manager/affiliate.html.erb:7
  8231 +msgid "Affiliate"
  8232 +msgstr "Affilié"
  8233 +
  8234 +#: app/views/profile_members/_index_buttons.html.erb:3
  8235 +msgid "Add members"
  8236 +msgstr "Ajouter des membres"
  8237 +
  8238 +#: app/views/profile_members/_index_buttons.html.erb:5
  8239 +#: app/views/invite/select_friends.html.erb:6
  8240 +#: app/views/invite/invite_friends.html.erb:5
  8241 +#: app/views/profile/members.html.erb:21
  8242 +msgid "Invite people to join"
  8243 +msgstr "Invitez les personnes à joindre"
  8244 +
  8245 +#: app/views/profile_members/_index_buttons.html.erb:8
  8246 +#: app/views/profile/send_mail.html.erb:3
  8247 +#: app/views/profile/members.html.erb:24
  8248 +msgid "Send e-mail to members"
  8249 +msgstr "Envoyer un e-mail aux membres"
8248 8250
8249 #: app/views/shared/logged_in/xmpp_chat.html.erb:61 8251 #: app/views/shared/logged_in/xmpp_chat.html.erb:61
8250 #, fuzzy 8252 #, fuzzy
@@ -8255,26 +8257,22 @@ msgstr &quot;Entrez votre commentaire&quot; @@ -8255,26 +8257,22 @@ msgstr &quot;Entrez votre commentaire&quot;
8255 msgid "\"Published at: #{show_date(content.updated_at)}\"" 8257 msgid "\"Published at: #{show_date(content.updated_at)}\""
8256 msgstr "" 8258 msgstr ""
8257 8259
8258 -#: app/views/shared/_profile_search_form.html.erb:1  
8259 -#: app/views/shared/_profile_search_form.html.erb:9  
8260 -#, fuzzy  
8261 -msgid "Find in %s's content"  
8262 -msgstr "Contenu principal" 8260 +#: app/views/profile_members/add_members.html.erb:1
  8261 +msgid "Add members to %s"
  8262 +msgstr "Ajouter des membres à %s"
8263 8263
8264 #: app/views/shared/_profile_search_form.html.erb:10 8264 #: app/views/shared/_profile_search_form.html.erb:10
8265 #, fuzzy 8265 #, fuzzy
8266 msgid "General" 8266 msgid "General"
8267 msgstr "Tâche générique" 8267 msgstr "Tâche générique"
8268 8268
8269 -#: app/views/shared/_profile_search_form.html.erb:10  
8270 -#, fuzzy  
8271 -msgid "Search all content"  
8272 -msgstr "Tout le contenu" 8269 +#: app/views/profile_members/change_role.html.erb:15
  8270 +msgid "Custom Roles:"
  8271 +msgstr "Rôles personnalisés :"
8273 8272
8274 -#: app/views/shared/_select_subcategories.html.erb:3  
8275 -#, fuzzy  
8276 -msgid "Click to select a category"  
8277 -msgstr "Choisissez une catégorie :" 8273 +#: app/views/maps/edit_location.html.erb:15
  8274 +msgid "Locate in the map"
  8275 +msgstr "Localiser sur la carte"
8278 8276
8279 #: app/views/shared/not_found.html.erb:2 8277 #: app/views/shared/not_found.html.erb:2
8280 msgid "There is no such page: %s" 8278 msgid "There is no such page: %s"
@@ -8313,10 +8311,9 @@ msgstr &quot;Aller à la page d&#39;accueil du site&quot; @@ -8313,10 +8311,9 @@ msgstr &quot;Aller à la page d&#39;accueil du site&quot;
8313 msgid "Open chat" 8311 msgid "Open chat"
8314 msgstr "Un contact" 8312 msgstr "Un contact"
8315 8313
8316 -#: app/views/shared/profile_actions/xmpp_chat.html.erb:1  
8317 -#, fuzzy  
8318 -msgid "Join chat room"  
8319 -msgstr "Se joindre" 8314 +#: app/views/maps/_google_map.js.erb:137
  8315 +msgid "Request denied"
  8316 +msgstr "Demande refusée"
8320 8317
8321 #: app/views/shared/access_denied.html.erb:3 lib/authenticated_system.rb:83 8318 #: app/views/shared/access_denied.html.erb:3 lib/authenticated_system.rb:83
8322 msgid "Access denied" 8319 msgid "Access denied"
@@ -8334,9 +8331,19 @@ msgstr &quot;&quot; @@ -8334,9 +8331,19 @@ msgstr &quot;&quot;
8334 "Si vous êtes supposé(e) avoir accès à cette zone, vous devriez sans doute en " 8331 "Si vous êtes supposé(e) avoir accès à cette zone, vous devriez sans doute en "
8335 "référer aux responsable et leur demander de vous y donner accès." 8332 "référer aux responsable et leur demander de vous y donner accès."
8336 8333
8337 -#: app/views/shared/access_denied.html.erb:14 public/500.html.erb:28  
8338 -msgid "Go to the site home page"  
8339 -msgstr "Aller à la page d'accueil du site" 8334 +#: app/views/categories/new.html.erb:1 app/views/categories/index.html.erb:7
  8335 +#: app/views/categories/index.html.erb:16
  8336 +#: app/views/categories/index.html.erb:25
  8337 +msgid "New category"
  8338 +msgstr "Nouvelle catégorie"
  8339 +
  8340 +#: app/views/categories/_category.html.erb:10
  8341 +msgid "Show"
  8342 +msgstr "Voir"
  8343 +
  8344 +#: app/views/categories/_category.html.erb:12
  8345 +msgid "Hide"
  8346 +msgstr "Cacher"
8340 8347
8341 #: app/views/shared/_lead_and_body.html.erb:18 8348 #: app/views/shared/_lead_and_body.html.erb:18
8342 msgid "Used when a short version of your text is needed." 8349 msgid "Used when a short version of your text is needed."
@@ -8354,13 +8361,13 @@ msgstr &quot;&quot; @@ -8354,13 +8361,13 @@ msgstr &quot;&quot;
8354 "Vous pouvez déplacer cette fenêtre pour avoir une meilleure vue sur " 8361 "Vous pouvez déplacer cette fenêtre pour avoir une meilleure vue sur "
8355 "certaines parties de l'écran." 8362 "certaines parties de l'écran."
8356 8363
8357 -#: app/views/shared/theme_test_panel.html.erb:9  
8358 -msgid "Finished testing"  
8359 -msgstr "Test terminé" 8364 +#: app/views/categories/_form.html.erb:22
  8365 +msgid "Display in the menu"
  8366 +msgstr "Afficher dans le menu"
8360 8367
8361 -#: app/views/shared/theme_test_panel.html.erb:10  
8362 -msgid "Edit theme"  
8363 -msgstr "Éditer le thème" 8368 +#: app/views/categories/_form.html.erb:24
  8369 +msgid "Pick a color"
  8370 +msgstr "Choisir la couleur"
8364 8371
8365 #: app/views/shared/_list_groups.html.erb:9 8372 #: app/views/shared/_list_groups.html.erb:9
8366 msgid "Role: %s" 8373 msgid "Role: %s"
@@ -8374,14 +8381,13 @@ msgstr &quot;Type : %s&quot; @@ -8374,14 +8381,13 @@ msgstr &quot;Type : %s&quot;
8374 msgid "Members: %s" 8381 msgid "Members: %s"
8375 msgstr "Membres : %s" 8382 msgstr "Membres : %s"
8376 8383
8377 -#: app/views/shared/_list_groups.html.erb:13  
8378 -msgid "Created at: %s"  
8379 -msgstr "Créé le : %s" 8384 +#: app/views/memberships/welcome.html.erb:1
  8385 +msgid "Community created"
  8386 +msgstr "Communauté créée"
8380 8387
8381 -#: app/views/shared/_list_groups.html.erb:16  
8382 -#, fuzzy  
8383 -msgid "Control panel of this group"  
8384 -msgstr "Panneau de contrôle" 8388 +#: app/views/memberships/welcome.html.erb:2
  8389 +msgid "Your community (%s) was successfully created."
  8390 +msgstr "Votre communauté (%s) a été créée avec succès."
8385 8391
8386 #: app/views/shared/_remove_suggestion.html.erb:4 8392 #: app/views/shared/_remove_suggestion.html.erb:4
8387 #, fuzzy 8393 #, fuzzy
public/500.html
@@ -67,7 +67,7 @@ @@ -67,7 +67,7 @@
67 67
68 68
69 <div id='fr' style='display: none' class='message'> 69 <div id='fr' style='display: none' class='message'>
70 - <h1>Problème temporaire du système.</h1> 70 + <h1>Problème temporaire du système</h1>
71 <p> 71 <p>
72 Notre équipe technique est en train d'y travailler. Merci de réessayer plus tard. Nous sommes désolés de la gêne occasionnée. 72 Notre équipe technique est en train d'y travailler. Merci de réessayer plus tard. Nous sommes désolés de la gêne occasionnée.
73 </p> 73 </p>
public/proposal-app
1 -Subproject commit 571085f87ca4820b178f27cd7de68fd784a12d6e 1 +Subproject commit 7434555263662042b20ff7ccc2b484a6939c62fa
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
@@ -49,7 +49,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -49,7 +49,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
49 end 49 end
50 50
51 should 'not list children of forbidden article' do 51 should 'not list children of forbidden article' do
52 - person = fast_create(Person) 52 + person = fast_create(Person, :environment_id => environment.id)
53 article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false) 53 article = fast_create(Article, :profile_id => person.id, :name => "Some thing", :published => false)
54 child1 = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing") 54 child1 = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing")
55 child2 = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing") 55 child2 = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing")
@@ -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 return child of forbidden article' do 60 should 'not return child 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 child = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing") 63 child = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing")
64 get "/api/v1/articles/#{article.id}/children/#{child.id}?#{params.to_query}" 64 get "/api/v1/articles/#{article.id}/children/#{child.id}?#{params.to_query}"
@@ -66,7 +66,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -66,7 +66,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
66 end 66 end
67 67
68 should 'not return private child' do 68 should 'not return private child' do
69 - person = fast_create(Person) 69 + person = fast_create(Person, :environment_id => environment.id)
70 article = fast_create(Article, :profile_id => person.id, :name => "Some thing") 70 article = fast_create(Article, :profile_id => person.id, :name => "Some thing")
71 child = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing", :published => false) 71 child = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing", :published => false)
72 get "/api/v1/articles/#{article.id}/children/#{child.id}?#{params.to_query}" 72 get "/api/v1/articles/#{article.id}/children/#{child.id}?#{params.to_query}"
@@ -74,7 +74,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -74,7 +74,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
74 end 74 end
75 75
76 should 'not list private child' do 76 should 'not list private child' do
77 - person = fast_create(Person) 77 + person = fast_create(Person, :environment_id => environment.id)
78 article = fast_create(Article, :profile_id => person.id, :name => "Some thing") 78 article = fast_create(Article, :profile_id => person.id, :name => "Some thing")
79 child = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing", :published => false) 79 child = fast_create(Article, :parent_id => article.id, :profile_id => person.id, :name => "Some thing", :published => false)
80 get "/api/v1/articles/#{article.id}/children?#{params.to_query}" 80 get "/api/v1/articles/#{article.id}/children?#{params.to_query}"
@@ -89,7 +89,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -89,7 +89,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
89 profile_kinds = %w(community person enterprise) 89 profile_kinds = %w(community person enterprise)
90 profile_kinds.each do |kind| 90 profile_kinds.each do |kind|
91 should "return article by #{kind}" do 91 should "return article by #{kind}" do
92 - profile = fast_create(kind.camelcase.constantize) 92 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
93 article = fast_create(Article, :profile_id => profile.id, :name => "Some thing") 93 article = fast_create(Article, :profile_id => profile.id, :name => "Some thing")
94 get "/api/v1/#{kind.pluralize}/#{profile.id}/articles/#{article.id}?#{params.to_query}" 94 get "/api/v1/#{kind.pluralize}/#{profile.id}/articles/#{article.id}?#{params.to_query}"
95 json = JSON.parse(last_response.body) 95 json = JSON.parse(last_response.body)
@@ -97,7 +97,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -97,7 +97,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
97 end 97 end
98 98
99 should "not return article by #{kind} if user has no permission to view it" do 99 should "not return article by #{kind} if user has no permission to view it" do
100 - profile = fast_create(kind.camelcase.constantize) 100 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
101 article = fast_create(Article, :profile_id => profile.id, :name => "Some thing", :published => false) 101 article = fast_create(Article, :profile_id => profile.id, :name => "Some thing", :published => false)
102 assert !article.published? 102 assert !article.published?
103 103
@@ -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 list forbidden article when listing articles by #{kind}" do 108 should "not list forbidden article when listing articles by #{kind}" 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
@@ -123,7 +123,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -123,7 +123,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
123 group_kinds = %w(community enterprise) 123 group_kinds = %w(community enterprise)
124 group_kinds.each do |kind| 124 group_kinds.each do |kind|
125 should "#{kind}: create article" do 125 should "#{kind}: create article" do
126 - profile = fast_create(kind.camelcase.constantize) 126 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
127 give_permission(user.person, 'post_content', profile) 127 give_permission(user.person, 'post_content', profile)
128 params[:article] = {:name => "Title"} 128 params[:article] = {:name => "Title"}
129 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" 129 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}"
@@ -132,16 +132,16 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -132,16 +132,16 @@ class ArticlesTest &lt; ActiveSupport::TestCase
132 end 132 end
133 133
134 should "#{kind}: do not create article if user has no permission to post content" do 134 should "#{kind}: do not create article if user has no permission to post content" do
135 - profile = fast_create(kind.camelcase.constantize) 135 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
136 give_permission(user.person, 'invite_members', profile) 136 give_permission(user.person, 'invite_members', 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}"
139 assert_equal 403, last_response.status 139 assert_equal 403, last_response.status
140 end 140 end
141 141
142 - should "#{kind}: create article with parent" do  
143 - profile = fast_create(kind.camelcase.constantize)  
144 - profile.add_member(user.person) 142 + should "#{kind} create article with parent" do
  143 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
  144 + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true)
145 article = fast_create(Article) 145 article = fast_create(Article)
146 146
147 params[:article] = {:name => "Title", :parent_id => article.id} 147 params[:article] = {:name => "Title", :parent_id => article.id}
@@ -150,9 +150,9 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -150,9 +150,9 @@ class ArticlesTest &lt; ActiveSupport::TestCase
150 assert_equal article.id, json["article"]["parent"]["id"] 150 assert_equal article.id, json["article"]["parent"]["id"]
151 end 151 end
152 152
153 - should "#{kind}: create article with content type passed as parameter" do  
154 - profile = fast_create(kind.camelcase.constantize)  
155 - profile.add_member(user.person) 153 + should "#{kind} create article with content type passed as parameter" do
  154 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
  155 + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true)
156 156
157 Article.delete_all 157 Article.delete_all
158 params[:article] = {:name => "Title"} 158 params[:article] = {:name => "Title"}
@@ -164,8 +164,8 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -164,8 +164,8 @@ class ArticlesTest &lt; ActiveSupport::TestCase
164 end 164 end
165 165
166 should "#{kind}: create article of TinyMceArticle type if no content type is passed as parameter" do 166 should "#{kind}: create article of TinyMceArticle type if no content type is passed as parameter" do
167 - profile = fast_create(kind.camelcase.constantize)  
168 - profile.add_member(user.person) 167 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
  168 + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true)
169 169
170 params[:article] = {:name => "Title"} 170 params[:article] = {:name => "Title"}
171 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" 171 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}"
@@ -175,7 +175,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -175,7 +175,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
175 end 175 end
176 176
177 should "#{kind}: not create article with invalid article content type" do 177 should "#{kind}: not create article with invalid article content type" do
178 - profile = fast_create(kind.camelcase.constantize) 178 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
179 profile.add_member(user.person) 179 profile.add_member(user.person)
180 180
181 params[:article] = {:name => "Title"} 181 params[:article] = {:name => "Title"}
@@ -186,20 +186,20 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -186,20 +186,20 @@ class ArticlesTest &lt; ActiveSupport::TestCase
186 assert_equal 403, last_response.status 186 assert_equal 403, last_response.status
187 end 187 end
188 188
189 - should "#{kind}: create article defining the correct profile" do  
190 - profile = fast_create(kind.camelcase.constantize)  
191 - profile.add_member(user.person) 189 + should "#{kind} create article defining the correct profile" do
  190 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
  191 + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true)
192 192
193 params[:article] = {:name => "Title"} 193 params[:article] = {:name => "Title"}
194 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" 194 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}"
195 json = JSON.parse(last_response.body) 195 json = JSON.parse(last_response.body)
196 196
197 - assert_equal profile, Article.last.profile 197 + assert_equal profile.id, json['article']['profile']['id']
198 end 198 end
199 199
200 should "#{kind}: create article defining the created_by" do 200 should "#{kind}: create article defining the created_by" do
201 - profile = fast_create(kind.camelcase.constantize)  
202 - profile.add_member(user.person) 201 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
  202 + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true)
203 203
204 params[:article] = {:name => "Title"} 204 params[:article] = {:name => "Title"}
205 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" 205 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}"
@@ -209,8 +209,8 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -209,8 +209,8 @@ class ArticlesTest &lt; ActiveSupport::TestCase
209 end 209 end
210 210
211 should "#{kind}: create article defining the last_changed_by" do 211 should "#{kind}: create article defining the last_changed_by" do
212 - profile = fast_create(kind.camelcase.constantize)  
213 - profile.add_member(user.person) 212 + profile = fast_create(kind.camelcase.constantize, :environment_id => environment.id)
  213 + Person.any_instance.stubs(:can_post_content?).with(profile).returns(true)
214 214
215 params[:article] = {:name => "Title"} 215 params[:article] = {:name => "Title"}
216 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}" 216 post "/api/v1/#{kind.pluralize}/#{profile.id}/articles?#{params.to_query}"
@@ -232,7 +232,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase @@ -232,7 +232,7 @@ class ArticlesTest &lt; ActiveSupport::TestCase
232 end 232 end
233 233
234 should 'person do not create article if user has no permission to post content' do 234 should 'person do not create article if user has no permission to post content' do
235 - person = fast_create(Person) 235 + person = fast_create(Person, :environment_id => environment.id)
236 params[:article] = {:name => "Title"} 236 params[:article] = {:name => "Title"}
237 post "/api/v1/people/#{person.id}/articles?#{params.to_query}" 237 post "/api/v1/people/#{person.id}/articles?#{params.to_query}"
238 assert_equal 403, last_response.status 238 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/helpers_test.rb
@@ -209,7 +209,9 @@ class APIHelpersTest &lt; ActiveSupport::TestCase @@ -209,7 +209,9 @@ class APIHelpersTest &lt; ActiveSupport::TestCase
209 serpro_client_id: '0000000000000000', 209 serpro_client_id: '0000000000000000',
210 verify_uri: 'http://localhost/api/verify', 210 verify_uri: 'http://localhost/api/verify',
211 } 211 }
212 - assert_equal test_captcha("127.0.0.1", {}, environment), "Missing captcha data" 212 + params = {}
  213 + params[:txtToken_captcha_serpro_gov_br] = '4324343'
  214 + assert_equal test_captcha("127.0.0.1", params, environment), _('Captcha text has not been filled')
213 end 215 end
214 216
215 should 'render not_found if endpoint is unavailable' do 217 should 'render not_found if endpoint is unavailable' do
@@ -234,6 +236,23 @@ class APIHelpersTest &lt; ActiveSupport::TestCase @@ -234,6 +236,23 @@ class APIHelpersTest &lt; ActiveSupport::TestCase
234 236
235 end 237 end
236 238
  239 + should 'captcha serpro say Name or service not known' do
  240 + environment = Environment.new
  241 + environment.api_captcha_settings = {
  242 + enabled: true,
  243 + provider: 'serpro',
  244 + serpro_client_id: '0000000000000000',
  245 + verify_uri: 'http://someserverthatdoesnotexist.mycompanythatdoesnotexist.com/validate',
  246 + }
  247 + params = {}
  248 + params[:txtToken_captcha_serpro_gov_br] = '4324343'
  249 + params[:captcha_text] = '4324343'
  250 + logger = Logger.new(File.join(Rails.root, 'log', 'test_api.log'))
  251 + stubs(:logger).returns(logger)
  252 + assert_equal test_captcha('127.0.0.1', params, environment), 'Serpro captcha error: getaddrinfo: Name or service not known'
  253 + end
  254 +
  255 +
237 protected 256 protected
238 257
239 def error!(info, status) 258 def error!(info, status)
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/environment_test.rb
@@ -759,13 +759,10 @@ class EnvironmentTest &lt; ActiveSupport::TestCase @@ -759,13 +759,10 @@ class EnvironmentTest &lt; ActiveSupport::TestCase
759 759
760 should 'set custom_person_fields with its dependecies' do 760 should 'set custom_person_fields with its dependecies' do
761 env = Environment.new 761 env = Environment.new
762 - env.custom_person_fields = {'cell_phone' => {'required' => 'true', 'active' => '', 'signup' => ''}, 'comercial_phone'=> {'required' => '', 'active' => 'true', 'signup' => '' }, 'description' => {'required' => '', 'active' => '', 'signup' => 'true'}} 762 + data = {'cell_phone' => {'required' => 'true', 'active' => '', 'signup' => ''}, 'comercial_phone'=> {'required' => '', 'active' => 'true', 'signup' => '' }, 'description' => {'required' => '', 'active' => '', 'signup' => 'true'}}
  763 + env.custom_person_fields = data
763 764
764 - assert_equal({'cell_phone' => {'required' => 'true', 'active' => 'true', 'signup' => 'true'}, 'comercial_phone'=> {'required' => '', 'active' => 'true', 'signup' => '' }, 'description' => {'required' => '', 'active' => 'true', 'signup' => 'true'}}, env.custom_person_fields)  
765 - end  
766 -  
767 - should 'have no custom_person_fields by default' do  
768 - assert_equal({}, Environment.new.custom_person_fields) 765 + assert(env.custom_person_fields.merge(data) == env.custom_person_fields)
769 end 766 end
770 767
771 should 'not set in custom_person_fields if not in person.fields' do 768 should 'not set in custom_person_fields if not in person.fields' do
@@ -773,7 +770,8 @@ class EnvironmentTest &lt; ActiveSupport::TestCase @@ -773,7 +770,8 @@ class EnvironmentTest &lt; ActiveSupport::TestCase
773 Person.stubs(:fields).returns(['cell_phone', 'comercial_phone']) 770 Person.stubs(:fields).returns(['cell_phone', 'comercial_phone'])
774 771
775 env.custom_person_fields = { 'birth_date' => {'required' => 'true', 'active' => 'true'}, 'cell_phone' => {'required' => 'true', 'active' => 'true'}} 772 env.custom_person_fields = { 'birth_date' => {'required' => 'true', 'active' => 'true'}, 'cell_phone' => {'required' => 'true', 'active' => 'true'}}
776 - assert_equal({'cell_phone' => {'required' => 'true','signup' => 'true', 'active' => 'true'}}, env.custom_person_fields) 773 + expected_hash = {'cell_phone' => {'required' => 'true', 'active' => 'true', 'signup' => 'true'}}
  774 + assert(env.custom_person_fields.merge(expected_hash) == env.custom_person_fields)
777 assert ! env.custom_person_fields.keys.include?('birth_date') 775 assert ! env.custom_person_fields.keys.include?('birth_date')
778 end 776 end
779 777
@@ -782,7 +780,8 @@ class EnvironmentTest &lt; ActiveSupport::TestCase @@ -782,7 +780,8 @@ class EnvironmentTest &lt; ActiveSupport::TestCase
782 Person.stubs(:fields).returns(['cell_phone', 'schooling']) 780 Person.stubs(:fields).returns(['cell_phone', 'schooling'])
783 781
784 env.custom_person_fields = { 'schooling' => {'required' => 'true', 'active' => 'true'}} 782 env.custom_person_fields = { 'schooling' => {'required' => 'true', 'active' => 'true'}}
785 - assert_equal({'schooling' => {'required' => 'true', 'signup' => 'true', 'active' => 'true'}, 'schooling_status' => {'required' => 'true', 'signup' => 'true', 'active' => 'true'}}, env.custom_person_fields) 783 + expected_hash = {'schooling' => {'required' => 'true', 'active' => 'true', 'signup' => 'true'}, 'schooling_status' => {'required' => 'true', 'signup' => 'true', 'active' => 'true'}}
  784 + assert(env.custom_person_fields.merge(expected_hash) == env.custom_person_fields)
786 assert ! env.custom_person_fields.keys.include?('birth_date') 785 assert ! env.custom_person_fields.keys.include?('birth_date')
787 end 786 end
788 787
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
util/debian-install/README.md
1 This directory contains the basic structure to test the installation of 1 This directory contains the basic structure to test the installation of
2 Noosfero debian packages, using a fresh Vagrant VM and packages built in 2 Noosfero debian packages, using a fresh Vagrant VM and packages built in
3 ${NOOSFEROROOT}/pkg/. 3 ${NOOSFEROROOT}/pkg/.
  4 +
  5 +To perform a test, do
  6 +
  7 +```
  8 +$ cd /path/to/noosfero
  9 +$ rake noosfero:deb
  10 +$ cd util/debian-install/
  11 +$ vagrant up
  12 +```
  13 +
  14 +To reset the environment in preparation for a new test, destroy the VM and
  15 +remove any local `*.deb` files :
  16 +
  17 +```
  18 +$ cd util/debian-install/
  19 +$ vagrant halt
  20 +$ vagrant destroy
  21 +$ rm -f *.deb
  22 +```
util/debian-install/Vagrantfile
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 VAGRANTFILE_API_VERSION = "2" 5 VAGRANTFILE_API_VERSION = "2"
6 6
7 require 'fileutils' 7 require 'fileutils'
8 -debs = `find ../../pkg/ -name '*.deb' | sort -t _ -V | tail -2`.split 8 +debs = `find ../../pkg/ -name '*.deb' | sort -t _ -V`.split
9 if debs.empty? 9 if debs.empty?
10 puts "W: no debs built in ../../pkg/; will either install existing local" 10 puts "W: no debs built in ../../pkg/; will either install existing local"
11 puts " ones, or the ones from the remote repository" 11 puts " ones, or the ones from the remote repository"
@@ -16,7 +16,7 @@ else @@ -16,7 +16,7 @@ else
16 16
17 local_debs.delete(fn) 17 local_debs.delete(fn)
18 18
19 - if File.stat(f) != File.stat(fn) 19 + if !File.exist?(fn) || File.stat(f) != File.stat(fn)
20 FileUtils::Verbose.rm_f(fn) 20 FileUtils::Verbose.rm_f(fn)
21 FileUtils::Verbose.ln f, '.' 21 FileUtils::Verbose.ln f, '.'
22 end 22 end