1 # Copyright (C) 2017 Heiko Bernloehr (FreeIT.de).
3 # This file is part of ECS.
5 # ECS is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Affero General Public License as
7 # published by the Free Software Foundation, either version 3 of
8 # the License, or (at your option) any later version.
10 # ECS is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Affero General Public License for more details.
15 # You should have received a copy of the GNU Affero General Public
16 # License along with ECS. If not, see <http://www.gnu.org/licenses/>.
19 class Admin::CommunitiesController < ApplicationController
23 # TODO verify http methods
27 render :action => 'list'
31 if ECS_CONFIG["participants"]["allow_anonymous"]
32 @communities=Community.all.distinct
34 @communities=Community.all.where.not(name: "public").distinct
39 @community = Community.find(params[:id])
43 @community = Community.new
47 @community = Community.new(community_params)
49 flash[:notice] = 'Community was successfully created.'
50 redirect_to admin_community_path(@community)
52 render :action => 'new'
57 @community = Community.find(params[:id])
61 @community = Community.find(params[:id])
62 if @community.update(community_params)
63 flash[:notice] = 'Community was successfully updated.'
64 redirect_to admin_community_path(@community)
66 render :action => 'edit'
71 Community.find(params[:id]).destroy
72 redirect_to admin_communities_path
75 # lists all participants of the community
76 def index_participants
77 @community = Community.find(params[:id])
78 @participants=Community.find(params[:id]).memberships.collect {|i| i.participant }.distinct.sort{|x,y| x.id <=> y.id }
81 # lists all those participants which has not joined the community
82 def index_nonparticipants
84 @participants=(Participant.all - @participants).sort{|x,y| x.id <=> y.id }
87 # community releases a participant
88 def destroy_participant
89 destroy_membership(params[:id], params[:p_id])
90 redirect_to admin_community_participants_path(:id=>params[:id])
93 # community invites a participant
94 def create_participant
95 create_membership(params[:id], params[:p_id])
96 redirect_to index_admin_community_nonparticipants_path(:id=>params[:id])
102 params.require(:community).permit(:name, :description)