projects_controller.rb 2.5 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
      flash[:notice] = 'Project was successfully created.' if @project.saved?
25 26
      format.html do
        if @project.saved?
27
          redirect_to @project
28 29 30
        else
          render action: "new"
        end
G
gitlabhq 已提交
31 32 33 34
      end
      format.js
    end
  end
G
gitlabhq 已提交
35

G
gitlabhq 已提交
36
  def update
37
    status = ProjectUpdateContext.new(project, current_user, params).execute
38

G
gitlabhq 已提交
39
    respond_to do |format|
40
      if status
41
        flash[:notice] = 'Project was successfully updated.'
42
        format.html { redirect_to edit_project_path(project), notice: 'Project was successfully updated.' }
N
Nihad Abbasov 已提交
43
        format.js
G
gitlabhq 已提交
44 45
      else
        format.html { render action: "edit" }
N
Nihad Abbasov 已提交
46
        format.js
G
gitlabhq 已提交
47
      end
G
gitlabhq 已提交
48 49 50 51
    end
  end

  def show
52
    limit = (params[:limit] || 20).to_i
R
randx 已提交
53
    @events = @project.events.recent.limit(limit).offset(params[:offset] || 0)
D
Dmitriy Zaporozhets 已提交
54 55

    respond_to do |format|
N
Nihad Abbasov 已提交
56
      format.html do
57
         unless @project.empty_repo?
D
Dmitriy Zaporozhets 已提交
58
           @last_push = current_user.recent_push(@project.id)
D
Dmitriy Zaporozhets 已提交
59 60 61 62 63
           render :show
         else
           render "projects/empty"
         end
      end
R
randx 已提交
64
      format.js
D
Dmitriy Zaporozhets 已提交
65
    end
66 67 68
  end

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

G
gitlabhq 已提交
72 73 74
  #
  # Wall
  #
75

G
gitlabhq 已提交
76
  def wall
77
    return render_404 unless @project.wall_enabled
G
gitlabhq 已提交
78
    @note = Note.new
G
gitlabhq 已提交
79

N
Nihad Abbasov 已提交
80
    respond_to do |format|
G
gitlabhq 已提交
81 82
      format.html
    end
G
gitlabhq 已提交
83
  end
84

V
Valery Sizov 已提交
85
  def graph
R
randx 已提交
86 87 88
    graph = Gitlab::Graph::JsonBuilder.new(project)

    @days_json, @commits_json = graph.days_json, graph.commits_json
V
Valery Sizov 已提交
89 90
  end

G
gitlabhq 已提交
91
  def destroy
92 93 94
    # 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 已提交
95
    project.destroy
96
    UsersProject.set_callback(:destroy, :after, :update_repository)
G
gitlabhq 已提交
97 98

    respond_to do |format|
R
randx 已提交
99
      format.html { redirect_to root_path }
G
gitlabhq 已提交
100 101 102
    end
  end
end