[noosfero/noosfero][master] 7 commits: Infra to display login popup when not logged users click in a link

Leandro Nunes gitlab at gitlab.com
Tue May 12 17:51:31 BRT 2015


Leandro Nunes pushed to branch master at Noosfero / noosfero


Commits:
af08948e by Victor Costa at 2015-05-12T17:19:26Z
Infra to display login popup when not logged users click in a link

- - - - -
f4818bdb by Victor Costa at 2015-05-12T17:19:26Z
require_auth_to_comment: option to display login popup when click in post comment button

- - - - -
663d9abc by Victor Costa at 2015-05-12T17:19:26Z
vote_plugin: display login popup when click on like/dislike

- - - - -
1a6baee6 by Victor Costa at 2015-05-12T17:19:26Z
Infra to display login popup when not logged users click in a link

- - - - -
8e131944 by Leandro Nunes dos Santos at 2015-05-12T17:19:26Z
adding require-login-popup for actions that must be logged in to work

- - - - -
33b629d3 by Leandro Nunes dos Santos at 2015-05-12T17:19:27Z
unit tests: display_login_popup? and stylesheet?

- - - - -
6e1949cf by Leandro Nunes at 2015-05-12T20:51:22Z
Merge branch 'login_popup' into 'master'

Display login popup to non logged users in actions that require login

 Create infrastructure to display login popup to non logged users in actions that require login
This infra was applied for join community, make a vote and create comment when require auth to comment plugin is activated

See merge request !572

- - - - -


11 changed files:

- app/views/blocks/profile_info_actions/_join_leave_community.html.erb
- lib/authenticated_system.rb
- + plugins/require_auth_to_comment/controllers/require_auth_to_comment_plugin_admin_controller.rb
- plugins/require_auth_to_comment/lib/require_auth_to_comment_plugin.rb
- + plugins/require_auth_to_comment/public/comment_require_login.js
- plugins/require_auth_to_comment/test/unit/require_auth_to_comment_plugin_test.rb
- + plugins/require_auth_to_comment/views/require_auth_to_comment_plugin_admin/index.html.erb
- plugins/vote/public/style.css
- plugins/vote/views/vote/_vote.html.erb
- public/javascripts/application.js
- + public/javascripts/require_login.js


Changes:

