userrightsprofile.class.inc.php 60 KB

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