[Git][noosfero/noosfero][master] 2 commits: Fixes community search when spreading w/ SubOrgPlugin
Rodrigo Souto
gitlab at mg.gitlab.com
Wed Apr 26 13:50:14 BRT 2017
Rodrigo Souto pushed to branch master at Noosfero / noosfero
Commits:
c571a634 by Gabriel Silva at 2017-04-24T17:33:04+00:00
Fixes community search when spreading w/ SubOrgPlugin
Signed-off-by: Gabriel Silva <gabriel93.silva at gmail.com>
- - - - -
9008a9aa by Rodrigo Souto at 2017-04-26T16:50:07+00:00
Merge branch 'fix_spread_search' into 'master'
Fixes community search when spreading content with SubOrgPlugin enabled
Closes #256
See merge request !1184
- - - - -
2 changed files:
- app/controllers/my_profile/cms_controller.rb
- + plugins/sub_organizations/test/functional/cms_controller_test.rb
Changes:
=====================================
app/controllers/my_profile/cms_controller.rb
=====================================
--- a/app/controllers/my_profile/cms_controller.rb
+++ b/app/controllers/my_profile/cms_controller.rb
@@ -253,8 +253,10 @@ class CmsController < MyProfileController
end
def search_communities_to_publish
- scope = user.memberships.distinct(false).group("profiles.id")
- render :text => find_by_contents(:profiles, environment, scope, params['q'], {:page => 1}, {:fields => ['name']})[:results].map {|community| {:id => community.id, :name => community.name} }.to_json
+ scope = user.memberships.distinct(false)
+ results = find_by_contents(:profiles, environment, scope, params['q'], {:page => 1}, {:fields => ['name']})[:results]
+ render :text => results.map {|community| {:id => community.id, :name => community.name} }
+ .uniq {|c| c[:id] }.to_json
end
def publish
=====================================
plugins/sub_organizations/test/functional/cms_controller_test.rb
=====================================
--- /dev/null
+++ b/plugins/sub_organizations/test/functional/cms_controller_test.rb
@@ -0,0 +1,24 @@
+require "test_helper"
+
+class CmsControllerTest < ActionController::TestCase
+
+ def setup
+ @env = Environment.default
+ @env.enable_plugin(SubOrganizationsPlugin)
+
+ @profile = create_user('profile').person
+ login_as(@profile.identifier)
+ end
+
+ should 'list and not duplicate sub organizations when spreading an article' do
+ c1 = fast_create(Community, :name => 'Testing community 1', :identifier => 'testcommunity1', :environment_id => @env)
+ c2 = fast_create(Community, :name => 'Testing community 2', :identifier => 'testcommunity2', :environment_id => @env)
+ SubOrganizationsPlugin::Relation.add_children(c1, c2)
+ c2.add_member @profile
+ c2.add_admin @profile
+
+ get :search_communities_to_publish, :profile => @profile.identifier, :q => 'Testing'
+ assert_equivalent [c1.id, c2.id], JSON.parse(@response.body).map{|c|c['id']}
+ end
+
+end
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/1edeaef80d31702bc25943d5ec91a26eeb25ac22...9008a9aae6c14c3db59f5d9b2b662e7a315939b1
---
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/1edeaef80d31702bc25943d5ec91a26eeb25ac22...9008a9aae6c14c3db59f5d9b2b662e7a315939b1
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170426/cb851582/attachment-0001.html>
More information about the Noosfero-dev
mailing list