[Git][noosfero/noosfero][master] person: fix by_role and members_of scopes
Rodrigo Souto
gitlab at mg.gitlab.com
Mon Mar 7 16:26:29 BRT 2016
Rodrigo Souto pushed to branch master at Noosfero / noosfero
Commits:
95cc44e0 by Rodrigo Souto at 2016-03-07T13:17:22-03:00
person: fix by_role and members_of scopes
Also define all roles as default set for profile_members_controller.
- - - - -
2 changed files:
- app/controllers/my_profile/profile_members_controller.rb
- app/models/person.rb
Changes:
=====================================
app/controllers/my_profile/profile_members_controller.rb
=====================================
--- a/app/controllers/my_profile/profile_members_controller.rb
+++ b/app/controllers/my_profile/profile_members_controller.rb
@@ -3,14 +3,15 @@ class ProfileMembersController < MyProfileController
def index
@filters = params[:filters] || {:roles => []}
- @filters[:roles] = [] unless @filters[:roles]
+ all_roles = Profile::Roles.organization_member_roles(environment.id) | Profile::Roles.organization_custom_roles(environment.id, profile.id)
+ @filters[:roles] = all_roles unless @filters[:roles].present?
@data = {}
field = 'name'
field = 'email' if @filters[:name] =~ /\@/
@data[:members] = profile.members_by(field, at filters[:name]).by_role(@filters[:roles])
session[:members_filtered] = @data[:members].map{|m|m.id} if request.post?
- @data[:roles] = Profile::Roles.organization_member_roles(environment.id) | Profile::Roles.organization_custom_roles(environment.id, profile.id)
+ @data[:roles] = all_roles
end
=====================================
app/models/person.rb
=====================================
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -22,7 +22,7 @@ class Person < Profile
joins << :user if User.attribute_names.include? field
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(joins).where([conditions])
+ distinct.select('profiles.*').joins(joins).where([conditions])
}
scope :not_members_of, -> resources {
@@ -52,15 +52,6 @@ class Person < Profile
( ( friendships.person_id = ? ) OR (profiles.public_profile = ?)) AND (profiles.visible = ?) )', 'environment_administrator', Profile.name, person.id, person.id, true, true]
).uniq
}
- scope :by_role, lambda { |roles|
-
- roles = [roles] unless roles.kind_of?(Array)
-
- if roles.length > 0
- {:select => 'DISTINCT profiles.*', :joins => :role_assignments, :conditions => ['role_assignments.role_id IN (?)', roles] }
- end
- }
-
def has_permission_with_admin?(permission, resource)
return true if resource.blank? || resource.admins.include?(self)
View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/95cc44e0e00a6fd77f3f8c1e3c919c7256491d4b
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160307/cddb7c09/attachment-0001.html>
More information about the Noosfero-dev
mailing list