userrightsprofile.class.inc.php 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695
  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("profile_list", 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', 'password', 'language', 'profile_list')); // 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("user_list", 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', 'user_list')); // 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" => "",
  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" => "",
  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" => "",
  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" => "",
  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" => "",
  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" => "",
  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. // Could be a class defined in a module that wasn't installed
  1357. continue;
  1358. //throw new CoreException("Invalid class name '$sClass'");
  1359. }
  1360. if ($sAllowedStimuli == 'any')
  1361. {
  1362. $aAllowedStimuli = array_keys(MetaModel::EnumStimuli($sClass));
  1363. }
  1364. elseif ($sAllowedStimuli == 'none')
  1365. {
  1366. $aAllowedStimuli = array();
  1367. }
  1368. else
  1369. {
  1370. $aAllowedStimuli = explode(',', $sAllowedStimuli);
  1371. }
  1372. foreach ($aAllowedStimuli as $sStimulusCode)
  1373. {
  1374. self::DoCreateStimulusGrant($iProfile, $sStimulusCode, $sClass);
  1375. }
  1376. }
  1377. }
  1378. public static function DoCreateDimensions()
  1379. {
  1380. $aClass = MetaModel::GetClasses();
  1381. foreach(self::$m_aDimensions as $sName => $aDimensionData)
  1382. {
  1383. $iDimension = self::DoCreateDimension($sName, $aDimensionData);
  1384. foreach($aClass as $sClass)
  1385. {
  1386. if (!MetaModel::IsValidClass($sClass))
  1387. {
  1388. throw new CoreException("Invalid class name '$sClass'");
  1389. }
  1390. self::DoCreateClassProjection($iDimension, $sClass);
  1391. }
  1392. }
  1393. }
  1394. public static function DoCreateProfiles()
  1395. {
  1396. self::DoCreateAdminProfile();
  1397. foreach(self::$m_aProfiles as $sName => $aProfileData)
  1398. {
  1399. self::DoCreateOneProfile($sName, $aProfileData);
  1400. }
  1401. }
  1402. public static function ComputeBasicProfiles()
  1403. {
  1404. // In this profiling scheme, one single module represents all the classes
  1405. //
  1406. self::$m_aModules = array(
  1407. 'UserData' => MetaModel::GetClasses('bizmodel'),
  1408. );
  1409. self::$m_aProfiles = array(
  1410. 'Reader' => array(
  1411. 'description' => 'Person having a ready-only access to the data',
  1412. 'write_modules' => '',
  1413. 'stimuli' => array(
  1414. ),
  1415. ),
  1416. 'Writer' => array(
  1417. 'description' => 'Contributor to the contents (read + write access)',
  1418. 'write_modules' => 'UserData',
  1419. 'stimuli' => array(
  1420. // any class => 'any'
  1421. ),
  1422. ),
  1423. );
  1424. }
  1425. public static function ComputeITILProfiles()
  1426. {
  1427. // In this profiling scheme, modules are based on ITIL recommendations
  1428. //
  1429. self::$m_aModules = array(
  1430. /*
  1431. 'WriteModule' => array(
  1432. 'someclass',
  1433. 'anotherclass',
  1434. ),
  1435. */
  1436. 'General' => MetaModel::GetClasses('structure'),
  1437. 'Documentation' => MetaModel::GetClasses('documentation'),
  1438. 'Configuration' => MetaModel::GetClasses('configmgmt'),
  1439. 'Incident' => MetaModel::GetClasses('incidentmgmt'),
  1440. 'Problem' => MetaModel::GetClasses('problemmgmt'),
  1441. 'Change' => MetaModel::GetClasses('changemgmt'),
  1442. 'Service' => MetaModel::GetClasses('servicemgmt'),
  1443. 'Call' => MetaModel::GetClasses('callmgmt'),
  1444. 'KnownError' => MetaModel::GetClasses('knownerrormgmt'),
  1445. );
  1446. self::$m_aProfiles = array(
  1447. 'Configuration Manager' => array(
  1448. 'description' => 'Person in charge of the documentation of the managed CIs',
  1449. 'write_modules' => 'General,Documentation,Configuration',
  1450. 'stimuli' => array(
  1451. //'bizServer' => 'none',
  1452. //'bizContract' => 'none',
  1453. //'bizIncidentTicket' => 'none',
  1454. //'bizChangeTicket' => 'any',
  1455. ),
  1456. ),
  1457. 'Service Desk Agent' => array(
  1458. 'description' => 'Person in charge of creating incident reports',
  1459. 'write_modules' => 'Incident,Call',
  1460. 'stimuli' => array(
  1461. 'Incident' => 'ev_assign',
  1462. 'UserRequest' => 'ev_assign',
  1463. ),
  1464. ),
  1465. 'Support Agent' => array(
  1466. 'description' => 'Person analyzing and solving the current incidents or problems',
  1467. 'write_modules' => 'Incident,Problem,KnownError',
  1468. 'stimuli' => array(
  1469. 'Incident' => 'ev_assign,ev_reassign,ev_resolve,ev_close',
  1470. 'UserRequest' => 'ev_assign,ev_reassign,ev_resolve,ev_close,ev_freeze',
  1471. ),
  1472. ),
  1473. 'Change Implementor' => array(
  1474. 'description' => 'Person executing the changes',
  1475. 'write_modules' => 'Change',
  1476. 'stimuli' => array(
  1477. 'NormalChange' => 'ev_plan,ev_replan,ev_implement,ev_monitor',
  1478. 'EmergencyChange' => 'ev_plan,ev_replan,ev_implement,ev_monitor',
  1479. 'RoutineChange' => 'ev_plan,ev_replan,ev_implement,ev_monitor',
  1480. ),
  1481. ),
  1482. 'Change Supervisor' => array(
  1483. 'description' => 'Person responsible for the overall change execution',
  1484. 'write_modules' => 'Change',
  1485. 'stimuli' => array(
  1486. 'NormalChange' => 'ev_validate,ev_reject,ev_assign,ev_reopen,ev_finish',
  1487. 'EmergencyChange' => 'ev_assign,ev_reopen,ev_finish',
  1488. 'RoutineChange' => 'ev_assign,ev_reopen,ev_finish',
  1489. ),
  1490. ),
  1491. 'Change Approver' => array(
  1492. 'description' => 'Person who could be impacted by some changes',
  1493. 'write_modules' => 'Change',
  1494. 'stimuli' => array(
  1495. 'NormalChange' => 'ev_approve,ev_notapprove',
  1496. 'EmergencyChange' => 'ev_approve,ev_notapprove',
  1497. 'RoutineChange' => 'none',
  1498. ),
  1499. ),
  1500. 'Service Manager' => array(
  1501. 'description' => 'Person responsible for the service delivered to the [internal] customer',
  1502. 'write_modules' => 'Service',
  1503. 'stimuli' => array(
  1504. ),
  1505. ),
  1506. 'Document author' => array(
  1507. 'description' => 'Any person who could contribute to documentation',
  1508. 'write_modules' => 'Documentation',
  1509. 'stimuli' => array(
  1510. ),
  1511. ),
  1512. );
  1513. }
  1514. }
  1515. UserRights::SelectModule('UserRightsProfile');
  1516. ?>