|
1 | 1 | class ProjectsController < ApplicationController |
2 | 2 | before_filter :authenticate_user!, except: [:build, :status, :index, :show] |
3 | 3 | before_filter :project, only: [:build, :integration, :show, :status, :edit, :update, :destroy, :charts] |
| 4 | + before_filter :authorize_access_project!, except: [:build, :gitlab, :status, :index, :show, :new, :create] |
4 | 5 | before_filter :authenticate_token!, only: [:build] |
5 | 6 | before_filter :no_cache, only: [:status] |
6 | 7 |
|
7 | 8 | layout 'project', except: [:index, :gitlab] |
8 | 9 |
|
9 | 10 | def index |
10 | | - @projects = Project.order('name ASC') |
11 | | - @projects = @projects.public unless current_user |
12 | | - @projects = @projects.page(params[:page]).per(20) |
| 11 | + @projects = Project.public.page(params[:page]) unless current_user |
| 12 | + end |
| 13 | + |
| 14 | + def gitlab |
| 15 | + current_user.reset_cache if params[:reset_cache] |
| 16 | + @page = (params[:page] || 1).to_i |
| 17 | + @per_page = 100 |
| 18 | + @gl_projects = current_user.gitlab_projects(@page, @per_page) |
| 19 | + @projects = Project.where(gitlab_id: @gl_projects.map(&:id)).order('name ASC') |
| 20 | + @total_count = @gl_projects.size |
| 21 | + @gl_projects.reject! { |gl_project| @projects.map(&:gitlab_id).include?(gl_project.id) } |
| 22 | + rescue |
| 23 | + @error = 'Failed to fetch GitLab projects' |
13 | 24 | end |
14 | 25 |
|
15 | 26 | def show |
16 | | - unless @project.public || current_user |
17 | | - authenticate_user! and return |
| 27 | + unless @project.public |
| 28 | + authenticate_user! |
| 29 | + authorize_access_project! |
18 | 30 | end |
19 | 31 |
|
20 | 32 | @ref = params[:ref] |
@@ -108,13 +120,6 @@ def charts |
108 | 120 | @charts[:year] = Charts::YearChart.new(@project) |
109 | 121 | end |
110 | 122 |
|
111 | | - def gitlab |
112 | | - @page = (params[:page] || 1).to_i |
113 | | - @per_page = 100 |
114 | | - @projects = current_user.gitlab_projects(@page, @per_page) |
115 | | - rescue |
116 | | - @error = 'Failed to fetch GitLab projects' |
117 | | - end |
118 | 123 |
|
119 | 124 | protected |
120 | 125 |
|
|
0 commit comments