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