blob: e44ab6add0bcf6f25661888cfbea7256d764f013 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# Copyright (C) 2017 Heiko Bernloehr (FreeIT.de).
#
# This file is part of ECS.
#
# ECS is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# ECS is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public
# License along with ECS. If not, see <http://www.gnu.org/licenses/>.
class Admin::CommunitiesController < ApplicationController
include Admin::Helper
# TODO verify http methods
def index
list
render :action => 'list'
end
def list
@communities=Community.all.distinct
end
def show
@community = Community.find(params[:id])
end
def new
@community = Community.new
end
def create
@community = Community.new(community_params)
if @community.save
flash[:notice] = 'Community was successfully created.'
redirect_to admin_community_path(@community)
else
render :action => 'new'
end
end
def edit
@community = Community.find(params[:id])
end
def update
@community = Community.find(params[:id])
if @community.update_attributes(community_params)
flash[:notice] = 'Community was successfully updated.'
redirect_to admin_community_path(@community)
else
render :action => 'edit'
end
end
def destroy
Community.find(params[:id]).destroy
redirect_to admin_communities_path
end
# lists all participants of the community
def index_participants
@community = Community.find(params[:id])
@participants=Community.find(params[:id]).memberships.collect {|i| i.participant }.distinct.sort{|x,y| x.id <=> y.id }
end
# lists all those participants which has not joined the community
def index_nonparticipants
index_participants
@participants=(Participant.all - @participants).sort{|x,y| x.id <=> y.id }
end
# community releases a participant
def destroy_participant
destroy_membership(params[:id], params[:p_id])
redirect_to admin_community_participants_path(:id=>params[:id])
end
# community invites a participant
def create_participant
create_membership(params[:id], params[:p_id])
redirect_to index_admin_community_nonparticipants_path(:id=>params[:id])
end
private
def community_params
params.require(:community).permit(:name, :description)
end
end
|