[Git][noosfero/noosfero][master] 2 commits: refactoring visible for person query
Leandro Nunes
gitlab at mg.gitlab.com
Tue Aug 2 10:05:44 BRT 2016
Leandro Nunes pushed to branch master at Noosfero / noosfero
Commits:
957db004 by Leandro Nunes dos Santos at 2016-08-02T09:08:12-03:00
refactoring visible for person query
- - - - -
b904d553 by Leandro Nunes at 2016-08-02T13:05:22+00:00
Merge branch 'refatoring_visible_for_person' into 'master'
refactoring visible for person query
transform visible_for_person in named scope and make some changes on generated query
See merge request !995
- - - - -
1 changed file:
- app/models/organization.rb
Changes:
=====================================
app/models/organization.rb
=====================================
--- a/app/models/organization.rb
+++ b/app/models/organization.rb
@@ -20,33 +20,28 @@ class Organization < Profile
# visible.
# 4) The user is not a member of the organization but the organization is
# visible, public and enabled.
- def self.listed_for_person(person)
+ scope :listed_for_person, lambda { |person|
+
joins('LEFT JOIN "role_assignments" ON ("role_assignments"."resource_id" = "profiles"."id"
AND "role_assignments"."resource_type" = \'Profile\') OR (
"role_assignments"."resource_id" = "profiles"."environment_id" AND
"role_assignments"."resource_type" = \'Environment\' )')
.joins('LEFT JOIN "roles" ON "role_assignments"."role_id" = "roles"."id"')
.where(
- ['( (roles.key = ? OR roles.key = ?) AND role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? )
- OR
- ( ( ( role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR
- ( profiles.enabled = ? ) ) AND
- ( profiles.visible = ? ) )',
- 'profile_admin', 'environment_administrator', Profile.name, person.id,
- Profile.name, person.id, true, true]
- ).uniq
- end
-
- def self.visible_for_person(person)
- listed_for_person(person).where(
- ['( (roles.key = ? OR roles.key = ?) AND role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? )
- OR
+ ['( (roles.key = ? OR roles.key = ?) AND role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR (
+ ( ( role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR ( profiles.enabled = ?)) AND (profiles.visible = ?) )',
+ 'profile_admin', 'environment_administrator', Profile.name, person.id, Profile.name, person.id, true, true]
+ ).uniq
+ }
+
+ scope :visible_for_person, lambda { |person|
+ listed_for_person(person).where( ['
( ( role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR
- ( profiles.enabled = ? AND profiles.public_profile = ? ) )',
- 'profile_admin', 'environment_administrator', Profile.name, person.id,
+ ( profiles.enabled = ? AND profiles.public_profile = ? ) )',
Profile.name, person.id, true, true]
)
- end
+ }
+
settings_items :closed, :type => :boolean, :default => false
def closed?
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/a3fb62836b7b2f5b69f1ef80bde8f53c00ab736f...b904d5530f1893028541fe0202eb30f083816918
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160802/490dbb6c/attachment-0001.html>
More information about the Noosfero-dev
mailing list