Skip to content

Commit

Permalink
Merge pull request #2828 from Leantime/userRoleIssues
Browse files Browse the repository at this point in the history
Fixing user role issue for manager
  • Loading branch information
marcelfolaron authored Nov 26, 2024
2 parents 28343d3 + 177d514 commit ce89ded
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 55 deletions.
3 changes: 2 additions & 1 deletion .pint/pint.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"exclude": [
"storage/",
"userfiles/"
"userfiles/",
"tests/Support/_generated"
]
}
1 change: 0 additions & 1 deletion app/Core/Http/ApiRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,4 @@ public function getBearerToken(): ?string

return null;
}

}
1 change: 0 additions & 1 deletion app/Core/Http/IncomingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,5 +285,4 @@ public function isApiRequest(): bool

return str_starts_with($requestUri, '/api/jsonrpc');
}

}
8 changes: 4 additions & 4 deletions app/Domain/Menu/Repositories/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ class Menu
10 => [
'type' => 'submenu', 'id' => 'Management', 'title' => 'menu.sidemenu_management', 'visual' => 'open', 'role' => 'manager',
'submenu' => [
5 => ['type' => 'item', 'module' => 'timesheets', 'title' => 'menu.all_timesheets', 'icon' => 'fa fa-fw fa-business-time', 'tooltip' => 'menu.all_timesheets_tooltip', 'href' => '/timesheets/showAll', 'active' => ['showAll']],
10 => ['type' => 'item', 'module' => 'projects', 'title' => 'menu.all_projects', 'icon' => 'fa fa-fw fa-briefcase', 'tooltip' => 'menu.all_projects_tooltip', 'href' => '/projects/showAll', 'active' => ['showAll']],
15 => ['type' => 'item', 'module' => 'clients', 'title' => 'menu.all_clients', 'icon' => 'fa fa-fw fa-address-book', 'tooltip' => 'menu.all_clients_tooltip', 'href' => '/clients/showAll', 'active' => ['showAll']],
20 => ['type' => 'item', 'module' => 'users', 'title' => 'menu.all_users', 'icon' => 'fa fa-fw fa-users', 'tooltip' => 'menu.all_users_tooltip', 'href' => '/users/showAll', 'active' => ['showAll']],
5 => ['type' => 'item', 'module' => 'timesheets', 'role' => 'manager', 'title' => 'menu.all_timesheets', 'icon' => 'fa fa-fw fa-business-time', 'tooltip' => 'menu.all_timesheets_tooltip', 'href' => '/timesheets/showAll', 'active' => ['showAll']],
10 => ['type' => 'item', 'module' => 'projects', 'role' => 'manager', 'title' => 'menu.all_projects', 'icon' => 'fa fa-fw fa-briefcase', 'tooltip' => 'menu.all_projects_tooltip', 'href' => '/projects/showAll', 'active' => ['showAll']],
15 => ['type' => 'item', 'module' => 'clients', 'role' => 'administrator', 'title' => 'menu.all_clients', 'icon' => 'fa fa-fw fa-address-book', 'tooltip' => 'menu.all_clients_tooltip', 'href' => '/clients/showAll', 'active' => ['showAll']],
20 => ['type' => 'item', 'module' => 'users', 'role' => 'administrator', 'title' => 'menu.all_users', 'icon' => 'fa fa-fw fa-users', 'tooltip' => 'menu.all_users_tooltip', 'href' => '/users/showAll', 'active' => ['showAll']],
],
],
15 => [
Expand Down
2 changes: 1 addition & 1 deletion app/Domain/Menu/Services/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function getUserProjectList(int $userId, null|int|string $client = null):
$favoriteProjects = $projects['favoriteProjects'];

//Filtered
$projects = $this->projectService->getProjectHierarchyAvailableToUser($userId, 'open', $client);
$projects = $this->projectService->getProjectHierarchyAvailableToUser($userId, 'open', empty($client) ? session('userdata.clientId') : $client);
$allAvailableProjects = $projects['allAvailableProjects'];
$allAvailableProjectsHierarchy = $projects['allAvailableProjectsHierarchy'];

Expand Down
10 changes: 10 additions & 0 deletions app/Domain/Menu/Templates/headMenu.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,23 @@ class="active"
</li>
@if ($login::userIsAtLeast("manager", true))
<li>
@if($login::userHasRole("manager"))
<a
href="{{ BASE_URL }}/projects/showAll/"
@if ($menuType == 'company')
class="active"
@endif
data-tippy-content="{{ __('popover.company') }}"
>{!! __('menu.company') !!}</a>
@else
<a
href="{{ BASE_URL }}/setting/editCompanySettings/"
@if ($menuType == 'company')
class="active"
@endif
data-tippy-content="{{ __('popover.company') }}"
>{!! __('menu.company') !!}</a>
@endif
</li>
@endif

Expand Down
42 changes: 23 additions & 19 deletions app/Domain/Menu/Templates/partials/leftnav/item.blade.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
<li
@if(
$module == $menuItem['module']
&& (!isset($menuItem['active']) || in_array($action, $menuItem['active']))
)
class='active'
@endif
>
<a href="{{ BASE_URL . $menuItem['href'] }}"
data-tippy-content="{{ strip_tags(__($menuItem['tooltip'])) }}"
data-tippy-placement="right"
@if(isset($menuItem['attributes']))
@foreach($menuItem['attributes'] as $key => $value)
{{ $key }}="{{ $value }}"
@endforeach
@endif
@if(!isset($menuItem['role']) || $login::userIsAtLeast($menuItem['role'] ?? 'editor'))

<li
@if(
$module == $menuItem['module']
&& (!isset($menuItem['active']) || in_array($action, $menuItem['active']))
)
class='active'
@endif
>
{!! $menuItem['title'] !!}
</a>
</li>
<a href="{{ BASE_URL . $menuItem['href'] }}"
data-tippy-content="{{ strip_tags(__($menuItem['tooltip'])) }}"
data-tippy-placement="right"
@if(isset($menuItem['attributes']))
@foreach($menuItem['attributes'] as $key => $value)
{{ $key }}="{{ $value }}"
@endforeach
@endif
>
{!! $menuItem['title'] !!}
</a>
</li>

@endif
48 changes: 26 additions & 22 deletions app/Domain/Menu/Templates/partials/leftnav/submenu.blade.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
<li class="submenuToggle">
<a href="javascript:void(0);"
@if ( $menuItem['visual'] !== 'always' )
onclick="leantime.menuController.toggleSubmenu('{{ $menuItem['id'] }}')"
@endif
>
<i class="submenuCaret fa fa-angle-{{ $menuItem['visual'] == 'closed' ? 'right' : 'down' }}"
id="submenu-icon-{{ $menuItem['id'] }}"></i>
<strong>{!! __($menuItem['title']) !!}</strong>
</a>
</li>
<ul id="submenu-{{ $menuItem['id'] }}" class="submenu {{ $menuItem['visual'] == 'closed' ? 'closed' : 'open' }}">
@foreach ($menuItem['submenu'] as $subkey => $submenuItem)
@switch ($submenuItem['type'])
@case('header')
@include("menu::partials.leftnav.header", ["menuItem" => $submenuItem, "module" => $module, "action" => $action])
@break
@case('item')
@include("menu::partials.leftnav.item", ["menuItem" => $submenuItem, "module" => $module, "action" => $action])
@endswitch
@endforeach
</ul>
@if(!isset($menuItem['role']) || $login::userIsAtLeast($menuItem['role'] ?? 'editor'))

<li class="submenuToggle">
<a href="javascript:void(0);"
@if ( $menuItem['visual'] !== 'always' )
onclick="leantime.menuController.toggleSubmenu('{{ $menuItem['id'] }}')"
@endif
>
<i class="submenuCaret fa fa-angle-{{ $menuItem['visual'] == 'closed' ? 'right' : 'down' }}"
id="submenu-icon-{{ $menuItem['id'] }}"></i>
<strong>{!! __($menuItem['title']) !!}</strong>
</a>
</li>
<ul id="submenu-{{ $menuItem['id'] }}" class="submenu {{ $menuItem['visual'] == 'closed' ? 'closed' : 'open' }}">
@foreach ($menuItem['submenu'] as $subkey => $submenuItem)
@switch ($submenuItem['type'])
@case('header')
@include("menu::partials.leftnav.header", ["menuItem" => $submenuItem, "module" => $module, "action" => $action])
@break
@case('item')
@include("menu::partials.leftnav.item", ["menuItem" => $submenuItem, "module" => $module, "action" => $action])
@endswitch
@endforeach
</ul>

@endif

5 changes: 3 additions & 2 deletions app/Domain/Projects/Repositories/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ public function getUserProjects(int $userId, string $projectStatus = 'all', ?int
return $values;
}

// Deprecated

//This populates the projects show all tab and shows users all the projects that they could access
public function getProjectsUserHasAccessTo($userId, string $status = 'all', string $clientId = ''): false|array
{

Expand All @@ -277,6 +276,7 @@ public function getProjectsUserHasAccessTo($userId, string $status = 'all', stri
project.dollarBudget,
project.menuType,
project.type,
project.parent,
project.modified,
client.name AS clientName,
client.id AS clientId,
Expand Down Expand Up @@ -364,6 +364,7 @@ public function getClientProjects($clientId): false|array
project.state,
project.menuType,
project.modified,
project.type,
client.name AS clientName,
client.id AS clientId
FROM zp_projects as project
Expand Down
7 changes: 3 additions & 4 deletions app/Domain/Projects/Services/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,10 @@ public function getProjectHierarchyAvailableToUser($userId, string $projectStatu
{

//Load all projects user is assigned to
$projects = $this->projectRepository->getUserProjects(
$projects = $this->projectRepository->getProjectsUserHasAccessTo(
userId: $userId,
projectStatus: $projectStatus,
status: $projectStatus,
clientId: (int) $clientId,
accessStatus: 'all'
);
$projects = self::dispatch_filter('afterLoadingProjects', $projects);

Expand Down Expand Up @@ -1637,7 +1636,7 @@ public function getClientManagerProjects(int $userId, int $clientId): array
}
}

return $userProjects;
return $allProjects;
}

/**
Expand Down

0 comments on commit ce89ded

Please sign in to comment.