// to this function and then remove it.
}
- // isCoManager - determines whether current user is group comanager.
- // This is a legacy function that we are getting rid of by replacing with rights check.
- function isCoManager() {
- return ($this->can('manage_users') && !$this->can('export_data'));
- }
-
// isClient - determines whether current user is a client.
function isClient() {
return $this->is_client;
return true;
}
+ // markUserDeleted marks a user in group as deleted.
+ function markUserDeleted($user_id) {
+ if (!$this->can('manage_users') || $this->id == $user_id)
+ return false;
+
+ // Make sure we operate on a legit user.
+ $user_details = $this->getUser($user_id);
+ if (!$user_details) return false;
+
+ $mdb2 = getConnection();
+
+ // Mark user to project binds as deleted.
+ $sql = "update tt_user_project_binds set status = NULL where user_id = $user_id";
+ $affected = $mdb2->exec($sql);
+ if (is_a($affected, 'PEAR_Error'))
+ return false;
+
+ // Mark user favorite reports as deleted.
+ $sql = "update tt_fav_reports set status = NULL where user_id = $user_id";
+ $affected = $mdb2->exec($sql);
+ if (is_a($affected, 'PEAR_Error'))
+ return false;
+
+ // Mark user as deleted.
+ $sql = "update tt_users set status = NULL where id = $user_id and group_id = ".$this->group_id;
+ $affected = $mdb2->exec($sql);
+ if (is_a($affected, 'PEAR_Error'))
+ return false;
+
+ return true;
+ }
+
// enablePlugin either enables or disables a specific plugin for group.
function enablePlugin($plugin, $enable = true)
{
return true;
}
- // markDeleted - marks user and its associated things as deleted.
- static function markDeleted($user_id) {
- $mdb2 = getConnection();
- global $user;
-
- // Preliminary checks. Only managers and co-managers can do this.
- if (!$user->canManageTeam())
- return false;
-
- // Tho logic is different depending on who is doing the operation.
- // Co-manager - mark user deleted.
- // Manager - mark user deleted. If manager is the only account in group, mark group items deleted.
-
- // Co-manager part.
- if ($user->isCoManager()) {
- // Mark user binds as deleted.
- $sql = "update tt_user_project_binds set status = NULL where user_id = $user_id";
- $affected = $mdb2->exec($sql);
- if (is_a($affected, 'PEAR_Error'))
- return false;
-
- // Mark favorite reports as deleted.
- $sql = "update tt_fav_reports set status = NULL where user_id = $user_id";
- $affected = $mdb2->exec($sql);
- if (is_a($affected, 'PEAR_Error'))
- return false;
-
- // Mark user as deleted.
- $sql = "update tt_users set status = NULL where id = $user_id and group_id = ".$user->group_id;
- $affected = $mdb2->exec($sql);
- if (is_a($affected, 'PEAR_Error'))
- return false;
-
- } elseif ($user->isManager()) {
- $user_count = ttTeamHelper::getUserCount($user->group_id);
-
- // Marking deleted a manager with active users is not allowed.
- if (($user_id == $user->id) && ($user_count > 1))
- return false;
-
- if (1 == $user_count) {
- // Mark tasks deleted.
- if (!ttTeamHelper::markTasksDeleted($user->group_id))
- return false;
-
- // Mark projects deleted.
- $sql = "update tt_projects set status = NULL where group_id = $user->group_id";
- $affected = $mdb2->exec($sql);
- if (is_a($affected, 'PEAR_Error'))
- return false;
-
- // Mark clients deleted.
- $sql = "update tt_clients set status = NULL where group_id = $user->group_id";
- $affected = $mdb2->exec($sql);
- if (is_a($affected, 'PEAR_Error'))
- return false;
-
- // Mark custom fields deleted.
- $sql = "update tt_custom_fields set status = NULL where group_id = $user->group_id";
- $affected = $mdb2->exec($sql);
- if (is_a($affected, 'PEAR_Error'))
- return false;
-
- // Mark group deleted.
- $sql = "update tt_groups set status = NULL where id = $user->group_id";
- $affected = $mdb2->exec($sql);
- if (is_a($affected, 'PEAR_Error'))
- return false;
- }
-
- // Mark user binds as deleted.
- $sql = "update tt_user_project_binds set status = NULL where user_id = $user_id";
- $affected = $mdb2->exec($sql);
- if (is_a($affected, 'PEAR_Error'))
- return false;
-
- // Mark favorite reports as deleted.
- $sql = "update tt_fav_reports set status = NULL where user_id = $user_id";
- $affected = $mdb2->exec($sql);
- if (is_a($affected, 'PEAR_Error'))
- return false;
-
- // Mark user as deleted.
- $sql = "update tt_users set status = NULL where id = $user_id and group_id = ".$user->group_id;
- $affected = $mdb2->exec($sql);
- if (is_a($affected, 'PEAR_Error'))
- return false;
- }
-
- return true;
- }
-
// The delete function permanently deletes a user and all associated data.
static function delete($user_id) {
$mdb2 = getConnection();