userrightsprofile.class.inc.php 58 KB

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