diff --git a/app/controllers/my_profile/memberships_controller.rb b/app/controllers/my_profile/memberships_controller.rb index 74daf44..b7fb269 100644 --- a/app/controllers/my_profile/memberships_controller.rb +++ b/app/controllers/my_profile/memberships_controller.rb @@ -6,15 +6,6 @@ class MembershipsController < MyProfileController @memberships = profile.memberships end - def join - @to_join = Profile.find(params[:id]) - if request.post? && params[:confirmation] - @to_join.add_member(profile) - flash[:notice] = _('%s administrator still needs to accept you as member.') % @to_join.name if @to_join.closed? - redirect_to @to_join.url - end - end - def leave @to_leave = Profile.find(params[:id]) diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index 1893333..44c5ca8 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -2,6 +2,7 @@ class ProfileController < PublicController needs_profile before_filter :check_access_to_profile + before_filter :login_required, :only => [:join, :refuse_join] helper TagsHelper @@ -42,6 +43,21 @@ class ProfileController < PublicController @articles = profile.top_level_articles end + def join + if request.post? && params[:confirmation] + profile.add_member(current_user.person) + flash[:notice] = _('%s administrator still needs to accept you as member.') % profile.name if profile.closed? + redirect_to profile.url + end + end + + def refuse_join + p = current_user.person + p.refused_communities << profile + p.save + redirect_to profile.url + end + protected def check_access_to_profile diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2617ad9..d43eb14 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -761,4 +761,11 @@ module ApplicationHelper end end + def ask_to_join? + return if environment.enabled?(:disable_join_community_popup) + return unless profile && profile.kind_of?(Community) + return true unless logged_in? + user.ask_to_join?(profile) + end + end diff --git a/app/models/environment.rb b/app/models/environment.rb index 601fe7e..f63abc1 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -37,6 +37,7 @@ class Environment < ActiveRecord::Base 'disable_select_city_for_contact' => _('Disable state/city select for contact form'), 'disable_contact_person' => _('Disable contact for people'), 'disable_contact_community' => _('Disable contact for groups/communities'), + 'disable_join_community_popup' => _('Disable the popup that ask to join a group/community'), } end diff --git a/app/models/person.rb b/app/models/person.rb index 693e818..9c3890c 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -219,4 +219,15 @@ class Person < Profile self.friends.include?(person) end + has_and_belongs_to_many :refused_communities, :class_name => 'Community', :join_table => 'refused_join_community' + + def ask_to_join?(community) + return false if memberships.include?(community) + !refused_communities.include?(community) + end + + def refuse_join(community) + refused_communities << community + end + end diff --git a/app/views/blocks/profile_info_actions/community.rhtml b/app/views/blocks/profile_info_actions/community.rhtml index 422ea07..b4be4b2 100644 --- a/app/views/blocks/profile_info_actions/community.rhtml +++ b/app/views/blocks/profile_info_actions/community.rhtml @@ -7,7 +7,7 @@ <% else %>