[noosfero/noosfero][rails4] 4 commits: rails4: use Noosfero::Mailer to set required default_url_options

Bráulio Bhavamitra gitlab at gitlab.com
Sun Apr 5 10:36:01 BRT 2015


Bráulio Bhavamitra pushed to rails4 at Noosfero / noosfero


Commits:
1654f0b4 by Braulio Bhavamitra at 2015-04-05T09:29:07Z
rails4: use Noosfero::Mailer to set required default_url_options

- - - - -
0ec08b06 by Braulio Bhavamitra at 2015-04-05T09:49:36Z
rails4: do not assert ActiveRecord::Relation as rails changes it

- - - - -
6c9ed5a6 by Braulio Bhavamitra at 2015-04-05T10:17:17Z
rails4: disable autosave on person association

- - - - -
adbf0c71 by Braulio Bhavamitra at 2015-04-05T10:33:54Z
rails4: Array is not used for AR results

- - - - -


29 changed files:

- app/mailers/comment_notifier.rb
- app/mailers/contact.rb
- app/mailers/mailing.rb
- app/mailers/pending_task_notifier.rb
- app/mailers/scrap_notifier.rb
- app/mailers/task_mailer.rb
- app/mailers/user_mailer.rb
- app/models/person.rb
- app/models/user.rb
- app/views/comment_notifier/mail_to_followers.html.erb
- app/views/comment_notifier/notification.text.erb
- app/views/contact/sender/notification.html.erb
- app/views/pending_task_notifier/notification.text.erb
- app/views/person_notifier/mailer/content_summary.html.erb
- app/views/scrap_notifier/notification.text.erb
- app/views/task_mailer/generic_message.text.erb
- app/views/task_mailer/target_notification.text.erb
- app/views/user/mailer/activation_code.html.erb
- app/views/user_mailer/activation_code.text.erb
- app/views/user_mailer/activation_email_notify.text.erb
- app/views/user_mailer/profiles_suggestions_email.html.erb
- + lib/noosfero/mailer.rb
- lib/noosfero/plugin/manager.rb
- plugins/work_assignment/lib/work_assignment_plugin/email_contact.rb
- test/unit/organization_test.rb
- test/unit/person_test.rb
- test/unit/product_category_test.rb
- vendor/plugins/access_control/lib/acts_as_accessible.rb
- vendor/plugins/access_control/lib/acts_as_accessor.rb


Changes:

=====================================
app/mailers/comment_notifier.rb
=====================================
--- a/app/mailers/comment_notifier.rb
+++ b/app/mailers/comment_notifier.rb
@@ -1,6 +1,8 @@
-class CommentNotifier < ActionMailer::Base
+class CommentNotifier < Noosfero::Mailer
+
   def notification(comment)
     profile = comment.article.profile
+    self.environment = profile.environment
     @recipient = profile.nickname || profile.name
     @sender = comment.author_name
     @sender_link = comment.author_link
@@ -8,7 +10,6 @@ class CommentNotifier < ActionMailer::Base
     @comment_url = comment.url
     @comment_title = comment.title
     @comment_body = comment.body
