userrightsprofile.class.inc.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074
  1. <?php
  2. /**
  3. * UserRightsProfile
  4. * User management Module, basing the right on profiles and a matrix (similar to UserRightsMatrix, but profiles and other decorations have been added)
  5. *
  6. * @package iTopORM
  7. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  8. * @author Denis Flaven <denisflave@free.fr>
  9. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  10. * @link www.itop.com
  11. * @since 1.0
  12. * @version 1.1.1.1 $
  13. */
  14. // It is supposed that this profile does exist in the DB
  15. // Possible improvement: add it when executing the setup procedure
  16. //
  17. define('ADMIN_PROFILE_ID', 1);
  18. class URP_Users extends DBObject
  19. {
  20. public static function Init()
  21. {
  22. $aParams = array
  23. (
  24. "category" => "addon/userrights",
  25. "name" => "user",
  26. "description" => "users and credentials",
  27. "key_type" => "autoincrement",
  28. "key_label" => "",
  29. "name_attcode" => "login",
  30. "state_attcode" => "",
  31. "reconc_keys" => array(),
  32. "db_table" => "priv_urp_users",
  33. "db_key_field" => "id",
  34. "db_finalclass_field" => "",
  35. );
  36. MetaModel::Init_Params($aParams);
  37. //MetaModel::Init_InheritAttributes();
  38. MetaModel::Init_AddAttribute(new AttributeInteger("userid", array("label"=>"User id", "description"=>"User identifier (depends on the business model)", "allowed_values"=>null, "sql"=>"userid", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  39. MetaModel::Init_AddAttribute(new AttributeString("login", array("label"=>"login", "description"=>"user identification string", "allowed_values"=>null, "sql"=>"login", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  40. MetaModel::Init_AddAttribute(new AttributeString("password", array("label"=>"password", "description"=>"user authentication string", "allowed_values"=>null, "sql"=>"pwd", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  41. MetaModel::Init_AddAttribute(new AttributeString("email", array("label"=>"email", "description"=>"email address", "allowed_values"=>null, "sql"=>"email", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  42. MetaModel::Init_AddAttribute(new AttributeString("firstname", array("label"=>"firstname", "description"=>"first name", "allowed_values"=>null, "sql"=>"firstname", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  43. MetaModel::Init_AddAttribute(new AttributeString("lastname", array("label"=>"lastname", "description"=>"last name", "allowed_values"=>null, "sql"=>"lastname", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  44. //MetaModel::Init_InheritFilters();
  45. MetaModel::Init_AddFilterFromAttribute("userid");
  46. MetaModel::Init_AddFilterFromAttribute("login");
  47. }
  48. }
  49. class URP_Profiles extends DBObject
  50. {
  51. public static function Init()
  52. {
  53. $aParams = array
  54. (
  55. "category" => "addon/userrights",
  56. "name" => "profile",
  57. "description" => "usage profiles",
  58. "key_type" => "autoincrement",
  59. "key_label" => "",
  60. "name_attcode" => "name",
  61. "state_attcode" => "",
  62. "reconc_keys" => array(),
  63. "db_table" => "priv_urp_profiles",
  64. "db_key_field" => "id",
  65. "db_finalclass_field" => "",
  66. );
  67. MetaModel::Init_Params($aParams);
  68. //MetaModel::Init_InheritAttributes();
  69. MetaModel::Init_AddAttribute(new AttributeString("name", array("label"=>"name", "description"=>"label", "allowed_values"=>null, "sql"=>"name", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  70. MetaModel::Init_AddAttribute(new AttributeString("description", array("label"=>"description", "description"=>"one line description", "allowed_values"=>null, "sql"=>"description", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  71. //MetaModel::Init_InheritFilters();
  72. MetaModel::Init_AddFilterFromAttribute("name");
  73. MetaModel::Init_AddFilterFromAttribute("description");
  74. }
  75. }
  76. class URP_Dimensions extends DBObject
  77. {
  78. public static function Init()
  79. {
  80. $aParams = array
  81. (
  82. "category" => "addon/userrights",
  83. "name" => "dimension",
  84. "description" => "application dimension (defining silos)",
  85. "key_type" => "autoincrement",
  86. "key_label" => "",
  87. "name_attcode" => "name",
  88. "state_attcode" => "",
  89. "reconc_keys" => array(),
  90. "db_table" => "priv_urp_dimensions",
  91. "db_key_field" => "id",
  92. "db_finalclass_field" => "",
  93. );
  94. MetaModel::Init_Params($aParams);
  95. //MetaModel::Init_InheritAttributes();
  96. MetaModel::Init_AddAttribute(new AttributeString("name", array("label"=>"name", "description"=>"label", "allowed_values"=>null, "sql"=>"name", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  97. MetaModel::Init_AddAttribute(new AttributeString("description", array("label"=>"description", "description"=>"one line description", "allowed_values"=>null, "sql"=>"description", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  98. MetaModel::Init_AddAttribute(new AttributeString("type", array("label"=>"type", "description"=>"class name or data type (projection unit)", "allowed_values"=>new ValueSetEnumClasses('bizmodel', 'String,Integer'), "sql"=>"type", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  99. //MetaModel::Init_InheritFilters();
  100. MetaModel::Init_AddFilterFromAttribute("name");
  101. MetaModel::Init_AddFilterFromAttribute("description");
  102. MetaModel::Init_AddFilterFromAttribute("type");
  103. }
  104. public function CheckProjectionSpec($oProjectionSpec, $sProjectedClass)
  105. {
  106. $sExpression = $oProjectionSpec->Get('value');
  107. $sAttribute = $oProjectionSpec->Get('attribute');
  108. // Shortcut: "any value" or "no value" means no projection
  109. if (empty($sExpression)) return;
  110. if ($sExpression == '<any>') return;
  111. // 1st - compute the data type for the dimension
  112. //
  113. $sType = $this->Get('type');
  114. if (MetaModel::IsValidClass($sType))
  115. {
  116. $sExpectedType = $sType;
  117. }
  118. else
  119. {
  120. $sExpectedType = '_scalar_';
  121. }
  122. // 2nd - compute the data type for the projection
  123. //
  124. $sTargetClass = '';
  125. if (($sExpression == '<this>') || ($sExpression == '<user>'))
  126. {
  127. $sTargetClass = $sProjectedClass;
  128. }
  129. elseif ($sExpression == '<any>')
  130. {
  131. $sTargetClass = '';
  132. }
  133. else
  134. {
  135. // Evaluate wether it is a constant or not
  136. try
  137. {
  138. $oObjectSearch = DBObjectSearch::FromOQL($sExpression);
  139. $sTargetClass = $oObjectSearch->GetClass();
  140. }
  141. catch (OqlException $e)
  142. {
  143. }
  144. }
  145. if (empty($sTargetClass))
  146. {
  147. $sFoundType = '_void_';
  148. }
  149. else
  150. {
  151. if (empty($sAttribute))
  152. {
  153. $sFoundType = $sTargetClass;
  154. }
  155. else
  156. {
  157. if (!MetaModel::IsValidAttCode($sTargetClass, $sAttribute))
  158. {
  159. throw new CoreException('Unkown attribute code in projection specification', array('found' => $sAttribute, 'expecting' => MetaModel::GetAttributesList($sTargetClass), 'class' => $sTargetClass, 'projection' => $oProjectionSpec));
  160. }
  161. $oAttDef = MetaModel::GetAttributeDef($sTargetClass, $sAttribute);
  162. if ($oAttDef->IsExternalKey())
  163. {
  164. $sFoundType = $oAttDef->GetTargetClass();
  165. }
  166. else
  167. {
  168. $sFoundType = '_scalar_';
  169. }
  170. }
  171. }
  172. // Compare the dimension type and projection type
  173. if (($sFoundType != '_void_') && ($sFoundType != $sExpectedType))
  174. {
  175. throw new CoreException('Wrong type in projection specification', array('found' => $sFoundType, 'expecting' => $sExpectedType, 'expression' => $sExpression, 'attribute' => $sAttribute, 'projection' => $oProjectionSpec));
  176. }
  177. }
  178. }
  179. class URP_UserProfile extends DBObject
  180. {
  181. public static function Init()
  182. {
  183. $aParams = array
  184. (
  185. "category" => "addon/userrights",
  186. "name" => "user_profile",
  187. "description" => "user profiles",
  188. "key_type" => "autoincrement",
  189. "key_label" => "",
  190. "name_attcode" => "",
  191. "state_attcode" => "",
  192. "reconc_keys" => array(),
  193. "db_table" => "priv_urp_userprofile",
  194. "db_key_field" => "id",
  195. "db_finalclass_field" => "",
  196. );
  197. MetaModel::Init_Params($aParams);
  198. //MetaModel::Init_InheritAttributes();
  199. MetaModel::Init_AddAttribute(new AttributeExternalKey("userid", array("targetclass"=>"URP_Users", "jointype"=> "", "label"=>"User", "description"=>"user account", "allowed_values"=>null, "sql"=>"userid", "is_null_allowed"=>false, "depends_on"=>array())));
  200. MetaModel::Init_AddAttribute(new AttributeExternalField("userlogin", array("label"=>"Login", "description"=>"User's login", "allowed_values"=>null, "extkey_attcode"=> 'userid', "target_attcode"=>"login")));
  201. MetaModel::Init_AddAttribute(new AttributeExternalKey("profileid", array("targetclass"=>"URP_Profiles", "jointype"=> "", "label"=>"profile", "description"=>"usage profile", "allowed_values"=>null, "sql"=>"profileid", "is_null_allowed"=>false, "depends_on"=>array())));
  202. MetaModel::Init_AddAttribute(new AttributeExternalField("profile", array("label"=>"Profile", "description"=>"Profile name", "allowed_values"=>null, "extkey_attcode"=> 'profileid', "target_attcode"=>"name")));
  203. //MetaModel::Init_InheritFilters();
  204. MetaModel::Init_AddFilterFromAttribute("userid");
  205. MetaModel::Init_AddFilterFromAttribute("profileid");
  206. }
  207. }
  208. class URP_ProfileProjection extends DBObject
  209. {
  210. public static function Init()
  211. {
  212. $aParams = array
  213. (
  214. "category" => "addon/userrights",
  215. "name" => "profile_projection",
  216. "description" => "profile projections",
  217. "key_type" => "autoincrement",
  218. "key_label" => "",
  219. "name_attcode" => "",
  220. "state_attcode" => "",
  221. "reconc_keys" => array(),
  222. "db_table" => "priv_urp_profileprojection",
  223. "db_key_field" => "id",
  224. "db_finalclass_field" => "",
  225. );
  226. MetaModel::Init_Params($aParams);
  227. //MetaModel::Init_InheritAttributes();
  228. MetaModel::Init_AddAttribute(new AttributeExternalKey("dimensionid", array("targetclass"=>"URP_Dimensions", "jointype"=> "", "label"=>"Dimension", "description"=>"application dimension", "allowed_values"=>null, "sql"=>"dimensionid", "is_null_allowed"=>false, "depends_on"=>array())));
  229. MetaModel::Init_AddAttribute(new AttributeExternalField("dimension", array("label"=>"Dimension", "description"=>"application dimension", "allowed_values"=>null, "extkey_attcode"=> 'dimensionid', "target_attcode"=>"name")));
  230. MetaModel::Init_AddAttribute(new AttributeExternalKey("profileid", array("targetclass"=>"URP_Profiles", "jointype"=> "", "label"=>"profile", "description"=>"usage profile", "allowed_values"=>null, "sql"=>"profileid", "is_null_allowed"=>false, "depends_on"=>array())));
  231. MetaModel::Init_AddAttribute(new AttributeExternalField("profile", array("label"=>"Profile", "description"=>"Profile name", "allowed_values"=>null, "extkey_attcode"=> 'profileid', "target_attcode"=>"name")));
  232. MetaModel::Init_AddAttribute(new AttributeString("value", array("label"=>"Value expression", "description"=>"OQL expression (using \$user) | constant | <any> | <user>+attribute code", "allowed_values"=>null, "sql"=>"value", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  233. MetaModel::Init_AddAttribute(new AttributeString("attribute", array("label"=>"Attribute", "description"=>"Target attribute code (optional)", "allowed_values"=>null, "sql"=>"attribute", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  234. //MetaModel::Init_InheritFilters();
  235. MetaModel::Init_AddFilterFromAttribute("dimensionid");
  236. MetaModel::Init_AddFilterFromAttribute("profileid");
  237. }
  238. public function ProjectUser(URP_Users $oUser)
  239. {
  240. $sExpr = $this->Get('value');
  241. if ($sExpr == '<user>')
  242. {
  243. $sColumn = $this->Get('attribute');
  244. if (empty($sColumn))
  245. {
  246. $aRes = array($oUser->GetKey());
  247. }
  248. else
  249. {
  250. $aRes = array($oUser->Get($sColumn));
  251. }
  252. }
  253. elseif ($sExpr == '<any>')
  254. {
  255. $aRes = null;
  256. }
  257. elseif (strtolower(substr($sExpr, 0, 6)) == 'select')
  258. {
  259. $sColumn = $this->Get('attribute');
  260. // SELECT...
  261. $oValueSetDef = new ValueSetObjects($sExpr, $sColumn);
  262. $aValues = $oValueSetDef->GetValues(array('user' => $oUser), '');
  263. $aRes = array_keys($aValues);
  264. }
  265. else
  266. {
  267. // Constant value(s)
  268. $aRes = explode(';', trim($sExpr));
  269. }
  270. return $aRes;
  271. }
  272. }
  273. class URP_ClassProjection extends DBObject
  274. {
  275. public static function Init()
  276. {
  277. $aParams = array
  278. (
  279. "category" => "addon/userrights",
  280. "name" => "class_projection",
  281. "description" => "class projections",
  282. "key_type" => "autoincrement",
  283. "key_label" => "",
  284. "name_attcode" => "",
  285. "state_attcode" => "",
  286. "reconc_keys" => array(),
  287. "db_table" => "priv_urp_classprojection",
  288. "db_key_field" => "id",
  289. "db_finalclass_field" => "",
  290. );
  291. MetaModel::Init_Params($aParams);
  292. //MetaModel::Init_InheritAttributes();
  293. MetaModel::Init_AddAttribute(new AttributeExternalKey("dimensionid", array("targetclass"=>"URP_Dimensions", "jointype"=> "", "label"=>"Dimension", "description"=>"application dimension", "allowed_values"=>null, "sql"=>"dimensionid", "is_null_allowed"=>false, "depends_on"=>array())));
  294. MetaModel::Init_AddAttribute(new AttributeExternalField("dimension", array("label"=>"Dimension", "description"=>"application dimension", "allowed_values"=>null, "extkey_attcode"=> 'dimensionid', "target_attcode"=>"name")));
  295. MetaModel::Init_AddAttribute(new AttributeString("class", array("label"=>"Class", "description"=>"Target class", "allowed_values"=>null, "sql"=>"class", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  296. MetaModel::Init_AddAttribute(new AttributeString("value", array("label"=>"Value expression", "description"=>"OQL expression (using \$this) | constant | <any> | <this>+attribute code", "allowed_values"=>null, "sql"=>"value", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  297. MetaModel::Init_AddAttribute(new AttributeString("attribute", array("label"=>"Attribute", "description"=>"Target attribute code (optional)", "allowed_values"=>null, "sql"=>"attribute", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  298. //MetaModel::Init_InheritFilters();
  299. MetaModel::Init_AddFilterFromAttribute("dimensionid");
  300. // #@# verifier
  301. MetaModel::Init_AddFilterFromAttribute("class");
  302. }
  303. public function ProjectObject($oObject)
  304. {
  305. $sExpr = $this->Get('value');
  306. if ($sExpr == '<this>')
  307. {
  308. $sColumn = $this->Get('attribute');
  309. if (empty($sColumn))
  310. {
  311. $aRes = array($oObject->GetKey());
  312. }
  313. else
  314. {
  315. $aRes = array($oObject->Get($sColumn));
  316. }
  317. }
  318. elseif ($sExpr == '<any>')
  319. {
  320. $aRes = null;
  321. }
  322. elseif (strtolower(substr($sExpr, 0, 6)) == 'select')
  323. {
  324. $sColumn = $this->Get('attribute');
  325. // SELECT...
  326. $oValueSetDef = new ValueSetObjects($sExpr, $sColumn);
  327. $aValues = $oValueSetDef->GetValues(array('this' => $oObject), '');
  328. $aRes = array_keys($aValues);
  329. }
  330. elseif ($sExpr == '<any>')
  331. {
  332. $aRes = null;
  333. }
  334. else
  335. {
  336. // Constant value(s)
  337. $aRes = explode(';', trim($sExpr));
  338. }
  339. return $aRes;
  340. }
  341. }
  342. class URP_ActionGrant extends DBObject
  343. {
  344. public static function Init()
  345. {
  346. $aParams = array
  347. (
  348. "category" => "addon/userrights",
  349. "name" => "action_permission",
  350. "description" => "permissions on classes",
  351. "key_type" => "autoincrement",
  352. "key_label" => "",
  353. "name_attcode" => "",
  354. "state_attcode" => "",
  355. "reconc_keys" => array(),
  356. "db_table" => "priv_urp_grant_actions",
  357. "db_key_field" => "id",
  358. "db_finalclass_field" => "",
  359. );
  360. MetaModel::Init_Params($aParams);
  361. //MetaModel::Init_InheritAttributes();
  362. // Common to all grant classes (could be factorized by class inheritence, but this has to be benchmarked)
  363. MetaModel::Init_AddAttribute(new AttributeExternalKey("profileid", array("targetclass"=>"URP_Profiles", "jointype"=> "", "label"=>"Profile", "description"=>"usage profile", "allowed_values"=>null, "sql"=>"profileid", "is_null_allowed"=>false, "depends_on"=>array())));
  364. MetaModel::Init_AddAttribute(new AttributeExternalField("profile", array("label"=>"Profile", "description"=>"usage profile", "allowed_values"=>null, "extkey_attcode"=> 'profileid', "target_attcode"=>"name")));
  365. MetaModel::Init_AddAttribute(new AttributeString("class", array("label"=>"class", "description"=>"class name", "allowed_values"=>null, "sql"=>"class", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  366. MetaModel::Init_AddAttribute(new AttributeEnum("permission", array("label"=>"permission", "description"=>"allowed or not allowed?", "allowed_values"=>new ValueSetEnum('yes,no'), "sql"=>"permission", "default_value"=>"yes", "is_null_allowed"=>false, "depends_on"=>array())));
  367. MetaModel::Init_AddAttribute(new AttributeString("action", array("label"=>"action", "description"=>"operations to perform on the given class", "allowed_values"=>null, "sql"=>"action", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  368. //MetaModel::Init_InheritFilters();
  369. // Common to all grant classes (could be factorized by class inheritence, but this has to be benchmarked)
  370. MetaModel::Init_AddFilterFromAttribute("profileid");
  371. MetaModel::Init_AddFilterFromAttribute("profile");
  372. MetaModel::Init_AddFilterFromAttribute("class");
  373. MetaModel::Init_AddFilterFromAttribute("permission");
  374. MetaModel::Init_AddFilterFromAttribute("action");
  375. }
  376. }
  377. class URP_StimulusGrant extends DBObject
  378. {
  379. public static function Init()
  380. {
  381. $aParams = array
  382. (
  383. "category" => "addon/userrights",
  384. "name" => "stimulus_permission",
  385. "description" => "permissions on stimilus in the life cycle of the object",
  386. "key_type" => "autoincrement",
  387. "key_label" => "",
  388. "name_attcode" => "",
  389. "state_attcode" => "",
  390. "reconc_keys" => array(),
  391. "db_table" => "priv_urp_grant_stimulus",
  392. "db_key_field" => "id",
  393. "db_finalclass_field" => "",
  394. );
  395. MetaModel::Init_Params($aParams);
  396. //MetaModel::Init_InheritAttributes();
  397. // Common to all grant classes (could be factorized by class inheritence, but this has to be benchmarked)
  398. MetaModel::Init_AddAttribute(new AttributeExternalKey("profileid", array("targetclass"=>"URP_Profiles", "jointype"=> "", "label"=>"Profile", "description"=>"usage profile", "allowed_values"=>null, "sql"=>"profileid", "is_null_allowed"=>false, "depends_on"=>array())));
  399. MetaModel::Init_AddAttribute(new AttributeExternalField("profile", array("label"=>"Profile", "description"=>"usage profile", "allowed_values"=>null, "extkey_attcode"=> 'profileid', "target_attcode"=>"name")));
  400. MetaModel::Init_AddAttribute(new AttributeString("class", array("label"=>"class", "description"=>"class name", "allowed_values"=>null, "sql"=>"class", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  401. MetaModel::Init_AddAttribute(new AttributeEnum("permission", array("label"=>"permission", "description"=>"allowed or not allowed?", "allowed_values"=>new ValueSetEnum('yes,no'), "sql"=>"permission", "default_value"=>"yes", "is_null_allowed"=>false, "depends_on"=>array())));
  402. MetaModel::Init_AddAttribute(new AttributeString("stimulus", array("label"=>"stimulus", "description"=>"stimulus code", "allowed_values"=>null, "sql"=>"action", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  403. //MetaModel::Init_InheritFilters();
  404. // Common to all grant classes (could be factorized by class inheritence, but this has to be benchmarked)
  405. MetaModel::Init_AddFilterFromAttribute("profileid");
  406. MetaModel::Init_AddFilterFromAttribute("profile");
  407. MetaModel::Init_AddFilterFromAttribute("class");
  408. MetaModel::Init_AddFilterFromAttribute("permission");
  409. MetaModel::Init_AddFilterFromAttribute("stimulus");
  410. }
  411. }
  412. class URP_AttributeGrant extends DBObject
  413. {
  414. public static function Init()
  415. {
  416. $aParams = array
  417. (
  418. "category" => "addon/userrights",
  419. "name" => "attribute_permission",
  420. "description" => "permissions at the attributes level",
  421. "key_type" => "autoincrement",
  422. "key_label" => "",
  423. "name_attcode" => "",
  424. "state_attcode" => "",
  425. "reconc_keys" => array(),
  426. "db_table" => "priv_urp_grant_attributes",
  427. "db_key_field" => "id",
  428. "db_finalclass_field" => "",
  429. );
  430. MetaModel::Init_Params($aParams);
  431. //MetaModel::Init_InheritAttributes();
  432. MetaModel::Init_AddAttribute(new AttributeExternalKey("actiongrantid", array("targetclass"=>"URP_ActionGrant", "jointype"=> "", "label"=>"Action grant", "description"=>"action grant", "allowed_values"=>null, "sql"=>"actiongrantid", "is_null_allowed"=>false, "depends_on"=>array())));
  433. MetaModel::Init_AddAttribute(new AttributeString("attcode", array("label"=>"attribute", "description"=>"attribute code", "allowed_values"=>null, "sql"=>"attcode", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  434. //MetaModel::Init_InheritFilters();
  435. MetaModel::Init_AddFilterFromAttribute("actiongrantid");
  436. MetaModel::Init_AddFilterFromAttribute("attcode");
  437. }
  438. }
  439. class UserRightsProfile extends UserRightsAddOnAPI
  440. {
  441. static public $m_aActionCodes = array(
  442. UR_ACTION_READ => 'read',
  443. UR_ACTION_MODIFY => 'modify',
  444. UR_ACTION_DELETE => 'delete',
  445. UR_ACTION_BULK_READ => 'bulk read',
  446. UR_ACTION_BULK_MODIFY => 'bulk modify',
  447. UR_ACTION_BULK_DELETE => 'bulk delete',
  448. );
  449. // Installation: create the very first user
  450. public function CreateAdministrator($sAdminUser, $sAdminPwd)
  451. {
  452. $oUser = new URP_Users();
  453. $oUser->Set('login', $sAdminUser);
  454. $oUser->Set('password', $sAdminPwd);
  455. $oUser->Set('email', 'n/a');
  456. $oUser->Set('firstname', 'administrator');
  457. $oUser->Set('lastname', 'itop');
  458. $oUser->Set('userid', 1); // let's mark it as #1 (for what purpose?)
  459. $iUserId = $oUser->DBInsertNoReload();
  460. // Add this user to the very specific 'admin' profile
  461. $oUserProfile = new URP_UserProfile();
  462. $oUserProfile->Set('userid', $iUserId);
  463. $oUserProfile->Set('profileid', ADMIN_PROFILE_ID);
  464. $oUserProfile->DBInsertNoReload();
  465. return true;
  466. }
  467. public function Setup()
  468. {
  469. // Dimensions/Profiles/Classes/Attributes/Stimuli could be added anytime
  470. // This procedure will then update the matrix with expected default values
  471. //
  472. $oProfileSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_Profiles"));
  473. while ($oProfile = $oProfileSet->Fetch())
  474. {
  475. $this->SetupProfile($oProfile);
  476. }
  477. $oDimensionSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_Dimensions"));
  478. while ($oDimension = $oDimensionSet->Fetch())
  479. {
  480. $this->SetupDimension($oDimension);
  481. }
  482. return true;
  483. }
  484. protected function SetupDimension($oDimension, $bNewDimension = false)
  485. {
  486. $iDimensionId = $oDimension->GetKey();
  487. // Create projections, for any class where it applies
  488. //
  489. foreach(array('bizmodel', 'application', 'gui', 'core/cmdb') as $sCategory)
  490. {
  491. foreach (MetaModel::GetClasses($sCategory) as $sClass)
  492. {
  493. if ($bNewDimension)
  494. {
  495. $bAddCell = true;
  496. }
  497. else
  498. {
  499. $oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_ClassProjection WHERE class = :class AND dimensionid = :dimension"), array(), array('class'=>$sClass, 'dimension'=>$iDimensionId));
  500. $bAddCell = ($oSet->Count() < 1);
  501. }
  502. if ($bAddCell)
  503. {
  504. // Create a new entry
  505. $oCProj = MetaModel::NewObject("URP_ClassProjection");
  506. $oCProj->Set("dimensionid", $iDimensionId);
  507. $oCProj->Set("class", $sClass);
  508. $oCProj->Set("value", "true");
  509. $iId = $oCProj->DBInsertNoReload();
  510. }
  511. }
  512. }
  513. // Create projections, for any existing profile
  514. //
  515. $oProfileSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_Profiles"));
  516. while ($oProfile = $oProfileSet->Fetch())
  517. {
  518. $iProfileId = $oProfile->GetKey();
  519. if ($bNewDimension)
  520. {
  521. $bAddCell = true;
  522. }
  523. else
  524. {
  525. $oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_ProfileProjection WHERE dimensionid = :dimension AND profileid = :profile"), array(), array('dimension'=>$iDimensionId, 'profile'=>$iProfileId));
  526. $bAddCell = ($oSet->Count() < 1);
  527. }
  528. if ($bAddCell)
  529. {
  530. // Create a new entry
  531. $oDProj = MetaModel::NewObject("URP_ProfileProjection");
  532. $oDProj->Set("dimensionid", $iDimensionId);
  533. $oDProj->Set("profileid", $iProfileId);
  534. $oDProj->Set("value", "true");
  535. $iId = $oDProj->DBInsertNoReload();
  536. }
  537. }
  538. }
  539. protected function SetupProfile($oProfile, $bNewProfile = false)
  540. {
  541. $iProfileId = $oProfile->GetKey();
  542. // Create grant records, for any class where it matters (the rest could be done later on)
  543. //
  544. foreach(array('bizmodel') as $sCategory)
  545. {
  546. foreach (MetaModel::GetClasses($sCategory) as $sClass)
  547. {
  548. foreach (self::$m_aActionCodes as $iActionCode => $sAction)
  549. {
  550. if ($bNewProfile)
  551. {
  552. $bAddCell = true;
  553. }
  554. else
  555. {
  556. $oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_ActionGrant WHERE class = :class AND action = :action AND profileid = :profile"), array(), array('class'=>$sClass, 'action'=>$sAction, 'profile'=>$iProfileId));
  557. $bAddCell = ($oSet->Count() < 1);
  558. }
  559. if ($bAddCell)
  560. {
  561. // Create a new entry
  562. $oMyActionGrant = MetaModel::NewObject("URP_ActionGrant");
  563. $oMyActionGrant->Set("profileid", $iProfileId);
  564. $oMyActionGrant->Set("class", $sClass);
  565. $oMyActionGrant->Set("action", $sAction);
  566. $oMyActionGrant->Set("permission", "yes");
  567. $iId = $oMyActionGrant->DBInsertNoReload();
  568. }
  569. }
  570. foreach (MetaModel::EnumStimuli($sClass) as $sStimulusCode => $oStimulus)
  571. {
  572. if ($bNewProfile)
  573. {
  574. $bAddCell = true;
  575. }
  576. else
  577. {
  578. $oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_StimulusGrant WHERE class = :class AND stimulus = :stimulus AND profileid = :profile"), array(), array('class'=>$sClass, 'stimulus'=>$sStimulusCode, 'profile'=>$iProfileId));
  579. $bAddCell = ($oSet->Count() < 1);
  580. }
  581. if ($bAddCell)
  582. {
  583. // Create a new entry
  584. $oMyStGrant = MetaModel::NewObject("URP_StimulusGrant");
  585. $oMyStGrant->Set("profileid", $iProfileId);
  586. $oMyStGrant->Set("class", $sClass);
  587. $oMyStGrant->Set("stimulus", $sStimulusCode);
  588. $oMyStGrant->Set("permission", "yes");
  589. $iId = $oMyStGrant->DBInsertNoReload();
  590. }
  591. }
  592. }
  593. }
  594. // Create the "My Bookmarks" menu item (parent_id = 0, rank = 6)
  595. if ($bNewProfile)
  596. {
  597. $bAddMenu = true;
  598. }
  599. else
  600. {
  601. //$oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT menuNode WHERE type = 'user' AND parent_id = 0 AND user_id = $iUserId"));
  602. //$bAddMenu = ($oSet->Count() < 1);
  603. }
  604. $bAddMenu = false;
  605. if ($bAddMenu)
  606. {
  607. $oMenu = MetaModel::NewObject('menuNode');
  608. $oMenu->Set('type', 'user');
  609. $oMenu->Set('parent_id', 0); // It's a toplevel entry
  610. $oMenu->Set('rank', 6); // Located just above the Admin Tools section (=7)
  611. $oMenu->Set('name', 'My Bookmarks');
  612. $oMenu->Set('label', 'My Favorite Items');
  613. $oMenu->Set('hyperlink', 'UI.php');
  614. $oMenu->Set('template', '<p></p><p></p><p style="text-align:center; font-family:Georgia, Times, serif; font-size:32px;">My bookmarks</p><p style="text-align:center; font-family:Georgia, Times, serif; font-size:14px;"><i>This section contains my most favorite search results</i></p>');
  615. $oMenu->Set('user_id', $iUserId);
  616. $oMenu->DBInsert();
  617. }
  618. }
  619. public function Init()
  620. {
  621. MetaModel::RegisterPlugin('userrights', 'ACbyProfile', array($this, 'CacheData'));
  622. }
  623. protected $m_aUsers = array(); // id -> object
  624. protected $m_aDimensions = array(); // id -> object
  625. protected $m_aClassProj = array(); // class,dimensionid -> object
  626. protected $m_aProfiles = array(); // id -> object
  627. protected $m_aUserProfiles = array(); // userid,profileid -> object
  628. protected $m_aProPro = array(); // profileid,dimensionid -> object
  629. protected $m_aAdmins = array(); // id of users being linked to the profile #ADMIN_PROFILE_ID
  630. protected $m_aClassActionGrants = array(); // profile, class, action -> permission
  631. protected $m_aObjectActionGrants = array(); // userid, class, id, action -> permission, list of attributes
  632. public function CacheData()
  633. {
  634. // Could be loaded in a shared memory (?)
  635. $oUserSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_Users"));
  636. while ($oUser = $oUserSet->Fetch())
  637. {
  638. $this->m_aUsers[$oUser->GetKey()] = $oUser;
  639. }
  640. $oDimensionSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_Dimensions"));
  641. while ($oDimension = $oDimensionSet->Fetch())
  642. {
  643. $this->m_aDimensions[$oDimension->GetKey()] = $oDimension;
  644. }
  645. $oClassProjSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_ClassProjection"));
  646. while ($oClassProj = $oClassProjSet->Fetch())
  647. {
  648. $this->m_aClassProjs[$oClassProj->Get('class')][$oClassProj->Get('dimensionid')] = $oClassProj;
  649. }
  650. $oProfileSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_Profiles"));
  651. while ($oProfile = $oProfileSet->Fetch())
  652. {
  653. $this->m_aProfiles[$oProfile->GetKey()] = $oProfile;
  654. }
  655. $oUserProfileSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_UserProfile"));
  656. while ($oUserProfile = $oUserProfileSet->Fetch())
  657. {
  658. $this->m_aUserProfiles[$oUserProfile->Get('userid')][$oUserProfile->Get('profileid')] = $oUserProfile;
  659. if ($oUserProfile->Get('profileid') == ADMIN_PROFILE_ID)
  660. {
  661. $this->m_aAdmins[] = $oUserProfile->Get('userid');
  662. }
  663. }
  664. $oProProSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_ProfileProjection"));
  665. while ($oProPro = $oProProSet->Fetch())
  666. {
  667. $this->m_aProPros[$oProPro->Get('profileid')][$oProPro->Get('dimensionid')] = $oProPro;
  668. }
  669. /*
  670. echo "<pre>\n";
  671. print_r($this->m_aUsers);
  672. print_r($this->m_aDimensions);
  673. print_r($this->m_aClassProjs);
  674. print_r($this->m_aProfiles);
  675. print_r($this->m_aUserProfiles);
  676. print_r($this->m_aProPros);
  677. echo "</pre>\n";
  678. exit;
  679. */
  680. return true;
  681. }
  682. public function CheckCredentials($sUserName, $sPassword)
  683. {
  684. $oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_Users WHERE login = :login"), array(), array('login' => $sUserName));
  685. if ($oSet->Count() < 1)
  686. {
  687. // todo: throw an exception?
  688. return false;
  689. }
  690. $oUser = $oSet->Fetch();
  691. if ($oUser->Get('password') == $sPassword)
  692. {
  693. return $oUser->GetKey();
  694. }
  695. // todo: throw an exception?
  696. return false;
  697. }
  698. public function GetUserId($sUserName)
  699. {
  700. $oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT URP_Users WHERE login = :login"), array(), array('login' => $sUserName));
  701. if ($oSet->Count() < 1)
  702. {
  703. // todo: throw an exception?
  704. return false;
  705. }
  706. $oUser = $oSet->Fetch();
  707. return $oUser->GetKey();
  708. }
  709. public function GetFilter($sUserName, $sClass)
  710. {
  711. $oNullFilter = new DBObjectSearch($sClass);
  712. return $oNullFilter;
  713. }
  714. protected function GetClassActionGrant($iProfile, $sClass, $sAction)
  715. {
  716. $aTest = @$this->m_aClassActionGrants[$iProfile][$sClass][$sAction];
  717. if (isset($aTest)) return $aTest;
  718. // Get the permission for this profile/class/action
  719. $oSearch = DBObjectSearch::FromOQL("SELECT URP_ActionGrant WHERE class = :class AND action = :action AND profileid = :profile AND permission = 'yes'");
  720. $oSet = new DBObjectSet($oSearch, array(), array('class'=>$sClass, 'action'=>$sAction, 'profile'=>$iProfile));
  721. if ($oSet->Count() < 1)
  722. {
  723. return null;
  724. }
  725. $oGrantRecord = $oSet->Fetch();
  726. $this->m_aClassActionGrants[$iProfile][$sClass][$sAction] = $oGrantRecord;
  727. return $oGrantRecord;
  728. }
  729. protected function GetObjectActionGrant($oUser, $sClass, $iActionCode, $oObject)
  730. {
  731. // load and cache permissions for the current user on the given object
  732. //
  733. $aTest = @$this->m_aObjectActionGrants[$oUser->GetKey()][$sClass][$oObject->GetKey][$iActionCode];
  734. if (is_array($aTest)) return $aTest;
  735. $sAction = self::$m_aActionCodes[$iActionCode];
  736. $iInstancePermission = UR_ALLOWED_NO;
  737. $aAttributes = array();
  738. foreach($this->GetMatchingProfiles($oUser, $oObject) as $iProfile)
  739. {
  740. $oGrantRecord = $this->GetClassActionGrant($iProfile, $sClass, $sAction);
  741. if (is_null($oGrantRecord))
  742. {
  743. continue; // loop to the next profile
  744. }
  745. else
  746. {
  747. $iInstancePermission = UR_ALLOWED_YES;
  748. // update the list of attributes with those allowed for this profile
  749. //
  750. $oSearch = DBObjectSearch::FromOQL("SELECT URP_AttributeGrant WHERE actiongrantid = :actiongrantid");
  751. $oSet = new DBObjectSet($oSearch, array(), array('actiongrantid' => $oGrantRecord->GetKey()));
  752. $aProfileAttributes = $oSet->GetColumnAsArray('attcode', false);
  753. if (count($aProfileAttributes) == 0)
  754. {
  755. $aAllAttributes = array_keys(MetaModel::ListAttributeDefs($sClass));
  756. $aAttributes = array_merge($aAttributes, $aAllAttributes);
  757. }
  758. else
  759. {
  760. $aAttributes = array_merge($aAttributes, $aProfileAttributes);
  761. }
  762. }
  763. }
  764. $aRes = array(
  765. 'permission' => $iInstancePermission,
  766. 'attributes' => $aAttributes,
  767. );
  768. $this->m_aObjectActionGrants[$oUser->GetKey()][$sClass][$oObject->GetKey()][$iActionCode] = $aRes;
  769. return $aRes;
  770. }
  771. public function IsActionAllowed($iUserId, $sClass, $iActionCode, dbObjectSet $oInstances)
  772. {
  773. // super admin rights
  774. if (in_array($iUserId, $this->m_aAdmins)) return true;
  775. $oUser = $this->m_aUsers[$iUserId];
  776. $oInstances->Rewind();
  777. while($oObject = $oInstances->Fetch())
  778. {
  779. $aObjectPermissions = $this->GetObjectActionGrant($oUser, $sClass, $iActionCode, $oObject);
  780. $iInstancePermission = $aObjectPermissions['permission'];
  781. if (isset($iGlobalPermission))
  782. {
  783. if ($iInstancePermission != $iGlobalPermission)
  784. {
  785. $iGlobalPermission = UR_ALLOWED_DEPENDS;
  786. break;
  787. }
  788. }
  789. else
  790. {
  791. $iGlobalPermission = $iInstancePermission;
  792. }
  793. }
  794. $oInstances->Rewind();
  795. if (isset($iGlobalPermission))
  796. {
  797. return $iGlobalPermission;
  798. }
  799. else
  800. {
  801. return UR_ALLOWED_NO;
  802. }
  803. }
  804. public function IsActionAllowedOnAttribute($iUserId, $sClass, $sAttCode, $iActionCode, dbObjectSet $oInstances)
  805. {
  806. // super admin rights
  807. if (in_array($iUserId, $this->m_aAdmins)) return true;
  808. $oUser = $this->m_aUsers[$iUserId];
  809. $oInstances->Rewind();
  810. while($oObject = $oInstances->Fetch())
  811. {
  812. $aObjectPermissions = $this->GetObjectActionGrant($oUser, $sClass, $iActionCode, $oObject);
  813. $aAttributes = $aObjectPermissions['attributes'];
  814. if (in_array($sAttCode, $aAttributes))
  815. {
  816. $iInstancePermission = $aObjectPermissions['permission'];
  817. }
  818. else
  819. {
  820. $iInstancePermission = UR_ALLOWED_NO;
  821. }
  822. if (isset($iGlobalPermission))
  823. {
  824. if ($iInstancePermission != $iGlobalPermission)
  825. {
  826. $iGlobalPermission = UR_ALLOWED_DEPENDS;
  827. }
  828. }
  829. else
  830. {
  831. $iGlobalPermission = $iInstancePermission;
  832. }
  833. }
  834. $oInstances->Rewind();
  835. if (isset($iGlobalPermission))
  836. {
  837. return $iGlobalPermission;
  838. }
  839. else
  840. {
  841. return UR_ALLOWED_NO;
  842. }
  843. }
  844. public function IsStimulusAllowed($iUserId, $sClass, $sStimulusCode, dbObjectSet $oInstances)
  845. {
  846. // super admin rights
  847. if (in_array($iUserId, $this->m_aAdmins)) return true;
  848. $oUser = $this->m_aUsers[$iUserId];
  849. // Note: this code is VERY close to the code of IsActionAllowed()
  850. $oInstances->Rewind();
  851. while($oObject = $oInstances->Fetch())
  852. {
  853. $iInstancePermission = UR_ALLOWED_NO;
  854. foreach($this->GetMatchingProfiles($oUser, $oObject) as $iProfile)
  855. {
  856. // Get the permission for this profile/class/stimulus
  857. $oSearch = DBObjectSearch::FromOQL("SELECT URP_StimulusGrant WHERE class = :class AND stimulus = :stimulus AND profileid = :profile AND permission = 'yes'");
  858. $oSet = new DBObjectSet($oSearch, array(), array('class'=>$sClass, 'stimulus'=>$sStimulusCode, 'profile'=>$iProfile));
  859. if ($oSet->Count() < 1)
  860. {
  861. return UR_ALLOWED_NO;
  862. }
  863. // no need to fetch the record, we've requested the records having permission = 'yes'
  864. $iInstancePermission = UR_ALLOWED_YES;
  865. }
  866. if (isset($iGlobalPermission))
  867. {
  868. if ($iInstancePermission != $iGlobalPermission)
  869. {
  870. $iGlobalPermission = UR_ALLOWED_DEPENDS;
  871. }
  872. }
  873. else
  874. {
  875. $iGlobalPermission = $iInstancePermission;
  876. }
  877. }
  878. $oInstances->Rewind();
  879. if (isset($iGlobalPermission))
  880. {
  881. return $iGlobalPermission;
  882. }
  883. else
  884. {
  885. return UR_ALLOWED_NO;
  886. }
  887. }
  888. protected function GetMatchingProfilesByDim($oUser, $oObject, $oDimension)
  889. {
  890. //
  891. // List profiles for which the user projection overlaps the object projection in the given dimension
  892. //
  893. $iUser = $oUser->GetKey();
  894. $sClass = get_class($oObject);
  895. $iPKey = $oObject->GetKey();
  896. $iDimension = $oDimension->GetKey();
  897. $aObjectProjection = $this->m_aClassProjs[$sClass][$iDimension]->ProjectObject($oObject);
  898. $aRes = array();
  899. if (array_key_exists($iUser, $this->m_aUserProfiles) > 0)
  900. {
  901. foreach ($this->m_aUserProfiles[$iUser] as $iProfile => $oProfile)
  902. {
  903. if (is_null($aObjectProjection))
  904. {
  905. $aRes[] = $iProfile;
  906. }
  907. else
  908. {
  909. // user projection to be cached on a given page !
  910. $aUserProjection = $this->m_aProPros[$iProfile][$iDimension]->ProjectUser($oUser);
  911. if (is_null($aUserProjection))
  912. {
  913. $aRes[] = $iProfile;
  914. }
  915. else
  916. {
  917. $aMatchingValues = array_intersect($aObjectProjection, $aUserProjection);
  918. if (count($aMatchingValues) > 0)
  919. {
  920. $aRes[] = $iProfile;
  921. }
  922. }
  923. }
  924. }
  925. }
  926. return $aRes;
  927. }
  928. protected $m_aMatchingProfiles = array(); // cache of the matching profiles for a given user/object
  929. protected function GetMatchingProfiles($oUser, $oObject)
  930. {
  931. $iUser = $oUser->GetKey();
  932. $sClass = get_class($oObject);
  933. $iObject = $oObject->GetKey();
  934. //
  935. // List profiles for which the user projection overlaps the object projection in each and every dimension
  936. // Caches the result
  937. //
  938. $aTest = @$this->m_aMatchingProfiles[$iUser][$sClass][$iObject];
  939. if (is_array($aTest))
  940. {
  941. return $aTest;
  942. }
  943. $aProfileRes = array();
  944. foreach ($this->m_aDimensions as $iDimension => $oDimension)
  945. {
  946. foreach ($this->GetMatchingProfilesByDim($oUser, $oObject, $oDimension) as $iProfile)
  947. {
  948. @$aProfileRes[$iProfile] += 1;
  949. }
  950. }
  951. $aRes = array();
  952. $iDimCount = count($this->m_aDimensions);
  953. foreach ($aProfileRes as $iProfile => $iMatches)
  954. {
  955. if ($iMatches == $iDimCount)
  956. {
  957. $aRes[] = $iProfile;
  958. }
  959. }
  960. $this->m_aMatchingProfiles[$iUser][$sClass][$iObject] = $aRes;
  961. return $aRes;
  962. }
  963. }
  964. UserRights::SelectModule('UserRightsProfile');
  965. ?>