You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

244 lines
5.9 KiB

  1. <?php
  2. use Illuminate\Http\Response;
  3. if (!function_exists('businessInfoIsEmpty')) {
  4. function businessInfoIsEmpty($userId)
  5. {
  6. return !isset(request('_business_info')['members'][$userId]);
  7. }
  8. }
  9. if (!function_exists('permit')) {
  10. function permit($actionName = null, $ids = [])
  11. {
  12. throw_if($actionName === null, '$actionName must not be null.');
  13. $response = call_user_func($actionName, $ids);
  14. if ($response === false) {
  15. abort(Response::HTTP_FORBIDDEN);
  16. }
  17. }
  18. }
  19. if (!function_exists('can')) {
  20. function can($actionName = null, $ids = [])
  21. {
  22. throw_if($actionName === null, '$actionName must not be null.');
  23. return call_user_func($actionName, $ids);
  24. }
  25. }
  26. if (!function_exists('isOwner')) {
  27. function isOwner()
  28. {
  29. return request('_business_info')['users'][auth()->user()->id]['owner'] == true;
  30. }
  31. }
  32. /**
  33. * Business Permit
  34. */
  35. if (!function_exists('businessAccess')) {
  36. function businessAccess($ids)
  37. {
  38. return isset(request('_business_info')['info']['users'][$ids['user_id']?? auth()->id()]);
  39. }
  40. }
  41. if (!function_exists('isBusinessOwner')) {
  42. function isBusinessOwner($ids)
  43. {
  44. return businessAccess($ids) && request('_business_info')['info']['users'][$ids['user_id'] ?? auth()->id()]['level'] == enum('levels.owner.id');
  45. }
  46. }
  47. if (!function_exists('isAtLeastBusinessAdmin')) {
  48. function isAtLeastBusinessAdmin($ids)
  49. {
  50. return businessAccess($ids) && request('_business_info')['info']['users'][$ids['user_id'] ?? auth()->id()]['level'] >= enum('levels.admin.id');
  51. }
  52. }
  53. if (!function_exists('businessEdit')) {
  54. function businessEdit($ids)
  55. {
  56. return isBusinessOwner($ids);
  57. }
  58. }
  59. if (!function_exists('businessUsers')) {
  60. function businessUsers($ids)
  61. {
  62. return isBusinessOwner($ids);
  63. }
  64. }
  65. if (!function_exists('businessWorkFlows')) {
  66. function businessWorkFlows($ids)
  67. {
  68. return isAtLeastBusinessAdmin($ids);
  69. }
  70. }
  71. if (!function_exists('businessProjects')) {
  72. function businessProjects($ids)
  73. {
  74. return isBusinessOwner($ids);
  75. }
  76. }
  77. if (!function_exists('businessTags')) {
  78. function businessTags($ids)
  79. {
  80. return isAtLeastBusinessAdmin($ids);
  81. }
  82. }
  83. if (!function_exists('businessStatuses')) {
  84. function businessStatuses($ids)
  85. {
  86. return isAtLeastBusinessAdmin($ids);
  87. }
  88. }
  89. /**
  90. * Project Permit
  91. */
  92. if (!function_exists('isInProject')) {
  93. function isInProject($ids)
  94. {
  95. return isset(request('_business_info')['info']['projects'][$ids['project_id']]['members'][$ids['user_id'] ?? auth()->id()]);
  96. }
  97. }
  98. if (!function_exists('isActiveInProject')) {
  99. function isActiveInProject($ids)
  100. {
  101. return request('_business_info')['info']['projects'][$ids['project_id']]['members'][$ids['user_id'] ?? auth()->id()]['level'] > 0;
  102. }
  103. }
  104. if (!function_exists('projectAccess')) {
  105. function projectAccess($ids)
  106. {
  107. return isInProject($ids) && isActiveInProject($ids);
  108. }
  109. }
  110. if (!function_exists('isOwnerLevelInProject')) {
  111. function isOwnerLevelInProject($ids)
  112. {
  113. return request('_business_info')['info']['projects'][$ids['project_id']]['members'][$ids['user_id'] ?? auth()->id()]['level'] == enum('levels.owner.id');
  114. }
  115. }
  116. if (!function_exists('isAtLeastAdminLevelInProject')) {
  117. function isAtLeastAdminLevelInProject($ids)
  118. {
  119. return request('_business_info')['info']['projects'][$ids['project_id']]['members'][$ids['user_id'] ?? auth()->id()]['level'] >= enum('levels.admin.id');
  120. }
  121. }
  122. if (!function_exists('isAtLeastColleagueLevelInProject')) {
  123. function isAtLeastColleagueLevelInProject($ids)
  124. {
  125. return request('_business_info')['info']['projects'][$ids['project_id']]['members'][$ids['user_id'] ?? auth()->id()]['level'] >= enum('levels.colleague.id');
  126. }
  127. }
  128. if (!function_exists('isAtLeastGuestLevelInProject')) {
  129. function isAtLeastGuestLevelInProject($ids)
  130. {
  131. return request('_business_info')['info']['projects'][$ids['project_id']]['members'][$ids['user_id'] ?? auth()->id()]['level'] >= enum('levels.guest.id');
  132. }
  133. }
  134. if (!function_exists('isDefiniteGuestInProject')) {
  135. function isDefiniteGuestInProject($ids)
  136. {
  137. return isInProject($ids) && request('_business_info')['info']['projects'][$ids['project_id']]['members'][$ids['user_id'] ?? auth()->id()]['level'] == enum('levels.guest.id');
  138. }
  139. }
  140. if (!function_exists('isProjectOwner')) {
  141. function isProjectOwner($ids)
  142. {
  143. return isInProject($ids) && isOwnerLevelInProject($ids);
  144. }
  145. }
  146. if (!function_exists('isProjectAdmin')) {
  147. function isProjectAdmin($ids)
  148. {
  149. return isInProject($ids) && isAtLeastAdminLevelInProject($ids);
  150. }
  151. }
  152. if (!function_exists('isProjectColleague')) {
  153. function isProjectColleague($ids)
  154. {
  155. return isInProject($ids) && isAtLeastColleagueLevelInProject($ids);
  156. }
  157. }
  158. if (!function_exists('isProjectGuest')) {
  159. function isProjectGuest($ids)
  160. {
  161. return isInProject($ids) && isAtLeastGuestLevelInProject($ids);
  162. }
  163. }
  164. if (!function_exists('projectEdit')) {
  165. function projectEdit($ids)
  166. {
  167. return isProjectAdmin($ids);
  168. }
  169. }
  170. if (!function_exists('projectUsers')) {
  171. function projectUsers($ids)
  172. {
  173. return isProjectOwner($ids);
  174. }
  175. }
  176. if (!function_exists('projectSystems')) {
  177. function projectSystems($ids)
  178. {
  179. return isProjectAdmin($ids);
  180. }
  181. }
  182. if (!function_exists('projectTasks')) {
  183. function projectTasks($ids)
  184. {
  185. return isProjectAdmin($ids);
  186. }
  187. }
  188. if (!function_exists('projectSprints')) {
  189. function projectSprints($ids)
  190. {
  191. return isProjectAdmin($ids);
  192. }
  193. }
  194. /**
  195. * other
  196. */
  197. if (!function_exists('isActiveUser')) {
  198. function isActiveUser($ids)
  199. {
  200. return businessAccess($ids) && request('_business_info')['info']['users'][$ids['user_id'] ?? auth()->id()]['level'] > enum('levels.inactive.id');
  201. }
  202. }