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