BigW Consortium Gitlab

projects_controller.rb 2.53 KB
Newer Older
1
require Rails.root.join('lib', 'gitlab', 'graph_commit')
Valery Sizov committed
2

gitlabhq committed
3
class ProjectsController < ApplicationController
4
  before_filter :project, except: [:index, :new, :create]
gitlabhq committed
5
  layout :determine_layout
gitlabhq committed
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]
gitlabhq committed
12

gitlabhq committed
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)
gitlabhq committed
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
gitlabhq committed
30 31 32 33
      end
      format.js
    end
  end
gitlabhq committed
34

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

  def show
48
    limit = (params[:limit] || 20).to_i
49
    @events = @project.events.recent.limit(limit).offset(params[:offset] || 0)
Dmitriy Zaporozhets committed
50 51

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

  def files
Dmitriy Zaporozhets committed
65
    @notes = @project.notes.where("attachment != 'NULL'").order("created_at DESC").limit(100)
66 67
  end

gitlabhq committed
68 69 70
  #
  # Wall
  #
71

gitlabhq committed
72
  def wall
73
    return render_404 unless @project.wall_enabled
gitlabhq committed
74
    @note = Note.new
gitlabhq committed
75

76
    respond_to do |format|
gitlabhq committed
77 78
      format.html
    end
gitlabhq committed
79
  end
80

Valery Sizov committed
81
  def graph
82
    @days_json, @commits_json = Gitlab::GraphCommit.to_graph(project)
Valery Sizov committed
83 84
  end

gitlabhq committed
85
  def destroy
86 87 88
    # 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)
gitlabhq committed
89
    project.destroy
90
    UsersProject.set_callback(:destroy, :after, :update_repository)
gitlabhq committed
91 92

    respond_to do |format|
93
      format.html { redirect_to root_path }
gitlabhq committed
94 95 96
    end
  end

Nihad Abbasov committed
97
  protected
gitlabhq committed
98

Nihad Abbasov committed
99
  def project
gitlabhq committed
100
    @project ||= Project.find_by_code(params[:id])
101
    @project || render_404
gitlabhq committed
102
  end
gitlabhq committed
103 104 105 106 107 108 109 110

  def determine_layout
    if @project && !@project.new_record?
      "project"
    else
      "application"
    end
  end
gitlabhq committed
111
end