diff --git a/app/controllers/my_profile/memberships_controller.rb b/app/controllers/my_profile/memberships_controller.rb index 56263b1..c97ab08 100644 --- a/app/controllers/my_profile/memberships_controller.rb +++ b/app/controllers/my_profile/memberships_controller.rb @@ -25,4 +25,19 @@ class MembershipsController < MyProfileController return end end + + def suggest + @suggestions = profile.suggested_communities.paginate(:per_page => 8, :page => params[:npage]) + end + + def remove_suggestion + @community = profile.suggested_communities.find_by_identifier(params[:id]) + redirect_to :action => 'suggest' unless @community + if @community && request.post? + suggestion = profile.profile_suggestions.find_by_suggestion_id @community.id + suggestion.disable + redirect_to :action => 'suggest' + end + end + end diff --git a/app/views/memberships/index.html.erb b/app/views/memberships/index.html.erb index e54862f..eeff0b5 100644 --- a/app/views/memberships/index.html.erb +++ b/app/views/memberships/index.html.erb @@ -16,6 +16,8 @@ <%= labelled_select(_('Filter')+': ', :filter_type, :first, :last, @filter, type_collection, :id => 'memberships_filter')%>

+

<%= link_to _('See some suggestions of communities...'), :action => 'suggest' %>

+ <% if @memberships.empty? %>

<%= _('No groups to list') %> diff --git a/app/views/memberships/remove_suggestion.html.erb b/app/views/memberships/remove_suggestion.html.erb new file mode 100644 index 0000000..de5e7d2 --- /dev/null +++ b/app/views/memberships/remove_suggestion.html.erb @@ -0,0 +1,5 @@ +

+

<%= _('Removing suggestion for community: %s') % @community.name %>

+ + <%= render :partial => 'shared/remove_suggestion', :locals => { :suggestion => @community } %> +
diff --git a/app/views/memberships/suggest.html.erb b/app/views/memberships/suggest.html.erb new file mode 100644 index 0000000..ace7597 --- /dev/null +++ b/app/views/memberships/suggest.html.erb @@ -0,0 +1,40 @@ +
+

<%= _("Communities suggestions for %s") % profile.name %>

+ + <% button_bar do %> + <%= button(:back, _('Go to groups list'), :controller => 'memberships') %> + <% end %> + + <% if @suggestions.empty? %> +

+ + <%= _('You have no suggestions yet.') %> + <%= link_to _('Do you want to see communities in this environment?'), :controller => 'search', :action => 'assets', :asset => 'communities' %> + +

+ <% else %> + + <% end %> + + <%= pagination_links @suggestions, :param_name => 'npage' %> +
+
diff --git a/public/javascripts/add-and-join.js b/public/javascripts/add-and-join.js index 551ec8d..470fd2d 100644 --- a/public/javascripts/add-and-join.js +++ b/public/javascripts/add-and-join.js @@ -12,7 +12,7 @@ jQuery(function($) { }) $(".join-community").live('click', function(){ - clicked = $(".join-community"); + clicked = $(this); url = clicked.attr("href"); loading_for_button(this); $.post(url, function(data){ diff --git a/test/functional/memberships_controller_test.rb b/test/functional/memberships_controller_test.rb index dbaa697..bd8bc43 100644 --- a/test/functional/memberships_controller_test.rb +++ b/test/functional/memberships_controller_test.rb @@ -327,4 +327,42 @@ class MembershipsControllerTest < ActionController::TestCase assert_includes assigns(:roles), role1 assert_not_includes assigns(:roles), role2 end + + should 'display list suggestions button' do + community = fast_create(Community) + profile.profile_suggestions.create(:suggestion => community) + get :index, :profile => 'testuser' + assert_tag :tag => 'a', :content => 'See some suggestions of communities...', :attributes => { :href => "/myprofile/testuser/memberships/suggest" } + end + + should 'display communities suggestions' do + community = fast_create(Community) + profile.profile_suggestions.create(:suggestion => community) + get :suggest, :profile => 'testuser' + assert_tag :tag => 'a', :content => community.name, :attributes => { :href => "/profile/#{community.identifier}" } + end + + should 'display button to join on community suggestion' do + community = fast_create(Community) + profile.profile_suggestions.create(:suggestion => community) + get :suggest, :profile => 'testuser' + assert_tag :tag => 'a', :attributes => { :href => "/profile/#{community.identifier}/join" } + end + + should 'display button to remove community suggestion' do + community = fast_create(Community) + profile.profile_suggestions.create(:suggestion => community) + get :suggest, :profile => 'testuser' + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testuser/memberships/remove_suggestion/#{community.identifier}" } + end + + should 'remove suggestion of community' do + community = fast_create(Community) + suggestion = profile.profile_suggestions.create(:suggestion => community) + post :remove_suggestion, :profile => 'testuser', :id => community.identifier + + assert_redirected_to :action => 'suggest' + assert_equal false, ProfileSuggestion.find(suggestion.id).enabled + end + end -- libgit2 0.21.2