| 1 |
class ProjectsController < ApplicationController |
| 2 |
before_filter :login_required, :only => [:create, :update, :destroy, :new] |
| 3 |
before_filter :require_user_has_ssh_keys, :only => [:new, :create] |
| 4 |
|
| 5 |
def index |
| 6 |
@projects = Project.paginate(:all, :order => "projects.created_at desc", |
| 7 |
:page => params[:page], :include => [:tags, { :repositories => :project } ]) |
| 8 |
|
| 9 |
@atom_auto_discovery_url = formatted_projects_path(:atom) |
| 10 |
respond_to do |format| |
| 11 |
format.html { @tags = Project.top_tags } |
| 12 |
format.xml { render :xml => @projects } |
| 13 |
format.atom { } |
| 14 |
end |
| 15 |
end |
| 16 |
|
| 17 |
def category |
| 18 |
tags = params[:id].to_s.gsub(/,\ ?/, " ") |
| 19 |
@projects = Project.paginate_by_tag(tags, :order => 'created_at desc', |
| 20 |
:page => params[:page]) |
| 21 |
@atom_auto_discovery_url = formatted_projects_category_path(params[:id], :atom) |
| 22 |
respond_to do |format| |
| 23 |
format.html do |
| 24 |
@tags = Project.tag_counts |
| 25 |
render :action => "index" |
| 26 |
end |
| 27 |
format.xml { render :xml => @projects } |
| 28 |
format.atom { render :action => "index"} |
| 29 |
end |
| 30 |
end |
| 31 |
|
| 32 |
def show |
| 33 |
@project = Project.find_by_slug!(params[:id], :include => [:repositories]) |
| 34 |
@mainline_repository = @project.mainline_repository |
| 35 |
@repositories = @project.repository_clones |
| 36 |
@events = @project.events.paginate(:all, :page => params[:page], |
| 37 |
:order => "created_at desc", :include => [:user, :project]) |
| 38 |
@atom_auto_discovery_url = formatted_project_path(@project, :atom) |
| 39 |
|
| 40 |
respond_to do |format| |
| 41 |
format.html |
| 42 |
format.xml { render :xml => @project } |
| 43 |
format.atom { } |
| 44 |
end |
| 45 |
end |
| 46 |
|
| 47 |
def new |
| 48 |
end |
| 49 |
|
| 50 |
def create |
| 51 |
@project = Project.new(params[:project]) |
| 52 |
@project.user = current_user |
| 53 |
if @project.save |
| 54 |
@project.create_event(Action::CREATE_PROJECT, @project, current_user) |
| 55 |
redirect_to projects_path |
| 56 |
else |
| 57 |
render :action => 'new' |
| 58 |
end |
| 59 |
end |
| 60 |
|
| 61 |
def edit |
| 62 |
@project = Project.find_by_slug!(params[:id]) |
| 63 |
end |
| 64 |
|
| 65 |
def update |
| 66 |
@project = Project.find_by_slug!(params[:id]) |
| 67 |
if @project.user != current_user |
| 68 |
flash[:error] = "You're not the owner of this project" |
| 69 |
redirect_to(project_path(@project)) and return |
| 70 |
end |
| 71 |
@project.attributes = params[:project] |
| 72 |
if @project.save |
| 73 |
@project.create_event(Action::UPDATE_PROJECT, @project, current_user) |
| 74 |
redirect_to project_path(@project) |
| 75 |
else |
| 76 |
render :action => 'new' |
| 77 |
end |
| 78 |
end |
| 79 |
|
| 80 |
def confirm_delete |
| 81 |
@project = Project.find_by_slug!(params[:id]) |
| 82 |
end |
| 83 |
|
| 84 |
def destroy |
| 85 |
@project = Project.find_by_slug!(params[:id]) |
| 86 |
if @project.can_be_deleted_by?(current_user) |
| 87 |
project_title = @project.title |
| 88 |
@project.destroy |
| 89 |
|
| 90 |
else |
| 91 |
flash[:error] = "You're not the owner of this project, or the project has clones" |
| 92 |
end |
| 93 |
redirect_to projects_path |
| 94 |
end |
| 95 |
end |