Skip to content

Commit

Permalink
Merge pull request #100 from adnanhemani/varun_superadmin_delete_all
Browse files Browse the repository at this point in the history
Varun superadmin delete all
  • Loading branch information
SidMasih authored Dec 2, 2016
2 parents 339c27d + dff0364 commit 3ecdae6
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 29 deletions.
18 changes: 18 additions & 0 deletions app/controllers/admins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ def superadmin
render "super"
end

def reset_semester
render "reset"
end

def reset_database
@reset_password = params[:reset_password]
if @reset_password == ENV["ADMIN_DELETE_DATA_PASSWORD"]
AdminMailer.all_data(@admin).deliver_now if not Rails.env.test?
User.delete_all
Team.delete_all
Submission.delete_all
Discussion.delete_all
redirect_to "/", :notice => "All data reset. Good luck with the new semester!"
else
redirect_to reset_semester_path, :notice => "Incorrect password"
end
end

def transfer
if @admin.superadmin == true and params[:transfer_admin] != nil
other_admin = Admin.find(params[:transfer_admin])
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ def create
@submission = Submission.new(submission_params)
end

@submission.team = @team

@submission.save!

@team.add_submission(@submission.id)

return redirect_to team_path(@team), notice: "Thanks for submitting your team for enrollment."
end

def destroy

end

private
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/team_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def submit
end

def unsubmit
@submission = @team.submission
@submission.destroy!
@team.withdraw_submission
redirect_to team_path(@team.id)
end
Expand Down
7 changes: 7 additions & 0 deletions app/mailers/admin_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ def look_at_submission(email)
mail(to: email, subject: "Teams are awaiting your approval!")
end

def all_data(admin)
@admin = admin
mail(to: @admin.email, subject: 'Reset Semester: All data that was deleted') do |format|
format.html
end
end

def self.send_look_at_submission
if !(Team.where("approved = ? AND submitted = ?", false, true).nil?)
Admin.all.each do |admin|
Expand Down
106 changes: 106 additions & 0 deletions app/views/admin_mailer/all_data.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<html>
<head>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
</head>
<body>
<h1>Teams</h1>
<table class="table table-striped table-hover" style="border: 1px solid black; padding: 15px; border-spacing: 5px; border-collapse: collapse; width: 100%; ">
<tr style="border: 1px solid black;">
<td>Team ID</td>
<td>Passcode</td>
<td>Members</td>
<td>Approved?</td>
<td>Submitted?</td>
<td>Submission ID</td>
<td>Created On</td>
<td>Updated On</td>
</tr>
<% Team.all.each do |t| %>
<tr>
<td><%= t.id %></td>
<td><%= t.passcode %></td>
<td><% t.users.each do |u| %>
<%= u.name %>
<br>
<% end %></td>
<td><%= t.approved ? 'Approved' : 'Not Approved' %></td>
<td><%= t.submitted ? 'Approved' : 'Not Approved' %></td>
<td><%= t.submission_id %></td>
<td><%= t.created_at %></td>
<td><%= t.updated_at %></td>
</tr>
<% end %>
</table>
<h1>Users</h1>
<table class="table table-striped table-hover" style="border: 1px solid black; padding: 15px; border-spacing: 5px; border-collapse: collapse; width: 100%; ">
<tr style="border: 1px solid black;">
<td>User ID</td>
<td>Name</td>
<td>Email</td>
<td>Major</td>
<td>SID</td>
<td>Team ID</td>
<td>Created On</td>
<td>Updated On</td>
</tr>
<% User.all.each do |u| %>
<tr>
<td><%= u.id %></td>
<td><%= u.name %></td>
<td><%= u.email %></td>
<td><%= u.major %></td>
<td><%= u.sid %></td>
<td><%= u.team_id %></td>
<td><%= u.created_at %></td>
<td><%= u.updated_at %></td>
</tr>
<% end %>
</table>
<h1>Discussions</h1>
<table class="table table-striped table-hover" style="border: 1px solid black; padding: 15px; border-spacing: 5px; border-collapse: collapse; width: 100%; ">
<tr style="border: 1px solid black;">
<td>Number</td>
<td>Time</td>
<td>Day</td>
<td>Teams</td>
<td>Capacity</td>
<td>Submission ID</td>
</tr>
<% Discussion.all.each do |d| %>
<tr>
<td><%= d.number %></td>
<td><%= d.time %></td>
<td><%= d.day %></td>
<td><% d.teams.each do |t| %>
<%= t.id %>
<br>
<% end %></td>
<td><%= d.capacity %></td>
<td><%= d.submission_id %></td>
</tr>
<% end %>
</table>
<h1>Submissions</h1>
<table class="table table-striped table-hover" style="border: 1px solid black; padding: 15px; border-spacing: 5px; border-collapse: collapse; width: 100%; ">
<tr style="border: 1px solid black;">
<td>Team ID</td>
<td>Discussion 1</td>
<td>Discussion 2</td>
<td>Discussion 3</td>
<td>Created On</td>
<td>Updated On</td>
</tr>
<% Submission.all.each do |s| %>
<tr>
<td><%= s.team.id %></td>
<td><%= s.disc1id %></td>
<td><%= s.disc2id %></td>
<td><%= s.disc3id %></td>
<td><%= s.created_at %></td>
<td><%= s.updated_at %></td>
</tr>
<% end %>
</table>
</body>
</html>
23 changes: 23 additions & 0 deletions app/views/admins/reset.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<body>
<title>Reset Semester</title>
<div class="container">
<h1>Reset Semester</h1>
<% if @admin.superadmin == true %>
<br>
<p>Warning: Resetting the semester will result in all users, teams, and discussions being deleted. This is to be used at the end of the semester, to prepare for a new semester of enrollment. This action can only be performed by the super admin, and is passcode protected. An email will be sent to you with all the data that has been deleted.</p>
<br>
<%= form_tag reset_database_path, class: "form-group" do %>
<div class="input-group">
<span class="input-group-addon">Password</span>
<%= text_field_tag :reset_password, params[:team_hash], class: "form-control" %>
<span class="input-group-btn">
<input type='submit' class='btn btn-primary' value='Reset' data-confirm="Are you absolutely sure you want to do this?"/>
</span>
</div>
<% end %>
<% else %>
<p>You don't have access to this page.</p>
<% end %>
</div>
</body>

