Commit 596c614bd732bd8834370e684e5f8900185706bd

Authored by Marcos Pereira
1 parent a2a44fe0
Exists in stable-spb-1.5

Adds required email moderation option

- Confirmation modal when joining community
- Moderation option in community control panel

Signed-off-by: Alexandre Barbosa <alexandreab@live.com>
Signed-off-by: Alvaro Fernando <alvarofernandoms@gmail.com>
Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com>
Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com>
(cherry picked from commit 7949d4e822a87f1fef6fd229ba5bdf7b5233238c)
app/controllers/public/profile_controller.rb
... ... @@ -86,8 +86,17 @@ class ProfileController &lt; PublicController
86 86 @articles = profile.top_level_articles.includes([:profile, :parent])
87 87 end
88 88  
  89 + def join_modal
  90 + profile.add_member(user)
  91 + session[:notice] = _('%s administrator still needs to accept you as member.') % profile.name
  92 + redirect_to :action => :index
  93 + end
  94 +
89 95 def join
90 96 if !user.memberships.include?(profile)
  97 + return if profile.community? && profile.requires_email &&
  98 + current_person && !current_person.public_fields.include?("email")
  99 +
91 100 profile.add_member(user)
92 101 if !profile.members.include?(user)
93 102 render :text => {:message => _('%s administrator still needs to accept you as member.') % profile.name}.to_json
... ...
app/helpers/application_helper.rb
... ... @@ -54,6 +54,8 @@ module ApplicationHelper
54 54  
55 55 include ThemeLoaderHelper
56 56  
  57 + include MembershipsHelper
  58 +
57 59 def locale
58 60 (@page && !@page.language.blank?) ? @page.language : FastGettext.locale
59 61 end
... ... @@ -967,11 +969,11 @@ module ApplicationHelper
967 969  
968 970 def task_information(task)
969 971 values = {}
  972 + values.merge!(task.information[:variables]) if task.information[:variables]
970 973 values.merge!({:requestor => link_to(task.requestor.name, task.requestor.url)}) if task.requestor
971 974 values.merge!({:subject => content_tag('span', task.subject, :class=>'task_target')}) if task.subject
972 975 values.merge!({:linked_subject => link_to(content_tag('span', task.linked_subject[:text], :class => 'task_target'), task.linked_subject[:url])}) if task.linked_subject
973   - values.merge!(task.information[:variables]) if task.information[:variables]
974   - task.information[:message] % values
  976 + (task.information[:message] % values).html_safe
975 977 end
976 978  
977 979 def add_zoom_to_article_images
... ...
app/helpers/memberships_helper.rb
1 1 module MembershipsHelper
  2 +
  3 + def join_community_button(logged)
  4 + url = logged ? profile.join_url : profile.join_not_logged_url
  5 +
  6 + if profile.requires_email? && current_person && !current_person.public_fields.include?("email")
  7 + modal_button :add, _('Join this community'), url, class: 'join-community'
  8 + else
  9 + button :add, _('Join this community'), url, class: 'join-community'
  10 + end
  11 + end
2 12 end
... ...
app/models/add_member.rb
... ... @@ -29,16 +29,18 @@ class AddMember &lt; Task
29 29 end
30 30  
31 31 def information
32   - requestor_email = " (#{requestor.email})" if requestor.may_display_field_to?("email")
33   -
34   - {:message => _("%{requestor}%{requestor_email} wants to be a member of '%{organization}'."),
35   - variables: {requestor: requestor.name, requestor_email: requestor_email, organization: organization.name}}
  32 + {:message => _("%{requestor} wants to be a member of '%{target}'."),
  33 + variables: {requestor: requestor.name, target: target.name}}
36 34 end
37 35  
38 36 def accept_details
39 37 true
40 38 end
41 39  
  40 + def footer
  41 + true
  42 + end
  43 +
42 44 def icon
43 45 {:type => :profile_image, :profile => requestor, :url => requestor.url}
44 46 end
... ...
app/models/community.rb
... ... @@ -2,6 +2,7 @@ class Community &lt; Organization
2 2  
3 3 attr_accessible :accessor_id, :accessor_type, :role_id, :resource_id, :resource_type
4 4 attr_accessible :address_reference, :district, :tag_list, :language, :description
  5 + attr_accessible :requires_email
5 6 after_destroy :check_invite_member_for_destroy
6 7  
7 8 def self.type_name
... ... @@ -12,6 +13,9 @@ class Community &lt; Organization
12 13 N_('Language')
13 14  
14 15 settings_items :language
  16 + settings_items :requires_email, :type => :boolean
  17 +
  18 + alias_method :requires_email?, :requires_email
15 19  
16 20 extend SetProfileRegionFromCityState::ClassMethods
17 21 set_profile_region_from_city_state
... ...
app/models/task.rb
... ... @@ -186,6 +186,10 @@ class Task &lt; ActiveRecord::Base
186 186 false
187 187 end
188 188  
  189 + def footer
  190 + false
  191 + end
  192 +
