Commit a729e69f15d0b96786e30182c5ef97b86a0cbf68

Authored by Larissa Reis
1 parent 99f5d74c

newsletter: Also search blogs by people's and enterprises' names

Now user can search for a blog either by its name or the name of the
profile the blog belongs to, instead of just the blog's or community's
name.
plugins/newsletter/controllers/newsletter_plugin_admin_controller.rb
@@ -30,14 +30,14 @@ class NewsletterPluginAdminController < PluginAdminController @@ -30,14 +30,14 @@ class NewsletterPluginAdminController < PluginAdminController
30 end 30 end
31 31
32 #TODO: Make this query faster 32 #TODO: Make this query faster
33 - def search_communities  
34 - communities = environment.communities 33 + def search_profiles
  34 + profiles = environment.profiles
35 blogs = Blog.joins(:profile).where(profiles: {environment_id: environment.id}) 35 blogs = Blog.joins(:profile).where(profiles: {environment_id: environment.id})
36 36
37 - found_communities = find_by_contents(:communities, environment, communities, params['q'], {:page => 1})[:results] 37 + found_profiles = find_by_contents(:profiles, environment, profiles, params['q'], {:page => 1})[:results]
38 found_blogs = find_by_contents(:blogs, environment, blogs, params['q'], {:page => 1})[:results] 38 found_blogs = find_by_contents(:blogs, environment, blogs, params['q'], {:page => 1})[:results]
39 39
40 - results = (found_blogs + found_communities.map(&:blogs).flatten).uniq 40 + results = (found_blogs + found_profiles.map(&:blogs).flatten).uniq
41 render :text => results.map { |blog| {:id => blog.id, :name => _("%s in %s") % [blog.name, blog.profile.name]} }.to_json 41 render :text => results.map { |blog| {:id => blog.id, :name => _("%s in %s") % [blog.name, blog.profile.name]} }.to_json
42 end 42 end
43 43
plugins/newsletter/features/newsletter_plugin.feature
1 Feature: newsletter plugin 1 Feature: newsletter plugin
2 2
3 Background: 3 Background:
4 - Given the following users  
5 - | login | name |  
6 - | joaosilva | Joao Silva |  
7 - And I am logged in as "joaosilva" 4 + Given I am logged in as admin
8 5
9 Scenario: as admin I can configure plugin 6 Scenario: as admin I can configure plugin
10 - Given I am logged in as admin  
11 When I go to the environment control panel 7 When I go to the environment control panel
12 And I follow "Plugins" 8 And I follow "Plugins"
13 Then I should see "Configuration" linking to "/admin/plugin/newsletter" 9 Then I should see "Configuration" linking to "/admin/plugin/newsletter"
14 10
15 Scenario: in the newsletter settings I can see the field to enable/disable 11 Scenario: in the newsletter settings I can see the field to enable/disable
16 - Given I am logged in as admin  
17 When I go to the environment control panel 12 When I go to the environment control panel
18 And I follow "Plugins" 13 And I follow "Plugins"
19 And I follow "Configuration" 14 And I follow "Configuration"
20 Then I should see "Enable send of newsletter to members on this environment" 15 Then I should see "Enable send of newsletter to members on this environment"
21 16
22 Scenario: redirect to newsletter visualization after save and visualize 17 Scenario: redirect to newsletter visualization after save and visualize
23 - Given I am logged in as admin  
24 - And "NewsletterPlugin" plugin is enabled 18 + Given "NewsletterPlugin" plugin is enabled
25 When I go to the environment control panel 19 When I go to the environment control panel
26 And I follow "Plugins" 20 And I follow "Plugins"
27 And I follow "Configuration" 21 And I follow "Configuration"
@@ -30,11 +24,58 @@ Feature: newsletter plugin @@ -30,11 +24,58 @@ Feature: newsletter plugin
30 And I should not see "Newsletter settings" 24 And I should not see "Newsletter settings"
31 25
32 Scenario: stay on newsletter settings page after save 26 Scenario: stay on newsletter settings page after save
33 - Given I am logged in as admin  
34 - And "NewsletterPlugin" plugin is enabled 27 + Given "NewsletterPlugin" plugin is enabled
35 When I go to the environment control panel 28 When I go to the environment control panel
36 And I follow "Plugins" 29 And I follow "Plugins"
37 And I follow "Configuration" 30 And I follow "Configuration"
38 And I press "Save" 31 And I press "Save"
39 Then I should see "Newsletter settings" 32 Then I should see "Newsletter settings"
40 And I should not see "If you can't view this email, click here" 33 And I should not see "If you can't view this email, click here"
  34 +
  35 + @selenium
  36 + Scenario: search community and select blog for newsletter
  37 + Given the following communities
  38 + | identifier | name |
  39 + | sample-community | Sample Community |
  40 + And the following blogs
  41 + | owner | name |
  42 + | sample-community | Sample Blog |
  43 + And "NewsletterPlugin" plugin is enabled
  44 + When I go to the environment control panel
  45 + And I follow "Plugins"
  46 + And I follow "Configuration"
  47 + And I type in "Sample Community" into autocomplete list "search-profiles" and I choose "Sample Blog in Sample Community"
  48 + And I press "Save"
  49 + Then I should see "Sample Blog in Sample Community"
  50 +
  51 + @selenium
  52 + Scenario: search profile and select blog for newsletter
  53 + Given the following users
  54 + | login | name |
  55 + | joaosilva | Joao Silva |
  56 + And the following blogs
  57 + | owner | name |
  58 + | joaosilva | Joao Blog |
  59 + And "NewsletterPlugin" plugin is enabled
  60 + When I go to the environment control panel
  61 + And I follow "Plugins"
  62 + And I follow "Configuration"
  63 + And I type in "Silva" into autocomplete list "search-profiles" and I choose "Joao Blog in Joao Silva"
  64 + And I press "Save"
  65 + Then I should see "Joao Blog in Joao Silva"
  66 +
  67 + @selenium
  68 + Scenario: search blog and select it for newsletter
  69 + Given the following communities
  70 + | identifier | name |
  71 + | sample-community | Sample Community |
  72 + And the following blogs
  73 + | owner | name |
  74 + | sample-community | Sample Blog |
  75 + And "NewsletterPlugin" plugin is enabled
  76 + When I go to the environment control panel
  77 + And I follow "Plugins"
  78 + And I follow "Configuration"
  79 + And I type in "Sample Blog" into autocomplete list "search-profiles" and I choose "Sample Blog in Sample Community"
  80 + And I press "Save"
  81 + Then I should see "Sample Blog in Sample Community"
