userrightsprofile.class.inc.php 57 KB

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