189 193 def icon
190 194 {:type => :defined_image, :src => "/images/icons-app/user-minor.png", :name => requestor.name, :url => requestor.url}
191 195 end
... ...
app/views/blocks/profile_info_actions/_join_leave_community.html.erb
... ... @@ -7,15 +7,12 @@
7 7 <%= button :delete, content_tag('span', _('Leave community')), profile.leave_url,
8 8 class: 'leave-community',
9 9 style: 'position: relative;' %>
10   - <%= button :add, content_tag('span', _('Join this community')), profile.join_url,
11   - class: 'join-community',
12   - style: 'position: relative; display: none;' %>
13 10 <% else %>
14   - <%= button :add, _('Join this community'), profile.join_url, class: 'join-community' %>
  11 + <%= join_community_button(true) %>
15 12 <% end %>
16 13 <% end %>
17 14 <% else %>
18   - <%= button :add, _('Join this community'), profile.join_not_logged_url %>
  15 + <%= join_community_button(false) %>
19 16 <% end %>
20 17 </div>
21 18  
... ...
app/views/profile/join.html.erb
1   -<h1><%= _('Joining %s') % profile.name %></h1>
  1 +<div class="join-community-confirmation">
2 2  
3   -<p>
4   -<%= _('Are you sure you want to join %s?') % profile.name %>
5   -</p>
  3 + <h1><%= _('To join %s, you must:') % profile.name %></h1>
6 4  
7   -<%= form_tag do %>
8   - <%= hidden_field_tag('back_to', @back_to) %>
9   - <%= hidden_field_tag(:confirmation, 1) %>
10   - <%= submit_button(:ok, _("Yes, I want to join.") % profile.name) %>
11   - <% if logged_in? && request.xhr? %>
12   - <%= modal_close_button _("No, I don't want") %>
13   - <% else %>
14   - <%= button(:cancel, _("No, I don't want."), profile.url) %>
  5 + <p>
  6 + <%= _("Authorize the visibility of your email address to the community administrator.") %>
  7 + </p>
  8 +
  9 + <%= form_tag url_for({:action => :join_modal, :controller => :profile}) do %>
  10 + <%= hidden_field_tag('back_to', @back_to) %>
  11 + <%= submit_button(:ok, _("Authorize")) %>
  12 + <%= modal_close_button _("Cancel") %>
15 13 <% end %>
16   -<% end %>
  14 +
  15 +</div>
  16 +
... ...
app/views/profile_editor/_moderation.html.erb
... ... @@ -9,7 +9,6 @@
9 9 <%= _('Send administrator Email for every task') %>
10 10 </div>
11 11 </div>
12   -
13 12 <div style='margin-bottom: 1em'>
14 13 <h4><%= _('Invitation moderation:')%></h4>
15 14 </div>
... ... @@ -36,6 +35,12 @@
36 35 <div style='margin-left: 30px'>
37 36 <%= _('<strong>Before</strong> joining this group (a moderator has to accept the member in pending request before member can access the intranet and/or the website).') %>
38 37 </div>
  38 + <div id = "requires_email_option" style="margin-left: 30px; margin-top: 10px; margin-bottom: 15px;<%=" display: none;" unless profile.closed? %>">
  39 + <%= check_box(:profile_data, :requires_email, :style => 'float: left') %>
  40 + <div style='margin-left: 30px'>
  41 + <%= _('New members must allow email visibility to the profile admin') %>
  42 + </div>
  43 + </div>
39 44 </div>
40 45 <div>
41 46 <%= radio_button 'profile_data', 'closed', 'false', :style => 'float: left' %>
... ...
app/views/tasks/_add_member_footer.html.erb 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +<% if (task.organization.requires_email || task.requestor.may_display_field_to?("email")) %>
  2 + <div>
  3 + Email:
  4 + <span id="task_email"> <%=task.requestor.email %> </span>
  5 + </div>
  6 +<% end %>
  7 +
... ...
app/views/tasks/_task.html.erb
... ... @@ -70,4 +70,10 @@
70 70 <% end %>
71 71 <% end %>
72 72  
  73 + <% if task.footer %>
  74 + <div id="task-footer-<%=task.id%>">
  75 + <%= render :partial => partial_for_class(task.class, nil, :footer), :locals => {:task => task} %>
  76 + </div>
  77 + <% end %>
  78 +
