To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / controllers / groups_controller.rb @ 1298:4f746d8966dd

History | View | Annotate | Download (3.62 KB)

1 0:513646585e45 Chris
# Redmine - project management software
2 1295:622f24f53b42 Chris
# Copyright (C) 2006-2013  Jean-Philippe Lang
3 0:513646585e45 Chris
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8 909:cbb26bc654de Chris
#
9 0:513646585e45 Chris
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13 909:cbb26bc654de Chris
#
14 0:513646585e45 Chris
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
18
class GroupsController < ApplicationController
19
  layout 'admin'
20 909:cbb26bc654de Chris
21 0:513646585e45 Chris
  before_filter :require_admin
22 1115:433d4f72a19b Chris
  before_filter :find_group, :except => [:index, :new, :create]
23
  accept_api_auth :index, :show, :create, :update, :destroy, :add_users, :remove_user
24 909:cbb26bc654de Chris
25 0:513646585e45 Chris
  helper :custom_fields
26 909:cbb26bc654de Chris
27 0:513646585e45 Chris
  def index
28 1115:433d4f72a19b Chris
    @groups = Group.sorted.all
29 0:513646585e45 Chris
30
    respond_to do |format|
31 1115:433d4f72a19b Chris
      format.html
32
      format.api
33 0:513646585e45 Chris
    end
34
  end
35
36
  def show
37
    respond_to do |format|
38 1115:433d4f72a19b Chris
      format.html
39
      format.api
40 0:513646585e45 Chris
    end
41
  end
42
43
  def new
44
    @group = Group.new
45
  end
46
47
  def create
48 1115:433d4f72a19b Chris
    @group = Group.new
49
    @group.safe_attributes = params[:group]
50 0:513646585e45 Chris
51
    respond_to do |format|
52
      if @group.save
53 909:cbb26bc654de Chris
        format.html {
54
          flash[:notice] = l(:notice_successful_create)
55
          redirect_to(params[:continue] ? new_group_path : groups_path)
56
        }
57 1115:433d4f72a19b Chris
        format.api  { render :action => 'show', :status => :created, :location => group_url(@group) }
58 0:513646585e45 Chris
      else
59
        format.html { render :action => "new" }
60 1115:433d4f72a19b Chris
        format.api  { render_validation_errors(@group) }
61 0:513646585e45 Chris
      end
62
    end
63
  end
64
65 1115:433d4f72a19b Chris
  def edit
66
  end
67
68 0:513646585e45 Chris
  def update
69 1115:433d4f72a19b Chris
    @group.safe_attributes = params[:group]
70 0:513646585e45 Chris
71
    respond_to do |format|
72 1115:433d4f72a19b Chris
      if @group.save
73 0:513646585e45 Chris
        flash[:notice] = l(:notice_successful_update)
74
        format.html { redirect_to(groups_path) }
75 1115:433d4f72a19b Chris
        format.api  { render_api_ok }
76 0:513646585e45 Chris
      else
77
        format.html { render :action => "edit" }
78 1115:433d4f72a19b Chris
        format.api  { render_validation_errors(@group) }
79 0:513646585e45 Chris
      end
80
    end
81
  end
82
83
  def destroy
84
    @group.destroy
85
86
    respond_to do |format|
87 1295:622f24f53b42 Chris
      format.html { redirect_to(groups_path) }
88 1115:433d4f72a19b Chris
      format.api  { render_api_ok }
89 0:513646585e45 Chris
    end
90
  end
91 909:cbb26bc654de Chris
92 0:513646585e45 Chris
  def add_users
93 1115:433d4f72a19b Chris
    @users = User.find_all_by_id(params[:user_id] || params[:user_ids])
94
    @group.users << @users if request.post?
95 0:513646585e45 Chris
    respond_to do |format|
96 1295:622f24f53b42 Chris
      format.html { redirect_to edit_group_path(@group, :tab => 'users') }
97 1115:433d4f72a19b Chris
      format.js
98
      format.api { render_api_ok }
99 0:513646585e45 Chris
    end
100
  end
101 909:cbb26bc654de Chris
102 0:513646585e45 Chris
  def remove_user
103 909:cbb26bc654de Chris
    @group.users.delete(User.find(params[:user_id])) if request.delete?
104 0:513646585e45 Chris
    respond_to do |format|
105 1295:622f24f53b42 Chris
      format.html { redirect_to edit_group_path(@group, :tab => 'users') }
106 1115:433d4f72a19b Chris
      format.js
107
      format.api { render_api_ok }
108 0:513646585e45 Chris
    end
109
  end
110 909:cbb26bc654de Chris
111 0:513646585e45 Chris
  def autocomplete_for_user
112 1295:622f24f53b42 Chris
    respond_to do |format|
113
      format.js
114
    end
115 0:513646585e45 Chris
  end
116 909:cbb26bc654de Chris
117 0:513646585e45 Chris
  def edit_membership
118
    @membership = Member.edit_membership(params[:membership_id], params[:membership], @group)
119
    @membership.save if request.post?
120
    respond_to do |format|
121 1295:622f24f53b42 Chris
      format.html { redirect_to edit_group_path(@group, :tab => 'memberships') }
122 1115:433d4f72a19b Chris
      format.js
123 14:1d32c0a0efbf Chris
    end
124 0:513646585e45 Chris
  end
125 909:cbb26bc654de Chris
126 0:513646585e45 Chris
  def destroy_membership
127
    Member.find(params[:membership_id]).destroy if request.post?
128
    respond_to do |format|
129 1295:622f24f53b42 Chris
      format.html { redirect_to edit_group_path(@group, :tab => 'memberships') }
130 1115:433d4f72a19b Chris
      format.js
131 0:513646585e45 Chris
    end
132
  end
133 1115:433d4f72a19b Chris
134
  private
135
136
  def find_group
137
    @group = Group.find(params[:id])
138
  rescue ActiveRecord::RecordNotFound
139
    render_404
140
  end
141 0:513646585e45 Chris
end