Blob of app/controllers/projects_controller.rb (raw blob data)

1 class ProjectsController < ApplicationController
2
3 before_filter :login_required, :only => [:create, :update, :destroy, :new]
4 before_filter :require_user_has_ssh_keys, :only => [:new, :create]
5 before_filter :find_project, :except => [:index, :category, :new, :create]
6 before_filter :authorised, :only => [ :update, :edit, :destroy, :new, :create ]
7
8 after_filter :increment_project_view, :only => [ :show ]
9
10 def index
11 @title = "Projects"
12 @public_projects = Project.find_all_active_public_projects(current_user)
13 #flash[:error] = "No public projects exist." if @public_projects.size == 0
14 @member_projects = Project.find_all_active_member_projects(current_user) if logged_in?
15 render :action => "ac_list"
16 end
17
18 def category
19 tags = params[:id].to_s.gsub(/,\ ?/, " ")
20 @projects = Project.paginate_by_tag(tags, :order => 'created_at desc',
21 :page => params[:page])
22 @atom_auto_discovery_url = formatted_projects_category_path(params[:id], :atom)
23 respond_to do |format|
24 format.html do
25 @tags = Project.tag_counts
26 render :action => "index"
27 end
28 format.xml { render :xml => @projects }
29 format.atom { render :action => "index"}
30 end
31 end
32
33 def show
34 # @wiki = @project.wiki
35 @title = "Summary"
36 @critical_tickets = Ticket.find_critical(@project.id)
37 @tickets = Ticket.find_recent(@project.id)
38 @url_suffix = ""
39 #FIXME mainline / hardcoded?
40 @repository = @project.repositories.find_by_name!("mainline")
41 @repository.has_commits? ? @commits = @repository.git.commits(@repository.head_candidate.name, 3, 0) : @commits = []
42 @messages = Message.find_by_project(@project.id, 3)
43 render :action => "ac_show"
44 end
45
46 def new
47 end
48
49 def create
50 @project = Project.new(params[:project])
51 @project.user = current_user
52 if @project.save
53 redirect_to projects_path
54 else
55 render :action => 'new'
56 end
57 end
58
59 def edit
60 end
61
62 def update
63 if @project.user != current_user
64 flash[:error] = "You're not the owner of this project"
65 redirect_to(project_path(@project)) and return
66 end
67 @project.attributes = params[:project]
68 if @project.save
69 redirect_to project_path(@project)
70 else
71 render :action => 'new'
72 end
73 end
74
75 def confirm_delete
76 end
77
78 def destroy
79 if @project.can_be_deleted_by?(current_user)
80 @project.destroy
81 else
82 flash[:error] = "You're not the owner of this project, or the project has clones"
83 end
84 redirect_to projects_path
85 end
86
87 def forum
88 @title, @url_suffix = Project.tab_settings(PRJ_TAB_FORUM)
89 render :action => "ac_forum"
90 end
91
92 def team
93 @title, @url_suffix = Project.tab_settings(PRJ_TAB_TEAM)
94 @messages = Message.find_by_project(@project.id, 40)
95 render :action => "ac_team"
96 end
97
98 def roadmap
99 @title, @url_suffix = Project.tab_settings(PRJ_TAB_SUMMARY)
100 render :action => "ac_roadmap"
101 end
102
103 def log
104 # Project events index page, shows list of all wikis for that project
105 @events = Event.find_by_project(@project.id)
106 unless @events.empty?
107 @title = "Log"
108 @url_suffix = ""
109 render :action => "ac_log_index"
110 else
111 flash[:error] = "No log for this project."
112 redirect_to project_path(@project.slug)
113 end
114 end
115
116 def config
117 @title, @url_suffix = Project.tab_settings(PRJ_TAB_CONFIG)
118 render :action => "ac_config"
119 end
120
121 def increment_project_view
122 if @project
123 @project.views = @project.views + 1
124 @project.save!
125 end
126 end
127
128 end