userrightsprofile.class.inc.php 59 KB

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