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

3
class ProjectsController < ProjectResourceController
4
  skip_before_filter :project, only: [:new, :create]
G
gitlabhq 已提交
5 6

  # Authorize
7 8 9
  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 已提交
10

C
Cyril 已提交
11 12
  layout 'application', only: [:new, :create]

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
    limit = (params[:limit] || 20).to_i
R
randx 已提交
49
    @events = @project.events.recent.limit(limit).offset(params[:offset] || 0)
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
           render :show
         else
           render "projects/empty"
         end
      end
R
randx 已提交
60
      format.js
D
Dmitriy Zaporozhets 已提交
61
    end
62 63 64
  end

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

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

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

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

V
Valery Sizov 已提交
81
  def graph
R
randx 已提交
82 83 84
    graph = Gitlab::Graph::JsonBuilder.new(project)

    @days_json, @commits_json = graph.days_json, graph.commits_json
V
Valery Sizov 已提交
85 86
  end

G
gitlabhq 已提交
87
  def destroy
88 89 90
    # 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 已提交
91
    project.destroy
92
    UsersProject.set_callback(:destroy, :after, :update_repository)
G
gitlabhq 已提交
93 94

    respond_to do |format|
R
randx 已提交
95
      format.html { redirect_to root_path }
G
gitlabhq 已提交
96 97 98
    end
  end
end