Commit bd20ec1a3415a9f945b5052a8f0f83cbd2806837
1 parent
4cac195a
Exists in
master
and in
4 other branches
Remove file from repository feature
After click on remove file button you will be asked for commit message via modal window. After submitting modal form file will be removed from repository Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
5 changed files
with
51 additions
and
4 deletions
Show diff stats
app/controllers/projects/blob_controller.rb
... | ... | @@ -7,9 +7,30 @@ class Projects::BlobController < Projects::ApplicationController |
7 | 7 | before_filter :authorize_code_access! |
8 | 8 | before_filter :require_non_empty_project |
9 | 9 | |
10 | + before_filter :blob | |
11 | + | |
10 | 12 | def show |
11 | - @blob = @repository.blob_at(@commit.id, @path) | |
13 | + end | |
14 | + | |
15 | + def destroy | |
16 | + result = Files::DeleteContext.new(@project, current_user, params, @ref, @path).execute | |
17 | + | |
18 | + if result[:status] == :success | |
19 | + flash[:notice] = "Your changes have been successfully commited" | |
20 | + redirect_to project_tree_path(@project, @ref) | |
21 | + else | |
22 | + flash[:alert] = result[:error] | |
23 | + render :show | |
24 | + end | |
25 | + end | |
26 | + | |
27 | + private | |
28 | + | |
29 | + def blob | |
30 | + @blob ||= @repository.blob_at(@commit.id, @path) | |
31 | + | |
32 | + return not_found! unless @blob | |
12 | 33 | |
13 | - not_found! unless @blob | |
34 | + @blob | |
14 | 35 | end |
15 | 36 | end | ... | ... |
app/views/projects/blob/_actions.html.haml
... | ... | @@ -4,7 +4,7 @@ |
4 | 4 | - if allowed_tree_edit? |
5 | 5 | = link_to "edit", project_edit_tree_path(@project, @id), class: "btn btn-small" |
6 | 6 | - else |
7 | - %span.btn.btn-small.disabled Edit | |
7 | + %span.btn.btn-small.disabled edit | |
8 | 8 | = link_to "raw", project_raw_path(@project, @id), class: "btn btn-small", target: "_blank" |
9 | 9 | -# only show normal/blame view links for text files |
10 | 10 | - if @blob.text? |
... | ... | @@ -13,3 +13,7 @@ |
13 | 13 | - else |
14 | 14 | = link_to "blame", project_blame_path(@project, @id), class: "btn btn-small" unless @blob.empty? |
15 | 15 | = link_to "history", project_commits_path(@project, @id), class: "btn btn-small" |
16 | + | |
17 | + - if allowed_tree_edit? | |
18 | + = link_to '#modal-remove-blob', class: "remove-blob btn btn-small btn-remove", "data-toggle" => "modal" do | |
19 | + remove | ... | ... |
... | ... | @@ -0,0 +1,19 @@ |
1 | +%div#modal-remove-blob.modal.hide | |
2 | + .modal-header | |
3 | + %a.close{href: "#", "data-dismiss" => "modal"} × | |
4 | + %h3.page-title Remove #{@blob.name} | |
5 | + %p.light | |
6 | + From branch | |
7 | + %strong= @ref | |
8 | + | |
9 | + .modal-body | |
10 | + = form_tag project_blob_path(@project, @id), method: :delete do | |
11 | + .control-group.commit_message-group | |
12 | + = label_tag 'commit_message', class: "control-label" do | |
13 | + Commit message | |
14 | + .controls | |
15 | + = text_area_tag 'commit_message', params[:commit_message], placeholder: "Removed this file because...", required: true, rows: 3 | |
16 | + .control-group | |
17 | + .controls | |
18 | + = submit_tag 'Remove file', class: 'btn btn-remove' | |
19 | + = link_to "Cancel", '#', class: "btn btn-cancel", "data-dismiss" => "modal" | ... | ... |
app/views/projects/blob/show.html.haml
config/routes.rb
... | ... | @@ -173,7 +173,7 @@ Gitlab::Application.routes.draw do |
173 | 173 | end |
174 | 174 | |
175 | 175 | scope module: :projects do |
176 | - resources :blob, only: [:show], constraints: {id: /.+/} | |
176 | + resources :blob, only: [:show, :destroy], constraints: {id: /.+/} | |
177 | 177 | resources :raw, only: [:show], constraints: {id: /.+/} |
178 | 178 | resources :tree, only: [:show], constraints: {id: /.+/, format: /(html|js)/ } |
179 | 179 | resources :edit_tree, only: [:show, :update], constraints: {id: /.+/}, path: 'edit' | ... | ... |