userrightsprofile.class.inc.php 59 KB

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