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 @ 1532:a0460a3d154f

History | View | Annotate | Download (3.63 KB)

1
# Redmine - project management software
2
# Copyright (C) 2006-2014  Jean-Philippe Lang
3
#
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
#
9
# 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
#
14
# 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

    
21
  before_filter :require_admin
22
  before_filter :find_group, :except => [:index, :new, :create]
23
  accept_api_auth :index, :show, :create, :update, :destroy, :add_users, :remove_user
24

    
25
  helper :custom_fields
26

    
27
  def index
28
    @groups = Group.sorted.all
29

    
30
    respond_to do |format|
31
      format.html
32
      format.api
33
    end
34
  end
35

    
36
  def show
37
    respond_to do |format|
38
      format.html
39
      format.api
40
    end
41
  end
42

    
43
  def new
44
    @group = Group.new
45
  end
46

    
47
  def create
48
    @group = Group.new
49
    @group.safe_attributes = params[:group]
50

    
51
    respond_to do |format|
52
      if @group.save
53
        format.html {
54
          flash[:notice] = l(:notice_successful_create)
55
          redirect_to(params[:continue] ? new_group_path : groups_path)
56
        }
57
        format.api  { render :action => 'show', :status => :created, :location => group_url(@group) }
58
      else
59
        format.html { render :action => "new" }
60
        format.api  { render_validation_errors(@group) }
61
      end
62
    end
63
  end
64

    
65
  def edit
66
  end
67

    
68
  def update
69
    @group.safe_attributes = params[:group]
70

    
71
    respond_to do |format|
72
      if @group.save
73
        flash[:notice] = l(:notice_successful_update)
74
        format.html { redirect_to(groups_path) }
75
        format.api  { render_api_ok }
76
      else
77
        format.html { render :action => "edit" }
78
        format.api  { render_validation_errors(@group) }
79
      end
80
    end
81
  end
82

    
83
  def destroy
84
    @group.destroy
85

    
86
    respond_to do |format|
87
      format.html { redirect_to(groups_path) }
88
      format.api  { render_api_ok }
89
    end
90
  end
91

    
92
  def add_users
93
    @users = User.where(:id => (params[:user_id] || params[:user_ids])).all
94
    @group.users << @users if request.post?
95
    respond_to do |format|
96
      format.html { redirect_to edit_group_path(@group, :tab => 'users') }
97
      format.js
98
      format.api { render_api_ok }
99
    end
100
  end
101

    
102
  def remove_user
103
    @group.users.delete(User.find(params[:user_id])) if request.delete?
104
    respond_to do |format|
105
      format.html { redirect_to edit_group_path(@group, :tab => 'users') }
106
      format.js
107
      format.api { render_api_ok }
108
    end
109
  end
110

    
111
  def autocomplete_for_user
112
    respond_to do |format|
113
      format.js
114
    end
115
  end
116

    
117
  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
      format.html { redirect_to edit_group_path(@group, :tab => 'memberships') }
122
      format.js
123
    end
124
  end
125

    
126
  def destroy_membership
127
    Member.find(params[:membership_id]).destroy if request.post?
128
    respond_to do |format|
129
      format.html { redirect_to edit_group_path(@group, :tab => 'memberships') }
130
      format.js
131
    end
132
  end
133

    
134
  private
135

    
136
  def find_group
137
    @group = Group.find(params[:id])
138
  rescue ActiveRecord::RecordNotFound
139
    render_404
140
  end
141
end