projects_controller.rb 2.5 KB
Newer Older
R
randx 已提交
1
require Rails.root.join('lib', 'gitlab', 'graph_commit')
V
Valery Sizov 已提交
2

G
gitlabhq 已提交
3
class ProjectsController < ApplicationController
4
  before_filter :project, except: [:index, :new, :create]
G
gitlabhq 已提交
5
  layout :determine_layout
G
gitlabhq 已提交
6 7 8

  # Authorize
  before_filter :add_project_abilities
9 10 11
  before_filter :authorize_read_project!, except: [:index, :new, :create]
  before_filter :authorize_admin_project!, only: [:edit, :update, :destroy]
  before_filter :require_non_empty_project, only: [:blob, :tree, :graph]
G
gitlabhq 已提交
12

G
gitlabhq 已提交
13 14 15 16 17 18 19 20
  def new
    @project = Project.new
  end

  def edit
  end

  def create
21
    @project = Project.create_by_user(params[:project], current_user)
G
gitlabhq 已提交
22 23

    respond_to do |format|
24 25 26 27 28 29
      format.html do
        if @project.saved?
          redirect_to(@project, notice: 'Project was successfully created.')
        else
          render action: "new"
        end
G
gitlabhq 已提交
30 31 32 33
      end
      format.js
    end
  end
G
gitlabhq 已提交
34

G
gitlabhq 已提交
35
  def update
G
gitlabhq 已提交
36
    respond_to do |format|
G
gitlabhq 已提交
37
      if project.update_attributes(params[:project])
38
        format.html { redirect_to edit_project_path(project), notice: 'Project was successfully updated.' }
N
Nihad Abbasov 已提交
39
        format.js
G
gitlabhq 已提交
40 41
      else
        format.html { render action: "edit" }
N
Nihad Abbasov 已提交
42
        format.js
G
gitlabhq 已提交
43
      end
G
gitlabhq 已提交
44 45 46 47
    end
  end

  def show
48 49
    limit = (params[:limit] || 20).to_i
    @events = @project.events.recent.limit(limit)
D
Dmitriy Zaporozhets 已提交
50 51

    respond_to do |format|
N
Nihad Abbasov 已提交
52
      format.html do
53
         unless @project.empty_repo?
D
Dmitriy Zaporozhets 已提交
54
           @last_push = current_user.recent_push(@project.id)
D
Dmitriy Zaporozhets 已提交
55 56 57 58 59 60
           render :show
         else
           render "projects/empty"
         end
      end
    end
61 62 63
  end

  def files
D
Dmitriy Zaporozhets 已提交
64
    @notes = @project.notes.where("attachment != 'NULL'").order("created_at DESC").limit(100)
65 66
  end

G
gitlabhq 已提交
67 68 69
  #
  # Wall
  #
70

G
gitlabhq 已提交
71
  def wall
72
    return render_404 unless @project.wall_enabled
G
gitlabhq 已提交
73
    @note = Note.new
G
gitlabhq 已提交
74

N
Nihad Abbasov 已提交
75
    respond_to do |format|
G
gitlabhq 已提交
76 77
      format.html
    end
G
gitlabhq 已提交
78
  end
79

V
Valery Sizov 已提交
80
  def graph
R
randx 已提交
81
    @days_json, @commits_json = Gitlab::GraphCommit.to_graph(project)
V
Valery Sizov 已提交
82 83
  end

G
gitlabhq 已提交
84
  def destroy
85 86 87
    # Disable the UsersProject update_repository call, otherwise it will be
    # called once for every person removed from the project
    UsersProject.skip_callback(:destroy, :after, :update_repository)
G
gitlabhq 已提交
88
    project.destroy
89
    UsersProject.set_callback(:destroy, :after, :update_repository)
G
gitlabhq 已提交
90 91

    respond_to do |format|
R
randx 已提交
92
      format.html { redirect_to root_path }
G
gitlabhq 已提交
93 94 95
    end
  end

N
Nihad Abbasov 已提交
96
  protected
G
gitlabhq 已提交
97

N
Nihad Abbasov 已提交
98
  def project
G
gitlabhq 已提交
99
    @project ||= Project.find_by_code(params[:id])
100
    @project || render_404
G
gitlabhq 已提交
101
  end
G
gitlabhq 已提交
102 103 104 105 106 107 108 109

  def determine_layout
    if @project && !@project.new_record?
      "project"
    else
      "application"
    end
  end
G
gitlabhq 已提交
110
end