Commit c6d40a343813401f1e3f9a43a6036adb1a5db747
1 parent
9b404dbe
Exists in
master
and in
20 other branches
rails4: Array is not used for AR results
Showing
4 changed files
with
13 additions
and
11 deletions
Show diff stats
app/models/person.rb
... | ... | @@ -17,19 +17,19 @@ class Person < Profile |
17 | 17 | acts_as_accessor |
18 | 18 | |
19 | 19 | scope :members_of, -> (resources) { |
20 | - resources = [resources] if !resources.kind_of?(Array) | |
20 | + resources = Array(resources) | |
21 | 21 | conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ') |
22 | 22 | select('DISTINCT profiles.*').joins(:role_assignments).where([conditions]) |
23 | 23 | } |
24 | 24 | |
25 | 25 | scope :not_members_of, -> (resources) { |
26 | - resources = [resources] if !resources.kind_of?(Array) | |
26 | + resources = Array(resources) | |
27 | 27 | conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ') |
28 | 28 | 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) |
29 | 29 | } |
30 | 30 | |
31 | 31 | scope :by_role, -> (roles) { |
32 | - roles = [roles] unless roles.kind_of?(Array) | |
32 | + roles = Array(roles) | |
33 | 33 | select('DISTINCT profiles.*').joins(:role_assignments).where('role_assignments.role_id IN (?)', roles) |
34 | 34 | } |
35 | 35 | ... | ... |
lib/noosfero/plugin/manager.rb
... | ... | @@ -57,7 +57,7 @@ class Noosfero::Plugin::Manager |
57 | 57 | |
58 | 58 | def pipeline(event, *args) |
59 | 59 | each do |plugin| |
60 | - result = plugin.send(event, *args) | |
60 | + result = Array(plugin.send event, *args) | |
61 | 61 | result = result.kind_of?(Array) ? result : [result] |
62 | 62 | raise ArgumentError, "Pipeline broken by #{plugin.class.name} on #{event} with #{result.length} arguments instead of #{args.length}." if result.length != args.length |
63 | 63 | args = result | ... | ... |
vendor/plugins/access_control/lib/acts_as_accessible.rb
1 | 1 | module ActsAsAccessible |
2 | - # This is the global hash of permissions and each item is of the form | |
2 | + # This is the global hash of permissions and each item is of the form | |
3 | 3 | # 'class_name' => permission_hash for each target have its own set of permissions |
4 | 4 | # but its not a namespace so each permission name should be unique |
5 | 5 | PERMISSIONS = {} |
... | ... | @@ -20,17 +20,19 @@ module ActsAsAccessible |
20 | 20 | end |
21 | 21 | |
22 | 22 | def affiliate(accessor, roles) |
23 | - roles = [roles] unless roles.kind_of?(Array) | |
24 | - roles.map {|role| accessor.add_role(role, self)}.any? | |
23 | + roles = Array(roles) | |
24 | + roles.map {|role| accessor.add_role(role, self)}.any? | |
25 | 25 | end |
26 | 26 | |
27 | 27 | def disaffiliate(accessor, roles) |
28 | - roles = [roles] unless roles.kind_of?(Array) | |
29 | - role_assignments.map{|ra|ra.destroy if roles.include?(ra.role) && ra.accessor == accessor} | |
28 | + roles = Array(roles) | |
29 | + role_assignments.map do |ra| | |
30 | + ra.destroy if roles.include?(ra.role) && ra.accessor == accessor | |
31 | + end | |
30 | 32 | end |
31 | 33 | |
32 | 34 | def roles |
33 | - Role.find_all_by_environment_id(environment.id).select do |r| | |
35 | + Role.find_all_by_environment_id(environment.id).select do |r| | |
34 | 36 | r.permissions.any?{ |p| PERMISSIONS[self.class.base_class.name].include?(p) } |
35 | 37 | end |
36 | 38 | end | ... | ... |
vendor/plugins/access_control/lib/acts_as_accessor.rb
... | ... | @@ -14,7 +14,7 @@ module ActsAsAccessor |
14 | 14 | end |
15 | 15 | |
16 | 16 | def define_roles(roles, resource) |
17 | - roles = [roles] unless roles.kind_of?(Array) | |
17 | + roles = Array(roles) | |
18 | 18 | actual_roles = RoleAssignment.where(role_attributes nil, resource).map(&:role) |
19 | 19 | |
20 | 20 | (roles - actual_roles).each {|r| add_role(r, resource) } | ... | ... |