Improved change tracking: user login replaced by the full name if available

Added a tab into the CSV import: browse the CSV imports history
Finalized the read-only mode (distinguish between users and everybody, admin message displayed on top of the main screen)

SVN:trunk[1007]
This commit is contained in:
Romain Quetiez
2010-12-03 10:18:28 +00:00
parent 53d5867b93
commit d85aba8ebc
24 changed files with 503 additions and 132 deletions

View File

@@ -110,6 +110,35 @@ abstract class User extends cmdbAbstractObject
abstract public function CanChangePassword();
abstract public function ChangePassword($sOldPassword, $sNewPassword);
/*
* Compute a name in best effort mode
*/
public function GetFriendlyName()
{
if (!MetaModel::IsValidAttCode(get_class($this), 'contactid'))
{
return $this->Get('login');
}
if ($this->Get('contactid') != 0)
{
$sFirstName = $this->Get('first_name');
$sLastName = $this->Get('last_name');
$sEmail = $this->Get('email');
if (strlen($sFirstName) > 0)
{
return "$sFirstName $sLastName";
}
elseif (strlen($sEmail) > 0)
{
return "$sLastName <$sEmail>";
}
else
{
return $sLastName;
}
}
}
/*
* Overload the standard behavior
*/
@@ -490,6 +519,24 @@ class UserRights
return $oUser->Get('contactid');
}
// Render the user name in best effort mode
public static function GetUserFriendlyName($sName = '')
{
if (empty($sName))
{
$oUser = self::$m_oUser;
}
else
{
$oUser = FindUser($sName);
}
if (is_null($oUser))
{
return '';
}
return $oUser->GetFriendlyName();
}
public static function IsImpersonated()
{
if (is_null(self::$m_oRealUser))
@@ -517,6 +564,15 @@ class UserRights
return self::$m_oRealUser->GetKey();
}
public static function GetRealUserFriendlyName()
{
if (is_null(self::$m_oRealUser))
{
return '';
}
return self::$m_oRealUser->GetFriendlyName();
}
protected static function CheckLogin()
{
if (!self::IsLoggedIn())
@@ -551,8 +607,6 @@ class UserRights
// When initializing, we need to let everything pass trough
if (!self::CheckLogin()) return true;
if (self::IsAdministrator($oUser)) return true;
if (MetaModel::DBIsReadOnly())
{
if ($iActionCode == UR_ACTION_MODIFY) return false;
@@ -561,6 +615,8 @@ class UserRights
if ($iActionCode == UR_ACTION_BULK_DELETE) return false;
}
if (self::IsAdministrator($oUser)) return true;
if (MetaModel::HasCategory($sClass, 'bizmodel'))
{
// #@# Temporary?????
@@ -589,8 +645,6 @@ class UserRights
// When initializing, we need to let everything pass trough
if (!self::CheckLogin()) return true;
if (self::IsAdministrator($oUser)) return true;
if (MetaModel::DBIsReadOnly())
{
if ($iActionCode == UR_ACTION_MODIFY) return false;
@@ -599,6 +653,8 @@ class UserRights
if ($iActionCode == UR_ACTION_BULK_DELETE) return false;
}
if (self::IsAdministrator($oUser)) return true;
if (MetaModel::HasCategory($sClass, 'bizmodel'))
{
if (is_null($oUser))
@@ -619,8 +675,6 @@ class UserRights
// When initializing, we need to let everything pass trough
if (!self::CheckLogin()) return true;
if (self::IsAdministrator($oUser)) return true;
if (MetaModel::DBIsReadOnly())
{
if ($iActionCode == UR_ACTION_MODIFY) return false;
@@ -629,6 +683,8 @@ class UserRights
if ($iActionCode == UR_ACTION_BULK_DELETE) return false;
}
if (self::IsAdministrator($oUser)) return true;
// this module is forbidden for non admins
if (MetaModel::HasCategory($sClass, 'addon/userrights')) return false;