userrightsprofile.class.inc.php 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729
  1. <?php
  2. /**
  3. * UserRightsProfile
  4. * User management Module, basing the right on profiles and a matrix (similar to UserRightsMatrix, but profiles and other decorations have been added)
  5. *
  6. * @package iTopORM
  7. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  8. * @author Denis Flaven <denisflave@free.fr>
  9. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  10. * @link www.itop.com
  11. * @since 1.0
  12. * @version 1.1.1.1 $
  13. */
  14. define('ADMIN_PROFILE_ID', 1);
  15. class UserRightsBaseClass extends cmdbAbstractObject
  16. {
  17. // Whenever something changes, reload the privileges
  18. public function DBInsertTracked(CMDBChange $oChange)
  19. {
  20. parent::DBInsertTracked($oChange);
  21. UserRights::FlushPrivileges();
  22. }
  23. public function DBUpdateTracked(CMDBChange $oChange)
  24. {
  25. parent::DBUpdateTracked($oChange);
  26. UserRights::FlushPrivileges();
  27. }
  28. public function DBDeleteTracked(CMDBChange $oChange)
  29. {
  30. parent::DBDeleteTracked($oChange);
  31. UserRights::FlushPrivileges();
  32. }
  33. }
  34. class URP_Users extends UserRightsBaseClass
  35. {
  36. public static function Init()
  37. {
  38. $aParams = array
  39. (
  40. "category" => "addon/userrights",
  41. "key_type" => "autoincrement",
  42. "key_label" => "",
  43. "name_attcode" => "login",
  44. "state_attcode" => "",
  45. "reconc_keys" => array(),
  46. "db_table" => "priv_urp_users",
  47. "db_key_field" => "id",
  48. "db_finalclass_field" => "",
  49. "display_template" => "",
  50. );
  51. MetaModel::Init_Params($aParams);
  52. //MetaModel::Init_InheritAttributes();
  53. MetaModel::Init_AddAttribute(new AttributeExternalKey("userid", array("targetclass"=>"bizPerson", "allowed_values"=>null, "sql"=>"userid", "is_null_allowed"=>true, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array())));
  54. MetaModel::Init_AddAttribute(new AttributeExternalField("last_name", array("allowed_values"=>null, "extkey_attcode"=> 'userid', "target_attcode"=>"name")));
  55. MetaModel::Init_AddAttribute(new AttributeExternalField("first_name", array("allowed_values"=>null, "extkey_attcode"=> 'userid', "target_attcode"=>"first_name")));
  56. MetaModel::Init_AddAttribute(new AttributeExternalField("email", array("allowed_values"=>null, "extkey_attcode"=> 'userid', "target_attcode"=>"email")));
  57. MetaModel::Init_AddAttribute(new AttributeString("login", array("allowed_values"=>null, "sql"=>"login", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  58. MetaModel::Init_AddAttribute(new AttributePassword("password", array("allowed_values"=>null, "sql"=>"pwd", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  59. MetaModel::Init_AddAttribute(new AttributeEnum("language", array("allowed_values"=>new ValueSetEnum('EN US,FR FR'), "sql"=>"language", "default_value"=>"EN US", "is_null_allowed"=>false, "depends_on"=>array())));
  60. MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("profiles", array("linked_class"=>"URP_UserProfile", "ext_key_to_me"=>"userid", "ext_key_to_remote"=>"profileid", "allowed_values"=>null, "count_min"=>1, "count_max"=>0, "depends_on"=>array())));
  61. //MetaModel::Init_InheritFilters();
  62. MetaModel::Init_AddFilterFromAttribute("userid");
  63. MetaModel::Init_AddFilterFromAttribute("login");
  64. MetaModel::Init_AddFilterFromAttribute("password");
  65. // Display lists
  66. MetaModel::Init_SetZListItems('details', array('userid', 'first_name', 'email', 'login', 'language')); // Attributes to be displayed for the complete details
  67. MetaModel::Init_SetZListItems('list', array('first_name', 'last_name', 'login')); // Attributes to be displayed for a list
  68. // Search criteria
  69. MetaModel::Init_SetZListItems('standard_search', array('login', 'userid')); // Criteria of the std search form
  70. MetaModel::Init_SetZListItems('advanced_search', array('login', 'userid')); // Criteria of the advanced search form
  71. }
  72. function GetGrantAsHtml($sClass, $iAction)
  73. {
  74. if (UserRights::IsActionAllowed($sClass, $iAction, null, $this->GetKey()))
  75. {
  76. return '<span style="background-color: #ddffdd;">yes</span>';
  77. }
  78. else
  79. {
  80. return '<span style="background-color: #ffdddd;">no</span>';
  81. }
  82. }
  83. function DoShowGrantSumary($oPage, $sClassCategory)
  84. {
  85. $iUserId = $this->GetKey();
  86. if (UserRights::IsAdministrator($iUserId))
  87. {
  88. // Looks dirty, but ok that's THE ONE
  89. $oPage->p('Has Read/Write access to any object in the database.');
  90. return;
  91. }
  92. $aDisplayData = array();
  93. foreach (MetaModel::GetClasses($sClassCategory) as $sClass)
  94. {
  95. $aClassStimuli = MetaModel::EnumStimuli($sClass);
  96. if (count($aClassStimuli) > 0)
  97. {
  98. $aStimuli = array();
  99. foreach ($aClassStimuli as $sStimulusCode => $oStimulus)
  100. {
  101. if (UserRights::IsStimulusAllowed($sClass, $sStimulusCode, null, $iUserId))
  102. {
  103. $aStimuli[] = '<span title="'.$sStimulusCode.': '.htmlentities($oStimulus->GetDescription()).'">'.htmlentities($oStimulus->GetLabel()).'</span>';
  104. }
  105. }
  106. $sStimuli = implode(', ', $aStimuli);
  107. }
  108. else
  109. {
  110. $sStimuli = '<em title="no lifecycle has been defined for this class">n/a</em>';
  111. }
  112. $aDisplayData[] = array(
  113. 'class' => MetaModel::GetName($sClass),
  114. 'read' => $this->GetGrantAsHtml($sClass, UR_ACTION_READ),
  115. 'bulkread' => $this->GetGrantAsHtml($sClass, UR_ACTION_BULK_READ),
  116. 'write' => $this->GetGrantAsHtml($sClass, UR_ACTION_MODIFY),
  117. 'bulkwrite' => $this->GetGrantAsHtml($sClass, UR_ACTION_BULK_MODIFY),
  118. 'stimuli' => $sStimuli,
  119. );
  120. }
  121. $aDisplayConfig = array();
  122. $aDisplayConfig['class'] = array('label' => 'Class', 'description' => '');
  123. $aDisplayConfig['read'] = array('label' => 'Read', 'description' => '');
  124. $aDisplayConfig['bulkread'] = array('label' => 'Bulk read', 'description' => 'List objects or export massively');
  125. $aDisplayConfig['write'] = array('label' => 'Write', 'description' => 'Create and edit (modify)');
  126. $aDisplayConfig['bulkwrite'] = array('label' => 'Bulk write', 'description' => 'Massively create/edit (CSV import)');
  127. $aDisplayConfig['stimuli'] = array('label' => 'Stimuli', 'description' => 'Allowed (compound) actions');
  128. $oPage->table($aDisplayConfig, $aDisplayData);
  129. }
  130. function DisplayBareRelations(WebPage $oPage)
  131. {
  132. parent::DisplayBareRelations($oPage);
  133. $oPage->SetCurrentTabContainer('Related Objects');
  134. $oPage->SetCurrentTab('Grants matrix');
  135. $this->DoShowGrantSumary($oPage, 'bizmodel');
  136. // debug
  137. if (false)
  138. {
  139. $oPage->SetCurrentTab('More on user rigths (dev only)');
  140. $oPage->add("<h3>User rights</h3>\n");
  141. $this->DoShowGrantSumary($oPage, 'addon/userrights');
  142. $oPage->add("<h3>Change log</h3>\n");
  143. $this->DoShowGrantSumary($oPage, 'core/cmdb');
  144. $oPage->add("<h3>Application</h3>\n");
  145. $this->DoShowGrantSumary($oPage, 'application');
  146. $oPage->add("<h3>GUI</h3>\n");
  147. $this->DoShowGrantSumary($oPage, 'gui');
  148. }
  149. }
  150. }
  151. class URP_Profiles extends UserRightsBaseClass
  152. {
  153. public static function Init()
  154. {
  155. $aParams = array
  156. (
  157. "category" => "addon/userrights",
  158. "key_type" => "autoincrement",
  159. "key_label" => "",
  160. "name_attcode" => "name",
  161. "state_attcode" => "",
  162. "reconc_keys" => array(),
  163. "db_table" => "priv_urp_profiles",
  164. "db_key_field" => "id",
  165. "db_finalclass_field" => "",
  166. "display_template" => "",
  167. );
  168. MetaModel::Init_Params($aParams);
  169. //MetaModel::Init_InheritAttributes();
  170. MetaModel::Init_AddAttribute(new AttributeString("name", array("allowed_values"=>null, "sql"=>"name", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  171. MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  172. MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("users", array("linked_class"=>"URP_UserProfile", "ext_key_to_me"=>"profileid", "ext_key_to_remote"=>"userid", "allowed_values"=>null, "count_min"=>1, "count_max"=>0, "depends_on"=>array())));
  173. //MetaModel::Init_InheritFilters();
  174. MetaModel::Init_AddFilterFromAttribute("name");
  175. MetaModel::Init_AddFilterFromAttribute("description");
  176. // Display lists
  177. MetaModel::Init_SetZListItems('details', array('name', 'description')); // Attributes to be displayed for the complete details
  178. MetaModel::Init_SetZListItems('list', array('name', 'description')); // Attributes to be displayed for a list
  179. // Search criteria
  180. MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  181. MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  182. }
  183. function GetGrantAsHtml($oUserRights, $sClass, $sAction)
  184. {
  185. $oGrant = $oUserRights->GetClassActionGrant($this->GetKey(), $sClass, $sAction);
  186. if (is_object($oGrant) && ($oGrant->Get('permission') == 'yes'))
  187. {
  188. return '<span style="background-color: #ddffdd;">yes</span>';
  189. }
  190. else
  191. {
  192. return '<span style="background-color: #ffdddd;">no</span>';
  193. }
  194. }
  195. function DoShowGrantSumary($oPage)
  196. {
  197. if ($this->GetName() == "Administrator")
  198. {
  199. // Looks dirty, but ok that's THE ONE
  200. $oPage->p('Has Read/Write access to any object in the database.');
  201. return;
  202. }
  203. // Note: for sure, we assume that the instance is derived from UserRightsProfile
  204. $oUserRights = UserRights::GetModuleInstance();
  205. $aDisplayData = array();
  206. foreach (MetaModel::GetClasses('bizmodel') as $sClass)
  207. {
  208. $aStimuli = array();
  209. foreach (MetaModel::EnumStimuli($sClass) as $sStimulusCode => $oStimulus)
  210. {
  211. $oGrant = $oUserRights->GetClassStimulusGrant($this->GetKey(), $sClass, $sStimulusCode);
  212. if (is_object($oGrant) && ($oGrant->Get('permission') == 'yes'))
  213. {
  214. $aStimuli[] = '<span title="'.$sStimulusCode.': '.htmlentities($oStimulus->GetDescription()).'">'.htmlentities($oStimulus->GetLabel()).'</span>';
  215. }
  216. }
  217. $sStimuli = implode(', ', $aStimuli);
  218. $aDisplayData[] = array(
  219. 'class' => MetaModel::GetName($sClass),
  220. 'read' => $this->GetGrantAsHtml($oUserRights, $sClass, 'Read'),
  221. 'bulkread' => $this->GetGrantAsHtml($oUserRights, $sClass, 'Bulk Read'),
  222. 'write' => $this->GetGrantAsHtml($oUserRights, $sClass, 'Modify'),
  223. 'bulkwrite' => $this->GetGrantAsHtml($oUserRights, $sClass, 'Bulk Modify'),
  224. 'stimuli' => $sStimuli,
  225. );
  226. }
  227. $aDisplayConfig = array();
  228. $aDisplayConfig['class'] = array('label' => 'Class', 'description' => '');
  229. $aDisplayConfig['read'] = array('label' => 'Read', 'description' => '');
  230. $aDisplayConfig['bulkread'] = array('label' => 'Bulk read', 'description' => 'List objects or export massively');
  231. $aDisplayConfig['write'] = array('label' => 'Write', 'description' => 'Create and edit (modify)');
  232. $aDisplayConfig['bulkwrite'] = array('label' => 'Bulk write', 'description' => 'Massively create/edit (CSV import)');
  233. $aDisplayConfig['stimuli'] = array('label' => 'Stimuli', 'description' => 'Allowed (compound) actions');
  234. $oPage->table($aDisplayConfig, $aDisplayData);
  235. }
  236. function DisplayBareRelations(WebPage $oPage)
  237. {
  238. parent::DisplayBareRelations($oPage);
  239. $oPage->SetCurrentTabContainer('Related Objects');
  240. $oPage->SetCurrentTab('Grants matrix');
  241. $this->DoShowGrantSumary($oPage);
  242. }
  243. }
  244. class URP_Dimensions extends UserRightsBaseClass
  245. {
  246. public static function Init()
  247. {
  248. $aParams = array
  249. (
  250. "category" => "addon/userrights",
  251. "key_type" => "autoincrement",
  252. "key_label" => "",
  253. "name_attcode" => "name",
  254. "state_attcode" => "",
  255. "reconc_keys" => array(),
  256. "db_table" => "priv_urp_dimensions",
  257. "db_key_field" => "id",
  258. "db_finalclass_field" => "",
  259. "display_template" => "../business/templates/default.html",
  260. );
  261. MetaModel::Init_Params($aParams);
  262. //MetaModel::Init_InheritAttributes();
  263. MetaModel::Init_AddAttribute(new AttributeString("name", array("allowed_values"=>null, "sql"=>"name", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  264. MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  265. MetaModel::Init_AddAttribute(new AttributeClass("type", array("class_category"=>"bizmodel", "more_values"=>"String,Integer", "sql"=>"type", "default_value"=>'String', "is_null_allowed"=>false, "depends_on"=>array())));
  266. //MetaModel::Init_InheritFilters();
  267. MetaModel::Init_AddFilterFromAttribute("name");
  268. MetaModel::Init_AddFilterFromAttribute("description");
  269. MetaModel::Init_AddFilterFromAttribute("type");
  270. // Display lists
  271. MetaModel::Init_SetZListItems('details', array('name', 'description', 'type')); // Attributes to be displayed for the complete details
  272. MetaModel::Init_SetZListItems('list', array('name', 'description')); // Attributes to be displayed for a list
  273. // Search criteria
  274. MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  275. MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  276. }
  277. public function CheckProjectionSpec($oProjectionSpec, $sProjectedClass)
  278. {
  279. $sExpression = $oProjectionSpec->Get('value');
  280. $sAttribute = $oProjectionSpec->Get('attribute');
  281. // Shortcut: "any value" or "no value" means no projection
  282. if (empty($sExpression)) return;
  283. if ($sExpression == '<any>') return;
  284. // 1st - compute the data type for the dimension
  285. //
  286. $sType = $this->Get('type');
  287. if (MetaModel::IsValidClass($sType))
  288. {
  289. $sExpectedType = $sType;
  290. }
  291. else
  292. {
  293. $sExpectedType = '_scalar_';
  294. }
  295. // 2nd - compute the data type for the projection
  296. //
  297. $sTargetClass = '';
  298. if (($sExpression == '<this>') || ($sExpression == '<user>'))
  299. {
  300. $sTargetClass = $sProjectedClass;
  301. }
  302. elseif ($sExpression == '<any>')
  303. {
  304. $sTargetClass = '';
  305. }
  306. else
  307. {
  308. // Evaluate wether it is a constant or not
  309. try
  310. {
  311. $oObjectSearch = DBObjectSearch::FromOQL($sExpression);
  312. $sTargetClass = $oObjectSearch->GetClass();
  313. }
  314. catch (OqlException $e)
  315. {
  316. }
  317. }
  318. if (empty($sTargetClass))
  319. {
  320. $sFoundType = '_void_';
  321. }
  322. else
  323. {
  324. if (empty($sAttribute))
  325. {
  326. $sFoundType = $sTargetClass;
  327. }
  328. else
  329. {
  330. if (!MetaModel::IsValidAttCode($sTargetClass, $sAttribute))
  331. {
  332. throw new CoreException('Unkown attribute code in projection specification', array('found' => $sAttribute, 'expecting' => MetaModel::GetAttributesList($sTargetClass), 'class' => $sTargetClass, 'projection' => $oProjectionSpec));
  333. }
  334. $oAttDef = MetaModel::GetAttributeDef($sTargetClass, $sAttribute);
  335. if ($oAttDef->IsExternalKey())
  336. {
  337. $sFoundType = $oAttDef->GetTargetClass();
  338. }
  339. else
  340. {
  341. $sFoundType = '_scalar_';
  342. }
  343. }
  344. }
  345. // Compare the dimension type and projection type
  346. if (($sFoundType != '_void_') && ($sFoundType != $sExpectedType))
  347. {
  348. throw new CoreException('Wrong type in projection specification', array('found' => $sFoundType, 'expecting' => $sExpectedType, 'expression' => $sExpression, 'attribute' => $sAttribute, 'projection' => $oProjectionSpec));
  349. }
  350. }
  351. }
  352. class URP_UserProfile extends UserRightsBaseClass
  353. {
  354. public static function Init()
  355. {
  356. $aParams = array
  357. (
  358. "category" => "addon/userrights",
  359. "key_type" => "autoincrement",
  360. "key_label" => "",
  361. "name_attcode" => "userid",
  362. "state_attcode" => "",
  363. "reconc_keys" => array(),
  364. "db_table" => "priv_urp_userprofile",
  365. "db_key_field" => "id",
  366. "db_finalclass_field" => "",
  367. "display_template" => "",
  368. );
  369. MetaModel::Init_Params($aParams);
  370. //MetaModel::Init_InheritAttributes();
  371. MetaModel::Init_AddAttribute(new AttributeExternalKey("userid", array("targetclass"=>"URP_Users", "jointype"=> "", "allowed_values"=>null, "sql"=>"userid", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
  372. MetaModel::Init_AddAttribute(new AttributeExternalField("userlogin", array("allowed_values"=>null, "extkey_attcode"=> 'userid', "target_attcode"=>"login")));
  373. MetaModel::Init_AddAttribute(new AttributeExternalKey("profileid", array("targetclass"=>"URP_Profiles", "jointype"=> "", "allowed_values"=>null, "sql"=>"profileid", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
  374. MetaModel::Init_AddAttribute(new AttributeExternalField("profile", array("allowed_values"=>null, "extkey_attcode"=> 'profileid', "target_attcode"=>"name")));
  375. MetaModel::Init_AddAttribute(new AttributeString("reason", array("allowed_values"=>null, "sql"=>"description", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  376. //MetaModel::Init_InheritFilters();
  377. MetaModel::Init_AddFilterFromAttribute("userid");
  378. MetaModel::Init_AddFilterFromAttribute("profileid");
  379. // Display lists
  380. MetaModel::Init_SetZListItems('details', array('userid', 'profileid', 'reason')); // Attributes to be displayed for the complete details
  381. MetaModel::Init_SetZListItems('list', array('userid', 'profileid', 'reason')); // Attributes to be displayed for a list
  382. // Search criteria
  383. MetaModel::Init_SetZListItems('standard_search', array('userid', 'profileid')); // Criteria of the std search form
  384. MetaModel::Init_SetZListItems('advanced_search', array('userid', 'profileid')); // Criteria of the advanced search form
  385. }
  386. public function GetName()
  387. {
  388. return "link between ".$this->Get('userlogin')." and ".$this->Get('profile');
  389. }
  390. }
  391. class URP_ProfileProjection extends UserRightsBaseClass
  392. {
  393. public static function Init()
  394. {
  395. $aParams = array
  396. (
  397. "category" => "addon/userrights",
  398. "key_type" => "autoincrement",
  399. "key_label" => "",
  400. "name_attcode" => "profileid",
  401. "state_attcode" => "",
  402. "reconc_keys" => array(),
  403. "db_table" => "priv_urp_profileprojection",
  404. "db_key_field" => "id",
  405. "db_finalclass_field" => "",
  406. "display_template" => "../business/templates/default.html",
  407. );
  408. MetaModel::Init_Params($aParams);
  409. //MetaModel::Init_InheritAttributes();
  410. MetaModel::Init_AddAttribute(new AttributeExternalKey("dimensionid", array("targetclass"=>"URP_Dimensions", "jointype"=> "", "allowed_values"=>null, "sql"=>"dimensionid", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array())));
  411. MetaModel::Init_AddAttribute(new AttributeExternalField("dimension", array("allowed_values"=>null, "extkey_attcode"=> 'dimensionid', "target_attcode"=>"name")));
  412. MetaModel::Init_AddAttribute(new AttributeExternalKey("profileid", array("targetclass"=>"URP_Profiles", "jointype"=> "", "allowed_values"=>null, "sql"=>"profileid", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array())));
  413. MetaModel::Init_AddAttribute(new AttributeExternalField("profile", array("allowed_values"=>null, "extkey_attcode"=> 'profileid', "target_attcode"=>"name")));
  414. MetaModel::Init_AddAttribute(new AttributeString("value", array("allowed_values"=>null, "sql"=>"value", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  415. MetaModel::Init_AddAttribute(new AttributeString("attribute", array("allowed_values"=>null, "sql"=>"attribute", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  416. //MetaModel::Init_InheritFilters();
  417. MetaModel::Init_AddFilterFromAttribute("dimensionid");
  418. MetaModel::Init_AddFilterFromAttribute("profileid");
  419. // Display lists
  420. MetaModel::Init_SetZListItems('details', array('dimensionid', 'profileid', 'value', 'attribute')); // Attributes to be displayed for the complete details
  421. MetaModel::Init_SetZListItems('list', array('dimensionid', 'profileid', 'value', 'attribute')); // Attributes to be displayed for a list
  422. // Search criteria
  423. MetaModel::Init_SetZListItems('standard_search', array('dimensionid', 'profileid')); // Criteria of the std search form
  424. MetaModel::Init_SetZListItems('advanced_search', array('dimensionid', 'profileid')); // Criteria of the advanced search form
  425. }
  426. public function ProjectUser(URP_Users $oUser)
  427. {
  428. $sExpr = $this->Get('value');
  429. if ($sExpr == '<user>')
  430. {
  431. $sColumn = $this->Get('attribute');
  432. if (empty($sColumn))
  433. {
  434. $aRes = array($oUser->GetKey());
  435. }
  436. else
  437. {
  438. $aRes = array($oUser->Get($sColumn));
  439. }
  440. }
  441. elseif ($sExpr == '<any>')
  442. {
  443. $aRes = null;
  444. }
  445. elseif (strtolower(substr($sExpr, 0, 6)) == 'select')
  446. {
  447. $sColumn = $this->Get('attribute');
  448. // SELECT...
  449. $oValueSetDef = new ValueSetObjects($sExpr, $sColumn);
  450. $aValues = $oValueSetDef->GetValues(array('user' => $oUser), '');
  451. $aRes = array_keys($aValues);
  452. }
  453. else
  454. {
  455. // Constant value(s)
  456. $aRes = explode(';', trim($sExpr));
  457. }
  458. return $aRes;
  459. }
  460. }
  461. class URP_ClassProjection extends UserRightsBaseClass
  462. {
  463. public static function Init()
  464. {
  465. $aParams = array
  466. (
  467. "category" => "addon/userrights",
  468. "key_type" => "autoincrement",
  469. "key_label" => "",
  470. "name_attcode" => "dimensionid",
  471. "state_attcode" => "",
  472. "reconc_keys" => array(),
  473. "db_table" => "priv_urp_classprojection",
  474. "db_key_field" => "id",
  475. "db_finalclass_field" => "",
  476. "display_template" => "../business/templates/default.html",
  477. );
  478. MetaModel::Init_Params($aParams);
  479. //MetaModel::Init_InheritAttributes();
  480. MetaModel::Init_AddAttribute(new AttributeExternalKey("dimensionid", array("targetclass"=>"URP_Dimensions", "jointype"=> "", "allowed_values"=>null, "sql"=>"dimensionid", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array())));
  481. MetaModel::Init_AddAttribute(new AttributeExternalField("dimension", array("allowed_values"=>null, "extkey_attcode"=> 'dimensionid', "target_attcode"=>"name")));
  482. MetaModel::Init_AddAttribute(new AttributeClass("class", array("class_category"=>"", "more_values"=>"", "sql"=>"class", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  483. MetaModel::Init_AddAttribute(new AttributeString("value", array("allowed_values"=>null, "sql"=>"value", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  484. MetaModel::Init_AddAttribute(new AttributeString("attribute", array("allowed_values"=>null, "sql"=>"attribute", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  485. //MetaModel::Init_InheritFilters();
  486. MetaModel::Init_AddFilterFromAttribute("dimensionid");
  487. // #@# verifier
  488. MetaModel::Init_AddFilterFromAttribute("class");
  489. // Display lists
  490. MetaModel::Init_SetZListItems('details', array('dimensionid', 'class', 'value', 'attribute')); // Attributes to be displayed for the complete details
  491. MetaModel::Init_SetZListItems('list', array('dimensionid', 'class', 'value', 'attribute')); // Attributes to be displayed for a list
  492. // Search criteria
  493. MetaModel::Init_SetZListItems('standard_search', array('dimensionid', 'class')); // Criteria of the std search form
  494. MetaModel::Init_SetZListItems('advanced_search', array('dimensionid', 'class')); // Criteria of the advanced search form
  495. }
  496. public function ProjectObject($oObject)
  497. {
  498. $sExpr = $this->Get('value');
  499. if ($sExpr == '<this>')
  500. {
  501. $sColumn = $this->Get('attribute');
  502. if (empty($sColumn))
  503. {
  504. $aRes = array($oObject->GetKey());
  505. }
  506. else
  507. {
  508. $aRes = array($oObject->Get($sColumn));
  509. }
  510. }
  511. elseif ($sExpr == '<any>')
  512. {
  513. $aRes = null;
  514. }
  515. elseif (strtolower(substr($sExpr, 0, 6)) == 'select')
  516. {
  517. $sColumn = $this->Get('attribute');
  518. // SELECT...
  519. $oValueSetDef = new ValueSetObjects($sExpr, $sColumn);
  520. $aValues = $oValueSetDef->GetValues(array('this' => $oObject), '');
  521. $aRes = array_keys($aValues);
  522. }
  523. elseif ($sExpr == '<any>')
  524. {
  525. $aRes = null;
  526. }
  527. else
  528. {
  529. // Constant value(s)
  530. $aRes = explode(';', trim($sExpr));
  531. }
  532. return $aRes;
  533. }
  534. }
  535. class URP_ActionGrant extends UserRightsBaseClass
  536. {
  537. public static function Init()
  538. {
  539. $aParams = array
  540. (
  541. "category" => "addon/userrights",
  542. "key_type" => "autoincrement",
  543. "key_label" => "",
  544. "name_attcode" => "profileid",
  545. "state_attcode" => "",
  546. "reconc_keys" => array(),
  547. "db_table" => "priv_urp_grant_actions",
  548. "db_key_field" => "id",
  549. "db_finalclass_field" => "",
  550. "display_template" => "../business/templates/default.html",
  551. );
  552. MetaModel::Init_Params($aParams);
  553. //MetaModel::Init_InheritAttributes();
  554. // Common to all grant classes (could be factorized by class inheritence, but this has to be benchmarked)
  555. MetaModel::Init_AddAttribute(new AttributeExternalKey("profileid", array("targetclass"=>"URP_Profiles", "jointype"=> "", "allowed_values"=>null, "sql"=>"profileid", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array())));
  556. MetaModel::Init_AddAttribute(new AttributeExternalField("profile", array("allowed_values"=>null, "extkey_attcode"=> 'profileid', "target_attcode"=>"name")));
  557. MetaModel::Init_AddAttribute(new AttributeClass("class", array("class_category"=>"", "more_values"=>"", "sql"=>"class", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  558. MetaModel::Init_AddAttribute(new AttributeEnum("permission", array("allowed_values"=>new ValueSetEnum('yes,no'), "sql"=>"permission", "default_value"=>"yes", "is_null_allowed"=>false, "depends_on"=>array())));
  559. MetaModel::Init_AddAttribute(new AttributeString("action", array("allowed_values"=>null, "sql"=>"action", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  560. //MetaModel::Init_InheritFilters();
  561. // Common to all grant classes (could be factorized by class inheritence, but this has to be benchmarked)
  562. MetaModel::Init_AddFilterFromAttribute("profileid");
  563. MetaModel::Init_AddFilterFromAttribute("profile");
  564. MetaModel::Init_AddFilterFromAttribute("class");
  565. MetaModel::Init_AddFilterFromAttribute("permission");
  566. MetaModel::Init_AddFilterFromAttribute("action");
  567. // Display lists
  568. MetaModel::Init_SetZListItems('details', array('profileid', 'class', 'permission', 'action')); // Attributes to be displayed for the complete details
  569. MetaModel::Init_SetZListItems('list', array('profileid', 'class', 'permission', 'action')); // Attributes to be displayed for a list
  570. // Search criteria
  571. MetaModel::Init_SetZListItems('standard_search', array('profileid', 'class', 'permission', 'action')); // Criteria of the std search form
  572. MetaModel::Init_SetZListItems('advanced_search', array('profileid', 'class', 'permission', 'action')); // Criteria of the advanced search form
  573. }
  574. }
  575. class URP_StimulusGrant extends UserRightsBaseClass
  576. {
  577. public static function Init()
  578. {
  579. $aParams = array
  580. (
  581. "category" => "addon/userrights",
  582. "key_type" => "autoincrement",
  583. "key_label" => "",
  584. "name_attcode" => "profileid",
  585. "state_attcode" => "",
  586. "reconc_keys" => array(),
  587. "db_table" => "priv_urp_grant_stimulus",
  588. "db_key_field" => "id",
  589. "db_finalclass_field" => "",
  590. "display_template" => "../business/templates/default.html",
  591. );
  592. MetaModel::Init_Params($aParams);
  593. //MetaModel::Init_InheritAttributes();
  594. // Common to all grant classes (could be factorized by class inheritence, but this has to be benchmarked)
  595. MetaModel::Init_AddAttribute(new AttributeExternalKey("profileid", array("targetclass"=>"URP_Profiles", "jointype"=> "", "allowed_values"=>null, "sql"=>"profileid", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array())));
  596. MetaModel::Init_AddAttribute(new AttributeExternalField("profile", array("allowed_values"=>null, "extkey_attcode"=> 'profileid', "target_attcode"=>"name")));
  597. MetaModel::Init_AddAttribute(new AttributeClass("class", array("class_category"=>"", "more_values"=>"", "sql"=>"class", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  598. MetaModel::Init_AddAttribute(new AttributeEnum("permission", array("allowed_values"=>new ValueSetEnum('yes,no'), "sql"=>"permission", "default_value"=>"yes", "is_null_allowed"=>false, "depends_on"=>array())));
  599. MetaModel::Init_AddAttribute(new AttributeString("stimulus", array("allowed_values"=>null, "sql"=>"action", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  600. //MetaModel::Init_InheritFilters();
  601. // Common to all grant classes (could be factorized by class inheritence, but this has to be benchmarked)
  602. MetaModel::Init_AddFilterFromAttribute("profileid");
  603. MetaModel::Init_AddFilterFromAttribute("profile");
  604. MetaModel::Init_AddFilterFromAttribute("class");
  605. MetaModel::Init_AddFilterFromAttribute("permission");
  606. MetaModel::Init_AddFilterFromAttribute("stimulus");
  607. // Display lists
  608. MetaModel::Init_SetZListItems('details', array('profileid', 'class', 'permission', 'stimulus')); // Attributes to be displayed for the complete details
  609. MetaModel::Init_SetZListItems('list', array('profileid', 'class', 'permission', 'stimulus')); // Attributes to be displayed for a list
  610. // Search criteria
  611. MetaModel::Init_SetZListItems('standard_search', array('profileid', 'class', 'permission', 'stimulus')); // Criteria of the std search form
  612. MetaModel::Init_SetZListItems('advanced_search', array('profileid', 'class', 'permission', 'stimulus')); // Criteria of the advanced search form
  613. }
  614. }
  615. class URP_AttributeGrant extends UserRightsBaseClass
  616. {
  617. public static function Init()
  618. {
  619. $aParams = array
  620. (
  621. "category" => "addon/userrights",
  622. "key_type" => "autoincrement",
  623. "key_label" => "",
  624. "name_attcode" => "actiongrantid",
  625. "state_attcode" => "",
  626. "reconc_keys" => array(),
  627. "db_table" => "priv_urp_grant_attributes",
  628. "db_key_field" => "id",
  629. "db_finalclass_field" => "",
  630. "display_template" => "../business/templates/default.html",
  631. );
  632. MetaModel::Init_Params($aParams);
  633. //MetaModel::Init_InheritAttributes();
  634. MetaModel::Init_AddAttribute(new AttributeExternalKey("actiongrantid", array("targetclass"=>"URP_ActionGrant", "jointype"=> "", "allowed_values"=>null, "sql"=>"actiongrantid", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array())));
  635. MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  636. //MetaModel::Init_InheritFilters();
  637. MetaModel::Init_AddFilterFromAttribute("actiongrantid");
  638. MetaModel::Init_AddFilterFromAttribute("attcode");
  639. // Display lists
  640. MetaModel::Init_SetZListItems('details', array('actiongrantid', 'attcode')); // Attributes to be displayed for the complete details
  641. MetaModel::Init_SetZListItems('list', array('actiongrantid', 'attcode')); // Attributes to be displayed for a list
  642. // Search criteria
  643. MetaModel::Init_SetZListItems('standard_search', array('actiongrantid', 'attcode')); // Criteria of the std search form
  644. MetaModel::Init_SetZListItems('advanced_search', array('actiongrantid', 'attcode')); // Criteria of the advanced search form
  645. }
  646. }
  647. class UserRightsProfile extends UserRightsAddOnAPI
  648. {
  649. static public $m_aActionCodes = array(
  650. UR_ACTION_READ => 'read',
  651. UR_ACTION_MODIFY => 'modify',
  652. UR_ACTION_DELETE => 'delete',
  653. UR_ACTION_BULK_READ => 'bulk read',
  654. UR_ACTION_BULK_MODIFY => 'bulk modify',
  655. UR_ACTION_BULK_DELETE => 'bulk delete',
  656. );
  657. // Installation: create the very first user
  658. public function CreateAdministrator($sAdminUser, $sAdminPwd)
  659. {
  660. // Create a change to record the history of the User object
  661. $oChange = MetaModel::NewObject("CMDBChange");
  662. $oChange->Set("date", time());
  663. $oChange->Set("userinfo", "Initialization");
  664. $iChangeId = $oChange->DBInsert();
  665. $oOrg = new bizOrganization();
  666. $oOrg->Set('name', 'My Company/Department');
  667. $oOrg->Set('code', 'SOMECODE');
  668. $oOrg->Set('status', 'implementation');
  669. //$oOrg->Set('parent_id', xxx);
  670. $iOrgId = $oOrg->DBInsertTrackedNoReload($oChange);
  671. // Location : optional
  672. //$oLocation = new bizLocation();
  673. //$oLocation->Set('name', 'MyOffice');
  674. //$oLocation->Set('status', 'implementation');
  675. //$oLocation->Set('org_id', $iOrgId);
  676. //$oLocation->Set('severity', 'high');
  677. //$oLocation->Set('address', 'my building in my city');
  678. //$oLocation->Set('country', 'my country');
  679. //$oLocation->Set('parent_location_id', xxx);
  680. //$iLocationId = $oLocation->DBInsertNoReload();
  681. $oContact = new bizPerson();
  682. $oContact->Set('name', 'My last name');
  683. $oContact->Set('first_name', 'My first name');
  684. $oContact->Set('status', 'available');
  685. $oContact->Set('org_id', $iOrgId);
  686. $oContact->Set('email', 'my.email@foo.org');
  687. $oContact->Set('phone', '');
  688. //$oContact->Set('location_id', $iLocationId);
  689. $oContact->Set('employee_number', '');
  690. $iContactId = $oContact->DBInsertTrackedNoReload($oChange);
  691. $oUser = new URP_Users();
  692. $oUser->Set('login', $sAdminUser);
  693. $oUser->Set('password', $sAdminPwd);
  694. $oUser->Set('userid', $iContactId);
  695. $iUserId = $oUser->DBInsertTrackedNoReload($oChange);
  696. // Add this user to the very specific 'admin' profile
  697. $oUserProfile = new URP_UserProfile();
  698. $oUserProfile->Set('userid', $iUserId);
  699. $oUserProfile->Set('profileid', ADMIN_PROFILE_ID);
  700. $oUserProfile->Set('reason', 'By definition, the administrator must have the administrator profile');
  701. $oUserProfile->DBInsertTrackedNoReload($oChange);
  702. return true;
  703. }
  704. public function IsAdministrator($iUserId)
  705. {
  706. if (in_array($iUserId, $this->m_aAdmins))
  707. {
  708. return true;
  709. }
  710. else
  711. {
  712. return false;
  713. }
  714. }
  715. public function Setup()
  716. {
  717. SetupProfiles::ComputeITILProfiles();
  718. //SetupProfiles::ComputeBasicProfiles();
  719. SetupProfiles::DoCreateDimensions();
  720. SetupProfiles::DoCreateDimensions();
  721. SetupProfiles::DoCreateProfiles();
  722. return true;
  723. }
  724. public function Init()
  725. {
  726. MetaModel::RegisterPlugin('userrights', 'ACbyProfile', array($this, 'CacheData'));
  727. }
  728. protected $m_aUsers = array(); // id -> object
  729. protected $m_aDimensions = array(); // id -> object
  730. protected $m_aClassProj = array(); // class,dimensionid -> object
  731. protected $m_aProfiles = array(); // id -> object
  732. protected $m_aUserProfiles = array(); // userid,profileid -> object
  733. protected $m_aProPro = array(); // profileid,dimensionid -> object
  734. protected $m_aLogin2UserId = array(); // login -> id
  735. protected $m_aAdmins = array(); // id of users being linked to the well-known admin profile
  736. protected $m_aClassActionGrants = array(); // profile, class, action -> permission
  737. protected $m_aClassStimulusGrants = array(); // profile, class, stimulus -> permission
  738. protected $m_aObjectActionGrants = array(); // userid, class, id, action -> permission, list of attributes
  739. public function CacheData()
  740. {
  741. // Could be loaded in a shared memory (?)
  742. $oUserSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_Users"));
  743. $this->m_aUsers = array();
  744. $this->m_aLogin2UserId = array();
  745. while ($oUser = $oUserSet->Fetch())
  746. {
  747. $this->m_aUsers[$oUser->GetKey()] = $oUser;
  748. $this->m_aLogin2UserId[$oUser->Get('login')] = $oUser->GetKey();
  749. }
  750. $oDimensionSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_Dimensions"));
  751. $this->m_aDimensions = array();
  752. while ($oDimension = $oDimensionSet->Fetch())
  753. {
  754. $this->m_aDimensions[$oDimension->GetKey()] = $oDimension;
  755. }
  756. $oClassProjSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_ClassProjection"));
  757. $this->m_aClassProjs = array();
  758. while ($oClassProj = $oClassProjSet->Fetch())
  759. {
  760. $this->m_aClassProjs[$oClassProj->Get('class')][$oClassProj->Get('dimensionid')] = $oClassProj;
  761. }
  762. $oProfileSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_Profiles"));
  763. $this->m_aProfiles = array();
  764. while ($oProfile = $oProfileSet->Fetch())
  765. {
  766. $this->m_aProfiles[$oProfile->GetKey()] = $oProfile;
  767. }
  768. $oUserProfileSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_UserProfile"));
  769. $this->m_aUserProfiles = array();
  770. $this->m_aAdmins = array();
  771. while ($oUserProfile = $oUserProfileSet->Fetch())
  772. {
  773. $this->m_aUserProfiles[$oUserProfile->Get('userid')][$oUserProfile->Get('profileid')] = $oUserProfile;
  774. if ($oUserProfile->Get('profileid') == ADMIN_PROFILE_ID)
  775. {
  776. $this->m_aAdmins[] = $oUserProfile->Get('userid');
  777. }
  778. }
  779. $oProProSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_ProfileProjection"));
  780. $this->m_aProPros = array();
  781. while ($oProPro = $oProProSet->Fetch())
  782. {
  783. $this->m_aProPros[$oProPro->Get('profileid')][$oProPro->Get('dimensionid')] = $oProPro;
  784. }
  785. /*
  786. echo "<pre>\n";
  787. print_r($this->m_aUsers);
  788. print_r($this->m_aDimensions);
  789. print_r($this->m_aClassProjs);
  790. print_r($this->m_aProfiles);
  791. print_r($this->m_aUserProfiles);
  792. print_r($this->m_aProPros);
  793. echo "</pre>\n";
  794. exit;
  795. */
  796. return true;
  797. }
  798. public function CheckCredentials($sUserName, $sPassword)
  799. {
  800. $oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_Users WHERE login = :login"), array(), array('login' => $sUserName));
  801. if ($oSet->Count() < 1)
  802. {
  803. // todo: throw an exception?
  804. return false;
  805. }
  806. $oUser = $oSet->Fetch();
  807. if ($oUser->Get('password') == $sPassword)
  808. {
  809. return $oUser->GetKey();
  810. }
  811. // todo: throw an exception?
  812. return false;
  813. }
  814. public function GetUserId($sUserName)
  815. {
  816. if (array_key_exists($sUserName, $this->m_aLogin2UserId))
  817. {
  818. // This happens really when the list of users is being loaded into the cache!!!
  819. $iUserId = $this->m_aLogin2UserId[$sUserName];
  820. return $iUserId;
  821. }
  822. return null;
  823. }
  824. public function GetUserLanguage($sUserName)
  825. {
  826. if (array_key_exists($sUserName, $this->m_aLogin2UserId))
  827. {
  828. // This happens really when the list of users is being loaded into the cache!!!
  829. $iUserId = $this->m_aLogin2UserId[$sUserName];
  830. $oUser = $this->m_aUsers[$iUserId];
  831. return $oUser->Get('language');
  832. }
  833. return 'EN US';
  834. }
  835. public function GetContactId($sUserName)
  836. {
  837. if (array_key_exists($sUserName, $this->m_aLogin2UserId))
  838. {
  839. // This happens really when the list of users is being loaded into the cache!!!
  840. $iUserId = $this->m_aLogin2UserId[$sUserName];
  841. $oUser = $this->m_aUsers[$iUserId];
  842. return $oUser->Get('userid');
  843. }
  844. return null;
  845. }
  846. public function GetFilter($sUserName, $sClass)
  847. {
  848. $oNullFilter = new DBObjectSearch($sClass);
  849. return $oNullFilter;
  850. }
  851. // This verb has been made public to allow the development of an accurate feedback for the current configuration
  852. public function GetClassActionGrant($iProfile, $sClass, $sAction)
  853. {
  854. if (isset($this->m_aClassActionGrants[$iProfile][$sClass][$sAction]))
  855. {
  856. return $this->m_aClassActionGrants[$iProfile][$sClass][$sAction];
  857. }
  858. // Get the permission for this profile/class/action
  859. $oSearch = DBObjectSearch::FromOQL("SELECT URP_ActionGrant WHERE class = :class AND action = :action AND profileid = :profile AND permission = 'yes'");
  860. $oSet = new DBObjectSet($oSearch, array(), array('class'=>$sClass, 'action'=>$sAction, 'profile'=>$iProfile));
  861. if ($oSet->Count() >= 1)
  862. {
  863. $oGrantRecord = $oSet->Fetch();
  864. }
  865. else
  866. {
  867. $sParentClass = MetaModel::GetParentPersistentClass($sClass);
  868. if (empty($sParentClass))
  869. {
  870. $oGrantRecord = null;
  871. }
  872. else
  873. {
  874. $oGrantRecord = $this->GetClassActionGrant($iProfile, $sParentClass, $sAction);
  875. }
  876. }
  877. $this->m_aClassActionGrants[$iProfile][$sClass][$sAction] = $oGrantRecord;
  878. return $oGrantRecord;
  879. }
  880. protected function GetObjectActionGrant($oUser, $sClass, $iActionCode, /*DBObject*/ $oObject = null)
  881. {
  882. if(is_null($oObject))
  883. {
  884. $iObjectRef = -999;
  885. }
  886. else
  887. {
  888. $iObjectRef = $oObject->GetKey();
  889. }
  890. // load and cache permissions for the current user on the given object
  891. //
  892. $aTest = @$this->m_aObjectActionGrants[$oUser->GetKey()][$sClass][$iObjectRef][$iActionCode];
  893. if (is_array($aTest)) return $aTest;
  894. $sAction = self::$m_aActionCodes[$iActionCode];
  895. $iInstancePermission = UR_ALLOWED_NO;
  896. $aAttributes = array();
  897. foreach($this->GetMatchingProfiles($oUser, $sClass, $oObject) as $iProfile)
  898. {
  899. $oGrantRecord = $this->GetClassActionGrant($iProfile, $sClass, $sAction);
  900. if (is_null($oGrantRecord))
  901. {
  902. continue; // loop to the next profile
  903. }
  904. else
  905. {
  906. $iInstancePermission = UR_ALLOWED_YES;
  907. // update the list of attributes with those allowed for this profile
  908. //
  909. $oSearch = DBObjectSearch::FromOQL("SELECT URP_AttributeGrant WHERE actiongrantid = :actiongrantid");
  910. $oSet = new DBObjectSet($oSearch, array(), array('actiongrantid' => $oGrantRecord->GetKey()));
  911. $aProfileAttributes = $oSet->GetColumnAsArray('attcode', false);
  912. if (count($aProfileAttributes) == 0)
  913. {
  914. $aAllAttributes = array_keys(MetaModel::ListAttributeDefs($sClass));
  915. $aAttributes = array_merge($aAttributes, $aAllAttributes);
  916. }
  917. else
  918. {
  919. $aAttributes = array_merge($aAttributes, $aProfileAttributes);
  920. }
  921. }
  922. }
  923. $aRes = array(
  924. 'permission' => $iInstancePermission,
  925. 'attributes' => $aAttributes,
  926. );
  927. $this->m_aObjectActionGrants[$oUser->GetKey()][$sClass][$iObjectRef][$iActionCode] = $aRes;
  928. return $aRes;
  929. }
  930. public function IsActionAllowed($iUserId, $sClass, $iActionCode, $oInstanceSet = null)
  931. {
  932. $oUser = $this->m_aUsers[$iUserId];
  933. if (is_null($oInstanceSet))
  934. {
  935. $aObjectPermissions = $this->GetObjectActionGrant($oUser, $sClass, $iActionCode);
  936. return $aObjectPermissions['permission'];
  937. }
  938. $oInstanceSet->Rewind();
  939. while($oObject = $oInstanceSet->Fetch())
  940. {
  941. $aObjectPermissions = $this->GetObjectActionGrant($oUser, $sClass, $iActionCode, $oObject);
  942. $iInstancePermission = $aObjectPermissions['permission'];
  943. if (isset($iGlobalPermission))
  944. {
  945. if ($iInstancePermission != $iGlobalPermission)
  946. {
  947. $iGlobalPermission = UR_ALLOWED_DEPENDS;
  948. break;
  949. }
  950. }
  951. else
  952. {
  953. $iGlobalPermission = $iInstancePermission;
  954. }
  955. }
  956. $oInstanceSet->Rewind();
  957. if (isset($iGlobalPermission))
  958. {
  959. return $iGlobalPermission;
  960. }
  961. else
  962. {
  963. return UR_ALLOWED_NO;
  964. }
  965. }
  966. public function IsActionAllowedOnAttribute($iUserId, $sClass, $sAttCode, $iActionCode, $oInstanceSet = null)
  967. {
  968. $oUser = $this->m_aUsers[$iUserId];
  969. if (is_null($oInstanceSet))
  970. {
  971. $aObjectPermissions = $this->GetObjectActionGrant($oUser, $sClass, $iActionCode);
  972. $aAttributes = $aObjectPermissions['attributes'];
  973. if (in_array($sAttCode, $aAttributes))
  974. {
  975. return $aObjectPermissions['permission'];
  976. }
  977. else
  978. {
  979. return UR_ALLOWED_NO;
  980. }
  981. }
  982. $oInstanceSet->Rewind();
  983. while($oObject = $oInstanceSet->Fetch())
  984. {
  985. $aObjectPermissions = $this->GetObjectActionGrant($oUser, $sClass, $iActionCode, $oObject);
  986. $aAttributes = $aObjectPermissions['attributes'];
  987. if (in_array($sAttCode, $aAttributes))
  988. {
  989. $iInstancePermission = $aObjectPermissions['permission'];
  990. }
  991. else
  992. {
  993. $iInstancePermission = UR_ALLOWED_NO;
  994. }
  995. if (isset($iGlobalPermission))
  996. {
  997. if ($iInstancePermission != $iGlobalPermission)
  998. {
  999. $iGlobalPermission = UR_ALLOWED_DEPENDS;
  1000. }
  1001. }
  1002. else
  1003. {
  1004. $iGlobalPermission = $iInstancePermission;
  1005. }
  1006. }
  1007. $oInstanceSet->Rewind();
  1008. if (isset($iGlobalPermission))
  1009. {
  1010. return $iGlobalPermission;
  1011. }
  1012. else
  1013. {
  1014. return UR_ALLOWED_NO;
  1015. }
  1016. }
  1017. // This verb has been made public to allow the development of an accurate feedback for the current configuration
  1018. public function GetClassStimulusGrant($iProfile, $sClass, $sStimulusCode)
  1019. {
  1020. if (isset($this->m_aClassStimulusGrants[$iProfile][$sClass][$sStimulusCode]))
  1021. {
  1022. return $this->m_aClassStimulusGrants[$iProfile][$sClass][$sStimulusCode];
  1023. }
  1024. // Get the permission for this profile/class/stimulus
  1025. $oSearch = DBObjectSearch::FromOQL("SELECT URP_StimulusGrant WHERE class = :class AND stimulus = :stimulus AND profileid = :profile AND permission = 'yes'");
  1026. $oSet = new DBObjectSet($oSearch, array(), array('class'=>$sClass, 'stimulus'=>$sStimulusCode, 'profile'=>$iProfile));
  1027. if ($oSet->Count() >= 1)
  1028. {
  1029. $oGrantRecord = $oSet->Fetch();
  1030. }
  1031. else
  1032. {
  1033. $oGrantRecord = null;
  1034. }
  1035. $this->m_aClassStimulusGrants[$iProfile][$sClass][$sStimulusCode] = $oGrantRecord;
  1036. return $oGrantRecord;
  1037. }
  1038. public function IsStimulusAllowed($iUserId, $sClass, $sStimulusCode, $oInstanceSet = null)
  1039. {
  1040. $oUser = $this->m_aUsers[$iUserId];
  1041. // Note: this code is VERY close to the code of IsActionAllowed()
  1042. if (is_null($oInstanceSet))
  1043. {
  1044. $iInstancePermission = UR_ALLOWED_NO;
  1045. foreach($this->GetMatchingProfiles($oUser, $sClass) as $iProfile)
  1046. {
  1047. $oGrantRecord = $this->GetClassStimulusGrant($iProfile, $sClass, $sStimulusCode);
  1048. if (!is_null($oGrantRecord))
  1049. {
  1050. // no need to fetch the record, we've requested the records having permission = 'yes'
  1051. $iInstancePermission = UR_ALLOWED_YES;
  1052. }
  1053. }
  1054. return $iInstancePermission;
  1055. }
  1056. $oInstanceSet->Rewind();
  1057. while($oObject = $oInstanceSet->Fetch())
  1058. {
  1059. $iInstancePermission = UR_ALLOWED_NO;
  1060. foreach($this->GetMatchingProfiles($oUser, $sClass, $oObject) as $iProfile)
  1061. {
  1062. $oGrantRecord = $this->GetClassStimulusGrant($iProfile, $sClass, $sStimulusCode);
  1063. if (!is_null($oGrantRecord))
  1064. {
  1065. // no need to fetch the record, we've requested the records having permission = 'yes'
  1066. $iInstancePermission = UR_ALLOWED_YES;
  1067. }
  1068. }
  1069. if (isset($iGlobalPermission))
  1070. {
  1071. if ($iInstancePermission != $iGlobalPermission)
  1072. {
  1073. $iGlobalPermission = UR_ALLOWED_DEPENDS;
  1074. }
  1075. }
  1076. else
  1077. {
  1078. $iGlobalPermission = $iInstancePermission;
  1079. }
  1080. }
  1081. $oInstanceSet->Rewind();
  1082. if (isset($iGlobalPermission))
  1083. {
  1084. return $iGlobalPermission;
  1085. }
  1086. else
  1087. {
  1088. return UR_ALLOWED_NO;
  1089. }
  1090. }
  1091. protected function GetMatchingProfilesByDim($oUser, $oObject, $oDimension)
  1092. {
  1093. //
  1094. // List profiles for which the user projection overlaps the object projection in the given dimension
  1095. //
  1096. $iUser = $oUser->GetKey();
  1097. $sClass = get_class($oObject);
  1098. $iPKey = $oObject->GetKey();
  1099. $iDimension = $oDimension->GetKey();
  1100. $aObjectProjection = $this->m_aClassProjs[$sClass][$iDimension]->ProjectObject($oObject);
  1101. $aRes = array();
  1102. if (array_key_exists($iUser, $this->m_aUserProfiles))
  1103. {
  1104. foreach ($this->m_aUserProfiles[$iUser] as $iProfile => $oProfile)
  1105. {
  1106. if (is_null($aObjectProjection))
  1107. {
  1108. $aRes[] = $iProfile;
  1109. }
  1110. else
  1111. {
  1112. // user projection to be cached on a given page !
  1113. $aUserProjection = $this->m_aProPros[$iProfile][$iDimension]->ProjectUser($oUser);
  1114. if (is_null($aUserProjection))
  1115. {
  1116. $aRes[] = $iProfile;
  1117. }
  1118. else
  1119. {
  1120. $aMatchingValues = array_intersect($aObjectProjection, $aUserProjection);
  1121. if (count($aMatchingValues) > 0)
  1122. {
  1123. $aRes[] = $iProfile;
  1124. }
  1125. }
  1126. }
  1127. }
  1128. }
  1129. return $aRes;
  1130. }
  1131. protected $m_aMatchingProfiles = array(); // cache of the matching profiles for a given user/object
  1132. protected function GetMatchingProfiles($oUser, $sClass, /*DBObject*/ $oObject = null)
  1133. {
  1134. $iUser = $oUser->GetKey();
  1135. if(is_null($oObject))
  1136. {
  1137. $iObjectRef = -999;
  1138. }
  1139. else
  1140. {
  1141. $iObjectRef = $oObject->GetKey();
  1142. }
  1143. //
  1144. // List profiles for which the user projection overlaps the object projection in each and every dimension
  1145. // Caches the result
  1146. //
  1147. $aTest = @$this->m_aMatchingProfiles[$iUser][$sClass][$iObjectRef];
  1148. if (is_array($aTest))
  1149. {
  1150. return $aTest;
  1151. }
  1152. if (is_null($oObject))
  1153. {
  1154. if (array_key_exists($iUser, $this->m_aUserProfiles))
  1155. {
  1156. $aRes = array_keys($this->m_aUserProfiles[$iUser]);
  1157. }
  1158. else
  1159. {
  1160. // no profile has been defined for this user
  1161. $aRes = array();
  1162. }
  1163. }
  1164. else
  1165. {
  1166. $aProfileRes = array();
  1167. foreach ($this->m_aDimensions as $iDimension => $oDimension)
  1168. {
  1169. foreach ($this->GetMatchingProfilesByDim($oUser, $oObject, $oDimension) as $iProfile)
  1170. {
  1171. @$aProfileRes[$iProfile] += 1;
  1172. }
  1173. }
  1174. $aRes = array();
  1175. $iDimCount = count($this->m_aDimensions);
  1176. foreach ($aProfileRes as $iProfile => $iMatches)
  1177. {
  1178. if ($iMatches == $iDimCount)
  1179. {
  1180. $aRes[] = $iProfile;
  1181. }
  1182. }
  1183. }
  1184. // store into the cache
  1185. $this->m_aMatchingProfiles[$iUser][$sClass][$iObjectRef] = $aRes;
  1186. return $aRes;
  1187. }
  1188. public function FlushPrivileges()
  1189. {
  1190. $this->CacheData();
  1191. }
  1192. }
  1193. //
  1194. // Create simple profiles into our user management model:
  1195. // - administrator
  1196. // - readers
  1197. // - contributors
  1198. //
  1199. class SetupProfiles
  1200. {
  1201. protected static $m_aDimensions = array(
  1202. 'organization' => array(
  1203. 'description' => '',
  1204. 'type' => 'bizOrganization',
  1205. ),
  1206. );
  1207. protected static $m_aActions = array(
  1208. UR_ACTION_READ => 'Read',
  1209. UR_ACTION_MODIFY => 'Modify',
  1210. UR_ACTION_DELETE => 'Delete',
  1211. UR_ACTION_BULK_READ => 'Bulk Read',
  1212. UR_ACTION_BULK_MODIFY => 'Bulk Modify',
  1213. UR_ACTION_BULK_DELETE => 'Bulk Delete',
  1214. );
  1215. // Note: It is possible to specify the same class in several modules
  1216. //
  1217. protected static $m_aModules = array();
  1218. protected static $m_aProfiles = array();
  1219. protected static function DoCreateClassProjection($iDimension, $sClass)
  1220. {
  1221. $oNewObj = MetaModel::NewObject("URP_ClassProjection");
  1222. $oNewObj->Set('dimensionid', $iDimension);
  1223. $oNewObj->Set('class', $sClass);
  1224. $oNewObj->Set('attribute', '');
  1225. $iId = $oNewObj->DBInsertNoReload();
  1226. return $iId;
  1227. }
  1228. protected static function DoCreateDimension($sName, $aDimensionData)
  1229. {
  1230. $oNewObj = MetaModel::NewObject("URP_Dimensions");
  1231. $oNewObj->Set('name', $sName);
  1232. $oNewObj->Set('description', $aDimensionData['description']);
  1233. $oNewObj->Set('type', $aDimensionData['type']);
  1234. $iId = $oNewObj->DBInsertNoReload();
  1235. return $iId;
  1236. }
  1237. protected static function DoCreateProfileProjection($iProfile, $iDimension)
  1238. {
  1239. $oNewObj = MetaModel::NewObject("URP_ProfileProjection");
  1240. $oNewObj->Set('profileid', $iProfile);
  1241. $oNewObj->Set('dimensionid', $iDimension);
  1242. $oNewObj->Set('value', '<any>');
  1243. $oNewObj->Set('attribute', '');
  1244. $iId = $oNewObj->DBInsertNoReload();
  1245. return $iId;
  1246. }
  1247. protected static function DoCreateActionGrant($iProfile, $iAction, $sClass, $bPermission = true)
  1248. {
  1249. $oNewObj = MetaModel::NewObject("URP_ActionGrant");
  1250. $oNewObj->Set('profileid', $iProfile);
  1251. $oNewObj->Set('permission', $bPermission);
  1252. $oNewObj->Set('class', $sClass);
  1253. $oNewObj->Set('action', self::$m_aActions[$iAction]);
  1254. $iId = $oNewObj->DBInsertNoReload();
  1255. return $iId;
  1256. }
  1257. protected static function DoCreateStimulusGrant($iProfile, $sStimulusCode, $sClass)
  1258. {
  1259. $oNewObj = MetaModel::NewObject("URP_StimulusGrant");
  1260. $oNewObj->Set('profileid', $iProfile);
  1261. $oNewObj->Set('permission', true);
  1262. $oNewObj->Set('class', $sClass);
  1263. $oNewObj->Set('stimulus', $sStimulusCode);
  1264. $iId = $oNewObj->DBInsertNoReload();
  1265. return $iId;
  1266. }
  1267. protected static function DoCreateAdminProfile()
  1268. {
  1269. $oNewObj = MetaModel::NewObject("URP_Profiles");
  1270. $oNewObj->Set('name', 'Administrator');
  1271. $oNewObj->Set('description', 'Has the rights on everything (bypassing any control)');
  1272. $iNewId = $oNewObj->DBInsertNoReload();
  1273. if ($iNewId != ADMIN_PROFILE_ID)
  1274. {
  1275. throw new CoreException('Admin profile could not be created with its standard id', array('requested'=>ADMIN_PROFILE_ID, 'obtained'=>$iNewId));
  1276. }
  1277. }
  1278. protected static function DoCreateOneProfile($sName, $aProfileData)
  1279. {
  1280. $sDescription = $aProfileData['description'];
  1281. if (strlen(trim($aProfileData['write_modules'])) == 0)
  1282. {
  1283. $aWriteModules = array();
  1284. }
  1285. else
  1286. {
  1287. $aWriteModules = explode(',', trim($aProfileData['write_modules']));
  1288. }
  1289. $aStimuli = $aProfileData['stimuli'];
  1290. $oNewObj = MetaModel::NewObject("URP_Profiles");
  1291. $oNewObj->Set('name', $sName);
  1292. $oNewObj->Set('description', $sDescription);
  1293. $iProfile = $oNewObj->DBInsertNoReload();
  1294. // Project in every dimension
  1295. //
  1296. $oDimensionSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_Dimensions"));
  1297. while ($oDimension = $oDimensionSet->Fetch())
  1298. {
  1299. $iDimension = $oDimension->GetKey();
  1300. self::DoCreateProfileProjection($iProfile, $iDimension);
  1301. }
  1302. // Grant read rights for everything
  1303. //
  1304. foreach (MetaModel::GetClasses('bizmodel') as $sClass)
  1305. {
  1306. self::DoCreateActionGrant($iProfile, UR_ACTION_READ, $sClass);
  1307. self::DoCreateActionGrant($iProfile, UR_ACTION_BULK_READ, $sClass);
  1308. }
  1309. // Grant write for given modules
  1310. // Start by compiling the information, because some modules may overlap
  1311. $aWriteableClasses = array();
  1312. foreach ($aWriteModules as $sModule)
  1313. {
  1314. //$oPage->p('Granting write access for the module"'.$sModule.'" - '.count(self::$m_aModules[$sModule]).' classes');
  1315. foreach (self::$m_aModules[$sModule] as $sClass)
  1316. {
  1317. $aWriteableClasses[$sClass] = true;
  1318. }
  1319. }
  1320. foreach ($aWriteableClasses as $sClass => $foo)
  1321. {
  1322. if (!MetaModel::IsValidClass($sClass))
  1323. {
  1324. throw new CoreException("Invalid class name '$sClass'");
  1325. }
  1326. self::DoCreateActionGrant($iProfile, UR_ACTION_MODIFY, $sClass);
  1327. self::DoCreateActionGrant($iProfile, UR_ACTION_DELETE, $sClass);
  1328. self::DoCreateActionGrant($iProfile, UR_ACTION_BULK_MODIFY, $sClass);
  1329. self::DoCreateActionGrant($iProfile, UR_ACTION_BULK_DELETE, $sClass);
  1330. }
  1331. // Grant stimuli for given classes
  1332. foreach ($aStimuli as $sClass => $sAllowedStimuli)
  1333. {
  1334. if (!MetaModel::IsValidClass($sClass))
  1335. {
  1336. throw new CoreException("Invalid class name '$sClass'");
  1337. }
  1338. if ($sAllowedStimuli == 'any')
  1339. {
  1340. $aAllowedStimuli = array_keys(MetaModel::EnumStimuli($sClass));
  1341. }
  1342. elseif ($sAllowedStimuli == 'none')
  1343. {
  1344. $aAllowedStimuli = array();
  1345. }
  1346. else
  1347. {
  1348. $aAllowedStimuli = explode(',', $sAllowedStimuli);
  1349. }
  1350. foreach ($aAllowedStimuli as $sStimulusCode)
  1351. {
  1352. self::DoCreateStimulusGrant($iProfile, $sStimulusCode, $sClass);
  1353. }
  1354. }
  1355. }
  1356. public static function DoCreateDimensions()
  1357. {
  1358. $aClass = MetaModel::GetClasses();
  1359. foreach(self::$m_aDimensions as $sName => $aDimensionData)
  1360. {
  1361. $iDimension = self::DoCreateDimension($sName, $aDimensionData);
  1362. foreach($aClass as $sClass)
  1363. {
  1364. if (!MetaModel::IsValidClass($sClass))
  1365. {
  1366. throw new CoreException("Invalid class name '$sClass'");
  1367. }
  1368. self::DoCreateClassProjection($iDimension, $sClass);
  1369. }
  1370. }
  1371. }
  1372. public static function DoCreateProfiles()
  1373. {
  1374. self::DoCreateAdminProfile();
  1375. foreach(self::$m_aProfiles as $sName => $aProfileData)
  1376. {
  1377. self::DoCreateOneProfile($sName, $aProfileData);
  1378. }
  1379. }
  1380. public static function ComputeBasicProfiles()
  1381. {
  1382. // In this profiling scheme, one single module represents all the classes
  1383. //
  1384. self::$m_aModules = array(
  1385. 'UserData' => MetaModel::GetClasses('bizmodel'),
  1386. );
  1387. self::$m_aProfiles = array(
  1388. 'Reader' => array(
  1389. 'description' => 'Person having a ready-only access to the data',
  1390. 'write_modules' => '',
  1391. 'stimuli' => array(
  1392. ),
  1393. ),
  1394. 'Writer' => array(
  1395. 'description' => 'Contributor to the contents (read + write access)',
  1396. 'write_modules' => 'UserData',
  1397. 'stimuli' => array(
  1398. // any class => 'any'
  1399. ),
  1400. ),
  1401. );
  1402. }
  1403. public static function ComputeITILProfiles()
  1404. {
  1405. // In this profiling scheme, modules are based on ITIL recommendations
  1406. //
  1407. self::$m_aModules = array(
  1408. 'General' => array(
  1409. 'bizOrganization',
  1410. ),
  1411. 'Documentation' => array(
  1412. 'bizDocument',
  1413. 'lnkDocumentRealObject',
  1414. 'lnkDocumentContract',
  1415. 'lnkDocumentError',
  1416. ),
  1417. 'Configuration' => array(
  1418. 'logRealObject',
  1419. 'lnkContactRealObject',
  1420. // 'lnkInterfaces',
  1421. 'lnkClientServer',
  1422. 'lnkInfraGrouping',
  1423. 'lnkContactInfra',
  1424. 'lnkContactTeam',
  1425. ),
  1426. 'Incident' => array(
  1427. 'bizIncidentTicket',
  1428. 'lnkRelatedTicket',
  1429. 'lnkInfraTicket',
  1430. 'lnkContactTicket',
  1431. ),
  1432. 'Problem' => array(
  1433. 'bizKnownError',
  1434. 'lnkInfraError',
  1435. 'lnkDocumentError',
  1436. ),
  1437. 'Change' => array(
  1438. 'bizChangeTicket',
  1439. 'lnkInfraChangeTicket',
  1440. 'lnkContactChange',
  1441. ),
  1442. 'Service' => array(
  1443. 'bizService',
  1444. 'bizContract',
  1445. 'lnkInfraContract',
  1446. 'lnkContactContract',
  1447. 'lnkDocumentContract',
  1448. ),
  1449. 'Call' => array(
  1450. 'bizServiceCall',
  1451. 'lnkCallTicket',
  1452. 'lnkInfraCall',
  1453. ),
  1454. );
  1455. self::$m_aProfiles = array(
  1456. 'Configuration Manager' => array(
  1457. 'description' => 'Person in charge of the documentation of the managed CIs',
  1458. 'write_modules' => 'Documentation,Configuration',
  1459. 'stimuli' => array(
  1460. 'bizServer' => 'any',
  1461. //'bizServer' => 'ev_store,ev_ship,ev_plug,ev_configuration_finished,ev_val_failed,ev_mtp,ev_start_change,ev_end_change,ev_decomission,ev_obsolete,ev_recycle',
  1462. 'bizContract' => 'none',
  1463. 'bizIncidentTicket' => 'none',
  1464. 'bizChangeTicket' => 'none',
  1465. ),
  1466. ),
  1467. 'Service Desk Agent' => array(
  1468. 'description' => 'Person in charge of creating incident reports',
  1469. 'write_modules' => 'Incident,Call',
  1470. 'stimuli' => array(
  1471. 'bizServer' => 'none',
  1472. 'bizContract' => 'none',
  1473. 'bizIncidentTicket' => 'ev_assign',
  1474. 'bizChangeTicket' => 'none',
  1475. 'bizServiceCall' => 'any',
  1476. ),
  1477. ),
  1478. 'Support Agent' => array(
  1479. 'description' => 'Person analyzing and solving the current incidents or problems',
  1480. 'write_modules' => 'Incident,Problem',
  1481. 'stimuli' => array(
  1482. 'bizIncidentTicket' => 'any',
  1483. //'bizIncidentTicket' => 'ev_assign,ev_reassign,ev_start_working,ev_close',
  1484. ),
  1485. ),
  1486. 'Change Implementor' => array(
  1487. 'description' => 'Person executing the changes',
  1488. 'write_modules' => 'Change',
  1489. 'stimuli' => array(
  1490. 'bizServer' => 'none',
  1491. 'bizContract' => 'none',
  1492. 'bizIncidentTicket' => 'none',
  1493. 'bizChangeTicket' => 'ev_plan,ev_replan,ev_implement,ev_monitor',
  1494. ),
  1495. ),
  1496. 'Change Supervisor' => array(
  1497. 'description' => 'Person responsible for the overall change execution',
  1498. 'write_modules' => 'Change',
  1499. 'stimuli' => array(
  1500. 'bizServer' => 'none',
  1501. 'bizContract' => 'none',
  1502. 'bizIncidentTicket' => 'none',
  1503. 'bizChangeTicket' => 'ev_assign,ev_validate,ev_reject,ev_reopen,ev_finish',
  1504. ),
  1505. ),
  1506. 'Change Approver' => array(
  1507. 'description' => 'Person who could be impacted by some changes',
  1508. 'write_modules' => 'Change',
  1509. 'stimuli' => array(
  1510. 'bizServer' => 'none',
  1511. 'bizContract' => 'none',
  1512. 'bizIncidentTicket' => 'none',
  1513. 'bizChangeTicket' => 'ev_approve,ev_notapprove',
  1514. ),
  1515. ),
  1516. 'Service Manager' => array(
  1517. 'description' => 'Person responsible for the service delivered to the [internal] customer',
  1518. 'write_modules' => 'Service',
  1519. 'stimuli' => array(
  1520. 'bizServer' => 'none',
  1521. 'bizContract' => 'any',
  1522. //'bizContract' => 'ev_freeze_version,ev_sign,ev_begin,ev_notice,ev_terminate,ev_elapsed',
  1523. 'bizIncidentTicket' => 'none',
  1524. 'bizChangeTicket' => 'none',
  1525. ),
  1526. ),
  1527. 'Document author' => array(
  1528. 'description' => 'Any person who could contribute to documentation',
  1529. 'write_modules' => 'Documentation',
  1530. 'stimuli' => array(
  1531. ),
  1532. ),
  1533. );
  1534. }
  1535. }
  1536. UserRights::SelectModule('UserRightsProfile');
  1537. ?>