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
244 lines
5.9 KiB
<?php
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
if (!function_exists('businessInfoIsEmpty')) {
|
|
function businessInfoIsEmpty($userId)
|
|
{
|
|
return !isset(request('_business_info')['members'][$userId]);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('permit')) {
|
|
function permit($actionName = null, $ids = [])
|
|
{
|
|
throw_if($actionName === null, '$actionName must not be null.');
|
|
|
|
$response = call_user_func($actionName, $ids);
|
|
|
|
if ($response === false) {
|
|
abort(Response::HTTP_FORBIDDEN);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
if (!function_exists('can')) {
|
|
function can($actionName = null, $ids = [])
|
|
{
|
|
throw_if($actionName === null, '$actionName must not be null.');
|
|
|
|
return call_user_func($actionName, $ids);
|
|
}
|
|
}
|
|
|
|
|
|
if (!function_exists('isOwner')) {
|
|
function isOwner()
|
|
{
|
|
return request('_business_info')['users'][auth()->user()->id]['owner'] == true;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Business Permit
|
|
*/
|
|
|
|
if (!function_exists('businessAccess')) {
|
|
function businessAccess($ids)
|
|
{
|
|
return isset(request('_business_info')['info']['users'][$ids['user_id']?? auth()->id()]);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('isBusinessOwner')) {
|
|
function isBusinessOwner($ids)
|
|
{
|
|
return businessAccess($ids) && request('_business_info')['info']['users'][$ids['user_id'] ?? auth()->id()]['level'] == enum('levels.owner.id');
|
|
}
|
|
}
|
|
|
|
if (!function_exists('isAtLeastBusinessAdmin')) {
|
|
function isAtLeastBusinessAdmin($ids)
|
|
{
|
|
return businessAccess($ids) && request('_business_info')['info']['users'][$ids['user_id'] ?? auth()->id()]['level'] >= enum('levels.admin.id');
|
|
}
|
|
}
|
|
|
|
if (!function_exists('businessEdit')) {
|
|
function businessEdit($ids)
|
|
{
|
|
return isBusinessOwner($ids);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('businessUsers')) {
|
|
function businessUsers($ids)
|
|
{
|
|
return isBusinessOwner($ids);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('businessWorkFlows')) {
|
|
function businessWorkFlows($ids)
|
|
{
|
|
return isAtLeastBusinessAdmin($ids);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('businessProjects')) {
|
|
function businessProjects($ids)
|
|
{
|
|
return isBusinessOwner($ids);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('businessTags')) {
|
|
function businessTags($ids)
|
|
{
|
|
return isAtLeastBusinessAdmin($ids);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('businessStatuses')) {
|
|
function businessStatuses($ids)
|
|
{
|
|
return isAtLeastBusinessAdmin($ids);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Project Permit
|
|
*/
|
|
|
|
if (!function_exists('isInProject')) {
|
|
function isInProject($ids)
|
|
{
|
|
return isset(request('_business_info')['info']['projects'][$ids['project_id']]['members'][$ids['user_id'] ?? auth()->id()]);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('isActiveInProject')) {
|
|
function isActiveInProject($ids)
|
|
{
|
|
return request('_business_info')['info']['projects'][$ids['project_id']]['members'][$ids['user_id'] ?? auth()->id()]['level'] > 0;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('projectAccess')) {
|
|
function projectAccess($ids)
|
|
{
|
|
return isInProject($ids) && isActiveInProject($ids);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('isOwnerLevelInProject')) {
|
|
function isOwnerLevelInProject($ids)
|
|
{
|
|
return request('_business_info')['info']['projects'][$ids['project_id']]['members'][$ids['user_id'] ?? auth()->id()]['level'] == enum('levels.owner.id');
|
|
}
|
|
}
|
|
|
|
if (!function_exists('isAtLeastAdminLevelInProject')) {
|
|
function isAtLeastAdminLevelInProject($ids)
|
|
{
|
|
return request('_business_info')['info']['projects'][$ids['project_id']]['members'][$ids['user_id'] ?? auth()->id()]['level'] >= enum('levels.admin.id');
|
|
}
|
|
}
|
|
|
|
if (!function_exists('isAtLeastColleagueLevelInProject')) {
|
|
function isAtLeastColleagueLevelInProject($ids)
|
|
{
|
|
return request('_business_info')['info']['projects'][$ids['project_id']]['members'][$ids['user_id'] ?? auth()->id()]['level'] >= enum('levels.colleague.id');
|
|
}
|
|
}
|
|
|
|
if (!function_exists('isAtLeastGuestLevelInProject')) {
|
|
function isAtLeastGuestLevelInProject($ids)
|
|
{
|
|
return request('_business_info')['info']['projects'][$ids['project_id']]['members'][$ids['user_id'] ?? auth()->id()]['level'] >= enum('levels.guest.id');
|
|
}
|
|
}
|
|
|
|
if (!function_exists('isDefiniteGuestInProject')) {
|
|
function isDefiniteGuestInProject($ids)
|
|
{
|
|
return isInProject($ids) && request('_business_info')['info']['projects'][$ids['project_id']]['members'][$ids['user_id'] ?? auth()->id()]['level'] == enum('levels.guest.id');
|
|
}
|
|
}
|
|
|
|
if (!function_exists('isProjectOwner')) {
|
|
function isProjectOwner($ids)
|
|
{
|
|
return isInProject($ids) && isOwnerLevelInProject($ids);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('isProjectAdmin')) {
|
|
function isProjectAdmin($ids)
|
|
{
|
|
return isInProject($ids) && isAtLeastAdminLevelInProject($ids);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('isProjectColleague')) {
|
|
function isProjectColleague($ids)
|
|
{
|
|
return isInProject($ids) && isAtLeastColleagueLevelInProject($ids);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('isProjectGuest')) {
|
|
function isProjectGuest($ids)
|
|
{
|
|
return isInProject($ids) && isAtLeastGuestLevelInProject($ids);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('projectEdit')) {
|
|
function projectEdit($ids)
|
|
{
|
|
return isProjectAdmin($ids);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('projectUsers')) {
|
|
function projectUsers($ids)
|
|
{
|
|
return isProjectOwner($ids);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('projectSystems')) {
|
|
function projectSystems($ids)
|
|
{
|
|
return isProjectAdmin($ids);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('projectTasks')) {
|
|
function projectTasks($ids)
|
|
{
|
|
return isProjectAdmin($ids);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('projectSprints')) {
|
|
function projectSprints($ids)
|
|
{
|
|
return isProjectAdmin($ids);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* other
|
|
*/
|
|
|
|
if (!function_exists('isActiveUser')) {
|
|
function isActiveUser($ids)
|
|
{
|
|
return businessAccess($ids) && request('_business_info')['info']['users'][$ids['user_id'] ?? auth()->id()]['level'] > enum('levels.inactive.id');
|
|
}
|
|
}
|
|
|