Skip to content

Commit

Permalink
Notifies admin user about password recovery requests.
Browse files Browse the repository at this point in the history
Admin is able to hide notifications.
  • Loading branch information
marano committed Aug 17, 2011
1 parent 792b730 commit 46fa7db
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 8 deletions.
6 changes: 6 additions & 0 deletions app/controllers/password_recovery_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ def create
render :new
end
end

def hide
PasswordRecoveryRequest.get(params[:password_recovery_request_id]).hide!
flash[:notice] = 'Password request notification was succefully hidden.'
redirect_to root_path
end
end
15 changes: 15 additions & 0 deletions app/models/password_recovery_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@ class PasswordRecoveryRequest < CouchRestRails::Document
include CouchRest::Validation

property :user_name
property :hidden, :cast_as => :boolean, :default => false

timestamps!

validates_presence_of :user_name

def ==(other)
user_name == other.user_name
end

def hide!
self.hidden = true
save
end

def self.to_display
PasswordRecoveryRequest.all.select { |request| request.hidden == false }
end
end
11 changes: 11 additions & 0 deletions app/views/home/_notifications.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% if is_admin? %>
<% @notifications = PasswordRecoveryRequest.to_display %>
<% unless @notifications.empty? %>
<p>These users requested password reset. Please contact them immediatly.<ul>
<ul>
<% @notifications.each do |notification| %>
<li><%= "#{notification.user_name} at #{time_ago_in_words notification.created_at} ago #{link_to("hide", hide_password_recovery_request_path(notification), :method => :delete)}" %></li>
<% end %>
</ul>
<% end %>
<% end %>
3 changes: 3 additions & 0 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<h2>Welcome to RapidFTR</h2>

<%= render 'notifications' %>

<p>
<% form_for @user, :url => user_preference_path(current_user_name), :html => {:method => :put} do |f| %>
<%= label_tag "user_time_zone", "Current time zone" %>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
map.admin 'admin', :controller=>"admin", :action=>"index"
map.resources :sessions, :except => :index
map.resources :password_recovery_requests, :only => [:new, :create]
map.hide_password_recovery_request 'password_recovery_request/:password_recovery_request_id/hide', :controller => "password_recovery_requests", :action => "hide", :via => :delete

map.login 'login', :controller=>'sessions', :action =>'new'
map.logout 'logout', :controller=>'sessions', :action =>'destroy'
Expand Down
22 changes: 22 additions & 0 deletions features/password_recovery_request.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,25 @@ Feature: As an user, I should be able to request my password to be recovered.
When I press "Request Password"

Then I should see "Thank you. A RapidFTR administrator will contact you shortly. If possible, contact the admin directly."


Scenario: An Admin user is able to see unhidden password recovery requests when he logs in
Given a password recovery request for duck

Given I am logged in as an admin

Given I am on the home page

Then I should see "hide"


Scenario: An Admin user is able to hide notifications
Given a password recovery request for duck

Given I am logged in as an admin

Given I am on the home page

When I follow "hide"

Then I should not see "duck"
6 changes: 3 additions & 3 deletions features/step_definitions/database_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@
ContactInformation.create contact_info
end




Given /^a password recovery request for (.+)$/ do |username|
PasswordRecoveryRequest.new(:user_name => username).save
end
1 change: 1 addition & 0 deletions features/support/reset_couchdb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
User.all.each {|u| u.destroy }
SuggestedField.all.each {|u| u.destroy }
ContactInformation.all.each {|c| c.destroy }
PasswordRecoveryRequest.all.each {|c| c.destroy }
RapidFTR::FormSectionSetup.reset_definitions
Sunspot.remove_all!(Child)
Sunspot.commit
Expand Down
19 changes: 14 additions & 5 deletions spec/models/password_recovery_request_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
require 'spec_helper'

describe Login do
describe "validation" do
it "" do
password_recovery_request = PasswordRecoveryRequest.new :user_name => ""
password_recovery_request.should_not be_valid
describe PasswordRecoveryRequest do
context 'a new request' do
before do
@request = PasswordRecoveryRequest.new :user_name => "duck"
@request.save
end
it "should tell new requests that were not hidden" do
PasswordRecoveryRequest.to_display.should =~ [ @request ]
end
context 'hiding a request' do
before { @request.hide! }
it 'should not be displayed' do
PasswordRecoveryRequest.to_display.should =~ []
end
end
end
end

0 comments on commit 46fa7db

Please sign in to comment.