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
|
class CommittersController < ApplicationController
before_filter :login_required, :only => [:new, :create, :destroy]
before_filter :find_repository,
:only => [:show, :new, :create, :edit, :update, :destroy]
def new
@committer = User.new
end
def create
@committer = User.find_by_login(params[:user][:login])
unless @committer
flash[:error] = "Could not find user by that name"
respond_to do |format|
format.html { redirect_to(new_committer_url(@repository.project, @repository)) }
format.xml { render :text => "Could not a find user by that name", :Status => :not_found }
end
return
end
if @repository.add_committer(@committer)
respond_to do |format|
format.html { redirect_to([@repository.project, @repository]) }
format.xml do
render :nothing, :status => :created,
:location => project_repository_path(@repository.project, @repository)
end
end
end
end
def destroy
@permission = @repository.permissions.find_by_user_id(params[:id])
respond_to do |format|
if @permission.destroy
flash[:success] = "User removed from repository"
format.html { redirect_to [@repository.project, @repository] }
format.xml { render :nothing, :status => :ok }
else
flash[:error] = "Could not remove user from repository"
format.html { redirect_to [@repository.project, @repository] }
format.xml { render :nothing, :status => :unprocessable_entity }
end
end
end
private
def find_repository
@repository = Repository.find_by_name!(params[:repository_id])
unless @repository.user == current_user
flash[:error] = "You're not the owner of this repository"
redirect_to [@repository.project, @repository]
end
end
end
|