[Git][noosfero/noosfero][master] 5 commits: Prevents spreading posts into its own profile
Gabriel Silva
gitlab at mg.gitlab.com
Mon Jul 2 14:25:30 BRT 2018
Gabriel Silva pushed to branch master at Noosfero / noosfero
Commits:
b21c2469 by Matheus Richard at 2018-06-28T18:05:52Z
Prevents spreading posts into its own profile
- - - - -
714ed711 by Matheus Richard at 2018-06-28T18:46:24Z
Filters LinkArticles on environment recent_documents
- - - - -
744a1d00 by Matheus Richard at 2018-06-29T01:38:49Z
Adds tests to cms controller
- - - - -
ae9d72e8 by Matheus Richard at 2018-06-29T17:19:28Z
Adds unit test to environment
- - - - -
c2181a00 by Gabriel Silva at 2018-07-02T17:25:25Z
Merge branch 'fixes-recent-documents-block' into 'master'
Fixes recent documents block
See merge request noosfero/noosfero!1560
- - - - -
4 changed files:
- app/controllers/my_profile/cms_controller.rb
- app/models/environment.rb
- plugins/pg_search/test/functional/cms_controller_test.rb
- test/unit/environment_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
@@ -259,8 +259,9 @@ class CmsController < MyProfileController
end
def search_communities_to_publish
- scope = user.memberships.distinct(false)
+ scope = user.memberships.distinct(false).where.not(id: profile)
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
=====================================
app/models/environment.rb
=====================================
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -783,7 +783,7 @@ class Environment < ApplicationRecord
has_many :articles, :through => :profiles
def recent_documents(limit = 10, options = {}, pagination = true)
- self.articles.recent(limit, options, pagination)
+ self.articles.where.not(type: 'LinkArticle').recent(limit, options, pagination)
end
has_many :events, :through => :profiles, :source => :articles, :class_name => 'Event'
=====================================
plugins/pg_search/test/functional/cms_controller_test.rb
=====================================
--- a/plugins/pg_search/test/functional/cms_controller_test.rb
+++ b/plugins/pg_search/test/functional/cms_controller_test.rb
@@ -5,22 +5,22 @@ class CmsControllerTest < ActionController::TestCase
def setup
@environment = Environment.default
@environment.enable_plugin('PgSearchPlugin')
+
+ @profile = create_user('profile').person
+ login_as(@profile.identifier)
+
+ @c1 = fast_create(Community, :name => 'Testing community 1', :identifier => 'testcommunity1', :environment_id => environment.id)
+ @c1.add_member @profile
+ @c2 = fast_create(Community, :name => 'Testing community 2', :identifier => 'testcommunity2', :environment_id => environment.id)
+ @c2.add_member @profile
+ @c2.add_admin @profile
end
attr_accessor :environment
should 'list communities available to spread' do
- profile = create_user('profile').person
- login_as(profile.identifier)
-
- c1 = fast_create(Community, :name => 'Testing community 1', :identifier => 'testcommunity1', :environment_id => environment.id)
- c1.add_member profile
- c2 = fast_create(Community, :name => 'Testing community 2', :identifier => 'testcommunity2', :environment_id => environment.id)
- c2.add_member profile
- c2.add_admin profile
-
assert_nothing_raised do
- get :search_communities_to_publish, :profile => profile.identifier, :q => 'Testing'
+ get :search_communities_to_publish, :profile => @profile.identifier, :q => 'Testing'
end
assert_match /Testing community 1/, @response.body
@@ -28,17 +28,17 @@ class CmsControllerTest < ActionController::TestCase
end
should 'not duplicated a community in list of communities available to spread' do
- profile = create_user('profile').person
- login_as(profile.identifier)
+ 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
- c1 = fast_create(Community, :name => 'Testing community 1', :identifier => 'testcommunity1', :environment_id => environment)
- c1.add_member profile
- c2 = fast_create(Community, :name => 'Testing community 2', :identifier => 'testcommunity2', :environment_id => environment)
- c2.add_member profile
- c2.add_admin profile
+ should 'not list the article community in list of communities available to spread' do
+ assert_nothing_raised do
+ get :search_communities_to_publish, :profile => @c1.identifier, :q => 'Testing'
+ end
- get :search_communities_to_publish, :profile => profile.identifier, :q => 'Testing'
- assert_equivalent [c1.id, c2.id], JSON.parse(@response.body).map{|c|c['id']}
+ assert_no_match /Testing community 1/, @response.body
+ assert_match /Testing community 2/, @response.body
end
end
=====================================
test/unit/environment_test.rb
=====================================
--- a/test/unit/environment_test.rb
+++ b/test/unit/environment_test.rb
@@ -335,6 +335,28 @@ class EnvironmentTest < ActiveSupport::TestCase
end
+ should 'not include link articles on recent_documents' do
+ environment = fast_create(Environment)
+
+ p1 = fast_create(Profile, environment_id: environment.id)
+ p2 = fast_create(Profile, environment_id: environment.id)
+
+ Article.destroy_all
+
+ doc1 = fast_create(Article, profile_id: p1.id)
+ doc2 = fast_create(Article, profile_id: p2.id)
+ link = LinkArticle.create!(
+ reference_article: doc1, profile: p2
+ )
+
+ all_recent = environment.recent_documents
+ [doc1, doc2].each do |item|
+ assert_includes all_recent, item
+ end
+
+ assert_not_includes all_recent, link
+ end
+
should 'have a description attribute' do
env = Environment.new
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/cdad36e5a4b6f24182549c60f3526a04004c2c3a...c2181a001dbab1bb1e14dc09b3afa1753470c028
--
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/cdad36e5a4b6f24182549c60f3526a04004c2c3a...c2181a001dbab1bb1e14dc09b3afa1753470c028
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/20180702/d41660cc/attachment-0001.html>
More information about the Noosfero-dev
mailing list