diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index 2c1d447..6f196d6 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -86,8 +86,17 @@ class ProfileController < PublicController @articles = profile.top_level_articles.includes([:profile, :parent]) end + def join_modal + profile.add_member(user) + session[:notice] = _('%s administrator still needs to accept you as member.') % profile.name + redirect_to :action => :index + end + def join if !user.memberships.include?(profile) + return if profile.community? && profile.requires_email && + current_person && !current_person.public_fields.include?("email") + profile.add_member(user) if !profile.members.include?(user) render :text => {:message => _('%s administrator still needs to accept you as member.') % profile.name}.to_json diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 26b8a80..8108526 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -54,6 +54,8 @@ module ApplicationHelper include TaskHelper + include MembershipsHelper + def locale (@page && !@page.language.blank?) ? @page.language : FastGettext.locale end @@ -984,11 +986,11 @@ module ApplicationHelper def task_information(task) values = {} + values.merge!(task.information[:variables]) if task.information[:variables] values.merge!({:requestor => link_to(task.requestor.name, task.requestor.url)}) if task.requestor values.merge!({:subject => content_tag('span', task.subject, :class=>'task_target')}) if task.subject values.merge!({:linked_subject => link_to(content_tag('span', task.linked_subject[:text], :class => 'task_target'), task.linked_subject[:url])}) if task.linked_subject - values.merge!(task.information[:variables]) if task.information[:variables] - task.information[:message] % values + (task.information[:message] % values).html_safe end def add_zoom_to_article_images diff --git a/app/helpers/memberships_helper.rb b/app/helpers/memberships_helper.rb index eaf43c7..0d83749 100644 --- a/app/helpers/memberships_helper.rb +++ b/app/helpers/memberships_helper.rb @@ -1,2 +1,12 @@ module MembershipsHelper + + def join_community_button(logged) + url = logged ? profile.join_url : profile.join_not_logged_url + + if profile.requires_email? && current_person && !current_person.public_fields.include?("email") + modal_button :add, _('Join this community'), url, class: 'join-community' + else + button :add, _('Join this community'), url, class: 'join-community' + end + end end diff --git a/app/models/add_member.rb b/app/models/add_member.rb index 7414397..fbf0e3a 100644 --- a/app/models/add_member.rb +++ b/app/models/add_member.rb @@ -29,16 +29,18 @@ class AddMember < Task end def information - requestor_email = " (#{requestor.email})" if requestor.may_display_field_to?("email") - - {:message => _("%{requestor}%{requestor_email} wants to be a member of '%{organization}'."), - variables: {requestor: requestor.name, requestor_email: requestor_email, organization: organization.name}} + {:message => _("%{requestor} wants to be a member of '%{target}'."), + variables: {requestor: requestor.name, target: target.name}} end def accept_details true end + def footer + true + end + def icon {:type => :profile_image, :profile => requestor, :url => requestor.url} end diff --git a/app/models/community.rb b/app/models/community.rb index b4fb5cf..6c4499b 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -2,6 +2,7 @@ class Community < Organization attr_accessible :accessor_id, :accessor_type, :role_id, :resource_id, :resource_type attr_accessible :address_reference, :district, :tag_list, :language, :description + attr_accessible :requires_email after_destroy :check_invite_member_for_destroy def self.type_name @@ -12,6 +13,9 @@ class Community < Organization N_('Language') settings_items :language + settings_items :requires_email, :type => :boolean + + alias_method :requires_email?, :requires_email extend SetProfileRegionFromCityState::ClassMethods set_profile_region_from_city_state diff --git a/app/models/task.rb b/app/models/task.rb index 94bb267..308b37b 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -190,6 +190,10 @@ class Task < ApplicationRecord false end + def footer + false + end + def icon {:type => :defined_image, :src => "/images/icons-app/user-minor.png", :name => requestor.name, :url => requestor.url} end diff --git a/app/views/blocks/profile_info_actions/_join_leave_community.html.erb b/app/views/blocks/profile_info_actions/_join_leave_community.html.erb index b561ec6..6933e7b 100644 --- a/app/views/blocks/profile_info_actions/_join_leave_community.html.erb +++ b/app/views/blocks/profile_info_actions/_join_leave_community.html.erb @@ -7,15 +7,12 @@ <%= button :delete, content_tag('span', _('Leave community')), profile.leave_url, class: 'leave-community', style: 'position: relative;' %> - <%= button :add, content_tag('span', _('Join this community')), profile.join_url, - class: 'join-community', - style: 'position: relative; display: none;' %> <% else %> - <%= button :add, _('Join this community'), profile.join_url, class: 'join-community' %> + <%= join_community_button(true) %> <% end %> <% end %> <% else %> - <%= button :add, _('Join this community'), profile.join_not_logged_url %> + <%= join_community_button(false) %> <% end %> diff --git a/app/views/profile/join.html.erb b/app/views/profile/join.html.erb index 2527f70..34edecd 100644 --- a/app/views/profile/join.html.erb +++ b/app/views/profile/join.html.erb @@ -1,16 +1,16 @@ -

