Commit f5936cfed5d6e1edb929a6fe8d0ab5eb726e0fee

Tidied up some controllers

Commit diff

app/controllers/application.rb

 
22# Likewise, all the methods added will be available for all controllers.
33
44class ApplicationController < ActionController::Base
5
56 session :session_key => '_ks1_session_id', :secret => GitlabConfig["cookie_secret"]
67 include AuthenticatedSystem
78 include ExceptionNotifiable
6363 def render_not_found
6464 render :file => "#{RAILS_ROOT}/public/ac_404.html", :status => 404
6565 end
66
67 def authorised
68 if !@is_member
69 flash[:error] = "Access denied."
70 redirect_to root_path
71 end
72 end
6673
6774end
toggle raw diff

app/controllers/articles_controller.rb

 
33#
44class ArticlesController < ApplicationController
55
6 after_filter :after_article
7 before_filter :find_project
6 after_filter :after_article, :only => [ :find_by_permalink ]
7 before_filter :find_project, :except => [ :find_by_date, :find_by_permalink, :find_by_type, :find_by_category,
8 :find_by_user, :find_by_sitename, :find_by_sitename_and_type, :find_by_project_and_type ]
9 before_filter :authorised, :only => [ :update, :edit, :destroy, :new, :create ]
810
911 # Show all articles, render grouped by year, month
1012 def index
3636 def edit
3737 if @project
3838 # Project article
39 @article = Article.find_by_id(params[:id], current_user)
39 @article = Article.find_by_id!(params[:id])
4040 if @article
4141 @title = "Editing: " + @project.title + ": " + @article.title
4242 render :action => "ac_project_edit"
239239
240240 # Increase view count for a permalink page
241241 def after_article
242 if action_name == "find_by_permalink" and @article != nil then
242 if @article
243243 @article.views = @article.views + 1
244244 @article.save!
245245 end
toggle raw diff

app/controllers/committers_controller.rb

 
11class CommittersController < ApplicationController
2
23 before_filter :login_required, :only => [:new, :create, :destroy, :list]
34 before_filter :find_project
45 before_filter :find_repository,
toggle raw diff

app/controllers/projects_controller.rb

 
33 before_filter :login_required, :only => [:create, :update, :destroy, :new]
44 before_filter :require_user_has_ssh_keys, :only => [:new, :create]
55 before_filter :find_project, :except => [:index, :category, :new, :create]
6 before_filter :authorised, :only => [ :update, :edit, :destroy, :new, :create ]
67
78 after_filter :increment_project_view
89
toggle raw diff

app/controllers/repositories_controller.rb

 
77 session :off, :only => [:writable_by]
88
99 def index
10 if params[:project_id] != nil
11 @project = Project.find_by_slug(params[:project_id], current_user)
12 if @project != nil
13 @repositories = @project.repositories.find(:all)
14 @title, @url_suffix = Project.tab_settings(PRJ_TAB_REPOS)
15 render :action => "ac_index"
16 else
17 flash[:error] = "Project not found."
18 redirect_to projects_path
19 end
10 if @project
11 @repositories = @project.repositories.find(:all)
12 @title, @url_suffix = Project.tab_settings(PRJ_TAB_REPOS)
13 render :action => "ac_index"
2014 else
21 flash[:error] = "No project specified."
15 flash[:error] = "Project not found."
2216 redirect_to projects_path
2317 end
2418 end
101101 end
102102
103103 private
104
104105 def require_adminship
105106 unless @project.admin?(current_user)
106107 respond_to do |format|
toggle raw diff

app/controllers/sessions_controller.rb

 
11# This controller handles the login/logout function of the site.
22class SessionsController < ApplicationController
3
34 # render new.rhtml
45 def new
56 render :action => "ac_new"
toggle raw diff

app/controllers/site_controller.rb

 
11class SiteController < ApplicationController
2 before_filter :login_required, :only => [:dashboard]
2
3 before_filter :login_required, :only => [ :dashboard ]
34
45 def index
56 @articles = Article.find_home(current_user)
toggle raw diff

app/controllers/wikis_controller.rb

 
11class WikisController < ApplicationController
22
33 before_filter :find_project
4 after_filter :after_wiki
4 before_filter :authorised, :only => [ :update, :edit, :destroy, :new, :create ]
5 after_filter :after_wiki, :only => [ :show ]
56
67 def index
78 if @project
165165
166166 # Increase view count for a wiki page
167167 def after_wiki
168 if action_name == "show" and @wiki != nil then
168 if @wiki
169169 @wiki.views = @wiki.views + 1
170170 @wiki.save!
171171 end
toggle raw diff

app/models/article.rb

 
8888 find(:first, :conditions => ["status = '#{:published}' AND id = '#{id}' AND ( audience = '#{:public}' OR project_id IN (" << @projects << ") )"])
8989 end
9090
91 # No membership test version
92 def self.find_by_id! (id)
93 find(:first, :conditions => ["id = '#{id}'"])
94 end
95
9196 # finds articles for a user based on the user slug e.g. /profiles/test-user/articles
9297 def self.find_by_user (user_id, curruser)
9398 @projects = Project.list_for_user(curruser)
110110 @projects = Project.list_for_user(curruser)
111111 find(:first, :conditions => ["status = '#{:published}' AND permalink = '#{permalink}' AND ( audience = '#{:public}' OR project_id IN (" << @projects << ") )"])
112112 end
113
113
114114 #
115115 def self.find_by_type (article_type, curruser)
116116 @projects = Project.list_for_user(curruser)
134134 find(:all, :conditions => ["status = '#{:published}' AND project_id = '#{project_id}' AND ( audience = '#{:public}' OR project_id IN (" << projects_allowed << ") )"], :order => "created_at DESC")
135135 end
136136
137 # only called if caller a member
137 # No membership test version
138138 def self.find_by_project! (project_id)
139139 find(:all, :conditions => ["project_id = '#{project_id}'"], :order => "created_at DESC")
140140 end
toggle raw diff

test/fixtures/tickets.yml

 
1515#
1616# Add message box prompt on delete wiki and article
1717#
18# Add delete wiki to actions box
19#
20# Change edit and del links to images on lists (like article and wiki)
21#
22# Can't edit a deleted wiki / article etc.
23#
1824
1925
2026#
toggle raw diff