diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb index ba466251b29db862d5b3220f5338d4bf9e0f2b93..087c1639ac64fc9e2e09836a84c3d8c1fbb4b591 100644 --- a/app/controllers/projects/blob_controller.rb +++ b/app/controllers/projects/blob_controller.rb @@ -7,9 +7,30 @@ class Projects::BlobController < Projects::ApplicationController before_filter :authorize_code_access! before_filter :require_non_empty_project + before_filter :blob + def show - @blob = @repository.blob_at(@commit.id, @path) + end + + def destroy + result = Files::DeleteContext.new(@project, current_user, params, @ref, @path).execute + + if result[:status] == :success + flash[:notice] = "Your changes have been successfully commited" + redirect_to project_tree_path(@project, @ref) + else + flash[:alert] = result[:error] + render :show + end + end + + private + + def blob + @blob ||= @repository.blob_at(@commit.id, @path) + + return not_found! unless @blob - not_found! unless @blob + @blob end end diff --git a/app/views/projects/blob/_actions.html.haml b/app/views/projects/blob/_actions.html.haml index f6cc62e707e09473c875d47d5fad35ac1bea402c..2f82bfe52f32122bba85be41760e395f1319bb36 100644 --- a/app/views/projects/blob/_actions.html.haml +++ b/app/views/projects/blob/_actions.html.haml @@ -4,7 +4,7 @@ - if allowed_tree_edit? = link_to "edit", project_edit_tree_path(@project, @id), class: "btn btn-small" - else - %span.btn.btn-small.disabled Edit + %span.btn.btn-small.disabled edit = link_to "raw", project_raw_path(@project, @id), class: "btn btn-small", target: "_blank" -# only show normal/blame view links for text files - if @blob.text? @@ -13,3 +13,7 @@ - else = link_to "blame", project_blame_path(@project, @id), class: "btn btn-small" unless @blob.empty? = link_to "history", project_commits_path(@project, @id), class: "btn btn-small" + + - if allowed_tree_edit? + = link_to '#modal-remove-blob', class: "remove-blob btn btn-small btn-remove", "data-toggle" => "modal" do + remove diff --git a/app/views/projects/blob/_remove.html.haml b/app/views/projects/blob/_remove.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..1c097330c44bc073559285c8c311aabf31845a38 --- /dev/null +++ b/app/views/projects/blob/_remove.html.haml @@ -0,0 +1,19 @@ +%div#modal-remove-blob.modal.hide + .modal-header + %a.close{href: "#", "data-dismiss" => "modal"} × + %h3.page-title Remove #{@blob.name} + %p.light + From branch + %strong= @ref + + .modal-body + = form_tag project_blob_path(@project, @id), method: :delete do + .control-group.commit_message-group + = label_tag 'commit_message', class: "control-label" do + Commit message + .controls + = text_area_tag 'commit_message', params[:commit_message], placeholder: "Removed this file because...", required: true, rows: 3 + .control-group + .controls + = submit_tag 'Remove file', class: 'btn btn-remove' + = link_to "Cancel", '#', class: "btn btn-cancel", "data-dismiss" => "modal" diff --git a/app/views/projects/blob/show.html.haml b/app/views/projects/blob/show.html.haml index d96595bc7f08b8ef479340a50a0b969a0fec7d10..56220e520f3b376d679ebd6419e67e28131151de 100644 --- a/app/views/projects/blob/show.html.haml +++ b/app/views/projects/blob/show.html.haml @@ -2,3 +2,6 @@ = render 'shared/ref_switcher', destination: 'blob', path: @path %div#tree-holder.tree-holder = render 'blob', blob: @blob + +- if allowed_tree_edit? + = render 'projects/blob/remove' diff --git a/config/routes.rb b/config/routes.rb index 06e8fddf705f731abd15897415cfede1422a0185..d89fc20c6c9c36f6c0fb40e5ef02bd1e5051ccd1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -173,7 +173,7 @@ Gitlab::Application.routes.draw do end scope module: :projects do - resources :blob, only: [:show], constraints: {id: /.+/} + resources :blob, only: [:show, :destroy], constraints: {id: /.+/} resources :raw, only: [:show], constraints: {id: /.+/} resources :tree, only: [:show], constraints: {id: /.+/, format: /(html|js)/ } resources :edit_tree, only: [:show, :update], constraints: {id: /.+/}, path: 'edit'