userrightsprofile.class.inc.php 59 KB

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