73 79 </div><!-- class="task_box" -->
... ...
public/designs/themes/base/style.scss
... ... @@ -1555,3 +1555,21 @@ table#recaptcha_table tr:hover td {
1555 1555 clear: both;
1556 1556 }
1557 1557  
  1558 +
  1559 +/*************************** join community confirmation ********************************/
  1560 +
  1561 +.join-community-confirmation h1 {
  1562 + font-variant: small-caps;
  1563 + font-size: 20px;
  1564 + color: #555753;
  1565 + text-align: left;
  1566 +}
  1567 +
  1568 +.join-community-confirmation {
  1569 + padding: 5px 20px 0px 20px;
  1570 +}
  1571 +
  1572 +.join-community-confirmation input.button.with-text {
  1573 + padding-right: 4px;
  1574 +}
  1575 +
... ...
public/javascripts/add-and-join.js
... ... @@ -18,9 +18,11 @@ jQuery(function($) {
18 18 })
19 19  
20 20 $(".join-community").live('click', function(){
  21 + $('#cboxClose').remove();
21 22 clicked = $(this);
22 23 url = clicked.attr("href");
23   - loading_for_button(this);
  24 + if (!clicked.hasClass('modal-toggle'))
  25 + loading_for_button(this);
24 26 $.post(url, function(data){
25 27 clicked.fadeOut(function(){
26 28 clicked.css("display","none");
... ...
public/javascripts/profile_editor.js
... ... @@ -23,4 +23,14 @@
23 23 });
24 24  
25 25 });
  26 +
  27 + $("#profile_data_closed_false").click(function(){
  28 + $("#requires_email_option").prop("checked",false);
  29 + $("#requires_email_option").hide();
  30 + });
  31 +
  32 + $("#profile_data_closed_true").click(function(){
  33 + $("#requires_email_option").show();
  34 + });
  35 +
26 36 })(jQuery);
... ...
test/functional/profile_controller_test.rb
... ... @@ -3,6 +3,8 @@ require &#39;profile_controller&#39;
3 3  
4 4 class ProfileControllerTest < ActionController::TestCase
5 5  
  6 + include MembershipsHelper
  7 +
6 8 self.default_params = {profile: 'testuser'}
7 9 def setup
8 10 Environment.default.enable('products_for_enterprises')
... ... @@ -408,6 +410,61 @@ class ProfileControllerTest &lt; ActionController::TestCase
408 410 assert_redirected_to :controller => 'account', :action => 'login'
409 411 end
410 412  
  413 + should 'show regular join button for person with public email' do
  414 + community = Community.create!(:name => 'my test community', :closed => true, :requires_email => true)
  415 + Person.any_instance.stubs(:public_fields).returns(["email"])
  416 + login_as(@profile.identifier)
  417 +
  418 + get :index, :profile => community.identifier
  419 + assert_no_tag :tag => 'a', :attributes => { :class => /modal-toggle join-community/ }
  420 + end
  421 +
  422 + should 'show join modal for person with private email' do
  423 + community = Community.create!(:name => 'my test community', :closed => true, :requires_email => true)
  424 + Person.any_instance.stubs(:public_fields).returns([])
  425 + login_as(@profile.identifier)
  426 +
  427 + get :index, :profile => community.identifier
  428 + assert_tag :tag => 'a', :attributes => { :class => /modal-toggle join-community/ }
  429 + end
  430 +
  431 + should 'show regular join button for community without email visibility requirement' do
  432 + community = Community.create!(:name => 'my test community', :closed => true, :requires_email => false)
  433 + Person.any_instance.stubs(:public_fields).returns([])
  434 + login_as(@profile.identifier)
  435 +
  436 + get :index, :profile => community.identifier
  437 + assert_no_tag :tag => 'a', :attributes => { :class => /modal-toggle join-community/ }
  438 + end
  439 +
  440 + should 'show regular join button for community without email visibility requirement and person with public email' do
  441 + community = Community.create!(:name => 'my test community', :closed => true, :requires_email => false)
  442 + Person.any_instance.stubs(:public_fields).returns(['email'])
  443 + login_as(@profile.identifier)
  444 +
  445 + get :index, :profile => community.identifier
  446 + assert_no_tag :tag => 'a', :attributes => { :class => /modal-toggle join-community/ }
  447 + end
  448 +
  449 + should 'render join modal for community with email visibility requirement and person with private email' do
  450 + community = Community.create!(:name => 'my test community', :closed => true, :requires_email => true)
  451 + login_as @profile.identifier
  452 + post :join, :profile => community.identifier
  453 + assert_template "join"
  454 + end
  455 +
  456 + should 'create add member task from join-community modal' do
  457 + community = Community.create!(:name => 'my test community', :closed => true, :requires_email => true)
  458 + admin = create_user('community-admin').person
  459 + community.add_admin(admin)
  460 +
  461 + login_as @profile.identifier
  462 + assert_difference 'AddMember.count' do
  463 + post :join_modal, :profile => community.identifier
  464 + end
  465 + assert_redirected_to :action => 'index'
  466 + end
  467 +
411 468 should 'actually leave profile' do
412 469 community = fast_create(Community)
413 470 admin = fast_create(Person)
... ...