projects_controller.rb 2.3 KB
Newer Older
1
class ProjectsController < ProjectResourceController
2
  skip_before_filter :project, only: [:new, :create]
3
  skip_before_filter :repository, only: [:new, :create]
G
gitlabhq 已提交
4 5

  # Authorize
6
  before_filter :authorize_read_project!, except: [:index, :new, :create]
7
  before_filter :authorize_admin_project!, only: [:edit, :update, :destroy, :transfer]
8
  before_filter :require_non_empty_project, only: [:blob, :tree, :graph]
G
gitlabhq 已提交
9

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

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

  def edit
  end

  def create
20
    @project = ::Projects::CreateContext.new(current_user, params[:project]).execute
G
gitlabhq 已提交
21 22

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

G
gitlabhq 已提交
35
  def update
36
    status = ::Projects::UpdateContext.new(project, current_user, params).execute
37

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

50 51
  def transfer
    ::Projects::TransferContext.new(project, current_user, params).execute
G
gitlabhq 已提交
52 53 54
  end

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

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

G
gitlabhq 已提交
71
  def destroy
72 73
    return access_denied! unless can?(current_user, :remove_project, project)

D
Dmitriy Zaporozhets 已提交
74
    project.team.truncate
G
gitlabhq 已提交
75 76 77
    project.destroy

    respond_to do |format|
R
randx 已提交
78
      format.html { redirect_to root_path }
G
gitlabhq 已提交
79 80
    end
  end
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

  def fork
    @project = ::Projects::ForkContext.new(project, current_user).execute

    respond_to do |format|
      format.html do
        if @project.saved? && @project.forked?
          redirect_to(@project, notice: 'Project was successfully forked.')
        else
          render action: "new"
        end
      end
      format.js
    end
  end
G
gitlabhq 已提交
96
end