=====================================
app/views/blocks/profile_info_actions/_join_leave_community.html.erb
=====================================
--- a/app/views/blocks/profile_info_actions/_join_leave_community.html.erb
+++ b/app/views/blocks/profile_info_actions/_join_leave_community.html.erb
@@ -1,4 +1,4 @@
-<div class='join-leave-button'>
+<div class='join-leave-button require-login-popup'>
   <% if logged_in? %>
     <% if profile.members.include?(user) %>
       <%= button(:delete, content_tag('span', _('Leave community')), profile.leave_url,


=====================================
lib/authenticated_system.rb
=====================================
--- a/lib/authenticated_system.rb
+++ b/lib/authenticated_system.rb
@@ -60,7 +60,11 @@ module AuthenticatedSystem
       if logged_in? && authorized?
         true
       else
-        access_denied
+        if params[:require_login_popup]
+          render :json => { :require_login_popup => true }
+        else
+          access_denied
+        end
       end
     end
 


=====================================
plugins/require_auth_to_comment/controllers/require_auth_to_comment_plugin_admin_controller.rb
=====================================
--- /dev/null
+++ b/plugins/require_auth_to_comment/controllers/require_auth_to_comment_plugin_admin_controller.rb
@@ -0,0 +1,14 @@
+class RequireAuthToCommentPluginAdminController < AdminController
+
+  def index
+    settings = params[:settings]
+    settings ||= {}
+    @settings = Noosfero::Plugin::Settings.new(environment, RequireAuthToCommentPlugin, settings)
+    if request.post?
+      @settings.save!
+      session[:notice] = 'Settings succefully saved.'
+      redirect_to :action => 'index'
+    end
+  end
+
+end


=====================================
plugins/require_auth_to_comment/lib/require_auth_to_comment_plugin.rb
=====================================
--- a/plugins/require_auth_to_comment/lib/require_auth_to_comment_plugin.rb
+++ b/plugins/require_auth_to_comment/lib/require_auth_to_comment_plugin.rb
@@ -21,11 +21,20 @@ class RequireAuthToCommentPlugin < Noosfero::Plugin
   end
 
   def stylesheet?
-    true
+    !display_login_popup?
+  end
+
+  def display_login_popup?
+    settings = Noosfero::Plugin::Settings.new(context.environment, self.class)
+    settings.require_type == 'display_login_popup'
+  end
+
+  def self.require_type_default_setting
+    'hide_button'
   end
 
   def js_files
-    ['hide_comment_form.js', 'jquery.livequery.min.js']
+    ['hide_comment_form.js', 'jquery.livequery.min.js'] + (display_login_popup? ? ['comment_require_login.js'] : [])
   end
 
   def body_beginning


=====================================
plugins/require_auth_to_comment/public/comment_require_login.js
=====================================
--- /dev/null
+++ b/plugins/require_auth_to_comment/public/comment_require_login.js
@@ -0,0 +1,8 @@
+(function($) {
+  $(window).bind('userDataLoaded', function(event, data) {
+    if (!data.login && $('meta[name="profile.allow_unauthenticated_comments"]').length <= 0) {
+      $('.display-comment-form').unbind();
+      $('.display-comment-form').addClass('require-login-popup');
+    }
+  });
+})(jQuery);


=====================================
plugins/require_auth_to_comment/test/unit/require_auth_to_comment_plugin_test.rb
=====================================
--- a/plugins/require_auth_to_comment/test/unit/require_auth_to_comment_plugin_test.rb
+++ b/plugins/require_auth_to_comment/test/unit/require_auth_to_comment_plugin_test.rb
@@ -5,9 +5,10 @@ class RequireAuthToCommentPluginTest < ActiveSupport::TestCase
   def setup
     @plugin = RequireAuthToCommentPlugin.new
     @comment = Comment.new
+    @environment = fast_create(Environment)
   end
 
-  attr_reader :plugin, :comment
+  attr_reader :plugin, :comment, :environment
 
   should 'reject comments for unauthenticated users' do
     plugin.context = logged_in(false)
@@ -29,6 +30,35 @@ class RequireAuthToCommentPluginTest < ActiveSupport::TestCase
     assert !comment.rejected?
   end
 
+  should 'the default require type setting be hide_button' do
+    assert_equal 'hide_button', plugin.class.require_type_default_setting
+  end
+
+  should 'display_login_popup? be false by default' do
+    context = mock();
+    context.expects(:environment).returns(environment)
+    plugin.expects(:context).returns(context)
+    assert !plugin.display_login_popup?
+  end
+
+  should 'display_login_popup? be true if require_type is defined as display_login_popup' do
+    context = mock();
+    context.expects(:environment).returns(environment)
+    environment[:settings] = {:require_auth_to_comment_plugin => {:require_type => "display_login_popup"}}
+    plugin.expects(:context).returns(context)
+    assert plugin.display_login_popup?
+  end
+
+  should 'not display stylesheet if login popup is active' do
+    plugin.expects(:display_login_popup?).returns(true)
+    assert !plugin.stylesheet?
+  end
+
+  should 'display stylesheet if login popup is inactive' do
+    plugin.expects(:display_login_popup?).returns(false)
+    assert plugin.stylesheet?
+  end
+
   protected
 
   def logged_in(boolean)


=====================================
plugins/require_auth_to_comment/views/require_auth_to_comment_plugin_admin/index.html.erb
=====================================
--- /dev/null
+++ b/plugins/require_auth_to_comment/views/require_auth_to_comment_plugin_admin/index.html.erb
@@ -0,0 +1,20 @@
+<h1><%= _('Require auth to comment Settings')%></h1>
+
+<%= form_for(:settings) do |f| %>
+
+  <div class="require-type">
+    <strong>
+      <div class="hide-button">
+        <%= radio_button(:settings, :require_type, 'hide_button') %> <%= _('Hide button') %>
+      </div>
+      <div class="display-login-popup">
+        <%= radio_button(:settings, :require_type, 'display_login_popup') %> <%= _('Display login popup') %>
+      </div>
+    </strong>
+  </div>
+
+  <% button_bar do %>
+    <%= submit_button(:save, _('Save'), :cancel => {:controller => 'plugins', :action => 'index'}) %>
+  <% end %>
+
+<% end %>


=====================================
plugins/vote/public/style.css
=====================================
--- a/plugins/vote/public/style.css
+++ b/plugins/vote/public/style.css
@@ -1,5 +1,4 @@
 .vote-actions {
-  position: absolute;
   top: 40px;
   right: 0px;
 }


=====================================
plugins/vote/views/vote/_vote.html.erb
=====================================
--- a/plugins/vote/views/vote/_vote.html.erb
+++ b/plugins/vote/views/vote/_vote.html.erb
@@ -5,7 +5,7 @@ reload_url = url_for(:controller => 'vote_plugin_profile', :profile => profile.i
 
 <span id="vote_<%= model %>_<%= target.id %>_<%= vote %>" data-reload_url=<%= reload_url %> class="vote-action action <%= action %>-action">
 
-  <%= link_to_remote content_tag(:span, count, :class=>'like-action-counter') + content_tag(:span, '', :class=>"action-icon #{action}"), :url => url, :html => {:class => "#{active ? 'like-action-active':''} #{user ? '':'disabled'}"} %>
+  <%= link_to content_tag(:span, count, :class=>'like-action-counter') + content_tag(:span, '', :class=>"action-icon #{action}"), url, :class => "#{active ? 'like-action-active':''} #{user ? '':'disabled'} require-login-popup" %>
 
   <% if !voters.blank? %>
     <span class="vote-detail">


=====================================
public/javascripts/application.js
=====================================
--- a/public/javascripts/application.js
+++ b/public/javascripts/application.js
@@ -27,6 +27,7 @@
 *= require manage-products.js
 *= require catalog.js
 *= require autogrow.js
+*= require require_login.js
 */
 
 // scope for noosfero stuff


=====================================
public/javascripts/require_login.js
=====================================
--- /dev/null
+++ b/public/javascripts/require_login.js
@@ -0,0 +1,25 @@
+(function($) {
+  $(window).bind('userDataLoaded', function(event, data) {
+    $(".require-login-popup").live('click', function(){
+      clicked = $(this);
+      url = clicked.attr("href");
+      if(url!=undefined && url!='' && url!='#') {
+        if(!data.login) {
+          url = $.param.querystring(url, "require_login_popup=true");
+        }
+        loading_for_button(this);
+        $.post(url, function(data){
+          if(data.require_login_popup) {
+            $('#link_login').click(); //TODO see a better way to show login popup
+          }
+        }).complete(function() {
+          clicked.css("cursor","");
+          $(".small-loading").remove();
+        });
+      } else {
+        $('#link_login').click();
+      }
+      return false;
+    });
+  });
+})(jQuery);



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/8e2f02dc74988c3611e17fded12feb452e5da2be...6e1949cf56bcd21d97924be81ce51257ee9f9dc3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150512/d4243872/attachment-0001.html>


More information about the Noosfero-dev mailing list