Created
December 3, 2008 20:55
-
-
Save adkron/31686 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'cgi' | |
module LoggedInControllerExtension | |
def self.included(base) | |
base.extend Setup | |
base.setup_logged_in | |
end | |
module Setup | |
def setup_logged_in | |
include InstanceMethods | |
before_filter :validate_ace_user | |
helper_method :current_user, :display_forecast_link?, :display_admin_home_link? | |
self.allow_forgery_protection = false | |
end | |
end | |
module InstanceMethods | |
protected | |
def current_user | |
@current_user | |
end | |
def validate_ace_user | |
username = session[ApplicationController::SESSION_KEY__USERNAME] | |
if username.nil? | |
if request.request_uri.length > 1 | |
referrer = "#{request.protocol}#{request.host_with_port}#{request.request_uri}" | |
session[ApplicationController::SESSION_KEY__REFERRER] = CGI::escape(referrer) | |
end | |
redirect_to :controller => "/login", :action => "index" | |
return false | |
end | |
@current_user = Member.find_by_username(username) | |
if (@current_user.inactive?) | |
flash[:error] = "Your account has been deactivated. For more information please contact support@#{AceConfig['email_domain']}" | |
clear_session | |
redirect_to :controller => '/login', :action => :index | |
end | |
true | |
end | |
def display_forecast_link? | |
@current_user.has_site_role?(:project_billing_admin) | |
end | |
def display_admin_home_link? | |
@current_user and @current_user.has_any_of_these_site_roles?( | |
:project_billing_admin, | |
:can_view_reports, | |
:hour_report_admin, | |
:news_admin, | |
:text_admin, | |
:template_task_admin, | |
:links_admin, | |
:work_order_admin | |
) | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.dirname(__FILE__) + '/../test_helper' | |
class LoggedInController < ApplicationController | |
include LoggedInControllerExtension | |
def web_method | |
render :text => '' | |
end | |
end | |
class LoggedInControllerTest < ActionController::TestCase | |
context "given an inactive user" do | |
setup do | |
get(:web_method, {}, {ApplicationController::SESSION_KEY__USERNAME => member(:inactive_user).username}) | |
end | |
should_respond_with :redirect | |
should_redirect_to "'/login'" | |
should_set_the_flash_to "Your account has been deactivated. For more information please contact support@#{AceConfig['email_domain']}" | |
should "clear session" do | |
assert_nil(@response.session[ApplicationController::SESSION_KEY__USERNAME]) | |
end | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+----------------------+-------+-------+---------+---------+-----+-------+ | |
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M | | |
+----------------------+-------+-------+---------+---------+-----+-------+ | |
| Controllers | 4137 | 3521 | 62 | 364 | 5 | 7 | | |
| Helpers | 975 | 812 | 0 | 119 | 0 | 4 | | |
| Models | 3946 | 3197 | 85 | 411 | 4 | 5 | | |
| Libraries | 6870 | 4844 | 71 | 418 | 5 | 9 | | |
| Integration tests | 1447 | 1217 | 19 | 20 | 1 | 58 | | |
| Functional tests | 7103 | 5181 | 90 | 561 | 6 | 7 | | |
| Unit tests | 7940 | 6000 | 100 | 639 | 6 | 7 | | |
+----------------------+-------+-------+---------+---------+-----+-------+ | |
| Total | 32418 | 24772 | 427 | 2532 | 5 | 7 | | |
+----------------------+-------+-------+---------+---------+-----+-------+ | |
Code LOC: 12374 Test LOC: 12398 Code to Test Ratio: 1:1.0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment