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
|
#--
# Copyright (C) 2007, 2008 Johan Sørensen <johan@johansorensen.com>
# Copyright (C) 2008 David A. Cuadrado <krawek@gmail.com>
#
# This program 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.
#
# 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#++
class CommittersController < ApplicationController
before_filter :login_required, :only => [:new, :create, :destroy, :list]
before_filter :find_project
before_filter :find_repository,
:only => [:show, :new, :create, :edit, :update, :destroy, :list]
def new
@committer = User.new
end
def create
@committer = User.find_by_login(params[:user][:login])
unless @committer
flash[:error] = I18n.t "committers_controller.create_error_not_found"
respond_to do |format|
format.html { redirect_to(new_committer_url(@repository.project, @repository)) }
format.xml { render :text => I18n.t( "committers_controller.create_error_not_found"), :status => :not_found }
end
return
end
respond_to do |format|
if @repository.add_committer(@committer)
@committership = @repository.committerships.find_by_user_id(@committer.id)
@project.create_event(Action::ADD_COMMITTER, @committership, current_user)
format.html { redirect_to([@repository.project, @repository]) }
format.xml do
render :xml => @committer
end
else
flash[:error] = I18n.t "committers_controller.create_error_already_commiter"
format.html { redirect_to(new_committer_url(@repository.project, @repository)) }
format.xml { render :text => I18n.t("committers_controller.create_error_already_commiter"), :status => :not_found }
end
end
end
def destroy
@committership = @repository.committerships.find_by_user_id(params[:id])
respond_to do |format|
if @committership.destroy
@project.create_event(Action::REMOVE_COMMITTER, @repository, current_user, params[:id])
flash[:success] = I18n.t "committers_controller.destroy_success"
format.html { redirect_to [@repository.project, @repository] }
format.xml { render :nothing, :status => :ok }
else
flash[:error] = I18n.t "committers_controller.destroy_error≈"
format.html { redirect_to [@repository.project, @repository] }
format.xml { render :nothing, :status => :unprocessable_entity }
end
end
end
def list
@committers = @repository.committers
respond_to do |format|
format.xml { render :xml => @committers }
end
end
def auto_complete_for_user_login
login = params[:user][:login]
@users = User.find(:all,
:conditions => [ 'LOWER(login) LIKE ?', '%' + login.downcase + '%' ],
:limit => 10)
render :layout => false
end
private
def find_repository
@repository = @project.repositories.find_by_name!(params[:repository_id])
unless @repository.user == current_user
flash[:error] = I18n.t "committers_controller.find_repository_error"
redirect_to [@repository.project, @repository]
end
end
end
|