Class | TaskGroup |
In: |
app/models/task_group.rb
|
Parent: | ActiveRecord::Base |
File: | task_group.rb |
(C): | Hipposoft 2008, 2009 |
Purpose: | Base class for things which group tasks, such as Projects or Customers. See below for more details. |
07-Mar-2008 (ADH): Created from project.rb.
DEFAULT_SORT_COLUMN | = | 'title' | Define default sort order for caller convenience. | |
DEFAULT_SORT_DIRECTION | = | 'ASC' | ||
DEFAULT_SORT_ORDER | = | "#{ DEFAULT_SORT_COLUMN } #{ DEFAULT_SORT_DIRECTION }" |
Find all projects which the given user is allowed to see. A conditions hash may be passed to further restrict the search (that is, the "{…}" in "find( :all, :conditions => {…})").
# File app/models/task_group.rb, line 53 53: def self.find_permitted( user, conditions = nil ) 54: 55: # Can't see any items if no user is given. Can see all items if 56: # the user is unrestricted. 57: 58: return [] unless user 59: 60: items = find( :all, { :conditions => conditions } ) 61: return items if user.privileged? 62: 63: allowed = [] 64: 65: items.each do | item | 66: allowed.push( item ) if item.is_permitted_for?( user ) 67: end 68: 69: return allowed 70: end
Is the given user permitted to update this object? Restricted users cannot modify things. Administrators always can. Managers only can if the object is still active.
# File app/models/task_group.rb, line 76 76: def can_be_modified_by?( user ) 77: return false if ( user.restricted? ) 78: return true if ( user.admin? ) 79: return self.active 80: end
Is permission granted for the given user to see this project? See also find_permitted. Returns ‘true’ if permitted, else ‘false’.
# File app/models/task_group.rb, line 85 85: def is_permitted_for?( user ) 86: return true if user.privileged? 87: 88: # User is restricted. User can only see this project if it 89: # has at least one task associated with it and at least one 90: # of those associated tasks appears in the user's permitted 91: # task list, so check the intersection of the two arrays. 92: 93: return false if ( self.tasks.empty? ) 94: return true if ( self.tasks & user.tasks ).length > 0 95: 96: # None of the project's tasks are in the user's permitted 97: # list, so the user is not permitted to see this project. 98: 99: return false 100: end