[Git][noosfero/noosfero][stable-1.7] Merge branch 'fix_spread_search' into 'master'

Rodrigo Souto gitlab at mg.gitlab.com
Wed Apr 26 13:50:40 BRT 2017


Rodrigo Souto pushed to branch stable-1.7 at Noosfero / noosfero


Commits:
28431359 by Rodrigo Souto at 2017-04-26T16:50:32+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
@@ -258,8 +258,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/commit/284313595335940e6d67ada7b6e95d5dee8ace5f

---
View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/284313595335940e6d67ada7b6e95d5dee8ace5f
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/1130ed4b/attachment-0001.html>


More information about the Noosfero-dev mailing list