class TaskGroup




Hipposoft 2008


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.



Define default sort order for caller convenience.


Public Class Methods

active() click to toggle source

Want to do this, for future compatibility with Rails 4:

scope :active,   -> { where( :active => true  ) }
scope :inactive, -> { where( :active => false ) }

…however it breaks:

Thus, bypass the syntactic sugar and just write the methods.

# File app/models/task_group.rb, line 34
def;   where( :active => true  ); end
find_permitted( user, conditions = nil ) click to toggle source

Find all objects 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 64
def self.find_permitted( user, conditions = nil )

  # Can't see any items if no user is given. Can see all items if
  # the user is unrestricted.

  return [] unless user

  items = find( :all, { :conditions => conditions } )
  return items if user.privileged?

  allowed = []

  items.each do | item |
    allowed.push( item ) if item.is_permitted_for?( user )

  return allowed
inactive() click to toggle source
# File app/models/task_group.rb, line 35
def self.inactive; where( :active => false ); end

Public Instance Methods

augmented_title() click to toggle source

Return the object’s title. This is done for loose compatibility with a Task object during report generation.

# File app/models/task_group.rb, line 56
def augmented_title
  return self.title
can_be_modified_by?( user ) click to toggle source

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 87
def can_be_modified_by?( user )
  return false if ( user.restricted? )
  return true  if ( user.admin?      )
is_permitted_for?( user ) click to toggle source

Is permission granted for the given user to see this object? See also find_permitted. Returns ‘true’ if permitted, else ‘false’.

# File app/models/task_group.rb, line 96
def is_permitted_for?( user )
  return true if user.privileged?

  # User is restricted. User can only see this object if it
  # has at least one task associated with it and at least one
  # of those associated tasks appears in the user's permitted
  # task list, so check the intersection of the two arrays.

  return ( self.tasks & user.tasks ).length > 0