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 @@ -
-<%= _('Are you sure you want to join %s?') % profile.name %> -
++ <%= _("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 %> + +