Advertisement
Guest User

Untitled

a guest
Feb 26th, 2016
1,701
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.20 KB | None | 0 0
  1. <?php
  2. namespace console\controllers;
  3.  
  4. use Yii;
  5. use yii\console\Controller;
  6.  
  7. class RbacController extends Controller
  8. {
  9. public function actionInit()
  10. {
  11. $auth = Yii::$app->authManager;
  12. // $auth->removeAll(); //remove previous rbac.php files under console/data
  13.  
  14. //CREATE PERMISSIONS
  15.  
  16. /*************** Assets Permission *************/
  17.  
  18. //Permission to create assets
  19. $createAsset = $auth->createPermission('createAsset');
  20. $createAsset->description = 'Create Asset';
  21. $auth->add($createAsset);
  22.  
  23. //Permission to edit assets
  24. $editAsset = $auth->createPermission('editAsset');
  25. $editAsset->description = 'Edit Asset';
  26. $auth->add($editAsset);
  27.  
  28. //Permission to view asset
  29. $viewAsset = $auth->createPermission('viewAsset');
  30. $viewAsset->description = 'View Asset';
  31. $auth->add($viewAsset);
  32.  
  33. //Permission to view asset
  34. $deleteAsset = $auth->createPermission('deleteAsset');
  35. $deleteAsset->description = 'Delete Asset';
  36. $auth->add($deleteAsset);
  37.  
  38.  
  39. /************** End of Assets Permission ******/
  40.  
  41.  
  42. /*************** Residents Permission *************/
  43. //Permission to create residents
  44. $createResident = $auth->createPermission('createResident');
  45. $createResident->description = 'Create Resident';
  46. $auth->add($createResident);
  47.  
  48. //Permission to edit resident
  49. $editResident = $auth->createPermission('editResident');
  50. $editResident->description = 'Edit Resident';
  51. $auth->add($editResident);
  52.  
  53. //Permission to view resident
  54. $viewResident = $auth->createPermission('viewResident');
  55. $viewResident->description = 'View Resident';
  56. $auth->add($viewResident);
  57.  
  58. //Permission to delete resident
  59. $deleteResident = $auth->createPermission('deleteResident');
  60. $deleteResident->description = 'Delete Asset';
  61. $auth->add($deleteResident);
  62.  
  63. /************** End of Residents Permission ******/
  64.  
  65. /*************** Report Permissions **************/
  66. //Permission to create report
  67. $createReport = $auth->createPermission('createReport');
  68. $createReport->description = 'Create Report';
  69. $auth->add($createReport);
  70.  
  71. //Permission to view report
  72. $viewReport = $auth->createPermission('viewReport');
  73. $viewReport->description = 'Edit Report';
  74. $auth->add($viewReport);
  75.  
  76. /*************** End of Report Permissions **************/
  77.  
  78. /*************** Payment Permissions **************/
  79. //Permission to make Payment
  80. $makePayment = $auth->createPermission('makePayment');
  81. $makePayment->description = 'Make Payment';
  82. $auth->add($makePayment);
  83.  
  84. //Permission to view Payment
  85. $viewPayment = $auth->createPermission('viewPayment');
  86. $viewPayment->description = 'View Payment';
  87. $auth->add($viewPayment);
  88.  
  89. /*************** End of Payment Permissions **************/
  90.  
  91. //Permission to view all dasboard
  92. $viewDashboards = $auth->createPermission('viewDashboards');
  93. $viewDashboards->description = 'View Dashboards';
  94. $auth->add($viewDashboards);
  95.  
  96. //Permission to create user profiles such as board, executive, and admin
  97. $createUserProfile = $auth->createPermission('createProfile');
  98. $createUserProfile->description = 'Create User Profile';
  99. $auth->add($createUserProfile);
  100.  
  101. $viewUserProfile = $auth->createPermission('viewProfile');
  102. $viewUserProfile->description = 'View User Profile';
  103. $auth->add($viewUserProfile);
  104.  
  105.  
  106. //ROLES
  107. $dataEntry = $auth->createRole('dataEntry'); //Data Entry role
  108. $auth->add($dataEntry);
  109. $auth->addChild($dataEntry, $createAsset);
  110. $auth->addChild($dataEntry, $editAsset);
  111. $auth->addChild($dataEntry, $createResident);
  112. $auth->addChild($dataEntry, $editResident);
  113.  
  114.  
  115. $resident = $auth->createRole('resident'); // Resident role
  116. $auth->add($resident);
  117. $auth->addChild($resident, $makePayment);
  118. $auth->addChild($resident, $viewPayment);
  119.  
  120.  
  121. $boardOfInland = $auth->createRole('board'); // Board of Inland Revenue role
  122. $auth->add($boardOfInland);
  123. $auth->addChild($boardOfInland, $dataEntry);
  124. $auth->addChild($boardOfInland, $resident);
  125. $auth->addChild($boardOfInland, $viewAsset);
  126. $auth->addChild($boardOfInland, $deleteAsset);
  127. $auth->addChild($boardOfInland, $deleteResident);
  128. $auth->addChild($boardOfInland, $createReport);
  129. $auth->addChild($boardOfInland, $viewReport);
  130.  
  131. $executiveMgmt = $auth->createRole('executive'); // Executive Management role
  132. $auth->add($executiveMgmt);
  133. $auth->addChild($executiveMgmt, $boardOfInland);
  134. $auth->addChild($executiveMgmt, $viewDashboards);
  135.  
  136. $admin = $auth->createRole('admin');
  137. $auth->add($admin);
  138. $auth->addChild($admin, $executiveMgmt);
  139. $auth->addChild($admin, $viewUserProfile);
  140. $auth->addChild($admin, $createUserProfile);
  141.  
  142.  
  143. $auth->assign($admin, 1);
  144.  
  145. }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement