userrightsprofile.class.inc.php 59 KB

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