1 change: 1 addition & 0 deletions app/views/shared/_head.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<li><%= link_to "Register New Admin", new_admin_path, {method: 'get'} %></li>
<% if Admin.find(session[:user_id]).superadmin == true %>
<li><%= link_to "Manage Admins", superadmin_path, {method: :get} %></li>
<li><%= link_to "Reset Semester", reset_semester_path, {method: :get} %></li>
<% end %>
<% end %>
<li><%= link_to "Logout", logout_path, {method: 'get'} %></li>
Expand Down
2 changes: 1 addition & 1 deletion app/views/team/team.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<% end %>
</div>
<div class="col-xs-2">
Warning: You need to submit your team to be considered for enrollment.
Warning: You need to submit your team to be considered for enrollment, make sure to do this when you have assembled your team.
</div>
<% else %>
<div class="col-xs-2">
Expand Down
22 changes: 11 additions & 11 deletions config/application.yml.asc
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
-----BEGIN PGP MESSAGE-----
Version: GnuPG v1

jA0EAwMCzX1vR3oXYmBgycDpNEJ2nY+FUGDFXJqpVTflmrPlXbyZFIu7mE3R8CDC
RcKxjx4MKOqCnfUUGDy22bZJNOzpKAEHtJ9AzOe9lkAtOWgxmmksUuTz5KpboDS0
GyceNC+ag8gqyEKGw51LjkcZEI5Ugx/tHz6tqJsR2iDVNe8RuiT175XY/KogmGqm
B9GDYikYf6TeOVYMT340wzlb9oLxL4OFtR4XmjCqkCXq7GLUt4/XiDCtR4O4LSTy
Ss2fN1LUwQtKbZRM15InSlmmIH90BNb4VUPMfS+dwIIYYW2X8VuJhSvYI2AR7A4s
78plK+XI2sRtfaWzDtGTZg96GnwjbmMwMyjyKMkIzkiKp7ivzJYh0Kvz7VgSnlkf
fM61EjbOHtjbnRPgTOe5e0K/kkN1tuWkVcL9pz9TomnQgctB/hNK5AAVut5HzKmk
Tz6Vwuocy81cdmPV/1nhFK7JaRB0/RQru9KgCwOAB3QTuxAOUyz8v1gLEmU8OL2c
0DaPHEsm0D+gYs7/B1pVb/F3QENWSIkr+qPa8nPH8QXCbeCA4jE4bT1TiTIcf7Le
wvADoTtansUTZu4=
=IbuS
jA0EAwMCG7xieGrm/C1gycEGmzipAKljnxD97E6CAnSAUgM/DUuC0YQaYulU6/bN
J4amg18l3zGOQho85119Gg4v46y3yLc0Bcq7f4RNF70j/S9iymouqvzzZNbxdOBn
ewl6Oxm/qXWKkXz31GmPnQSzB2i7meVmm4zMlWB8JZiFxbRcQT2pWXAIMddkGeHT
ycT2w6RdeeM980xVlZwClq0Ums5N+gSrOLk0A8MFeherejW40KOszdlr7o0kDv9h
3vRinSUsWFzBDg8y9KWIhPokwcaOiyDFbD7W8jPHsRMGxb1Nt+y1DzVnMm6/zje5
nxro961wsJXoOPZQRzjYYbQUqbDFfh4OVWRZyyi289oOKXqlRv9T/x+0HdakL2W3
bPnTCJ4c1alcM5e311FAmO8pswRI1m4fV+C8UX5Q80/DX/hd3O4ynzVxkEkO6EWA
ar+qpzsvLn+OimJhWHs4oGZgKoESBsPjHPEARyXxeZcSmMWbewwyt7KHk7IoMN++
fkJJTkF+XAApKN8YpYGJC7+a7ozfOiX5yGw+t6gB+SMoIDAZrIda83bAG+q+Q8IP
r/3Sg0LhQJBZsbi1hzD1JOSphWkErLj69UT1j5hl2YVsk8aLkIko/Q==
=pBsM
-----END PGP MESSAGE-----
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
get '/admin/approve_team', to: 'admins#approve'
get '/admin/disapprove_team', to: 'admins#disapprove'
get '/admin/superadmin', to: 'admins#superadmin', as: "superadmin"
get '/admin/reset_semester', to: 'admins#reset_semester', as: "reset_semester"
post '/admin/reset_database', to: 'admins#reset_database', as: "reset_database"
patch '/admin/transfer', to: 'admins#transfer', as: 'admin_transfer'
patch '/admin/delete', to: 'admins#delete', as: 'admin_delete'
get '/admin/tutorial', to: 'admins#admin_tutorial'
Expand Down
27 changes: 13 additions & 14 deletions features/admins/super_admin_delete_database.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Feature: Super admin deletes all data
I want to be able to delete the entire database