plugins/newsletter/views/newsletter_plugin_admin/index.html.erb
@@ -29,11 +29,11 @@ @@ -29,11 +29,11 @@
29 %> 29 %>
30 30
31 <p><%= _('Blogs from which news will be compiled') %></p> 31 <p><%= _('Blogs from which news will be compiled') %></p>
32 - <% search_action = url_for(:action => 'search_communities') %> 32 + <% search_action = url_for(:action => 'search_profiles') %>
33 <% selected_blogs = @blogs.map { |blog| {:id => blog.id, :name => _("%s in %s") % [blog.name, blog.profile.name]} } %> 33 <% selected_blogs = @blogs.map { |blog| {:id => blog.id, :name => _("%s in %s") % [blog.name, blog.profile.name]} } %>
34 <%= token_input_field_tag( 34 <%= token_input_field_tag(
35 - 'newsletter[blog_ids]', 'search-communities', search_action,  
36 - { hint_text: _('Type in the communities\' or blogs\' names'), 35 + 'newsletter[blog_ids]', 'search-profiles', search_action,
  36 + { hint_text: _('Type in the profiles\' or blogs\' names'),
37 focus: false, pre_populate: selected_blogs }) %> 37 focus: false, pre_populate: selected_blogs }) %>
38 38
39 <br/> 39 <br/>