userrightsprofile.class.inc.php 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * UserRightsProfile
  18. * User management Module, basing the right on profiles and a matrix (similar to UserRightsMatrix, but profiles and other decorations have been added)
  19. *
  20. * @author Erwan Taloc <erwan.taloc@combodo.com>
  21. * @author Romain Quetiez <romain.quetiez@combodo.com>
  22. * @author Denis Flaven <denis.flaven@combodo.com>
  23. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  24. */
  25. define('ADMIN_PROFILE_ID', 1);
  26. class UserRightsBaseClass extends cmdbAbstractObject
  27. {
  28. // Whenever something changes, reload the privileges
  29. public function DBInsertTracked(CMDBChange $oChange)
  30. {
  31. parent::DBInsertTracked($oChange);
  32. UserRights::FlushPrivileges();
  33. }
  34. public function DBUpdateTracked(CMDBChange $oChange)
  35. {
  36. parent::DBUpdateTracked($oChange);
  37. UserRights::FlushPrivileges();
  38. }
  39. public function DBDeleteTracked(CMDBChange $oChange)
  40. {
  41. parent::DBDeleteTracked($oChange);
  42. UserRights::FlushPrivileges();
  43. }
  44. }
  45. class URP_Users extends UserRightsBaseClass
  46. {
  47. public static function Init()
  48. {
  49. $aParams = array
  50. (
  51. "category" => "addon/userrights",
  52. "key_type" => "autoincrement",
  53. "name_attcode" => "login",
  54. "state_attcode" => "",
  55. "reconc_keys" => array(),
  56. "db_table" => "priv_urp_users",
  57. "db_key_field" => "id",
  58. "db_finalclass_field" => "",
  59. "display_template" => "",
  60. );
  61. MetaModel::Init_Params($aParams);
  62. //MetaModel::Init_InheritAttributes();
  63. 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())));
  64. MetaModel::Init_AddAttribute(new AttributeExternalField("last_name", array("allowed_values"=>null, "extkey_attcode"=> 'userid', "target_attcode"=>"name")));
  65. MetaModel::Init_AddAttribute(new AttributeExternalField("first_name", array("allowed_values"=>null, "extkey_attcode"=> 'userid', "target_attcode"=>"first_name")));
  66. MetaModel::Init_AddAttribute(new AttributeExternalField("email", array("allowed_values"=>null, "extkey_attcode"=> 'userid', "target_attcode"=>"email")));
  67. MetaModel::Init_AddAttribute(new AttributeString("login", array("allowed_values"=>null, "sql"=>"login", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  68. MetaModel::Init_AddAttribute(new AttributePassword("password", array("allowed_values"=>null, "sql"=>"pwd", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  69. //MetaModel::Init_AddAttribute(new AttributeString("language", array("allowed_values"=>array('EN US,FR FR'), "sql"=>"language", "default_value"=>"EN US", "is_null_allowed"=>false, "depends_on"=>array())));
  70. MetaModel::Init_AddAttribute(new AttributeApplicationLanguage("language", array("sql"=>"language", "default_value"=>"EN US", "is_null_allowed"=>false, "depends_on"=>array())));
  71. 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())));
  72. // Display lists
  73. MetaModel::Init_SetZListItems('details', array('userid', 'first_name', 'email', 'login', 'language')); // Attributes to be displayed for the complete details
  74. MetaModel::Init_SetZListItems('list', array('first_name', 'last_name', 'login')); // Attributes to be displayed for a list
  75. // Search criteria
  76. MetaModel::Init_SetZListItems('standard_search', array('login', 'userid')); // Criteria of the std search form
  77. MetaModel::Init_SetZListItems('advanced_search', array('login', 'userid')); // Criteria of the advanced search form
  78. }
  79. function GetGrantAsHtml($sClass, $iAction)
  80. {
  81. if (UserRights::IsActionAllowed($sClass, $iAction, null, $this->GetKey()))
  82. {
  83. return '<span style="background-color: #ddffdd;">'.Dict::S('UI:UserManagement:ActionAllowed:Yes').'</span>';
  84. }
  85. else
  86. {
  87. return '<span style="background-color: #ffdddd;">'.Dict::S('UI:UserManagement:ActionAllowed:No').'</span>';
  88. }
  89. }
  90. function DoShowGrantSumary($oPage, $sClassCategory)
  91. {
  92. $iUserId = $this->GetKey();
  93. if (UserRights::IsAdministrator($iUserId))
  94. {
  95. // Looks dirty, but ok that's THE ONE
  96. $oPage->p(Dict::S('UI:UserManagement:AdminProfile+'));
  97. return;
  98. }
  99. $aDisplayData = array();
  100. foreach (MetaModel::GetClasses($sClassCategory) as $sClass)
  101. {
  102. $aClassStimuli = MetaModel::EnumStimuli($sClass);
  103. if (count($aClassStimuli) > 0)
  104. {
  105. $aStimuli = array();
  106. foreach ($aClassStimuli as $sStimulusCode => $oStimulus)
  107. {
  108. if (UserRights::IsStimulusAllowed($sClass, $sStimulusCode, null, $iUserId))
  109. {
  110. $aStimuli[] = '<span title="'.$sStimulusCode.': '.htmlentities($oStimulus->GetDescription()).'">'.htmlentities($oStimulus->GetLabel()).'</span>';
  111. }
  112. }
  113. $sStimuli = implode(', ', $aStimuli);
  114. }
  115. else
  116. {
  117. $sStimuli = '<em title="'.Dict::S('UI:UserManagement:NoLifeCycleApplicable+').'">'.Dict::S('UI:UserManagement:NoLifeCycleApplicable').'</em>';
  118. }
  119. $aDisplayData[] = array(
  120. 'class' => MetaModel::GetName($sClass),
  121. 'read' => $this->GetGrantAsHtml($sClass, UR_ACTION_READ),
  122. 'bulkread' => $this->GetGrantAsHtml($sClass, UR_ACTION_BULK_READ),
  123. 'write' => $this->GetGrantAsHtml($sClass, UR_ACTION_MODIFY),
  124. 'bulkwrite' => $this->GetGrantAsHtml($sClass, UR_ACTION_BULK_MODIFY),
  125. 'stimuli' => $sStimuli,
  126. );
  127. }
  128. $aDisplayConfig = array();
  129. $aDisplayConfig['class'] = array('label' => Dict::S('UI:UserManagement:Class'), 'description' => Dict::S('UI:UserManagement:Class+'));
  130. $aDisplayConfig['read'] = array('label' => Dict::S('UI:UserManagement:Action:Read'), 'description' => Dict::S('UI:UserManagement:Action:Read+'));
  131. $aDisplayConfig['bulkread'] = array('label' => Dict::S('UI:UserManagement:Action:BulkRead'), 'description' => Dict::S('UI:UserManagement:Action:BulkRead+'));
  132. $aDisplayConfig['write'] = array('label' => Dict::S('UI:UserManagement:Action:Modify'), 'description' => Dict::S('UI:UserManagement:Action:Modify+'));
  133. $aDisplayConfig['bulkwrite'] = array('label' => Dict::S('UI:UserManagement:Action:BulkModify'), 'description' => Dict::S('UI:UserManagement:Action:BulkModify+'));
  134. $aDisplayConfig['stimuli'] = array('label' => Dict::S('UI:UserManagement:Action:Stimuli'), 'description' => Dict::S('UI:UserManagement:Action:Stimuli+'));
  135. $oPage->table($aDisplayConfig, $aDisplayData);
  136. }
  137. function DisplayBareRelations(WebPage $oPage)
  138. {
  139. parent::DisplayBareRelations($oPage);
  140. $oPage->SetCurrentTabContainer('Related Objects');
  141. $oPage->SetCurrentTab(Dict::S('UI:UserManagement:GrantMatrix'));
  142. $this->DoShowGrantSumary($oPage, 'bizmodel');
  143. // debug
  144. if (false)
  145. {
  146. $oPage->SetCurrentTab('More on user rigths (dev only)');
  147. $oPage->add("<h3>User rights</h3>\n");
  148. $this->DoShowGrantSumary($oPage, 'addon/userrights');
  149. $oPage->add("<h3>Change log</h3>\n");
  150. $this->DoShowGrantSumary($oPage, 'core/cmdb');
  151. $oPage->add("<h3>Application</h3>\n");
  152. $this->DoShowGrantSumary($oPage, 'application');
  153. $oPage->add("<h3>GUI</h3>\n");
  154. $this->DoShowGrantSumary($oPage, 'gui');
  155. }
  156. }
  157. }
  158. class URP_Profiles extends UserRightsBaseClass
  159. {
  160. public static function Init()
  161. {
  162. $aParams = array
  163. (
  164. "category" => "addon/userrights",
  165. "key_type" => "autoincrement",
  166. "name_attcode" => "name",
  167. "state_attcode" => "",
  168. "reconc_keys" => array(),
  169. "db_table" => "priv_urp_profiles",
  170. "db_key_field" => "id",
  171. "db_finalclass_field" => "",
  172. "display_template" => "",
  173. );
  174. MetaModel::Init_Params($aParams);
  175. //MetaModel::Init_InheritAttributes();
  176. MetaModel::Init_AddAttribute(new AttributeString("name", array("allowed_values"=>null, "sql"=>"name", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  177. MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  178. 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())));
  179. // Display lists
  180. MetaModel::Init_SetZListItems('details', array('name', 'description')); // Attributes to be displayed for the complete details
  181. MetaModel::Init_SetZListItems('list', array('description')); // Attributes to be displayed for a list
  182. // Search criteria
  183. MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  184. MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  185. }
  186. function GetGrantAsHtml($oUserRights, $sClass, $sAction)
  187. {
  188. $oGrant = $oUserRights->GetClassActionGrant($this->GetKey(), $sClass, $sAction);
  189. if (is_object($oGrant) && ($oGrant->Get('permission') == 'yes'))
  190. {
  191. return '<span style="background-color: #ddffdd;">'.Dict::S('UI:UserManagement:ActionAllowed:Yes').'</span>';
  192. }
  193. else
  194. {
  195. return '<span style="background-color: #ffdddd;">'.Dict::S('UI:UserManagement:ActionAllowed:No').'</span>';
  196. }
  197. }
  198. function DoShowGrantSumary($oPage)
  199. {
  200. if ($this->GetName() == "Administrator")
  201. {
  202. // Looks dirty, but ok that's THE ONE
  203. $oPage->p(Dict::S('UI:UserManagement:AdminProfile+'));
  204. return;
  205. }
  206. // Note: for sure, we assume that the instance is derived from UserRightsProfile
  207. $oUserRights = UserRights::GetModuleInstance();
  208. $aDisplayData = array();
  209. foreach (MetaModel::GetClasses('bizmodel') as $sClass)
  210. {
  211. $aStimuli = array();
  212. foreach (MetaModel::EnumStimuli($sClass) as $sStimulusCode => $oStimulus)
  213. {
  214. $oGrant = $oUserRights->GetClassStimulusGrant($this->GetKey(), $sClass, $sStimulusCode);
  215. if (is_object($oGrant) && ($oGrant->Get('permission') == 'yes'))
  216. {
  217. $aStimuli[] = '<span title="'.$sStimulusCode.': '.htmlentities($oStimulus->GetDescription()).'">'.htmlentities($oStimulus->GetLabel()).'</span>';
  218. }
  219. }
  220. $sStimuli = implode(', ', $aStimuli);
  221. $aDisplayData[] = array(
  222. 'class' => MetaModel::GetName($sClass),
  223. 'read' => $this->GetGrantAsHtml($oUserRights, $sClass, 'Read'),
  224. 'bulkread' => $this->GetGrantAsHtml($oUserRights, $sClass, 'Bulk Read'),
  225. 'write' => $this->GetGrantAsHtml($oUserRights, $sClass, 'Modify'),
  226. 'bulkwrite' => $this->GetGrantAsHtml($oUserRights, $sClass, 'Bulk Modify'),
  227. 'delete' => $this->GetGrantAsHtml($oUserRights, $sClass, 'Delete'),
  228. 'bulkdelete' => $this->GetGrantAsHtml($oUserRights, $sClass, 'Bulk Delete'),
  229. 'stimuli' => $sStimuli,
  230. );
  231. }
  232. $aDisplayConfig = array();
  233. $aDisplayConfig['class'] = array('label' => Dict::S('UI:UserManagement:Class'), 'description' => Dict::S('UI:UserManagement:Class+'));
  234. $aDisplayConfig['read'] = array('label' => Dict::S('UI:UserManagement:Action:Read'), 'description' => Dict::S('UI:UserManagement:Action:Read+'));
  235. $aDisplayConfig['bulkread'] = array('label' => Dict::S('UI:UserManagement:Action:BulkRead'), 'description' => Dict::S('UI:UserManagement:Action:BulkRead+'));
  236. $aDisplayConfig['write'] = array('label' => Dict::S('UI:UserManagement:Action:Modify'), 'description' => Dict::S('UI:UserManagement:Action:Modify+'));
  237. $aDisplayConfig['bulkwrite'] = array('label' => Dict::S('UI:UserManagement:Action:BulkModify'), 'description' => Dict::S('UI:UserManagement:Action:BulkModify+'));
  238. $aDisplayConfig['delete'] = array('label' => Dict::S('UI:UserManagement:Action:Delete'), 'description' => Dict::S('UI:UserManagement:Action:Delete+'));
  239. $aDisplayConfig['bulkdelete'] = array('label' => Dict::S('UI:UserManagement:Action:BulkDelete'), 'description' => Dict::S('UI:UserManagement:Action:BulkDelete+'));
  240. $aDisplayConfig['stimuli'] = array('label' => Dict::S('UI:UserManagement:Action:Stimuli'), 'description' => Dict::S('UI:UserManagement:Action:Stimuli+'));
  241. $oPage->table($aDisplayConfig, $aDisplayData);
  242. }
  243. function DisplayBareRelations(WebPage $oPage)
  244. {
  245. parent::DisplayBareRelations($oPage);
  246. $oPage->SetCurrentTabContainer('Related Objects');
  247. $oPage->SetCurrentTab(Dict::S('UI:UserManagement:GrantMatrix'));
  248. $this->DoShowGrantSumary($oPage);
  249. }
  250. }
  251. class URP_Dimensions extends UserRightsBaseClass
  252. {
  253. public static function Init()
  254. {
  255. $aParams = array
  256. (
  257. "category" => "addon/userrights",
  258. "key_type" => "autoincrement",
  259. "name_attcode" => "name",
  260. "state_attcode" => "",
  261. "reconc_keys" => array(),
  262. "db_table" => "priv_urp_dimensions",
  263. "db_key_field" => "id",
  264. "db_finalclass_field" => "",
  265. "display_template" => "../business/templates/default.html",
  266. );
  267. MetaModel::Init_Params($aParams);
  268. //MetaModel::Init_InheritAttributes();
  269. MetaModel::Init_AddAttribute(new AttributeString("name", array("allowed_values"=>null, "sql"=>"name", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  270. MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  271. 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())));
  272. // Display lists
  273. MetaModel::Init_SetZListItems('details', array('name', 'description', 'type')); // Attributes to be displayed for the complete details
  274. MetaModel::Init_SetZListItems('list', array('description')); // Attributes to be displayed for a list
  275. // Search criteria
  276. MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  277. MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  278. }
  279. public function CheckProjectionSpec($oProjectionSpec, $sProjectedClass)
  280. {
  281. $sExpression = $oProjectionSpec->Get('value');
  282. $sAttribute = $oProjectionSpec->Get('attribute');
  283. // Shortcut: "any value" or "no value" means no projection
  284. if (empty($sExpression)) return;
  285. if ($sExpression == '<any>') return;
  286. // 1st - compute the data type for the dimension
  287. //
  288. $sType = $this->Get('type');
  289. if (MetaModel::IsValidClass($sType))
  290. {
  291. $sExpectedType = $sType;
  292. }
  293. else
  294. {
  295. $sExpectedType = '_scalar_';
  296. }
  297. // 2nd - compute the data type for the projection
  298. //
  299. $sTargetClass = '';
  300. if (($sExpression == '<this>') || ($sExpression == '<user>'))
  301. {
  302. $sTargetClass = $sProjectedClass;
  303. }
  304. elseif ($sExpression == '<any>')
  305. {
  306. $sTargetClass = '';
  307. }
  308. else
  309. {
  310. // Evaluate wether it is a constant or not
  311. try
  312. {
  313. $oObjectSearch = DBObjectSearch::FromOQL($sExpression);
  314. $sTargetClass = $oObjectSearch->GetClass();
  315. }
  316. catch (OqlException $e)
  317. {
  318. }
  319. }
  320. if (empty($sTargetClass))
  321. {
  322. $sFoundType = '_void_';
  323. }
  324. else
  325. {
  326. if (empty($sAttribute))
  327. {
  328. $sFoundType = $sTargetClass;
  329. }
  330. else
  331. {
  332. if (!MetaModel::IsValidAttCode($sTargetClass, $sAttribute))
  333. {
  334. throw new CoreException('Unkown attribute code in projection specification', array('found' => $sAttribute, 'expecting' => MetaModel::GetAttributesList($sTargetClass), 'class' => $sTargetClass, 'projection' => $oProjectionSpec));
  335. }
  336. $oAttDef = MetaModel::GetAttributeDef($sTargetClass, $sAttribute);
  337. if ($oAttDef->IsExternalKey())
  338. {
  339. $sFoundType = $oAttDef->GetTargetClass();
  340. }
  341. else
  342. {
  343. $sFoundType = '_scalar_';
  344. }
  345. }
  346. }
  347. // Compare the dimension type and projection type
  348. if (($sFoundType != '_void_') && ($sFoundType != $sExpectedType))
  349. {
  350. throw new CoreException('Wrong type in projection specification', array('found' => $sFoundType, 'expecting' => $sExpectedType, 'expression' => $sExpression, 'attribute' => $sAttribute, 'projection' => $oProjectionSpec));
  351. }
  352. }
  353. }
  354. class URP_UserProfile extends UserRightsBaseClass
  355. {
  356. public static function Init()
  357. {
  358. $aParams = array
  359. (
  360. "category" => "addon/userrights",
  361. "key_type" => "autoincrement",
  362. "name_attcode" => "userid",
  363. "state_attcode" => "",
  364. "reconc_keys" => array(),
  365. "db_table" => "priv_urp_userprofile",
  366. "db_key_field" => "id",
  367. "db_finalclass_field" => "",
  368. "display_template" => "",
  369. );
  370. MetaModel::Init_Params($aParams);
  371. //MetaModel::Init_InheritAttributes();
  372. 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())));
  373. MetaModel::Init_AddAttribute(new AttributeExternalField("userlogin", array("allowed_values"=>null, "extkey_attcode"=> 'userid', "target_attcode"=>"login")));
  374. 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())));
  375. MetaModel::Init_AddAttribute(new AttributeExternalField("profile", array("allowed_values"=>null, "extkey_attcode"=> 'profileid', "target_attcode"=>"name")));
  376. MetaModel::Init_AddAttribute(new AttributeString("reason", array("allowed_values"=>null, "sql"=>"description", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  377. // Display lists
  378. MetaModel::Init_SetZListItems('details', array('userid', 'profileid', 'reason')); // Attributes to be displayed for the complete details
  379. MetaModel::Init_SetZListItems('list', array('profileid', 'reason')); // Attributes to be displayed for a list
  380. // Search criteria
  381. MetaModel::Init_SetZListItems('standard_search', array('userid', 'profileid')); // Criteria of the std search form
  382. MetaModel::Init_SetZListItems('advanced_search', array('userid', 'profileid')); // Criteria of the advanced search form
  383. }
  384. public function GetName()
  385. {
  386. return Dict::Format('UI:UserManagement:LinkBetween_User_And_Profile', $this->Get('userlogin'), $this->Get('profile'));
  387. }
  388. }
  389. class URP_ProfileProjection extends UserRightsBaseClass
  390. {
  391. public static function Init()
  392. {
  393. $aParams = array
  394. (
  395. "category" => "addon/userrights",
  396. "key_type" => "autoincrement",
  397. "name_attcode" => "profileid",
  398. "state_attcode" => "",
  399. "reconc_keys" => array(),
  400. "db_table" => "priv_urp_profileprojection",
  401. "db_key_field" => "id",
  402. "db_finalclass_field" => "",
  403. "display_template" => "../business/templates/default.html",
  404. );
  405. MetaModel::Init_Params($aParams);
  406. //MetaModel::Init_InheritAttributes();
  407. 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())));
  408. MetaModel::Init_AddAttribute(new AttributeExternalField("dimension", array("allowed_values"=>null, "extkey_attcode"=> 'dimensionid', "target_attcode"=>"name")));
  409. 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())));
  410. MetaModel::Init_AddAttribute(new AttributeExternalField("profile", array("allowed_values"=>null, "extkey_attcode"=> 'profileid', "target_attcode"=>"name")));
  411. MetaModel::Init_AddAttribute(new AttributeString("value", array("allowed_values"=>null, "sql"=>"value", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  412. MetaModel::Init_AddAttribute(new AttributeString("attribute", array("allowed_values"=>null, "sql"=>"attribute", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  413. // Display lists
  414. MetaModel::Init_SetZListItems('details', array('dimensionid', 'profileid', 'value', 'attribute')); // Attributes to be displayed for the complete details
  415. MetaModel::Init_SetZListItems('list', array('profileid', 'value', 'attribute')); // Attributes to be displayed for a list
  416. // Search criteria
  417. MetaModel::Init_SetZListItems('standard_search', array('dimensionid', 'profileid')); // Criteria of the std search form
  418. MetaModel::Init_SetZListItems('advanced_search', array('dimensionid', 'profileid')); // Criteria of the advanced search form
  419. }
  420. public function ProjectUser(URP_Users $oUser)
  421. {
  422. $sExpr = $this->Get('value');
  423. if ($sExpr == '<user>')
  424. {
  425. $sColumn = $this->Get('attribute');
  426. if (empty($sColumn))
  427. {
  428. $aRes = array($oUser->GetKey());
  429. }
  430. else
  431. {
  432. $aRes = array($oUser->Get($sColumn));
  433. }
  434. }
  435. elseif ($sExpr == '<any>')
  436. {
  437. $aRes = null;
  438. }
  439. elseif (strtolower(substr($sExpr, 0, 6)) == 'select')
  440. {
  441. $sColumn = $this->Get('attribute');
  442. // SELECT...
  443. $oValueSetDef = new ValueSetObjects($sExpr, $sColumn);
  444. $aRes = $oValueSetDef->GetValues(array('user' => $oUser), '');
  445. }
  446. else
  447. {
  448. // Constant value(s)
  449. $aRes = explode(';', trim($sExpr));
  450. }
  451. return $aRes;
  452. }
  453. }
  454. class URP_ClassProjection extends UserRightsBaseClass
  455. {
  456. public static function Init()
  457. {
  458. $aParams = array
  459. (
  460. "category" => "addon/userrights",
  461. "key_type" => "autoincrement",
  462. "name_attcode" => "dimensionid",
  463. "state_attcode" => "",
  464. "reconc_keys" => array(),
  465. "db_table" => "priv_urp_classprojection",
  466. "db_key_field" => "id",
  467. "db_finalclass_field" => "",
  468. "display_template" => "../business/templates/default.html",
  469. );
  470. MetaModel::Init_Params($aParams);
  471. //MetaModel::Init_InheritAttributes();
  472. 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())));
  473. MetaModel::Init_AddAttribute(new AttributeExternalField("dimension", array("allowed_values"=>null, "extkey_attcode"=> 'dimensionid', "target_attcode"=>"name")));
  474. MetaModel::Init_AddAttribute(new AttributeClass("class", array("class_category"=>"", "more_values"=>"", "sql"=>"class", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  475. MetaModel::Init_AddAttribute(new AttributeString("value", array("allowed_values"=>null, "sql"=>"value", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  476. MetaModel::Init_AddAttribute(new AttributeString("attribute", array("allowed_values"=>null, "sql"=>"attribute", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  477. // Display lists
  478. MetaModel::Init_SetZListItems('details', array('dimensionid', 'class', 'value', 'attribute')); // Attributes to be displayed for the complete details
  479. MetaModel::Init_SetZListItems('list', array('class', 'value', 'attribute')); // Attributes to be displayed for a list
  480. // Search criteria
  481. MetaModel::Init_SetZListItems('standard_search', array('dimensionid', 'class')); // Criteria of the std search form
  482. MetaModel::Init_SetZListItems('advanced_search', array('dimensionid', 'class')); // Criteria of the advanced search form
  483. }
  484. public function ProjectObject($oObject)
  485. {
  486. $sExpr = $this->Get('value');
  487. if ($sExpr == '<this>')
  488. {
  489. $sColumn = $this->Get('attribute');
  490. if (empty($sColumn))
  491. {
  492. $aRes = array($oObject->GetKey());
  493. }
  494. else
  495. {
  496. $aRes = array($oObject->Get($sColumn));
  497. }
  498. }
  499. elseif ($sExpr == '<any>')
  500. {
  501. $aRes = null;
  502. }
  503. elseif (strtolower(substr($sExpr, 0, 6)) == 'select')
  504. {
  505. $sColumn = $this->Get('attribute');
  506. // SELECT...
  507. $oValueSetDef = new ValueSetObjects($sExpr, $sColumn);
  508. $aRes = $oValueSetDef->GetValues(array('this' => $oObject), '');
  509. }
  510. elseif ($sExpr == '<any>')
  511. {
  512. $aRes = null;
  513. }
  514. else
  515. {
  516. // Constant value(s)
  517. $aRes = explode(';', trim($sExpr));
  518. }
  519. return $aRes;
  520. }
  521. }
  522. class URP_ActionGrant extends UserRightsBaseClass
  523. {
  524. public static function Init()
  525. {
  526. $aParams = array
  527. (
  528. "category" => "addon/userrights",
  529. "key_type" => "autoincrement",
  530. "name_attcode" => "profileid",
  531. "state_attcode" => "",
  532. "reconc_keys" => array(),
  533. "db_table" => "priv_urp_grant_actions",
  534. "db_key_field" => "id",
  535. "db_finalclass_field" => "",
  536. "display_template" => "../business/templates/default.html",
  537. );
  538. MetaModel::Init_Params($aParams);
  539. //MetaModel::Init_InheritAttributes();
  540. // Common to all grant classes (could be factorized by class inheritence, but this has to be benchmarked)
  541. 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())));
  542. MetaModel::Init_AddAttribute(new AttributeExternalField("profile", array("allowed_values"=>null, "extkey_attcode"=> 'profileid', "target_attcode"=>"name")));
  543. MetaModel::Init_AddAttribute(new AttributeClass("class", array("class_category"=>"", "more_values"=>"", "sql"=>"class", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  544. 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())));
  545. MetaModel::Init_AddAttribute(new AttributeString("action", array("allowed_values"=>null, "sql"=>"action", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  546. // Display lists
  547. MetaModel::Init_SetZListItems('details', array('profileid', 'class', 'permission', 'action')); // Attributes to be displayed for the complete details
  548. MetaModel::Init_SetZListItems('list', array('class', 'permission', 'action')); // Attributes to be displayed for a list
  549. // Search criteria
  550. MetaModel::Init_SetZListItems('standard_search', array('profileid', 'class', 'permission', 'action')); // Criteria of the std search form
  551. MetaModel::Init_SetZListItems('advanced_search', array('profileid', 'class', 'permission', 'action')); // Criteria of the advanced search form
  552. }
  553. }
  554. class URP_StimulusGrant extends UserRightsBaseClass
  555. {
  556. public static function Init()
  557. {
  558. $aParams = array
  559. (
  560. "category" => "addon/userrights",
  561. "key_type" => "autoincrement",
  562. "name_attcode" => "profileid",
  563. "state_attcode" => "",
  564. "reconc_keys" => array(),
  565. "db_table" => "priv_urp_grant_stimulus",
  566. "db_key_field" => "id",
  567. "db_finalclass_field" => "",
  568. "display_template" => "../business/templates/default.html",
  569. );
  570. MetaModel::Init_Params($aParams);
  571. //MetaModel::Init_InheritAttributes();
  572. // Common to all grant classes (could be factorized by class inheritence, but this has to be benchmarked)
  573. 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())));
  574. MetaModel::Init_AddAttribute(new AttributeExternalField("profile", array("allowed_values"=>null, "extkey_attcode"=> 'profileid', "target_attcode"=>"name")));
  575. MetaModel::Init_AddAttribute(new AttributeClass("class", array("class_category"=>"", "more_values"=>"", "sql"=>"class", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  576. 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())));
  577. MetaModel::Init_AddAttribute(new AttributeString("stimulus", array("allowed_values"=>null, "sql"=>"action", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  578. // Display lists
  579. MetaModel::Init_SetZListItems('details', array('profileid', 'class', 'permission', 'stimulus')); // Attributes to be displayed for the complete details
  580. MetaModel::Init_SetZListItems('list', array('class', 'permission', 'stimulus')); // Attributes to be displayed for a list
  581. // Search criteria
  582. MetaModel::Init_SetZListItems('standard_search', array('profileid', 'class', 'permission', 'stimulus')); // Criteria of the std search form
  583. MetaModel::Init_SetZListItems('advanced_search', array('profileid', 'class', 'permission', 'stimulus')); // Criteria of the advanced search form
  584. }
  585. }
  586. class URP_AttributeGrant extends UserRightsBaseClass
  587. {
  588. public static function Init()
  589. {
  590. $aParams = array
  591. (
  592. "category" => "addon/userrights",
  593. "key_type" => "autoincrement",
  594. "name_attcode" => "actiongrantid",
  595. "state_attcode" => "",
  596. "reconc_keys" => array(),
  597. "db_table" => "priv_urp_grant_attributes",
  598. "db_key_field" => "id",
  599. "db_finalclass_field" => "",
  600. "display_template" => "../business/templates/default.html",
  601. );
  602. MetaModel::Init_Params($aParams);
  603. //MetaModel::Init_InheritAttributes();
  604. 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())));
  605. MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  606. // Display lists
  607. MetaModel::Init_SetZListItems('details', array('actiongrantid', 'attcode')); // Attributes to be displayed for the complete details
  608. MetaModel::Init_SetZListItems('list', array('attcode')); // Attributes to be displayed for a list
  609. // Search criteria
  610. MetaModel::Init_SetZListItems('standard_search', array('actiongrantid', 'attcode')); // Criteria of the std search form
  611. MetaModel::Init_SetZListItems('advanced_search', array('actiongrantid', 'attcode')); // Criteria of the advanced search form
  612. }
  613. }
  614. class UserRightsProfile extends UserRightsAddOnAPI
  615. {
  616. static public $m_aActionCodes = array(
  617. UR_ACTION_READ => 'read',
  618. UR_ACTION_MODIFY => 'modify',
  619. UR_ACTION_DELETE => 'delete',
  620. UR_ACTION_BULK_READ => 'bulk read',
  621. UR_ACTION_BULK_MODIFY => 'bulk modify',
  622. UR_ACTION_BULK_DELETE => 'bulk delete',
  623. );
  624. // Installation: create the very first user
  625. public function CreateAdministrator($sAdminUser, $sAdminPwd)
  626. {
  627. // Create a change to record the history of the User object
  628. $oChange = MetaModel::NewObject("CMDBChange");
  629. $oChange->Set("date", time());
  630. $oChange->Set("userinfo", "Initialization");
  631. $iChangeId = $oChange->DBInsert();
  632. $oOrg = new bizOrganization();
  633. $oOrg->Set('name', 'My Company/Department');
  634. $oOrg->Set('code', 'SOMECODE');
  635. $oOrg->Set('status', 'implementation');
  636. //$oOrg->Set('parent_id', xxx);
  637. $iOrgId = $oOrg->DBInsertTrackedNoReload($oChange);
  638. // Location : optional
  639. //$oLocation = new bizLocation();
  640. //$oLocation->Set('name', 'MyOffice');
  641. //$oLocation->Set('status', 'implementation');
  642. //$oLocation->Set('org_id', $iOrgId);
  643. //$oLocation->Set('severity', 'high');
  644. //$oLocation->Set('address', 'my building in my city');
  645. //$oLocation->Set('country', 'my country');
  646. //$oLocation->Set('parent_location_id', xxx);
  647. //$iLocationId = $oLocation->DBInsertNoReload();
  648. $oContact = new bizPerson();
  649. $oContact->Set('name', 'My last name');
  650. $oContact->Set('first_name', 'My first name');
  651. $oContact->Set('status', 'available');
  652. $oContact->Set('org_id', $iOrgId);
  653. $oContact->Set('email', 'my.email@foo.org');
  654. $oContact->Set('phone', '');
  655. //$oContact->Set('location_id', $iLocationId);
  656. $oContact->Set('employee_number', '');
  657. $iContactId = $oContact->DBInsertTrackedNoReload($oChange);
  658. $oUser = new URP_Users();
  659. $oUser->Set('login', $sAdminUser);
  660. $oUser->Set('password', $sAdminPwd);
  661. $oUser->Set('userid', $iContactId);
  662. $iUserId = $oUser->DBInsertTrackedNoReload($oChange);
  663. // Add this user to the very specific 'admin' profile
  664. $oUserProfile = new URP_UserProfile();
  665. $oUserProfile->Set('userid', $iUserId);
  666. $oUserProfile->Set('profileid', ADMIN_PROFILE_ID);
  667. $oUserProfile->Set('reason', 'By definition, the administrator must have the administrator profile');
  668. $oUserProfile->DBInsertTrackedNoReload($oChange);
  669. return true;
  670. }
  671. public function IsAdministrator($iUserId)
  672. {
  673. if (in_array($iUserId, $this->m_aAdmins))
  674. {
  675. return true;
  676. }
  677. else
  678. {
  679. return false;
  680. }
  681. }
  682. public function Setup()
  683. {
  684. SetupProfiles::ComputeITILProfiles();
  685. //SetupProfiles::ComputeBasicProfiles();
  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. if (array_key_exists($iDimension, $this->m_aClassProjs[$sClass]))
  1067. {
  1068. $aObjectProjection = $this->m_aClassProjs[$sClass][$iDimension]->ProjectObject($oObject);
  1069. }
  1070. else
  1071. {
  1072. // No projection for a given class: default to 'any'
  1073. $aObjectProjection = null;
  1074. }
  1075. $aRes = array();
  1076. if (array_key_exists($iUser, $this->m_aUserProfiles))
  1077. {
  1078. foreach ($this->m_aUserProfiles[$iUser] as $iProfile => $oProfile)
  1079. {
  1080. if (is_null($aObjectProjection))
  1081. {
  1082. $aRes[] = $iProfile;
  1083. }
  1084. else
  1085. {
  1086. // user projection to be cached on a given page !
  1087. if (array_key_exists($iDimension, $this->m_aProPros[$iProfile]))
  1088. {
  1089. $aUserProjection = $this->m_aProPros[$iProfile][$iDimension]->ProjectUser($oUser);
  1090. }
  1091. else
  1092. {
  1093. // No projection for a given profile: default to 'any'
  1094. $aUserProjection = null;
  1095. }
  1096. if (is_null($aUserProjection))
  1097. {
  1098. $aRes[] = $iProfile;
  1099. }
  1100. else
  1101. {
  1102. $aMatchingValues = array_intersect($aObjectProjection, $aUserProjection);
  1103. if (count($aMatchingValues) > 0)
  1104. {
  1105. $aRes[] = $iProfile;
  1106. }
  1107. }
  1108. }
  1109. }
  1110. }
  1111. return $aRes;
  1112. }
  1113. protected $m_aMatchingProfiles = array(); // cache of the matching profiles for a given user/object
  1114. protected function GetMatchingProfiles($oUser, $sClass, /*DBObject*/ $oObject = null)
  1115. {
  1116. $iUser = $oUser->GetKey();
  1117. if(is_null($oObject))
  1118. {
  1119. $iObjectRef = -999;
  1120. }
  1121. else
  1122. {
  1123. $iObjectRef = $oObject->GetKey();
  1124. }
  1125. //
  1126. // List profiles for which the user projection overlaps the object projection in each and every dimension
  1127. // Caches the result
  1128. //
  1129. $aTest = @$this->m_aMatchingProfiles[$iUser][$sClass][$iObjectRef];
  1130. if (is_array($aTest))
  1131. {
  1132. return $aTest;
  1133. }
  1134. if (is_null($oObject))
  1135. {
  1136. if (array_key_exists($iUser, $this->m_aUserProfiles))
  1137. {
  1138. $aRes = array_keys($this->m_aUserProfiles[$iUser]);
  1139. }
  1140. else
  1141. {
  1142. // no profile has been defined for this user
  1143. $aRes = array();
  1144. }
  1145. }
  1146. else
  1147. {
  1148. $aProfileRes = array();
  1149. foreach ($this->m_aDimensions as $iDimension => $oDimension)
  1150. {
  1151. foreach ($this->GetMatchingProfilesByDim($oUser, $oObject, $oDimension) as $iProfile)
  1152. {
  1153. @$aProfileRes[$iProfile] += 1;
  1154. }
  1155. }
  1156. $aRes = array();
  1157. $iDimCount = count($this->m_aDimensions);
  1158. foreach ($aProfileRes as $iProfile => $iMatches)
  1159. {
  1160. if ($iMatches == $iDimCount)
  1161. {
  1162. $aRes[] = $iProfile;
  1163. }
  1164. }
  1165. }
  1166. // store into the cache
  1167. $this->m_aMatchingProfiles[$iUser][$sClass][$iObjectRef] = $aRes;
  1168. return $aRes;
  1169. }
  1170. public function FlushPrivileges()
  1171. {
  1172. $this->CacheData();
  1173. }
  1174. }
  1175. //
  1176. // Create simple profiles into our user management model:
  1177. // - administrator
  1178. // - readers
  1179. // - contributors
  1180. //
  1181. class SetupProfiles
  1182. {
  1183. protected static $m_aDimensions = array(
  1184. 'organization' => array(
  1185. 'description' => '',
  1186. 'type' => 'bizOrganization',
  1187. ),
  1188. );
  1189. protected static $m_aActions = array(
  1190. UR_ACTION_READ => 'Read',
  1191. UR_ACTION_MODIFY => 'Modify',
  1192. UR_ACTION_DELETE => 'Delete',
  1193. UR_ACTION_BULK_READ => 'Bulk Read',
  1194. UR_ACTION_BULK_MODIFY => 'Bulk Modify',
  1195. UR_ACTION_BULK_DELETE => 'Bulk Delete',
  1196. );
  1197. // Note: It is possible to specify the same class in several modules
  1198. //
  1199. protected static $m_aModules = array();
  1200. protected static $m_aProfiles = array();
  1201. protected static function DoCreateClassProjection($iDimension, $sClass)
  1202. {
  1203. $oNewObj = MetaModel::NewObject("URP_ClassProjection");
  1204. $oNewObj->Set('dimensionid', $iDimension);
  1205. $oNewObj->Set('class', $sClass);
  1206. $oNewObj->Set('attribute', '');
  1207. $iId = $oNewObj->DBInsertNoReload();
  1208. return $iId;
  1209. }
  1210. protected static function DoCreateDimension($sName, $aDimensionData)
  1211. {
  1212. $oNewObj = MetaModel::NewObject("URP_Dimensions");
  1213. $oNewObj->Set('name', $sName);
  1214. $oNewObj->Set('description', $aDimensionData['description']);
  1215. $oNewObj->Set('type', $aDimensionData['type']);
  1216. $iId = $oNewObj->DBInsertNoReload();
  1217. return $iId;
  1218. }
  1219. protected static function DoCreateProfileProjection($iProfile, $iDimension)
  1220. {
  1221. $oNewObj = MetaModel::NewObject("URP_ProfileProjection");
  1222. $oNewObj->Set('profileid', $iProfile);
  1223. $oNewObj->Set('dimensionid', $iDimension);
  1224. $oNewObj->Set('value', '<any>');
  1225. $oNewObj->Set('attribute', '');
  1226. $iId = $oNewObj->DBInsertNoReload();
  1227. return $iId;
  1228. }
  1229. protected static function DoCreateActionGrant($iProfile, $iAction, $sClass, $bPermission = true)
  1230. {
  1231. $oNewObj = MetaModel::NewObject("URP_ActionGrant");
  1232. $oNewObj->Set('profileid', $iProfile);
  1233. $oNewObj->Set('permission', $bPermission ? 'yes' : 'no');
  1234. $oNewObj->Set('class', $sClass);
  1235. $oNewObj->Set('action', self::$m_aActions[$iAction]);
  1236. $iId = $oNewObj->DBInsertNoReload();
  1237. return $iId;
  1238. }
  1239. protected static function DoCreateStimulusGrant($iProfile, $sStimulusCode, $sClass)
  1240. {
  1241. $oNewObj = MetaModel::NewObject("URP_StimulusGrant");
  1242. $oNewObj->Set('profileid', $iProfile);
  1243. $oNewObj->Set('permission', 'yes');
  1244. $oNewObj->Set('class', $sClass);
  1245. $oNewObj->Set('stimulus', $sStimulusCode);
  1246. $iId = $oNewObj->DBInsertNoReload();
  1247. return $iId;
  1248. }
  1249. protected static function DoCreateAdminProfile()
  1250. {
  1251. $oNewObj = MetaModel::NewObject("URP_Profiles");
  1252. $oNewObj->Set('name', 'Administrator');
  1253. $oNewObj->Set('description', 'Has the rights on everything (bypassing any control)');
  1254. $iNewId = $oNewObj->DBInsertNoReload();
  1255. if ($iNewId != ADMIN_PROFILE_ID)
  1256. {
  1257. throw new CoreException('Admin profile could not be created with its standard id', array('requested'=>ADMIN_PROFILE_ID, 'obtained'=>$iNewId));
  1258. }
  1259. }
  1260. protected static function DoCreateOneProfile($sName, $aProfileData)
  1261. {
  1262. $sDescription = $aProfileData['description'];
  1263. if (strlen(trim($aProfileData['write_modules'])) == 0)
  1264. {
  1265. $aWriteModules = array();
  1266. }
  1267. else
  1268. {
  1269. $aWriteModules = explode(',', trim($aProfileData['write_modules']));
  1270. }
  1271. $aStimuli = $aProfileData['stimuli'];
  1272. $oNewObj = MetaModel::NewObject("URP_Profiles");
  1273. $oNewObj->Set('name', $sName);
  1274. $oNewObj->Set('description', $sDescription);
  1275. $iProfile = $oNewObj->DBInsertNoReload();
  1276. // Project in every dimension
  1277. //
  1278. $oDimensionSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_Dimensions"));
  1279. while ($oDimension = $oDimensionSet->Fetch())
  1280. {
  1281. $iDimension = $oDimension->GetKey();
  1282. self::DoCreateProfileProjection($iProfile, $iDimension);
  1283. }
  1284. // Grant read rights for everything
  1285. //
  1286. foreach (MetaModel::GetClasses('bizmodel') as $sClass)
  1287. {
  1288. self::DoCreateActionGrant($iProfile, UR_ACTION_READ, $sClass);
  1289. self::DoCreateActionGrant($iProfile, UR_ACTION_BULK_READ, $sClass);
  1290. }
  1291. // Grant write for given modules
  1292. // Start by compiling the information, because some modules may overlap
  1293. $aWriteableClasses = array();
  1294. foreach ($aWriteModules as $sModule)
  1295. {
  1296. //$oPage->p('Granting write access for the module"'.$sModule.'" - '.count(self::$m_aModules[$sModule]).' classes');
  1297. foreach (self::$m_aModules[$sModule] as $sClass)
  1298. {
  1299. $aWriteableClasses[$sClass] = true;
  1300. }
  1301. }
  1302. foreach ($aWriteableClasses as $sClass => $foo)
  1303. {
  1304. if (!MetaModel::IsValidClass($sClass))
  1305. {
  1306. throw new CoreException("Invalid class name '$sClass'");
  1307. }
  1308. self::DoCreateActionGrant($iProfile, UR_ACTION_MODIFY, $sClass);
  1309. self::DoCreateActionGrant($iProfile, UR_ACTION_DELETE, $sClass);
  1310. self::DoCreateActionGrant($iProfile, UR_ACTION_BULK_MODIFY, $sClass);
  1311. // By default, do not allow bulk deletion operations for standard users
  1312. // self::DoCreateActionGrant($iProfile, UR_ACTION_BULK_DELETE, $sClass);
  1313. }
  1314. // Grant stimuli for given classes
  1315. foreach ($aStimuli as $sClass => $sAllowedStimuli)
  1316. {
  1317. if (!MetaModel::IsValidClass($sClass))
  1318. {
  1319. throw new CoreException("Invalid class name '$sClass'");
  1320. }
  1321. if ($sAllowedStimuli == 'any')
  1322. {
  1323. $aAllowedStimuli = array_keys(MetaModel::EnumStimuli($sClass));
  1324. }
  1325. elseif ($sAllowedStimuli == 'none')
  1326. {
  1327. $aAllowedStimuli = array();
  1328. }
  1329. else
  1330. {
  1331. $aAllowedStimuli = explode(',', $sAllowedStimuli);
  1332. }
  1333. foreach ($aAllowedStimuli as $sStimulusCode)
  1334. {
  1335. self::DoCreateStimulusGrant($iProfile, $sStimulusCode, $sClass);
  1336. }
  1337. }
  1338. }
  1339. public static function DoCreateDimensions()
  1340. {
  1341. $aClass = MetaModel::GetClasses();
  1342. foreach(self::$m_aDimensions as $sName => $aDimensionData)
  1343. {
  1344. $iDimension = self::DoCreateDimension($sName, $aDimensionData);
  1345. foreach($aClass as $sClass)
  1346. {
  1347. if (!MetaModel::IsValidClass($sClass))
  1348. {
  1349. throw new CoreException("Invalid class name '$sClass'");
  1350. }
  1351. self::DoCreateClassProjection($iDimension, $sClass);
  1352. }
  1353. }
  1354. }
  1355. public static function DoCreateProfiles()
  1356. {
  1357. self::DoCreateAdminProfile();
  1358. foreach(self::$m_aProfiles as $sName => $aProfileData)
  1359. {
  1360. self::DoCreateOneProfile($sName, $aProfileData);
  1361. }
  1362. }
  1363. public static function ComputeBasicProfiles()
  1364. {
  1365. // In this profiling scheme, one single module represents all the classes
  1366. //
  1367. self::$m_aModules = array(
  1368. 'UserData' => MetaModel::GetClasses('bizmodel'),
  1369. );
  1370. self::$m_aProfiles = array(
  1371. 'Reader' => array(
  1372. 'description' => 'Person having a ready-only access to the data',
  1373. 'write_modules' => '',
  1374. 'stimuli' => array(
  1375. ),
  1376. ),
  1377. 'Writer' => array(
  1378. 'description' => 'Contributor to the contents (read + write access)',
  1379. 'write_modules' => 'UserData',
  1380. 'stimuli' => array(
  1381. // any class => 'any'
  1382. ),
  1383. ),
  1384. );
  1385. }
  1386. public static function ComputeITILProfiles()
  1387. {
  1388. // In this profiling scheme, modules are based on ITIL recommendations
  1389. //
  1390. self::$m_aModules = array(
  1391. 'General' => array(
  1392. 'bizOrganization',
  1393. ),
  1394. 'Documentation' => array(
  1395. 'bizDocument',
  1396. 'lnkDocumentRealObject',
  1397. 'lnkDocumentContract',
  1398. 'lnkDocumentError',
  1399. ),
  1400. 'Configuration' => array(
  1401. 'logRealObject',
  1402. 'lnkContactRealObject',
  1403. // 'lnkInterfaces',
  1404. 'lnkClientServer',
  1405. 'lnkInfraGrouping',
  1406. 'lnkContactInfra',
  1407. 'lnkContactTeam',
  1408. ),
  1409. 'Incident' => array(
  1410. 'bizIncidentTicket',
  1411. 'lnkRelatedTicket',
  1412. 'lnkInfraTicket',
  1413. 'lnkContactTicket',
  1414. ),
  1415. 'Problem' => array(
  1416. 'bizKnownError',
  1417. 'lnkInfraError',
  1418. 'lnkDocumentError',
  1419. ),
  1420. 'Change' => array(
  1421. 'bizChangeTicket',
  1422. 'lnkInfraChangeTicket',
  1423. 'lnkContactChange',
  1424. ),
  1425. 'Service' => array(
  1426. 'bizService',
  1427. 'bizContract',
  1428. 'lnkInfraContract',
  1429. 'lnkContactContract',
  1430. 'lnkDocumentContract',
  1431. ),
  1432. 'Call' => array(
  1433. 'bizServiceCall',
  1434. 'lnkCallTicket',
  1435. 'lnkInfraCall',
  1436. ),
  1437. );
  1438. self::$m_aProfiles = array(
  1439. 'Configuration Manager' => array(
  1440. 'description' => 'Person in charge of the documentation of the managed CIs',
  1441. 'write_modules' => 'Documentation,Configuration',
  1442. 'stimuli' => array(
  1443. 'bizServer' => 'any',
  1444. //'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',
  1445. 'bizContract' => 'none',
  1446. 'bizIncidentTicket' => 'none',
  1447. 'bizChangeTicket' => 'none',
  1448. ),
  1449. ),
  1450. 'Service Desk Agent' => array(
  1451. 'description' => 'Person in charge of creating incident reports',
  1452. 'write_modules' => 'Incident,Call',
  1453. 'stimuli' => array(
  1454. 'bizServer' => 'none',
  1455. 'bizContract' => 'none',
  1456. 'bizIncidentTicket' => 'ev_assign',
  1457. 'bizChangeTicket' => 'none',
  1458. 'bizServiceCall' => 'any',
  1459. ),
  1460. ),
  1461. 'Support Agent' => array(
  1462. 'description' => 'Person analyzing and solving the current incidents or problems',
  1463. 'write_modules' => 'Incident,Problem',
  1464. 'stimuli' => array(
  1465. 'bizIncidentTicket' => 'any',
  1466. //'bizIncidentTicket' => 'ev_assign,ev_reassign,ev_start_working,ev_close',
  1467. ),
  1468. ),
  1469. 'Change Implementor' => array(
  1470. 'description' => 'Person executing the changes',
  1471. 'write_modules' => 'Change',
  1472. 'stimuli' => array(
  1473. 'bizServer' => 'none',
  1474. 'bizContract' => 'none',
  1475. 'bizIncidentTicket' => 'none',
  1476. 'bizChangeTicket' => 'ev_plan,ev_replan,ev_implement,ev_monitor',
  1477. ),
  1478. ),
  1479. 'Change Supervisor' => array(
  1480. 'description' => 'Person responsible for the overall change execution',
  1481. 'write_modules' => 'Change',
  1482. 'stimuli' => array(
  1483. 'bizServer' => 'none',
  1484. 'bizContract' => 'none',
  1485. 'bizIncidentTicket' => 'none',
  1486. 'bizChangeTicket' => 'ev_assign,ev_validate,ev_reject,ev_reopen,ev_finish',
  1487. ),
  1488. ),
  1489. 'Change Approver' => array(
  1490. 'description' => 'Person who could be impacted by some changes',
  1491. 'write_modules' => 'Change',
  1492. 'stimuli' => array(
  1493. 'bizServer' => 'none',
  1494. 'bizContract' => 'none',
  1495. 'bizIncidentTicket' => 'none',
  1496. 'bizChangeTicket' => 'ev_approve,ev_notapprove',
  1497. ),
  1498. ),
  1499. 'Service Manager' => array(
  1500. 'description' => 'Person responsible for the service delivered to the [internal] customer',
  1501. 'write_modules' => 'Service',
  1502. 'stimuli' => array(
  1503. 'bizServer' => 'none',
  1504. 'bizContract' => 'any',
  1505. //'bizContract' => 'ev_freeze_version,ev_sign,ev_begin,ev_notice,ev_terminate,ev_elapsed',
  1506. 'bizIncidentTicket' => 'none',
  1507. 'bizChangeTicket' => 'none',
  1508. ),
  1509. ),
  1510. 'Document author' => array(
  1511. 'description' => 'Any person who could contribute to documentation',
  1512. 'write_modules' => 'Documentation',
  1513. 'stimuli' => array(
  1514. ),
  1515. ),
  1516. );
  1517. }
  1518. }
  1519. UserRights::SelectModule('UserRightsProfile');
  1520. ?>