Skip to content

Commit

Permalink
Logic for repo deletion
Browse files Browse the repository at this point in the history
Issue #219
  • Loading branch information
dmac committed Apr 25, 2012
1 parent edce596 commit ba39835
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
10 changes: 9 additions & 1 deletion lib/admin_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
require "resque_jobs/clone_new_repo"
require "addressable/uri"
require "fileutils"

class Barkeep < Sinatra::Base
before "/admin*" do
Expand Down Expand Up @@ -88,6 +89,13 @@ class Barkeep < Sinatra::Base
nil
end

post "/admin/repos/delete_repo" do
repo = GitRepo.first(:name => params[:name])
FileUtils.rm_rf(repo.path)
repo.destroy
nil
end

# You can view log files from within the UI.
get "/admin/log/:file_name" do
next if params[:file_name].include?("..")
Expand All @@ -114,4 +122,4 @@ def admin_erb(view, view_params = {})
html_with_admin_layout = erb("admin/#{view}".to_sym, { :layout => :"admin/layout" }.merge(view_params))
erb html_with_admin_layout
end
end
end
2 changes: 1 addition & 1 deletion models/commit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Commit < Sequel::Model
one_to_many :comments
many_to_one :approved_by_user, :class => User

add_association_dependencies :comments => :destroy, :commit_files => :delete
add_association_dependencies :comments => :destroy, :commit_files => :destroy

add_filter(:message) { |message| StringFilter.escape_html(message) }
add_filter(:message) do |message, commit|
Expand Down
2 changes: 2 additions & 0 deletions models/commit_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class CommitFile < Sequel::Model
many_to_one :commit
one_to_many :comments

add_association_dependencies :comments => :destroy

#list of general comments for this file
def file_comments
comments_dataset.filter(:line_number => nil).order(:created_at).all
Expand Down
27 changes: 23 additions & 4 deletions views/admin/repos.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

<script>
$(document).ready(function() {
var showConfirmationMessage = function(message) {
$("#confirmationMessage").show();
$("#confirmationMessage").html(message);
};

$("button#clone").click(function() {
var showConfirmationMessage = function(message) {
$("#confirmationMessage").show();
$("#confirmationMessage").html(message);
};
var repoUrl = $("#newRepoUrl").val();
$.ajax({
type: "post",
Expand All @@ -21,6 +22,24 @@
error: function(response) { showConfirmationMessage(response.responseText); }
});
});

$(".trash").click(function(e) {
var repoRow = $(e.target).closest("tr");
var repoName = repoRow.find("td:nth-of-type(1)").html();
var repoUrl = repoRow.find("td:nth-of-type(2)").html();
if(confirm("Are you sure you want to delete this repository?\n\n" + repoName + "\n" + repoUrl)) {
$.ajax({
type: "post",
url: "/admin/repos/delete_repo",
data: { name: repoName },
success: function() {
repoRow.remove();
showConfirmationMessage(repoName + " has been deleted.");
},
error: function(response) { showConfirmationMessage(response.responseText); }
})
}
});
});
</script>

Expand Down

0 comments on commit ba39835

Please sign in to comment.