<%= _('Joining %s') % profile.name %>

+
-

-<%= _('Are you sure you want to join %s?') % profile.name %> -

+

<%= _('To join %s, you must:') % profile.name %>

-<%= form_tag do %> - <%= hidden_field_tag('back_to', @back_to) %> - <%= hidden_field_tag(:confirmation, 1) %> - <%= submit_button(:ok, _("Yes, I want to join.") % profile.name) %> - <% if logged_in? && request.xhr? %> - <%= modal_close_button _("No, I don't want") %> - <% else %> - <%= button(:cancel, _("No, I don't want."), profile.url) %> +

+ <%= _("Authorize the visibility of your email address to the community administrator.") %> +

+ + <%= form_tag url_for({:action => :join_modal, :controller => :profile}) do %> + <%= hidden_field_tag('back_to', @back_to) %> + <%= submit_button(:ok, _("Authorize")) %> + <%= modal_close_button _("Cancel") %> <% end %> -<% end %> + +
+ diff --git a/app/views/profile_editor/_moderation.html.erb b/app/views/profile_editor/_moderation.html.erb index 33f5e42..ac0da0e 100644 --- a/app/views/profile_editor/_moderation.html.erb +++ b/app/views/profile_editor/_moderation.html.erb @@ -9,7 +9,6 @@ <%= _('Send administrator Email for every task') %> -

<%= _('Invitation moderation:')%>

