diff --git a/app/controllers/invitations_controller.rb b/app/controllers/invitations_controller.rb index 9a39183..227d545 100644 --- a/app/controllers/invitations_controller.rb +++ b/app/controllers/invitations_controller.rb @@ -81,9 +81,20 @@ class InvitationsController < ApplicationController return redirect_to "/invitations" end + def delete_request + if !@user.is_moderator? return redirect_to "/invitations" - else - render :action => :build end + + if !(ir = InvitationRequest.where(:code => params[:code].to_s).first) + flash[:error] = "Invalid or expired invitation request" + return redirect_to "/invitations" + end + + ir.destroy! + flash[:success] = "Successfully deleted invitation request from " << + ir.name.to_s << "." + + return redirect_to "/invitations" end end diff --git a/app/views/invitations/index.html.erb b/app/views/invitations/index.html.erb index f1be44a..a8369ab 100644 --- a/app/views/invitations/index.html.erb +++ b/app/views/invitations/index.html.erb @@ -13,8 +13,11 @@ Date/Time Name - Memo + Memo + <% if @user.is_moderator? %> + + <% end %> <% bit = 0 %> <% @invitation_requests.each do |ir| %> @@ -22,18 +25,25 @@ <%= ir.created_at.strftime("%Y-%m-%d %H:%M:%S") %> <%= ir.name %> <%= raw ir.markeddown_memo %> - <%= form_tag send_invitation_for_request_url, :confirm => "Are " << - "you sure you want to invite this person and remove this request?" do %> + <%= form_tag send_invitation_for_request_url do %> <%= hidden_field_tag "code", ir.code %> - <%= submit_tag "Send Invitiation" %> + <%= submit_tag "Send Invitiation", :data => { :confirm => "Are " << + "you sure you want to invite this person and remove this request?" } %> <% end %> + <% if @user.is_moderator? %> + <%= form_tag delete_invitation_request_url do %> + <%= hidden_field_tag "code", ir.code %> + <%= submit_tag "Delete", :data => { :confirm => "Are you sure " << + "you want to delete this request?" } %> + <% end %> + <% end %> <% bit = (bit == 1 ? 0 : 1) %> <% end %> <% if @invitation_requests.count == 0 %> - No invitation - requests + align="center">No invitation requests <% end %> diff --git a/config/routes.rb b/config/routes.rb index 678f886..cb90e6d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -88,6 +88,8 @@ Lobsters::Application.routes.draw do post "/invitations/send_for_request" => "invitations#send_for_request", :as => "send_invitation_for_request" get "/invitations/:invitation_code" => "signup#invited" + post "/invitations/delete_request" => "invitations#delete_request", + :as => "delete_invitation_request" get "/moderations" => "moderations#index" get "/moderations/page/:page" => "moderations#index"