Class: GroupsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/groups_controller.rb

Overview

Redmine - project management software Copyright © 2006-2009 Jean-Philippe Lang

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program 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 General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Instance Method Summary collapse

Methods inherited from ApplicationController

accept_key_auth, #accept_key_auth_actions, #api_key_from_request, #api_offset_and_limit, #api_request?, #authorize, #authorize_global, #back_url, #check_if_login_required, #check_project_privacy, #check_project_uniqueness, #default_template, #delete_broken_cookies, #deny_access, #filename_for_content_disposition, #find_current_user, #find_issues, #find_model_object, #find_optional_project, #find_project, #find_project_by_project_id, #find_project_from_association, #invalid_authenticity_token, #logged_user=, model_object, #object_errors_to_json, #parse_qvalues, #per_page_option, #pick_layout, #query_statement_invalid, #redirect_back_or_default, #render_403, #render_404, #render_attachment_warning_if_needed, #render_error, #render_feed, #render_validation_errors, #require_admin, #require_login, #set_flash_from_bulk_issue_save, #set_localization, #use_layout, #user_setup

Methods included from Redmine::MenuManager::MenuController

#current_menu_item, included, #menu_items, #redirect_to_project_menu_item

Methods included from Redmine::Search::Controller

#default_search_scope, #default_search_scopes, included

Methods included from Redmine::I18n

#current_language, #day_name, #find_language, #format_date, #format_time, included, #l, #l_hours, #l_or_humanize, #ll, #month_name, #set_language_if_valid, #valid_languages

Instance Method Details

#add_usersObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/controllers/groups_controller.rb', line 109

def add_users
  @group = Group.find(params[:id])
  users = User.find_all_by_id(params[:user_ids])
  @group.users << users if request.post?
  respond_to do |format|
    format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
    format.js { 
      render(:update) {|page| 
        page.replace_html "tab-content-users", :partial => 'groups/users'
        users.each {|user| page.visual_effect(:highlight, "user-#{user.id}") }
      }
    }
  end
end

#autocomplete_for_userObject



133
134
135
136
137
# File 'app/controllers/groups_controller.rb', line 133

def autocomplete_for_user
  @group = Group.find(params[:id])
  @users = User.active.like(params[:q]).find(:all, :limit => 100) - @group.users
  render :layout => false
end

#createObject

POST /groups POST /groups.xml



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/groups_controller.rb', line 65

def create
  @group = Group.new(params[:group])

  respond_to do |format|
    if @group.save
      flash[:notice] = l(:notice_successful_create)
      format.html { redirect_to(groups_path) }
      format.xml  { render :xml => @group, :status => :created, :location => @group }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @group.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /groups/1 DELETE /groups/1.xml



99
100
101
102
103
104
105
106
107
# File 'app/controllers/groups_controller.rb', line 99

def destroy
  @group = Group.find(params[:id])
  @group.destroy

  respond_to do |format|
    format.html { redirect_to(groups_url) }
    format.xml  { head :ok }
  end
end

#destroy_membershipObject



162
163
164
165
166
167
168
169
# File 'app/controllers/groups_controller.rb', line 162

def destroy_membership
  @group = Group.find(params[:id])
  Member.find(params[:membership_id]).destroy if request.post?
  respond_to do |format|
    format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
    format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'groups/memberships'} }
  end
end

#editObject

GET /groups/1/edit



59
60
61
# File 'app/controllers/groups_controller.rb', line 59

def edit
  @group = Group.find(params[:id], :include => :projects)
end

#edit_membershipObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'app/controllers/groups_controller.rb', line 139

def edit_membership
  @group = Group.find(params[:id])
  @membership = Member.edit_membership(params[:membership_id], params[:membership], @group)
  @membership.save if request.post?
  respond_to do |format|
    if @membership.valid?
      format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
      format.js {
        render(:update) {|page|
          page.replace_html "tab-content-memberships", :partial => 'groups/memberships'
          page.visual_effect(:highlight, "member-#{@membership.id}")
        }
      }
    else
      format.js {
        render(:update) {|page|
          page.alert(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', ')))
        }
      }
    end
  end
end

#indexObject

GET /groups GET /groups.xml



27
28
29
30
31
32
33
34
# File 'app/controllers/groups_controller.rb', line 27

def index
  @groups = Group.find(:all, :order => 'lastname')

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @groups }
  end
end

#newObject

GET /groups/new GET /groups/new.xml



49
50
51
52
53
54
55
56
# File 'app/controllers/groups_controller.rb', line 49

def new
  @group = Group.new
  
  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @group }
  end
end

#remove_userObject



124
125
126
127
128
129
130
131
# File 'app/controllers/groups_controller.rb', line 124

def remove_user
  @group = Group.find(params[:id])
  @group.users.delete(User.find(params[:user_id])) if request.post?
  respond_to do |format|
    format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
    format.js { render(:update) {|page| page.replace_html "tab-content-users", :partial => 'groups/users'} }
  end
end

#showObject

GET /groups/1 GET /groups/1.xml



38
39
40
41
42
43
44
45
# File 'app/controllers/groups_controller.rb', line 38

def show
  @group = Group.find(params[:id])

  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @group }
  end
end

#updateObject

PUT /groups/1 PUT /groups/1.xml



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/controllers/groups_controller.rb', line 82

def update
  @group = Group.find(params[:id])

  respond_to do |format|
    if @group.update_attributes(params[:group])
      flash[:notice] = l(:notice_successful_update)
      format.html { redirect_to(groups_path) }
      format.xml  { head :ok }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @group.errors, :status => :unprocessable_entity }
    end
  end
end