Skip to content

Commit

Permalink
Making a commit before deleting something that's potentially important
Browse files Browse the repository at this point in the history
  • Loading branch information
iamringo committed Jun 3, 2009
1 parent 0aa7e75 commit 1e62988
Show file tree
Hide file tree
Showing 6 changed files with 8,452 additions and 57 deletions.
8 changes: 7 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
before_filter :delete_user_permission_cache
before_filter :set_user_exists
include HoptoadNotifier::Catcher
helper_method :get_department
helper_method :get_user

protected
# Returns a valid user model based on whether the user exists in the database
def get_user
session[:user_exists] ? User.find_by_login(session[:user]) : User.new(:login => session[:user])
session[:user_exists] ? User.find_by_login(session[:casfilteruser]) : User.new(:login => session[:casfilteruser])
end

def delete_user_permission_cache
get_user.delete_permission_cache
end

def set_user_exists
session[:user_exists] = true if User.find_by_login(session[:casfilteruser])
end

#get department choice off the session
def get_department
# y session["current_chooser_choice"]
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/index_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ class IndexController < ApplicationController
# Check authentication with CAS login
before_filter CASClient::Frameworks::Rails::Filter
before_filter :chooser

def index
# raise get_user.to_yaml
# raise user.to_yaml
# raise session.to_yaml
end
end
22 changes: 11 additions & 11 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
module ApplicationHelper
# Returns a valid user model based on whether the user exists
# in the database
def get_user
if session[:user]
if session[:user_exists]
return User.find_by_login(session[:user])
else
return User.new(:login => session[:user])
end
end
end
# def get_user
# if session[:user]
# if session[:user_exists]
# return User.find_by_login(session[:casfilteruseruser])
# else
# return User.new(:login => session[:casfilteruseruser])
# end
# end
# end

