/**
  * Returns true if $user can update this object
  *
  * @param User $user
  * @param string $manage_permission_name
  * @return boolean
  */
 function canEdit($user)
 {
     if ($this->getState() < STATE_VISIBLE) {
         return false;
     }
     // if
     $project = $this->getProject();
     if (!instance_of($project, 'Project')) {
         return false;
     }
     // if
     if ($user->isProjectManager() || $user->isProjectLeader($project)) {
         return true;
         // administrators and project managers have all permissions
     }
     // if
     if ($this->getVisibility() < VISIBILITY_NORMAL && !$user->canSeePrivate()) {
         return false;
     }
     // if
     if ($this->permission_name && $user->getProjectPermission($this->permission_name, $project) >= PROJECT_PERMISSION_MANAGE) {
         return true;
         // Management permissions
     }
     // if
     if ($this->getCreatedById() == $user->getId()) {
         return true;
         // Author
     }
     // if
     // Assingments
     //
     // If this object is not assigned to anyone in particular than anyone can
     // update it. If we have assignees than $user needs to be assigned to this
     // object in order to be able to update it
     if ($this->can_have_assignees) {
         if ($this->hasAssignees()) {
             return Assignments::isAssignee($user, $this);
         } else {
             return true;
         }
         // if
     }
     // if
     return false;
 }