module.itop-profiles-itil.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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. 'dictionary' => array(
  40. //'en.dict.itop-profiles-itil.php',
  41. //'fr.dict.itop-profiles-itil.php',
  42. //'de.dict.itop-profiles-itil.php',
  43. ),
  44. 'data.struct' => array(
  45. //'data.struct.itop-profiles-itil.xml',
  46. ),
  47. 'data.sample' => array(
  48. //'data.sample.itop-profiles-itil.xml',
  49. ),
  50. // Documentation
  51. //
  52. 'doc.manual_setup' => '',
  53. 'doc.more_information' => '',
  54. // Default settings
  55. //
  56. 'settings' => array(
  57. //'some_setting' => 'some value',
  58. ),
  59. )
  60. );
  61. // Module installation handler
  62. //
  63. class CreateITILProfilesInstaller extends ModuleInstallerAPI
  64. {
  65. public static function BeforeWritingConfig(Config $oConfiguration)
  66. {
  67. //$oConfiguration->SetModuleSetting('user-rigths-profile', 'myoption', 'myvalue');
  68. return $oConfiguration;
  69. }
  70. public static function AfterDatabaseCreation(Config $oConfiguration)
  71. {
  72. self::ComputeITILProfiles();
  73. //self::ComputeBasicProfiles();
  74. self::DoCreateProfiles();
  75. UserRights::FlushPrivileges(true /* reset admin cache */);
  76. }
  77. protected static $m_aActions = array(
  78. UR_ACTION_READ => 'Read',
  79. UR_ACTION_MODIFY => 'Modify',
  80. UR_ACTION_DELETE => 'Delete',
  81. UR_ACTION_BULK_READ => 'Bulk Read',
  82. UR_ACTION_BULK_MODIFY => 'Bulk Modify',
  83. UR_ACTION_BULK_DELETE => 'Bulk Delete',
  84. );
  85. // Note: It is possible to specify the same class in several modules
  86. //
  87. protected static $m_aModules = array();
  88. protected static $m_aProfiles = array();
  89. protected static function DoCreateActionGrant($iProfile, $iAction, $sClass, $bPermission = true)
  90. {
  91. $oNewObj = MetaModel::NewObject("URP_ActionGrant");
  92. $oNewObj->Set('profileid', $iProfile);
  93. $oNewObj->Set('permission', $bPermission ? 'yes' : 'no');
  94. $oNewObj->Set('class', $sClass);
  95. $oNewObj->Set('action', self::$m_aActions[$iAction]);
  96. $iId = $oNewObj->DBInsertNoReload();
  97. return $iId;
  98. }
  99. protected static function DoCreateStimulusGrant($iProfile, $sStimulusCode, $sClass)
  100. {
  101. $oNewObj = MetaModel::NewObject("URP_StimulusGrant");
  102. $oNewObj->Set('profileid', $iProfile);
  103. $oNewObj->Set('permission', 'yes');
  104. $oNewObj->Set('class', $sClass);
  105. $oNewObj->Set('stimulus', $sStimulusCode);
  106. $iId = $oNewObj->DBInsertNoReload();
  107. return $iId;
  108. }
  109. protected static function DoCreateOneProfile($sName, $aProfileData)
  110. {
  111. $sDescription = $aProfileData['description'];
  112. if (strlen(trim($aProfileData['write_modules'])) == 0)
  113. {
  114. $aWriteModules = array();
  115. }
  116. else
  117. {
  118. $aWriteModules = explode(',', trim($aProfileData['write_modules']));
  119. }
  120. if (strlen(trim($aProfileData['delete_modules'])) == 0)
  121. {
  122. $aDeleteModules = array();
  123. }
  124. else
  125. {
  126. $aDeleteModules = explode(',', trim($aProfileData['delete_modules']));
  127. }
  128. $aStimuli = $aProfileData['stimuli'];
  129. $oNewObj = MetaModel::NewObject("URP_Profiles");
  130. $oNewObj->Set('name', $sName);
  131. $oNewObj->Set('description', $sDescription);
  132. $iProfile = $oNewObj->DBInsertNoReload();
  133. // Grant read rights for everything
  134. //
  135. foreach (MetaModel::GetClasses('bizmodel') as $sClass)
  136. {
  137. self::DoCreateActionGrant($iProfile, UR_ACTION_READ, $sClass);
  138. self::DoCreateActionGrant($iProfile, UR_ACTION_BULK_READ, $sClass);
  139. }
  140. // Grant write for given modules
  141. // Start by compiling the information, because some modules may overlap
  142. $aWriteableClasses = array();
  143. foreach ($aWriteModules as $sModule)
  144. {
  145. //$oPage->p('Granting write access for the module"'.$sModule.'" - '.count(self::$m_aModules[$sModule]).' classes');
  146. foreach (self::$m_aModules[$sModule] as $sClass)
  147. {
  148. $aWriteableClasses[$sClass] = true;
  149. }
  150. }
  151. foreach ($aWriteableClasses as $sClass => $foo)
  152. {
  153. if (!MetaModel::IsValidClass($sClass))
  154. {
  155. throw new CoreException("Invalid class name '$sClass'");
  156. }
  157. self::DoCreateActionGrant($iProfile, UR_ACTION_MODIFY, $sClass);
  158. self::DoCreateActionGrant($iProfile, UR_ACTION_BULK_MODIFY, $sClass);
  159. }
  160. // Grant delete for given modules
  161. // Start by compiling the information, because some modules may overlap
  162. $aDeletableClasses = array();
  163. foreach ($aDeleteModules as $sModule)
  164. {
  165. //$oPage->p('Granting delete access for the module"'.$sModule.'" - '.count(self::$m_aModules[$sModule]).' classes');
  166. foreach (self::$m_aModules[$sModule] as $sClass)
  167. {
  168. $aDeletableClasses[$sClass] = true;
  169. }
  170. }
  171. foreach ($aDeletableClasses as $sClass => $foo)
  172. {
  173. if (!MetaModel::IsValidClass($sClass))
  174. {
  175. throw new CoreException("Invalid class name '$sClass'");
  176. }
  177. self::DoCreateActionGrant($iProfile, UR_ACTION_DELETE, $sClass);
  178. // By default, do not allow bulk deletion operations for standard users
  179. // self::DoCreateActionGrant($iProfile, UR_ACTION_BULK_DELETE, $sClass);
  180. }
  181. // Grant stimuli for given classes
  182. foreach ($aStimuli as $sClass => $sAllowedStimuli)
  183. {
  184. if (!MetaModel::IsValidClass($sClass))
  185. {
  186. // Could be a class defined in a module that wasn't installed
  187. continue;
  188. //throw new CoreException("Invalid class name '$sClass'");
  189. }
  190. if ($sAllowedStimuli == 'any')
  191. {
  192. $aAllowedStimuli = array_keys(MetaModel::EnumStimuli($sClass));
  193. }
  194. elseif ($sAllowedStimuli == 'none')
  195. {
  196. $aAllowedStimuli = array();
  197. }
  198. else
  199. {
  200. $aAllowedStimuli = explode(',', $sAllowedStimuli);
  201. }
  202. foreach ($aAllowedStimuli as $sStimulusCode)
  203. {
  204. self::DoCreateStimulusGrant($iProfile, $sStimulusCode, $sClass);
  205. }
  206. }
  207. }
  208. public static function DoCreateProfiles()
  209. {
  210. URP_Profiles::DoCreateAdminProfile();
  211. URP_Profiles::DoCreateUserPortalProfile();
  212. foreach(self::$m_aProfiles as $sName => $aProfileData)
  213. {
  214. self::DoCreateOneProfile($sName, $aProfileData);
  215. }
  216. }
  217. public static function ComputeBasicProfiles()
  218. {
  219. // In this profiling scheme, one single module represents all the classes
  220. //
  221. self::$m_aModules = array(
  222. 'UserData' => MetaModel::GetClasses('bizmodel'),
  223. );
  224. self::$m_aProfiles = array(
  225. 'Reader' => array(
  226. 'description' => 'Person having a ready-only access to the data',
  227. 'write_modules' => '',
  228. 'delete_modules' => '',
  229. 'stimuli' => array(
  230. ),
  231. ),
  232. 'Writer' => array(
  233. 'description' => 'Contributor to the contents (read + write access)',
  234. 'write_modules' => 'UserData',
  235. 'delete_modules' => 'UserData',
  236. 'stimuli' => array(
  237. // any class => 'any'
  238. ),
  239. ),
  240. );
  241. }
  242. public static function ComputeITILProfiles()
  243. {
  244. // In this profiling scheme, modules are based on ITIL recommendations
  245. //
  246. self::$m_aModules = array(
  247. 'General' => MetaModel::GetClasses('structure'),
  248. 'Documentation' => MetaModel::GetClasses('documentation'),
  249. 'Configuration' => MetaModel::GetClasses('configmgmt'),
  250. 'Incident' => MetaModel::GetClasses('incidentmgmt'),
  251. 'Problem' => MetaModel::GetClasses('problemmgmt'),
  252. 'Change' => MetaModel::GetClasses('changemgmt'),
  253. 'Service' => MetaModel::GetClasses('servicemgmt'),
  254. 'Call' => MetaModel::GetClasses('requestmgmt'),
  255. 'KnownError' => MetaModel::GetClasses('knownerrormgmt'),
  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' => 'Incident,Call',
  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',
  281. 'delete_modules' => 'Incident',
  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' => 'Problem,KnownError',
  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' => 'Change',
  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' => 'Change',
  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' => 'Change',
  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' => 'Service',
  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',
  336. 'stimuli' => array(
  337. ),
  338. ),
  339. );
  340. }
  341. }
  342. ?>