def notice_script(div = 'notice', notice=flash[:notice], message="Message:", timeout=0)
#I know these are redundant, but I was having issues passing flash values:
Expand All @@ -23,9 +23,9 @@ def notice_script(div = 'notice', notice=flash[:notice], message="Message:", tim
javascript_tag "$('#{div}').hide();#{notice_popup(notice, message)};" + (timeout > 0 ? "setTimeout('hide_box()', #{timeout});" : "")
end

def has_any_admin_item?(items)
def has_any_admin_item?(items, user)
for item in items
return true if (CASACL.auth_index?(user ||= get_user, item))
return true if (user.permission_strings.include?(item))
end
return false
end
Expand Down
83 changes: 42 additions & 41 deletions app/models/payform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,60 @@ class Payform < ActiveRecord::Base
has_and_belongs_to_many :payform_items
belongs_to :department
belongs_to :user

validates_presence_of :week, :year, :department_id, :user_id
named_scope :unsubmitted, lambda { |dept_id| {

named_scope :unsubmitted, lambda { |dept_id| {
:conditions => ["department_id = ? AND submitted IS ?", dept_id, nil]
}}
named_scope :unapproved, lambda { |dept_id| {
:conditions => ["department_id = ? AND submitted IS NOT ? AND approved IS ?", dept_id, nil, nil]
}}
named_scope :unprinted, lambda { |dept_id| {
:conditions => ["department_id = ? AND approved IS NOT ? AND printed IS ?", dept_id, nil, nil]
named_scope :unapproved, lambda { |dept_id| {
:conditions => ["department_id = ? AND submitted IS NOT ? AND approved IS ?", dept_id, nil, nil]
}}
named_scope :unprinted, lambda { |dept_id| {
:conditions => ["department_id = ? AND approved IS NOT ? AND printed IS ?", dept_id, nil, nil]
}}
named_scope :in_department, lambda { |dept_id| { :conditions => ["department_id = ?", dept_id] }}

def get_status_text
self.printed ? 'printed' : self.approved ? 'approved' : self.submitted ? 'submitted' : 'unsubmitted'
end

def get_dates
Payform.get_days(self.year, self.week)
end

def get_date
Payform.get_day(self.year, self.week)
end

def self.get_days (year, week)
dates = []
7.times {|n| d = get_day(year, week)+(n-6)
7.times {|n| d = get_day(year, week)+(n-6)
dates << d unless d > Date.today}
dates
end

def self.get_day (year, week)
Date.commercial(year, week, 6)
end

def valid_user?(user)
self.user_id == user.id ? true : false
end

def authorized?(user, controller_name)
if controller_name == 'payform'
self.user_id == user.id and user.authorized?(self.department.payform_configuration.payform_permission.name) ? true : false
else
user.authorized?(self.department.payform_configuration.payform_admin_permission.name) ? true : false
end
end

#gets the payform with the given commercial week#, year, user id, and department id
def self.get_payform(week, year, user, department)
Payform.first(:conditions => ["user_id = ? and week = ? and year = ? and department_id = ?", user.id, week, year, department.id])
end

#finds or creates a payform with the given week, year, user, and department
def self.find_or_create(week, year, user, department)
payform = Payform.get_payform(week, year, user, department)
Expand All @@ -64,7 +64,7 @@ def self.find_or_create(week, year, user, department)
end
payform
end

def unsubmit
if self.submitted and !self.printed
self.submitted = self.approved = self.approved_by = nil
Expand All @@ -76,7 +76,7 @@ def unsubmit
end
return true
end

def unapprove
if self.approved and !self.printed
self.approved = nil
Expand All @@ -88,15 +88,15 @@ def unapprove
end
return true
end

def total_hours
@total_hours ||= round_up_to_nearest_quarter_hour self.payform_items.active.to_a.sum(&:hours)
end

def category_hours(cat_id)
self.payform_items.to_a.sum { |p| (p.category_id == cat_id and p.active?) ? p.hours : 0 }
end

# admin returns all jobs, otherwise only active jobs returned
# OPTIMIZE: should this be a helper method since you are getting the "admin" value from the is_admin? helper method
def misc_jobs(admin=false)
Expand All @@ -106,18 +106,27 @@ def misc_jobs(admin=false)
end
admin ? m_jobs : (m_jobs.compact.collect do |p| p if p.active? end).compact
end


def has_active_shifts?
current_report = ShiftReport.find_current_report(self.user)
if current_report && current_report.start < (self.get_date + 1)
return true
else
return false
end
end

protected

# METHODS TO ROUND TOTAL HOURS TO NEAREST QUARTER HOUR
def round_up_to_nearest_quarter_hour(hours)
round_up(hours*4)/4
end

def round_up(num, nearest=1)
num % nearest == 0 ? num : num + nearest - (num % nearest)
end

def validate
if (approved or printed) and !submitted
errors.add("Cannot approve or print unsubmitted payform, so the submitted field")
Expand All @@ -129,19 +138,11 @@ def validate
errors.add("Payform owner is not authorized for payform department")
end
end

private

def has_active_shifts?
current_report = ShiftReport.find_current_report(self.user)
if current_report && current_report.start < (self.get_date + 1)
return true
else
return false
end
end











end
8 changes: 5 additions & 3 deletions app/views/layouts/include/nav.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<ul id="miniTabs">
<% if (user = get_user) %>
<li><%= link_to "Home", { :controller => "/", :action => "index" } %></li>
<% if (has_any_admin_item?(['user_admin', 'admin/main', 'applicants'])) %>
<% if (has_any_admin_item?(['user_admin', 'admin/main', 'applicants'], user)) %>
<li>
<% if (CASACL.auth_index?(user, 'user_admin')) %>
<% if (user.permission_strings.include? 'user_admin') %>
<%= link_to "User Admin", { :controller => "/user_admin", :action => "index" } %>
<% end %>
</li>
Expand All @@ -13,4 +13,6 @@
<li><%= link_if_authorized 'payform' %></li>
<li><%= link_if_authorized 'payform_admin' %></li>
<% end %>
</ul>
<%# raise user.to_yaml %>
</ul>

Loading

0 comments on commit 1e62988

Please sign in to comment.