PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/itop-profiles-itil/module.itop-profiles-itil.php

https://github.com/adiakin/itop
PHP | 370 lines | 271 code | 28 blank | 71 comment | 11 complexity | 77f1d351dc8ec557f396660202194066 MD5 | raw file
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. SetupWebPage::AddModule(
  17. __FILE__, // Path to the current file, all other file names are relative to the directory containing this file
  18. 'itop-profiles-itil/1.0.0',
  19. array(
  20. // Identification
  21. //
  22. 'label' => 'Create standard ITIL profiles',
  23. 'category' => 'create_profiles',
  24. // Setup
  25. //
  26. 'dependencies' => array(
  27. ),
  28. 'mandatory' => true,
  29. 'visible' => false,
  30. 'installer' => 'CreateITILProfilesInstaller',
  31. // Components
  32. //
  33. 'datamodel' => array(
  34. //'model.itop-profiles-itil.php',
  35. ),
  36. 'webservice' => array(
  37. //'webservices.itop-profiles-itil.php',
  38. ),
  39. 'data.struct' => array(
  40. //'data.struct.itop-profiles-itil.xml',
  41. ),
  42. 'data.sample' => array(
  43. //'data.sample.itop-profiles-itil.xml',
  44. ),
  45. // Documentation
  46. //
  47. 'doc.manual_setup' => '',
  48. 'doc.more_information' => '',
  49. // Default settings
  50. //
  51. 'settings' => array(
  52. //'some_setting' => 'some value',
  53. ),
  54. )
  55. );
  56. // Module installation handler
  57. //
  58. class CreateITILProfilesInstaller extends ModuleInstallerAPI
  59. {
  60. public static function BeforeWritingConfig(Config $oConfiguration)
  61. {
  62. //$oConfiguration->SetModuleSetting('user-rigths-profile', 'myoption', 'myvalue');
  63. return $oConfiguration;
  64. }
  65. public static function AfterDatabaseCreation(Config $oConfiguration, $sPreviousVersion, $sCurrentVersion)
  66. {
  67. self::ComputeITILProfiles();
  68. //self::ComputeBasicProfiles();
  69. $bFirstInstall = empty($sPreviousVersion);
  70. self::DoCreateProfiles($bFirstInstall);
  71. UserRights::FlushPrivileges(true /* reset admin cache */);
  72. }
  73. // Note: It is possible to specify the same class in several modules
  74. //
  75. protected static $m_aModules = array();
  76. protected static $m_aProfiles = array();
  77. protected static function DoSetupProfile($sName, $aProfileData)
  78. {
  79. $sDescription = $aProfileData['description'];
  80. if (strlen(trim($aProfileData['write_modules'])) == 0)
  81. {
  82. $aWriteModules = array();
  83. }
  84. else
  85. {
  86. $aWriteModules = explode(',', trim($aProfileData['write_modules']));
  87. }
  88. if (strlen(trim($aProfileData['delete_modules'])) == 0)
  89. {
  90. $aDeleteModules = array();
  91. }
  92. else
  93. {
  94. $aDeleteModules = explode(',', trim($aProfileData['delete_modules']));
  95. }
  96. $aStimuli = $aProfileData['stimuli'];
  97. $iProfile = URP_Profiles::DoCreateProfile($sName, $sDescription);
  98. // Warning: BulkInsert is working because we will load one single class
  99. // having one single table !
  100. // the benefit is: 10 queries (1 per profile) instead of 1500
  101. // which divides the overall user rights setup process by 5
  102. DBObject::BulkInsertStart();
  103. // Grant read rights for everything
  104. //
  105. foreach (MetaModel::GetClasses('bizmodel') as $sClass)
  106. {
  107. URP_Profiles::DoCreateActionGrant($iProfile, UR_ACTION_READ, $sClass);
  108. URP_Profiles::DoCreateActionGrant($iProfile, UR_ACTION_BULK_READ, $sClass);
  109. }
  110. // Grant write for given modules
  111. // Start by compiling the information, because some modules may overlap
  112. $aWriteableClasses = array();
  113. foreach ($aWriteModules as $sModule)
  114. {
  115. //$oPage->p('Granting write access for the module"'.$sModule.'" - '.count(self::$m_aModules[$sModule]).' classes');
  116. foreach (self::$m_aModules[$sModule] as $sClass)
  117. {
  118. $aWriteableClasses[$sClass] = true;
  119. }
  120. }
  121. foreach ($aWriteableClasses as $sClass => $foo)
  122. {
  123. if (!MetaModel::IsValidClass($sClass))
  124. {
  125. throw new CoreException("Invalid class name '$sClass'");
  126. }
  127. URP_Profiles::DoCreateActionGrant($iProfile, UR_ACTION_MODIFY, $sClass);
  128. URP_Profiles::DoCreateActionGrant($iProfile, UR_ACTION_BULK_MODIFY, $sClass);
  129. }
  130. // Grant delete for given modules
  131. // Start by compiling the information, because some modules may overlap
  132. $aDeletableClasses = array();
  133. foreach ($aDeleteModules as $sModule)
  134. {
  135. //$oPage->p('Granting delete access for the module"'.$sModule.'" - '.count(self::$m_aModules[$sModule]).' classes');
  136. foreach (self::$m_aModules[$sModule] as $sClass)
  137. {
  138. $aDeletableClasses[$sClass] = true;
  139. }
  140. }
  141. foreach ($aDeletableClasses as $sClass => $foo)
  142. {
  143. if (!MetaModel::IsValidClass($sClass))
  144. {
  145. throw new CoreException("Invalid class name '$sClass'");
  146. }
  147. URP_Profiles::DoCreateActionGrant($iProfile, UR_ACTION_DELETE, $sClass);
  148. // By default, do not allow bulk deletion operations for standard users
  149. // URP_Profiles::DoCreateActionGrant($iProfile, UR_ACTION_BULK_DELETE, $sClass);
  150. }
  151. // Grant stimuli for given classes
  152. foreach ($aStimuli as $sClass => $sAllowedStimuli)
  153. {
  154. if (!MetaModel::IsValidClass($sClass))
  155. {
  156. // Could be a class defined in a module that wasn't installed
  157. continue;
  158. //throw new CoreException("Invalid class name '$sClass'");
  159. }
  160. if ($sAllowedStimuli == 'any')
  161. {
  162. $aAllowedStimuli = array_keys(MetaModel::EnumStimuli($sClass));
  163. }
  164. elseif ($sAllowedStimuli == 'none')
  165. {
  166. $aAllowedStimuli = array();
  167. }
  168. else
  169. {
  170. $aAllowedStimuli = explode(',', $sAllowedStimuli);
  171. }
  172. foreach ($aAllowedStimuli as $sStimulusCode)
  173. {
  174. URP_Profiles::DoCreateStimulusGrant($iProfile, $sStimulusCode, $sClass);
  175. }
  176. }
  177. // Again: this is working only because action/stimulus grant are classes made of a single table!
  178. DBObject::BulkInsertFlush();
  179. }
  180. /*
  181. * Create the built-in User Portal profile with its reserved name
  182. */
  183. public static function DoCreateUserPortalProfile()
  184. {
  185. // Do not attempt to create this profile if the module 'User Request Management' is not installed
  186. // Note: ideally, the creation of this profile should be moved to the 'User Request Management' module
  187. if (!MetaModel::IsValidClass('UserRequest')) return;
  188. $iNewId = URP_Profiles::DoCreateProfile(PORTAL_PROFILE_NAME, 'Has the rights to access to the user portal. People having this profile will not be allowed to access the standard application, they will be automatically redirected to the user portal.', true /* reserved name */);
  189. // Grant read rights for everything
  190. //
  191. foreach (MetaModel::GetClasses('bizmodel') as $sClass)
  192. {
  193. URP_Profiles::DoCreateActionGrant($iNewId, UR_ACTION_READ, $sClass);
  194. URP_Profiles::DoCreateActionGrant($iNewId, UR_ACTION_BULK_READ, $sClass);
  195. }
  196. // Can create UserRequests and attach Documents to it
  197. URP_Profiles::DoCreateActionGrant($iNewId, UR_ACTION_MODIFY, 'UserRequest');
  198. URP_Profiles::DoCreateActionGrant($iNewId, UR_ACTION_MODIFY, 'lnkTicketToDoc');
  199. URP_Profiles::DoCreateActionGrant($iNewId, UR_ACTION_DELETE, 'lnkTicketToDoc');
  200. URP_Profiles::DoCreateActionGrant($iNewId, UR_ACTION_MODIFY, 'FileDoc');
  201. // Can close user requests
  202. URP_Profiles::DoCreateStimulusGrant($iNewId, 'ev_close', 'UserRequest');
  203. }
  204. public static function DoCreateProfiles($bFirstInstall = true)
  205. {
  206. URP_Profiles::DoCreateAdminProfile(); // Will be created only if it does not exist
  207. self::DoCreateUserPortalProfile(); // Will be created only if it does not exist and updated otherwise
  208. foreach(self::$m_aProfiles as $sName => $aProfileData)
  209. {
  210. self::DoSetupProfile($sName, $aProfileData);
  211. }
  212. }
  213. public static function ComputeBasicProfiles()
  214. {
  215. // In this profiling scheme, one single module represents all the classes
  216. //
  217. self::$m_aModules = array(
  218. 'UserData' => MetaModel::GetClasses('bizmodel'),
  219. );
  220. self::$m_aProfiles = array(
  221. 'Reader' => array(
  222. 'description' => 'Person having a ready-only access to the data',
  223. 'write_modules' => '',
  224. 'delete_modules' => '',
  225. 'stimuli' => array(
  226. ),
  227. ),
  228. 'Writer' => array(
  229. 'description' => 'Contributor to the contents (read + write access)',
  230. 'write_modules' => 'UserData',
  231. 'delete_modules' => 'UserData',
  232. 'stimuli' => array(
  233. // any class => 'any'
  234. ),
  235. ),
  236. );
  237. }
  238. public static function ComputeITILProfiles()
  239. {
  240. // In this profiling scheme, modules are based on ITIL recommendations
  241. //
  242. self::$m_aModules = array(
  243. 'General' => MetaModel::GetClasses('structure'),
  244. 'Documentation' => MetaModel::GetClasses('documentation'),
  245. 'Configuration' => MetaModel::GetClasses('configmgmt'),
  246. 'Incident' => MetaModel::GetClasses('incidentmgmt'),
  247. 'Problem' => MetaModel::GetClasses('problemmgmt'),
  248. 'Change' => MetaModel::GetClasses('changemgmt'),
  249. 'Service' => MetaModel::GetClasses('servicemgmt'),
  250. 'Call' => MetaModel::GetClasses('requestmgmt'),
  251. 'KnownError' => MetaModel::GetClasses('knownerrormgmt'),
  252. 'LnkTickets' => MetaModel::GetClasses('lnkticket'),
  253. 'LnkIncidents' => MetaModel::GetClasses('lnkincident'),
  254. 'LnkServices' => MetaModel::GetClasses('lnkservice'),
  255. 'LnkKnownErrors' => MetaModel::GetClasses('lnkknownerror'),
  256. );
  257. self::$m_aProfiles = array(
  258. 'Configuration Manager' => array(
  259. 'description' => 'Person in charge of the documentation of the managed CIs',
  260. 'write_modules' => 'General,Documentation,Configuration',
  261. 'delete_modules' => 'General,Documentation,Configuration',
  262. 'stimuli' => array(
  263. //'Server' => 'none',
  264. //'Contract' => 'none',
  265. //'IncidentTicket' => 'none',
  266. //'ChangeTicket' => 'any',
  267. ),
  268. ),
  269. 'Service Desk Agent' => array(
  270. 'description' => 'Person in charge of creating incident reports',
  271. 'write_modules' => 'Incident,Call',
  272. 'delete_modules' => 'LnkTickets,LnkIncidents',
  273. 'stimuli' => array(
  274. 'Incident' => 'ev_assign',
  275. 'UserRequest' => 'ev_assign',
  276. ),
  277. ),
  278. 'Support Agent' => array(
  279. 'description' => 'Person analyzing and solving the current incidents',
  280. 'write_modules' => 'Incident,Call',
  281. 'delete_modules' => 'LnkTickets,LnkIncidents',
  282. 'stimuli' => array(
  283. 'Incident' => 'ev_assign,ev_reassign,ev_resolve,ev_close',
  284. 'UserRequest' => 'ev_assign,ev_reassign,ev_resolve,ev_close,ev_freeze',
  285. ),
  286. ),
  287. 'Problem Manager' => array(
  288. 'description' => 'Person analyzing and solving the current problems',
  289. 'write_modules' => 'Problem,KnownError',
  290. 'delete_modules' => 'LnkTickets,LnkKnownErrors',
  291. 'stimuli' => array(
  292. 'Problem' => 'ev_assign,ev_reassign,ev_resolve,ev_close',
  293. ),
  294. ),
  295. 'Change Implementor' => array(
  296. 'description' => 'Person executing the changes',
  297. 'write_modules' => 'Change',
  298. 'delete_modules' => 'LnkTickets',
  299. 'stimuli' => array(
  300. 'NormalChange' => 'ev_plan,ev_replan,ev_implement,ev_monitor',
  301. 'EmergencyChange' => 'ev_plan,ev_replan,ev_implement,ev_monitor',
  302. 'RoutineChange' => 'ev_plan,ev_replan,ev_implement,ev_monitor',
  303. ),
  304. ),
  305. 'Change Supervisor' => array(
  306. 'description' => 'Person responsible for the overall change execution',
  307. 'write_modules' => 'Change',
  308. 'delete_modules' => 'LnkTickets',
  309. 'stimuli' => array(
  310. 'NormalChange' => 'ev_validate,ev_reject,ev_assign,ev_reopen,ev_finish',
  311. 'EmergencyChange' => 'ev_assign,ev_reopen,ev_finish',
  312. 'RoutineChange' => 'ev_assign,ev_reopen,ev_finish',
  313. ),
  314. ),
  315. 'Change Approver' => array(
  316. 'description' => 'Person who could be impacted by some changes',
  317. 'write_modules' => 'Change',
  318. 'delete_modules' => 'LnkTickets',
  319. 'stimuli' => array(
  320. 'NormalChange' => 'ev_approve,ev_notapprove',
  321. 'EmergencyChange' => 'ev_approve,ev_notapprove',
  322. 'RoutineChange' => 'none',
  323. ),
  324. ),
  325. 'Service Manager' => array(
  326. 'description' => 'Person responsible for the service delivered to the [internal] customer',
  327. 'write_modules' => 'Service',
  328. 'delete_modules' => 'LnkServices',
  329. 'stimuli' => array(
  330. ),
  331. ),
  332. 'Document author' => array(
  333. 'description' => 'Any person who could contribute to documentation',
  334. 'write_modules' => 'Documentation',
  335. 'delete_modules' => 'Documentation,LnkTickets',
  336. 'stimuli' => array(
  337. ),
  338. ),
  339. );
  340. }
  341. }
  342. ?>