userrightsprofile.class.inc.php 58 KB

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