class TaskGroup

File

task_group.rb

(C)

Hipposoft 2008

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.

Constants

DEFAULT_SORT_COLUMN

Define default sort order for caller convenience.

DEFAULT_SORT_DIRECTION
DEFAULT_SORT_ORDER

Public Class Methods

find_permitted( user, conditions = nil ) click to toggle source

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
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 )
  end

  return allowed
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 45
def augmented_title
  return self.title
end
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 76
def can_be_modified_by?( user )
  return false if ( user.restricted? )
  return true  if ( user.admin?      )
  return self.active
end
is_permitted_for?( user ) click to toggle source

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
def is_permitted_for?( user )
  return true if user.privileged?

  # User is restricted. User can only see this project 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 false if ( self.tasks.empty? )
  return true  if ( self.tasks & user.tasks ).length > 0

  # None of the project's tasks are in the user's permitted
  # list, so the user is not permitted to see this project.

  return false
end