userrightsprofile.class.inc.php 59 KB

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