@@ -36,6 +35,12 @@
<%= _('Before joining this group (a moderator has to accept the member in pending request before member can access the intranet and/or the website).').html_safe %>
+
"> + <%= check_box(:profile_data, :requires_email, :style => 'float: left') %> +
+ <%= _('New members must allow email visibility to the profile admin') %> +
+
<%= radio_button 'profile_data', 'closed', 'false', :style => 'float: left' %> diff --git a/app/views/tasks/_add_member_footer.html.erb b/app/views/tasks/_add_member_footer.html.erb new file mode 100644 index 0000000..5fdcc88 --- /dev/null +++ b/app/views/tasks/_add_member_footer.html.erb @@ -0,0 +1,7 @@ +<% if (task.organization.requires_email || task.requestor.may_display_field_to?("email")) %> +
+ Email: + <%=task.requestor.email %> +
+<% end %> + diff --git a/app/views/tasks/_task.html.erb b/app/views/tasks/_task.html.erb index cc7b7f2..d66be0c 100644 --- a/app/views/tasks/_task.html.erb +++ b/app/views/tasks/_task.html.erb @@ -70,4 +70,10 @@ <% end %> <% end %> + <% if task.footer %> + + <% end %> +
diff --git a/public/designs/themes/base/style.scss b/public/designs/themes/base/style.scss index a6c5994..b02ff0d 100644 --- a/public/designs/themes/base/style.scss +++ b/public/designs/themes/base/style.scss @@ -1555,3 +1555,21 @@ table#recaptcha_table tr:hover td { clear: both; } + +/*************************** join community confirmation ********************************/ + +.join-community-confirmation h1 { + font-variant: small-caps; + font-size: 20px; + color: #555753; + text-align: left; +} + +.join-community-confirmation { + padding: 5px 20px 0px 20px; +} + +.join-community-confirmation input.button.with-text { + padding-right: 4px; +} + diff --git a/public/javascripts/add-and-join.js b/public/javascripts/add-and-join.js index 09c32c2..cbcd8c5 100644 --- a/public/javascripts/add-and-join.js +++ b/public/javascripts/add-and-join.js @@ -18,9 +18,11 @@ jQuery(function($) { }) $(".join-community").live('click', function(){ + $('#cboxClose').remove(); clicked = $(this); url = clicked.attr("href"); - loading_for_button(this); + if (!clicked.hasClass('modal-toggle')) + loading_for_button(this); $.post(url, function(data){ clicked.fadeOut(function(){ clicked.css("display","none"); diff --git a/public/javascripts/profile_editor.js b/public/javascripts/profile_editor.js index 18727ac..78c05b7 100644 --- a/public/javascripts/profile_editor.js +++ b/public/javascripts/profile_editor.js @@ -23,4 +23,14 @@ }); }); + + $("#profile_data_closed_false").click(function(){ + $("#requires_email_option").prop("checked",false); + $("#requires_email_option").hide(); + }); + + $("#profile_data_closed_true").click(function(){ + $("#requires_email_option").show(); + }); + })(jQuery); diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index 0bd8275..57da6e0 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -3,6 +3,8 @@ require 'profile_controller' class ProfileControllerTest < ActionController::TestCase + include MembershipsHelper + self.default_params = {profile: 'testuser'} def setup @profile = create_user('testuser').person @@ -384,6 +386,61 @@ class ProfileControllerTest < ActionController::TestCase assert_redirected_to :controller => 'account', :action => 'login' end + should 'show regular join button for person with public email' do + community = Community.create!(:name => 'my test community', :closed => true, :requires_email => true) + Person.any_instance.stubs(:public_fields).returns(["email"]) + login_as(@profile.identifier) + + get :index, :profile => community.identifier + assert_no_tag :tag => 'a', :attributes => { :class => /modal-toggle join-community/ } + end + + should 'show join modal for person with private email' do + community = Community.create!(:name => 'my test community', :closed => true, :requires_email => true) + Person.any_instance.stubs(:public_fields).returns([]) + login_as(@profile.identifier) + + get :index, :profile => community.identifier + assert_tag :tag => 'a', :attributes => { :class => /modal-toggle join-community/ } + end + + should 'show regular join button for community without email visibility requirement' do + community = Community.create!(:name => 'my test community', :closed => true, :requires_email => false) + Person.any_instance.stubs(:public_fields).returns([]) + login_as(@profile.identifier) + + get :index, :profile => community.identifier + assert_no_tag :tag => 'a', :attributes => { :class => /modal-toggle join-community/ } + end + + should 'show regular join button for community without email visibility requirement and person with public email' do + community = Community.create!(:name => 'my test community', :closed => true, :requires_email => false) + Person.any_instance.stubs(:public_fields).returns(['email']) + login_as(@profile.identifier) + + get :index, :profile => community.identifier + assert_no_tag :tag => 'a', :attributes => { :class => /modal-toggle join-community/ } + end + + should 'render join modal for community with email visibility requirement and person with private email' do + community = Community.create!(:name => 'my test community', :closed => true, :requires_email => true) + login_as @profile.identifier + post :join, :profile => community.identifier + assert_template "join" + end + + should 'create add member task from join-community modal' do + community = Community.create!(:name => 'my test community', :closed => true, :requires_email => true) + admin = create_user('community-admin').person + community.add_admin(admin) + + login_as @profile.identifier + assert_difference 'AddMember.count' do + post :join_modal, :profile => community.identifier + end + assert_redirected_to :action => 'index' + end + should 'actually leave profile' do community = fast_create(Community) admin = fast_create(Person) -- libgit2 0.21.2