-    @environment = profile.environment.name
     @url = profile.environment.top_url
 
     mail(
@@ -20,6 +21,8 @@ class CommentNotifier < ActionMailer::Base
 
   def mail_to_followers(comment, emails)
     profile = comment.article.profile
+    self.environment = profile.environment
+
     @recipient = profile.nickname || profile.name
     @sender = comment.author_name
     @sender_link = comment.author_link
@@ -28,7 +31,6 @@ class CommentNotifier < ActionMailer::Base
     @unsubscribe_url = comment.article.view_url.merge({:unfollow => true})
     @comment_title = comment.title
     @comment_body = comment.body
-    @environment = profile.environment.name
     @url = profile.environment.top_url
 
     mail(

=====================================
app/mailers/contact.rb
=====================================
--- a/app/mailers/contact.rb
+++ b/app/mailers/contact.rb
@@ -30,14 +30,16 @@ class Contact
     Contact::Sender.notification(self).deliver
   end
 
-  class Sender < ActionMailer::Base
+  class Sender < Noosfero::Mailer
+
     def notification(contact)
+      self.environment = contact.dest.environment
+
       @name = contact.name
       @email = contact.email
       @city = contact.city
       @state = contact.state
       @message = contact.message
-      @environment = contact.dest.environment.name
       @url = url_for(:host => contact.dest.environment.default_hostname, :controller => 'home')
       @target = contact.dest.name
 

=====================================
app/mailers/mailing.rb
=====================================
--- a/app/mailers/mailing.rb
+++ b/app/mailers/mailing.rb
@@ -48,7 +48,8 @@ class Mailing < ActiveRecord::Base
     end
   end
 
-  class Sender < ActionMailer::Base
+  class Sender < Noosfero::Mailer
+
     def notification(mailing, recipient)
       @message = mailing.body
       @signature_message = mailing.signature_message

=====================================
app/mailers/pending_task_notifier.rb
=====================================
--- a/app/mailers/pending_task_notifier.rb
+++ b/app/mailers/pending_task_notifier.rb
@@ -1,10 +1,11 @@
-class PendingTaskNotifier < ActionMailer::Base
+class PendingTaskNotifier < Noosfero::Mailer
 
   def notification(person)
+    self.environment = person.environment
+
     @person = person
     @tasks = person.tasks.pending
     @organizations_with_pending_tasks = person.organizations_with_pending_tasks
-    @environment = person.environment.name
     @url = url_for(:host => person.environment.default_hostname, :controller => 'home')
     @default_hostname = person.environment.default_hostname
     @url_for_pending_tasks = url_for(:host => person.environment.default_hostname, :controller => 'tasks', :profile => person.identifier)

=====================================
app/mailers/scrap_notifier.rb
=====================================
--- a/app/mailers/scrap_notifier.rb
+++ b/app/mailers/scrap_notifier.rb
@@ -1,12 +1,14 @@
-class ScrapNotifier < ActionMailer::Base
+class ScrapNotifier < Noosfero::Mailer
+
   def notification(scrap)
     sender, receiver = scrap.sender, scrap.receiver
+    self.environment = sender.environment
+
     @recipient = receiver.name
     @sender = sender.name
     @sender_link = sender.url
     @scrap_content = scrap.content
     @wall_url = scrap.scrap_wall_url
-    @environment = sender.environment.name
     @url = sender.environment.top_url
     mail(
       to: receiver.email,

=====================================
app/mailers/task_mailer.rb
=====================================
--- a/app/mailers/task_mailer.rb
+++ b/app/mailers/task_mailer.rb
@@ -1,9 +1,10 @@
-class TaskMailer < ActionMailer::Base
+class TaskMailer < Noosfero::Mailer
 
   def target_notification(task, message)
+    self.environment = task.environment
+
     @message = extract_message(message)
     @target = task.target.name
-    @environment = task.environment.name
     @url = generate_environment_url(task, :controller => 'home')
     url_for_tasks_list = task.target.kind_of?(Environment) ? '' : url_for(task.target.tasks_url)
     @tasks_url = url_for_tasks_list
@@ -16,6 +17,8 @@ class TaskMailer < ActionMailer::Base
   end
 
   def invitation_notification(task)
+    self.environment = task.requestor.environment
+
     msg = task.expanded_message
     @message = msg.gsub /<url>/, generate_environment_url(task, :controller => 'account', :action => 'signup', :invitation_code => task.code)
 
@@ -27,11 +30,12 @@ class TaskMailer < ActionMailer::Base
   end
 
   def generic_message(name, task)
+    self.environment = task.requestor.environment
+
     return if !task.respond_to?("#{name}_message")
 
     @message = extract_message(task.send("#{name}_message"))
     @requestor = task.requestor.name
-    @environment = task.requestor.environment.name
     @url = url_for(:host => task.requestor.environment.default_hostname, :controller => 'home')
 
     mail(

=====================================
app/mailers/user_mailer.rb
=====================================
--- a/app/mailers/user_mailer.rb
+++ b/app/mailers/user_mailer.rb
@@ -1,10 +1,12 @@
-class UserMailer < ActionMailer::Base
+class UserMailer < Noosfero::Mailer
+
   def activation_email_notify(user)
+    self.environment = user.environment
+
     user_email = "#{user.login}@#{user.email_domain}"
     @name = user.name
     @email = user_email
     @webmail = MailConf.webmail_url(user.login, user.email_domain)
-    @environment = user.environment.name
     @url = url_for(:host => user.environment.default_hostname, :controller => 'home')
 
     mail(
@@ -15,9 +17,10 @@ class UserMailer < ActionMailer::Base
   end
 
   def activation_code(user)
+    self.environment = user.environment
+
     @recipient = user.name
     @activation_code = user.activation_code
-    @environment = user.environment.name
     @url = user.environment.top_url
     @redirection = (true if user.return_to)
     @join = (user.community_to_join if user.community_to_join)
@@ -30,6 +33,8 @@ class UserMailer < ActionMailer::Base
   end
 
   def signup_welcome_email(user)
+    self.environment = user.environment
+
     @body = user.environment.signup_welcome_text_body.gsub('{user_name}', user.name)
     email_subject = user.environment.signup_welcome_text_subject
     mail(
@@ -42,8 +47,9 @@ class UserMailer < ActionMailer::Base
   end
 
   def profiles_suggestions_email(user)
+    self.environment = user.environment
+
     @recipient = user.name
-    @environment = user.environment.name
     @url = user.environment.top_url
     @people_suggestions_url = user.people_suggestions_url
     @people_suggestions = user.suggested_people.sample(3)

=====================================
app/models/person.rb
=====================================
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -17,19 +17,19 @@ class Person < Profile
   acts_as_accessor
 
   scope :members_of, -> (resources) {
-    resources = [resources] if !resources.kind_of?(Array)
+    resources = Array(resources)
     conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ')
     select('DISTINCT profiles.*').joins(:role_assignments).where([conditions])
   }
 
   scope :not_members_of, -> (resources) {
-    resources = [resources] if !resources.kind_of?(Array)
+    resources = Array(resources)
     conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ')
     select('DISTINCT profiles.*').where('"profiles"."id" NOT IN (SELECT DISTINCT profiles.id FROM "profiles" INNER JOIN "role_assignments" ON "role_assignments"."accessor_id" = "profiles"."id" AND "role_assignments"."accessor_type" = (\'Profile\') WHERE "profiles"."type" IN (\'Person\') AND (%s))' % conditions)
   }
 
   scope :by_role, -> (roles) {
-    roles = [roles] unless roles.kind_of?(Array)
+    roles = Array(roles)
     select('DISTINCT profiles.*').joins(:role_assignments).where('role_assignments.role_id IN (?)', roles)
   }
 
@@ -291,8 +291,7 @@ class Person < Profile
   end
 
   after_update do |person|
-    # FIXME: causes infinite loop with rails4
-    #person.user.save!
+    person.user.save!
   end
 
   def is_admin?(environment = nil)

=====================================
app/models/user.rb
=====================================
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -84,7 +84,8 @@ class User < ActiveRecord::Base
     end
   end
 
-  has_one :person, :dependent => :destroy
+  # set autosave to false as we do manually when needed and Person syncs with us
+  has_one :person, dependent: :destroy, autosave: false
   belongs_to :environment
 
   attr_protected :activated_at

=====================================
app/views/comment_notifier/mail_to_followers.html.erb
=====================================
--- a/app/views/comment_notifier/mail_to_followers.html.erb
+++ b/app/views/comment_notifier/mail_to_followers.html.erb
@@ -18,5 +18,5 @@
 <%= _("Greetings,") %>
 
 --
-<%= _('%s team.') % @environment %>
+<%= _('%s team.') % @environment.name %>
 <%= url_for @url %>

=====================================
app/views/comment_notifier/notification.text.erb
=====================================
--- a/app/views/comment_notifier/notification.text.erb
+++ b/app/views/comment_notifier/notification.text.erb
@@ -15,5 +15,5 @@
 <%= _("Greetings,") %>
 
 --
-<%= _('%s team.') % @environment %>
+<%= _('%s team.') % @environment.name %>
 <%= url_for @url %>

=====================================
app/views/contact/sender/notification.html.erb
=====================================
--- a/app/views/contact/sender/notification.html.erb
+++ b/app/views/contact/sender/notification.html.erb
@@ -5,7 +5,7 @@
   </head>
   <body>
     <p><%= _('This message was sent by %{sender} to %{target} on %{environment}.') %
-    {:sender => @name, :target => @target, :environment => @environment} %></p>
+    {:sender => @name, :target => @target, :environment => @environment.name} %></p>
     <%= _('Information about the user who sent this message:')%>
     <ul>
       <li><%= content_tag('b', _('Name')+': ') + @name.to_s %></li>
@@ -20,7 +20,7 @@
 
     --<br/>
     <%= _('Greetings,') %><br/>
-    <%= _('%s team.') % @environment %><br/>
+    <%= _('%s team.') % @environment.name %><br/>
     <%= @url %>
   </body>
 </html>

=====================================
app/views/pending_task_notifier/notification.text.erb
=====================================
--- a/app/views/pending_task_notifier/notification.text.erb
+++ b/app/views/pending_task_notifier/notification.text.erb
@@ -21,5 +21,5 @@
 <%= _('Greetings,') %>
 
 --
-<%= _('%s team.') % @environment %>
+<%= _('%s team.') % @environment.name %>
 <%= @url %>

=====================================
app/views/person_notifier/mailer/content_summary.html.erb
=====================================
--- a/app/views/person_notifier/mailer/content_summary.html.erb
+++ b/app/views/person_notifier/mailer/content_summary.html.erb
@@ -3,7 +3,7 @@
   <div style="display: table; background-color: white; margin: 26px 0;">
     <div style="padding: 25px 20px 20px 20px;text-align: left;">
       <%= link_to @url, :style => "text-decoration: none;" do %>
-        <span style="font-weight:bold;font-size: 28px;margin: 0;color: white;background-color: #AAAAAA;padding: 5px;"><%= @environment %></span>
+        <span style="font-weight:bold;font-size: 28px;margin: 0;color: white;background-color: #AAAAAA;padding: 5px;"><%= @environment.name %></span>
       <% end %>
       <span style="font-weight:bold;color: #333;font-size:19px;margin-left: 8px;"><%= _("%s's Notifications") % @profile.name %></h3>
     </div>
@@ -34,7 +34,7 @@
 
       <div style="color:#444444;font-size:11px;margin-bottom: 20px;">
         <p style="margin:0"><%= _("Greetings,") %></p>
-        <p style="margin:0"><%= _('%s team.') % @environment %></p>
+        <p style="margin:0"><%= _('%s team.') % @environment.name %></p>
         <p style="margin:0"><%= link_to @url, url_for(@url) %></p>
       </div>
     </div>

=====================================
app/views/scrap_notifier/notification.text.erb
=====================================
--- a/app/views/scrap_notifier/notification.text.erb
+++ b/app/views/scrap_notifier/notification.text.erb
@@ -12,5 +12,5 @@
 <%= _("Greetings,") %>
 
 --
-<%= _('%s team.') % @environment %>
+<%= _('%s team.') % @environment.name %>
 <%= url_for @url %>

=====================================
app/views/task_mailer/generic_message.text.erb
=====================================
--- a/app/views/task_mailer/generic_message.text.erb
+++ b/app/views/task_mailer/generic_message.text.erb
@@ -5,5 +5,5 @@
 <%= _('Greetings,') %>
 
 --
-<%= _('%s team.') % @environment %>
+<%= _('%s team.') % @environment.name %>
 <%= @url %>

=====================================
app/views/task_mailer/target_notification.text.erb
=====================================
--- a/app/views/task_mailer/target_notification.text.erb
+++ b/app/views/task_mailer/target_notification.text.erb
@@ -6,5 +6,5 @@
 <%= @tasks_url %>
 
 --
-<%= _('%s team.') % @environment %>
+<%= _('%s team.') % @environment.name %>
 <%= @url %>

=====================================
app/views/user/mailer/activation_code.html.erb
=====================================
--- a/app/views/user/mailer/activation_code.html.erb
+++ b/app/views/user/mailer/activation_code.html.erb
@@ -1,9 +1,9 @@
 <%= _('Hi, %{recipient}!') % { :recipient => @recipient } %>
 
-<%= word_wrap(_('Welcome to %{environment}! To activate your account, follow the link: %{activation_url}') % { :environment => @environment, :activation_url => @url + url_for(:controller => :account, :action => :activate, :activation_code => @activation_code, :redirection => @redirection, :join => @join) }) %>
+<%= word_wrap(_('Welcome to %{environment}! To activate your account, follow the link: %{activation_url}') % { :environment => @environment.name, :activation_url => @url + url_for(:controller => :account, :action => :activate, :activation_code => @activation_code, :redirection => @redirection, :join => @join) }) %>
 
 <%= _("Greetings,") %>
 
 --
-<%= _('%s team.') % @environment %>
+<%= _('%s team.') % @environment.name %>
 <%= url_for @url %>

=====================================
app/views/user_mailer/activation_code.text.erb
=====================================
--- a/app/views/user_mailer/activation_code.text.erb
+++ b/app/views/user_mailer/activation_code.text.erb
@@ -1,9 +1,9 @@
 <%= _('Hi, %{recipient}!') % { :recipient => @recipient } %>
 
-<%= word_wrap(_('Welcome to %{environment}! To activate your account, follow the link: %{activation_url}') % { :environment => @environment, :activation_url => @url + url_for(:controller => :account, :action => :activate, :activation_code => @activation_code, :redirection => @redirection, :join => @join) }) %>
+<%= word_wrap(_('Welcome to %{environment}! To activate your account, follow the link: %{activation_url}') % { :environment => @environment.name, :activation_url => @url + url_for(:controller => :account, :action => :activate, :activation_code => @activation_code, :redirection => @redirection, :join => @join) }) %>
 
 <%= _("Greetings,") %>
 
 --
-<%= _('%s team.') % @environment %>
+<%= _('%s team.') % @environment.name %>
 <%= url_for @url %>

=====================================
app/views/user_mailer/activation_email_notify.text.erb
=====================================
--- a/app/views/user_mailer/activation_email_notify.text.erb
+++ b/app/views/user_mailer/activation_email_notify.text.erb
@@ -8,5 +8,5 @@
 <%= _('Greetings,') %>
 
 --
-<%= _('%s team.') % @environment %>
+<%= _('%s team.') % @environment.name %>
 <%= @url %>

=====================================
app/views/user_mailer/profiles_suggestions_email.html.erb
=====================================
--- a/app/views/user_mailer/profiles_suggestions_email.html.erb
+++ b/app/views/user_mailer/profiles_suggestions_email.html.erb
@@ -29,5 +29,5 @@
 <%= _("Greetings,") %>
 
 --
-<%= _('%s team.') % @environment %>
+<%= _('%s team.') % @environment.name %>
 <%= @url %>

=====================================
lib/noosfero/mailer.rb
=====================================
--- /dev/null
+++ b/lib/noosfero/mailer.rb
@@ -0,0 +1,13 @@
+
+class Noosfero::Mailer < ActionMailer::Base
+
+  attr_accessor :environment
+
+  def default_url_options options = nil
+    options ||= {}
+    options[:host] = environment.default_hostname if environment
+    options
+  end
+
+end
+

=====================================
lib/noosfero/plugin/manager.rb
=====================================
--- a/lib/noosfero/plugin/manager.rb
+++ b/lib/noosfero/plugin/manager.rb
@@ -63,8 +63,7 @@ class Noosfero::Plugin::Manager
   def pipeline(event, *args)
     each do |plugin|
       # result_for can't be used here and default must be returned to keep args
-      result = plugin.send event, *args
-      result = result.kind_of?(Array) ? result : [result]
+      result = Array(plugin.send event, *args)
       raise ArgumentError, "Pipeline broken by #{plugin.class.name} on #{event} with #{result.length} arguments instead of #{args.length}." if result.length != args.length
       args = result
     end

=====================================
plugins/work_assignment/lib/work_assignment_plugin/email_contact.rb
=====================================
--- a/plugins/work_assignment/lib/work_assignment_plugin/email_contact.rb
+++ b/plugins/work_assignment/lib/work_assignment_plugin/email_contact.rb
@@ -28,9 +28,11 @@ class WorkAssignmentPlugin::EmailContact
     WorkAssignmentPlugin::EmailContact::EmailSender.notification(self).deliver
   end
 
-  class EmailSender < ActionMailer::Base
+  class EmailSender < Noosfero::Mailer
 
     def notification(email_contact)
+      self.environment = email_contact.sender.environment
+
       name = email_contact.sender.name
       email = email_contact.sender.email
       message = email_contact.message

=====================================
test/unit/organization_test.rb
=====================================
--- a/test/unit/organization_test.rb
+++ b/test/unit/organization_test.rb
@@ -130,7 +130,7 @@ class OrganizationTest < ActiveSupport::TestCase
 
   should 'list pending enterprise validations' do
     org = Organization.new
-    assert_kind_of ActiveRecord::Relation, org.pending_validations
+    assert org.pending_validations.empty?
   end
 
   should 'be able to find a pending validation by its code' do
@@ -148,7 +148,7 @@ class OrganizationTest < ActiveSupport::TestCase
 
   should 'be able to find already processed validations' do
     org = Organization.new
-    assert_kind_of ActiveRecord::Relation, org.processed_validations
+    assert org.processed_validations.empty?
   end
 
   should 'be able to find an already processed validation by its code' do
@@ -188,7 +188,7 @@ class OrganizationTest < ActiveSupport::TestCase
     org.foundation_year = 20.07
     org.valid?
     assert org.errors[:foundation_year.to_s].present?
-    
+
     org.foundation_year = 2007
     org.valid?
     assert ! org.errors[:foundation_year.to_s].present?
@@ -208,7 +208,7 @@ class OrganizationTest < ActiveSupport::TestCase
 
     assert o.members.include?(p), "Organization should add the new member"
   end
-  
+
   should 'allow to remove members' do
     c = fast_create(Organization)
     p = create_user('myothertestuser').person

=====================================
test/unit/person_test.rb
=====================================
--- a/test/unit/person_test.rb
+++ b/test/unit/person_test.rb
@@ -1346,14 +1346,12 @@ class PersonTest < ActiveSupport::TestCase
 
     abusers = Person.abusers
 
-    assert_equal ActiveRecord::Relation, abusers.class
     assert_includes abusers, abuser1
     assert_includes abusers, abuser2
     assert_not_includes abusers, person
 
     non_abusers = Person.non_abusers
 
-    assert_equal ActiveRecord::Relation, non_abusers.class
     assert_not_includes non_abusers, abuser1
     assert_not_includes non_abusers, abuser2
     assert_includes non_abusers, person

=====================================
test/unit/product_category_test.rb
=====================================
--- a/test/unit/product_category_test.rb
+++ b/test/unit/product_category_test.rb
@@ -53,7 +53,6 @@ class ProductCategoryTest < ActiveSupport::TestCase
 
     scope = ProductCategory.by_enterprise(enterprise)
 
-    assert_equal ActiveRecord::Relation, scope.class
     assert_equivalent [c1,c2], scope
   end
 

=====================================
vendor/plugins/access_control/lib/acts_as_accessible.rb
=====================================
--- a/vendor/plugins/access_control/lib/acts_as_accessible.rb
+++ b/vendor/plugins/access_control/lib/acts_as_accessible.rb
@@ -1,5 +1,5 @@
 module ActsAsAccessible
-  # This is the global hash of permissions and each item is of the form 
+  # This is the global hash of permissions and each item is of the form
   # 'class_name' => permission_hash for each target have its own set of permissions
   # but its not a namespace so each permission name should be unique
   PERMISSIONS = {}
@@ -20,17 +20,19 @@ module ActsAsAccessible
   end
 
   def affiliate(accessor, roles)
-    roles = [roles] unless roles.kind_of?(Array)
-    roles.map {|role| accessor.add_role(role, self)}.any? 
+    roles = Array(roles)
+    roles.map {|role| accessor.add_role(role, self)}.any?
   end
 
   def disaffiliate(accessor, roles)
-    roles = [roles] unless roles.kind_of?(Array)
-    role_assignments.map{|ra|ra.destroy if roles.include?(ra.role) && ra.accessor == accessor} 
+    roles = Array(roles)
+    role_assignments.map do |ra|
+      ra.destroy if roles.include?(ra.role) && ra.accessor == accessor
+    end
   end
 
   def roles
-    Role.find_all_by_environment_id(environment.id).select do |r| 
+    Role.find_all_by_environment_id(environment.id).select do |r|
       r.permissions.any?{ |p| PERMISSIONS[self.class.base_class.name].include?(p) }
     end
   end

=====================================
vendor/plugins/access_control/lib/acts_as_accessor.rb
=====================================
--- a/vendor/plugins/access_control/lib/acts_as_accessor.rb
+++ b/vendor/plugins/access_control/lib/acts_as_accessor.rb
@@ -14,7 +14,7 @@ module ActsAsAccessor
   end
 
   def define_roles(roles, resource)
-    roles = [roles] unless roles.kind_of?(Array)
+    roles = Array(roles)
     actual_roles = RoleAssignment.where(role_attributes nil, resource).map(&:role)
 
     (roles - actual_roles).each {|r| add_role(r, resource) }


View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/11b47ca741839507264b4d86228bb0e71ad151f5...adbf0c711768c3b7ab5400b7fa85af7c9a361bd8
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150405/f1780914/attachment-0001.html>


More information about the Noosfero-dev mailing list