Background:
Given the following admin exists
| name | email | password |
| Bob | supreme_ruler@aol.com | ilikcats |
Given the following admins exist
| name | email | superadmin |
| Bob | supreme_ruler@aol.com | true |
Given the following users exist
| name | email | team | major | sid |
| Jorge | legueoflegends667@hotmail.com | somepassc | Football Player | 999 |
Expand All @@ -26,14 +26,13 @@ Feature: Super admin deletes all data
And I log in as an admin with email "[email protected]"

Scenario: Super admin successfully deletes everything from database
When PENDING: I press "Delete All Data"
Then PENDING: I should see "Warning: this will delete all users, teams, discussions, and sections"
And PENDING: I should see "Enter a password to confirm this action"
When PENDING: I fill in "enrollme"
And PENDING: I press "Enter"
Then PENDING: I should see "All data deleted"
And PENDING: I should not see "Jorge"
And PENDING: I should not see "Pending"
When PENDING: I press "Choose Discussions"
Then PENDING: I should not see "54321"

Then print page body
When I follow "Reset Semester"
Then I should see "Warning: Resetting the semester will result in all users, teams, and discussions being deleted."
And I should see "Password"
When I fill in "reset_password" with API['ADMIN_DELETE_DATA_PASSWORD']
And I press "Reset"
Then I should see "All data reset"
And I should not see "Jorge"
When I press "Discussions"
Then I should not see "54321"
3 changes: 2 additions & 1 deletion features/step_definitions/enrollme_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
end

And /^my team is submitted$/ do
Submission.create!(:disc1id => 1, :disc2id => 1, :disc3id => 1)
Submission.create!(:disc1id => 1, :disc2id => 1, :disc3id => 1, :team => @team)
@team.add_submission(1)
end

Expand Down Expand Up @@ -94,6 +94,7 @@
end
end


Then /^byebug$/ do
byebug
end
Expand Down

0 comments on commit 3ecdae6

Please sign in to comment.