Commit fe6897823ec70d42d6617e90bc69a58c98aa9302
1 parent
d7403b43
Exists in
master
and in
27 other branches
social-share: plugin configuration page
Creates configuration page for plugin. Environment admin can select networks which will have social buttons among those provided by Social Share Privacy. Selected network list is saved as environment setting. (ActionItem3238)
Showing
8 changed files
with
162 additions
and
0 deletions
Show diff stats
plugins/social_share_privacy/controllers/social_share_privacy_plugin_admin_controller.rb
0 → 100644
... | ... | @@ -0,0 +1,27 @@ |
1 | +class SocialSharePrivacyPluginAdminController < AdminController | |
2 | + append_view_path File.join(File.dirname(__FILE__) + '/../views') | |
3 | + | |
4 | + protect 'edit_environment_features', :environment | |
5 | + | |
6 | + include SocialSharePrivacyPluginHelper | |
7 | + | |
8 | + def index | |
9 | + @settings = Noosfero::Plugin::Settings.new(environment, SocialSharePrivacyPlugin, params[:settings]) | |
10 | + @settings.networks ||= [] | |
11 | + | |
12 | + @available_networks = social_share_privacy_networks.sort | |
13 | + @settings.networks &= @available_networks | |
14 | + @available_networks -= @settings.networks | |
15 | + | |
16 | + if request.post? | |
17 | + begin | |
18 | + @settings.save! | |
19 | + session[:notice] = _('Option updated successfully.') | |
20 | + rescue Exception => exception | |
21 | + session[:notice] = _('Option wasn\'t updated successfully.') | |
22 | + end | |
23 | + redirect_to :controller => 'plugins', :action => 'index' | |
24 | + end | |
25 | + end | |
26 | + | |
27 | +end | ... | ... |
plugins/social_share_privacy/lib/social_share_privacy_plugin.rb
plugins/social_share_privacy/lib/social_share_privacy_plugin_helper.rb
0 → 100644
plugins/social_share_privacy/test/functional/social_share_privacy_plugin_admin_controller_test.rb
0 → 100644
... | ... | @@ -0,0 +1,54 @@ |
1 | +require File.dirname(__FILE__) + '/../../../../test/test_helper' | |
2 | +require File.dirname(__FILE__) + '/../../controllers/social_share_privacy_plugin_admin_controller' | |
3 | + | |
4 | +# Re-raise errors caught by the controller. | |
5 | +class SocialSharePrivacyPluginAdminController; def rescue_action(e) raise e end; end | |
6 | + | |
7 | +class SocialSharePrivacyPluginAdminControllerTest < ActionController::TestCase | |
8 | + | |
9 | + def setup | |
10 | + @environment = Environment.default | |
11 | + @profile = create_user('profile').person | |
12 | + @environment.add_admin(@profile) | |
13 | + login_as(@profile.identifier) | |
14 | + end | |
15 | + | |
16 | + attr_reader :environment | |
17 | + | |
18 | + should 'list networks not selected available in alphabetic order' do | |
19 | + Noosfero::Plugin::Settings.new(environment, SocialSharePrivacyPlugin, :networks => ['gplus']).save! | |
20 | + @controller.stubs(:social_share_privacy_networks).returns(['gplus', 'twitter', 'facebook']) | |
21 | + get :index | |
22 | + assert_equal ['facebook', 'twitter'], assigns(:available_networks) | |
23 | + end | |
24 | + | |
25 | + should 'list networks selected in order' do | |
26 | + Noosfero::Plugin::Settings.new(environment, SocialSharePrivacyPlugin, :networks => ['gplus', 'buffer']).save! | |
27 | + get :index | |
28 | + assert_equal ['gplus', 'buffer'], assigns(:settings).networks | |
29 | + end | |
30 | + | |
31 | + should 'save social networks buttons settings' do | |
32 | + post :index, :settings => {:networks => ['facebook', 'gplus']} | |
33 | + @settings = Noosfero::Plugin::Settings.new(environment.reload, SocialSharePrivacyPlugin) | |
34 | + assert_equal ['facebook', 'gplus'], @settings.settings[:networks] | |
35 | + end | |
36 | + | |
37 | + should 'remove all buttons if none selected' do | |
38 | + Noosfero::Plugin::Settings.new(environment, SocialSharePrivacyPlugin, :networks => ['twitter', 'gplus', 'buffer']).save! | |
39 | + post :index, :settings => {:networks => ['']} | |
40 | + @settings = Noosfero::Plugin::Settings.new(environment.reload, SocialSharePrivacyPlugin) | |
41 | + assert_equal [], @settings.settings[:networks] | |
42 | + end | |
43 | + | |
44 | + should 'ignore unknown networks' do | |
45 | + post :index, :settings => {:networks => ['orkut']} | |
46 | + @settings = Noosfero::Plugin::Settings.new(environment.reload, SocialSharePrivacyPlugin) | |
47 | + assert_equal [], @settings.settings[:networks] | |
48 | + end | |
49 | + | |
50 | + should 'redirect to index after save' do | |
51 | + post :index | |
52 | + assert_redirected_to :controller => 'plugins', :action => 'index' | |
53 | + end | |
54 | +end | ... | ... |
plugins/social_share_privacy/test/unit/social_share_privacy_helper_test.rb
0 → 100644
... | ... | @@ -0,0 +1,11 @@ |
1 | +require File.dirname(__FILE__) + '/../../../../test/test_helper' | |
2 | + | |
3 | +class SocialSharePrivacyPluginHelperTest < ActiveSupport::TestCase | |
4 | + | |
5 | + include SocialSharePrivacyPluginHelper | |
6 | + | |
7 | + should 'list social networks provided' do | |
8 | + assert_equal ['buffer', 'facebook', 'gplus', 'mail', 'stumbleupon', 'xing', 'delicious', 'fbshare', 'hackernews', 'pinterest', 'tumblr', 'disqus', 'flattr', 'linkedin', 'reddit', 'twitter'].sort, social_share_privacy_networks.sort | |
9 | + end | |
10 | + | |
11 | +end | ... | ... |
plugins/social_share_privacy/test/unit/social_share_privacy_test.rb
... | ... | @@ -20,4 +20,9 @@ class SocialSharePrivacyPluginTest < ActiveSupport::TestCase |
20 | 20 | assert_equal "A plugin that adds share buttons from other networks.", SocialSharePrivacyPlugin.plugin_description |
21 | 21 | end |
22 | 22 | |
23 | + should 'have default value for networks setting' do | |
24 | + @settings = Noosfero::Plugin::Settings.new(Environment.default, SocialSharePrivacyPlugin) | |
25 | + assert_equal [], @settings.get_setting(:networks) | |
26 | + end | |
27 | + | |
23 | 28 | end | ... | ... |
plugins/social_share_privacy/views/social_share_privacy_plugin_admin/index.html.erb
0 → 100644
... | ... | @@ -0,0 +1,44 @@ |
1 | +<h1><%= _('Social Share Privacy Options')%></h1> | |
2 | + | |
3 | +<p><%= _('Choose the social networks you want to enable the share buttons.') %></p> | |
4 | + | |
5 | +<script type="text/javascript"> | |
6 | + jQuery(document).ready(function() { | |
7 | + jQuery('#add').click(function() { | |
8 | + return !jQuery('#social-networks-list option:selected').remove().appendTo('#selected-social-networks'); | |
9 | + }); | |
10 | + jQuery('#remove').click(function() { | |
11 | + return !jQuery('#selected-social-networks option:selected').remove().appendTo('#social-networks-list'); | |
12 | + }); | |
13 | + | |
14 | + jQuery('form').submit(function() { | |
15 | + jQuery('#selected-social-networks option').each(function(i) { | |
16 | + jQuery(this).attr('selected','selected'); | |
17 | + }); | |
18 | + }); | |
19 | + }); | |
20 | + </script> | |
21 | + | |
22 | +<div id='available-networks'> | |
23 | + <%= labelled_form_field(_('Available networks'), select_tag('networks[]', options_for_select(@available_networks), {:id => 'social-networks-list', :multiple => true, :size => 6 }) ) %> | |
24 | +</div> | |
25 | + | |
26 | +<div id='selection-buttons'> | |
27 | + <%= button :down, _('Add'), '#', { :id => 'add' } %> | |
28 | + <%= button :up, _('Remove'), '#', { :id => 'remove' } %> | |
29 | +</div> | |
30 | + | |
31 | +<%= form_tag do %> | |
32 | + <div id='selected-networks'> | |
33 | + <%= hidden_field_tag 'settings[networks][]' %> | |
34 | + <%= labelled_form_field(_('Selected networks'), select_tag('settings[networks]', options_for_select(@settings.networks), {:id => 'selected-social-networks', :multiple => true, :size => 6 })) %> | |
35 | + </div> | |
36 | + | |
37 | + <p> | |
38 | + <%= _('The same order in which you arrange the social networks here will be used for arranging the share buttons.') %> | |
39 | + </p> | |
40 | + | |
41 | + <% button_bar do %> | |
42 | + <%= submit_button 'save', _('Save'), :cancel => {:controller => 'plugins', :action => 'index'} %> | |
43 | + <% end %> | |
44 | +<% end %> | ... | ... |