Module: CreatesCommit

Extended by:
ActiveSupport::Concern
Included in:
Projects::BlobController, Projects::CommitController, Projects::TreeController
Defined in:
app/controllers/concerns/creates_commit.rb

Instance Method Summary collapse

Instance Method Details

#authorize_edit_tree!Object


37
38
39
40
41
# File 'app/controllers/concerns/creates_commit.rb', line 37

def authorize_edit_tree!
  return if can_collaborate_with_project?

  access_denied!
end

#create_commit(service, success_path:, failure_path:, failure_view: nil, success_notice: nil) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/concerns/creates_commit.rb', line 4

def create_commit(service, success_path:, failure_path:, failure_view: nil, success_notice: nil)
  set_commit_variables

  commit_params = @commit_params.merge(
    source_project: @project,
    source_branch: @ref,
    target_branch: @target_branch
  )

  result = service.new(@tree_edit_project, current_user, commit_params).execute

  if result[:status] == :success
    update_flash_notice(success_notice)

    respond_to do |format|
      format.html { redirect_to final_success_path(success_path) }
      format.json { render json: { message: "success", filePath: final_success_path(success_path) } }
    end
  else
    flash[:alert] = result[:message]
    respond_to do |format|
      format.html do
        if failure_view
          render failure_view
        else
          redirect_to failure_path
        end
      end
      format.json { render json: { message: "failed", filePath: failure_path } }
    end
  end
end