improve permission checks for report access (#2658)

This commit is contained in:
Kevin Papst
2021-07-13 06:21:31 +02:00
committed by GitHub
parent a1f90ffaba
commit 7661d43327
3 changed files with 31 additions and 23 deletions

View File

@@ -14,7 +14,6 @@ use App\Entity\Project;
use App\Project\ProjectStatisticService; use App\Project\ProjectStatisticService;
use App\Reporting\ProjectDetails\ProjectDetailsForm; use App\Reporting\ProjectDetails\ProjectDetailsForm;
use App\Reporting\ProjectDetails\ProjectDetailsQuery; use App\Reporting\ProjectDetails\ProjectDetailsQuery;
use App\Utils\LocaleSettings;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
@@ -23,9 +22,9 @@ final class ProjectDetailsController extends AbstractController
{ {
/** /**
* @Route(path="/reporting/project_details", name="report_project_details", methods={"GET"}) * @Route(path="/reporting/project_details", name="report_project_details", methods={"GET"})
* @Security("is_granted('view_reporting') and is_granted('details_project')") * @Security("is_granted('view_reporting') and (is_granted('details_project') or is_granted('details_teamlead_project') or is_granted('details_team_project'))")
*/ */
public function __invoke(Request $request, ProjectStatisticService $service, LocaleSettings $localeSettings) public function __invoke(Request $request, ProjectStatisticService $service)
{ {
$dateFactory = $this->getDateTimeFactory(); $dateFactory = $this->getDateTimeFactory();
$user = $this->getUser(); $user = $this->getUser();

View File

@@ -51,9 +51,11 @@ final class ReportingService
} }
if ($this->security->isGranted('budget_project')) { if ($this->security->isGranted('budget_project')) {
$event->addReport(new Report('project_view', 'report_project_view', 'report_project_view', 'project')); $event->addReport(new Report('project_view', 'report_project_view', 'report_project_view', 'project'));
if ($this->security->isGranted('details_project')) { }
$event->addReport(new Report('project_details', 'report_project_details', 'report_project_details', 'project')); if ($this->security->isGranted('details_project') || $this->security->isGranted('details_teamlead_project') || $this->security->isGranted('details_team_project')) {
} $event->addReport(new Report('project_details', 'report_project_details', 'report_project_details', 'project'));
}
if ($this->security->isGranted('budget_project')) {
$event->addReport(new Report('inactive_projects', 'report_project_inactive', 'report_inactive_project', 'project')); $event->addReport(new Report('inactive_projects', 'report_project_inactive', 'report_inactive_project', 'project'));
} }

View File

@@ -8,6 +8,7 @@
{% set tableId = 'project-details-form' %} {% set tableId = 'project-details-form' %}
{% set view_revenue_tab = project_details is not null and is_granted('budget', project_details.project) %} {% set view_revenue_tab = project_details is not null and is_granted('budget', project_details.project) %}
{% set view_revenue_user = project_details is not null and is_granted('view_rate_other_timesheet') %} {% set view_revenue_user = project_details is not null and is_granted('view_rate_other_timesheet') %}
{% set see_users = is_granted('view_other_timesheet') or is_granted('view_other_reporting') %}
{% block stylesheets %} {% block stylesheets %}
{{ parent() }} {{ parent() }}
@@ -78,17 +79,17 @@
{% endif %} {% endif %}
{% if hasData %} {% if hasData %}
{{ _self.project_details(project_view, project_details, view_revenue_tab, view_revenue_user) }} {{ _self.project_details(project_view, project_details, view_revenue_tab, view_revenue_user, see_users) }}
{% set currency = project_view.project.customer.currency %} {% set currency = project_view.project.customer.currency %}
{%- for yearStat in project_details.years|reverse %} {%- for yearStat in project_details.years|reverse %}
{% set year = yearStat.year %} {% set year = yearStat.year %}
{{ _self.duration_stat(year, year, year, month_names(), yearStat, project_details.getYearActivities(year), project_details.userYears(year), currency, view_revenue_tab) }} {{ _self.duration_stat(year, year, year, month_names(), yearStat, project_details.getYearActivities(year), project_details.userYears(year), currency, view_revenue_tab, see_users) }}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% macro duration_stat(id, title, year, labels, yearStat, activities, users, currency, view_revenue_tab) %} {% macro duration_stat(id, title, year, labels, yearStat, activities, users, currency, view_revenue_tab, see_users) %}
{% set rates = [] %} {% set rates = [] %}
{% set durations = [] %} {% set durations = [] %}
{% set chartPrefix = 'chart' ~ id %} {% set chartPrefix = 'chart' ~ id %}
@@ -106,7 +107,9 @@
<div class="nav-tabs-custom"> <div class="nav-tabs-custom">
<ul class="nav nav-tabs pull-right"> <ul class="nav nav-tabs pull-right">
{% if see_users %}
<li><a data-chart="{{ chartPrefix }}User" href="#user-chart-{{ id}}" data-toggle="tab">{{ 'label.user'|trans }}</a></li> <li><a data-chart="{{ chartPrefix }}User" href="#user-chart-{{ id}}" data-toggle="tab">{{ 'label.user'|trans }}</a></li>
{% endif %}
<li><a data-chart="{{ chartPrefix }}Activity" href="#activity-chart-{{ id}}" data-toggle="tab">{{ 'label.activity'|trans }}</a></li> <li><a data-chart="{{ chartPrefix }}Activity" href="#activity-chart-{{ id}}" data-toggle="tab">{{ 'label.activity'|trans }}</a></li>
{% if view_revenue_tab %} {% if view_revenue_tab %}
<li><a data-chart="{{ chartPrefix }}Rate" href="#revenue-chart-{{ id }}" data-toggle="tab">{{ 'stats.revenue'|trans }}</a></li> <li><a data-chart="{{ chartPrefix }}Rate" href="#revenue-chart-{{ id }}" data-toggle="tab">{{ 'stats.revenue'|trans }}</a></li>
@@ -134,9 +137,11 @@
<div class="chart tab-pane" id="activity-chart-{{ id }}"> <div class="chart tab-pane" id="activity-chart-{{ id }}">
{{ _self.activity_tab(activities, yearStat.duration, currency, chartPrefix, view_revenue_tab) }} {{ _self.activity_tab(activities, yearStat.duration, currency, chartPrefix, view_revenue_tab) }}
</div> </div>
{% if see_users %}
<div class="chart tab-pane" id="user-chart-{{ id }}"> <div class="chart tab-pane" id="user-chart-{{ id }}">
{{ _self.user_tab(year, users) }} {{ _self.user_tab(year, users) }}
</div> </div>
{% endif %}
</div> </div>
</div> </div>
{% endmacro %} {% endmacro %}
@@ -239,7 +244,7 @@
entry = ProjectViewModel entry = ProjectViewModel
project_details = ProjectDetailsModel project_details = ProjectDetailsModel
#} #}
{% macro project_details(entry, project_details, view_revenue_tab, view_revenue_user) %} {% macro project_details(entry, project_details, view_revenue_tab, view_revenue_user, see_users) %}
{% set activities = project_details.activities %} {% set activities = project_details.activities %}
{% set years = project_details.years %} {% set years = project_details.years %}
{% import "macros/progressbar.html.twig" as progress %} {% import "macros/progressbar.html.twig" as progress %}
@@ -260,7 +265,9 @@
<div class="nav-tabs-custom"> <div class="nav-tabs-custom">
<ul class="nav nav-tabs pull-right"> <ul class="nav nav-tabs pull-right">
{% if see_users %}
<li><a data-chart="{{ chartPrefix }}User" href="#user-chart" data-toggle="tab">{{ 'label.user'|trans }}</a></li> <li><a data-chart="{{ chartPrefix }}User" href="#user-chart" data-toggle="tab">{{ 'label.user'|trans }}</a></li>
{% endif %}
<li><a data-chart="{{ chartPrefix }}Activity" href="#activity-chart" data-toggle="tab">{{ 'label.activity'|trans }}</a></li> <li><a data-chart="{{ chartPrefix }}Activity" href="#activity-chart" data-toggle="tab">{{ 'label.activity'|trans }}</a></li>
{% if view_revenue_tab %} {% if view_revenue_tab %}
<li><a data-chart="{{ chartPrefix }}Rate" href="#revenue-chart" data-toggle="tab">{{ 'stats.revenue'|trans }}</a></li> <li><a data-chart="{{ chartPrefix }}Rate" href="#revenue-chart" data-toggle="tab">{{ 'stats.revenue'|trans }}</a></li>
@@ -290,12 +297,14 @@
</th> </th>
<td>{{ entry.durationTotal|duration }}</td> <td>{{ entry.durationTotal|duration }}</td>
</tr> </tr>
{% if view_revenue_tab %}
<tr> <tr>
<th class="w-min"> <th class="w-min">
{{ 'stats.amountTotal'|trans }} {{ 'stats.amountTotal'|trans }}
</th> </th>
<td>{{ entry.rateTotal|money(currency) }}</td> <td>{{ entry.rateTotal|money(currency) }}</td>
</tr> </tr>
{% endif %}
</table> </table>
</div> </div>
<div class="col-xs-12 col-md-6"> <div class="col-xs-12 col-md-6">
@@ -312,38 +321,34 @@
{% endif %} {% endif %}
</td> </td>
</tr> </tr>
{% if is_granted('create_export') %}
<tr> <tr>
<th class="w-min"> <th class="w-min">
{{ 'label.not_exported'|trans }} {{ 'label.not_exported'|trans }}
</th> </th>
<td> <td>
{% if is_granted('create_export') %} <a href="{{ path('export', {'customers[]': project.customer.id, 'projects[]': project.id, 'daterange': '', 'preview': true}) }}">
<a href="{{ path('export', {'customers[]': project.customer.id, 'projects[]': project.id, 'daterange': '', 'preview': true}) }}">
{{ entry.notExportedDuration|duration }}
</a>
{% else %}
{{ entry.notExportedDuration|duration }} {{ entry.notExportedDuration|duration }}
{% endif %} </a>
</td> </td>
</tr> </tr>
{% endif %}
{% if is_granted('view_invoice') %}
<tr> <tr>
<th class="w-min"> <th class="w-min">
{{ 'label.not_invoiced'|trans }} {{ 'label.not_invoiced'|trans }}
</th> </th>
<td> <td>
{% if is_granted('view_invoice') %} <a href="{{ path('invoice', {'customers[]': project.customer.id, 'projects[]': project.id, 'daterange': ''}) }}">
<a href="{{ path('invoice', {'customers[]': project.customer.id, 'projects[]': project.id, 'daterange': ''}) }}">
{{ entry.notBilledRate|money(currency) }}
</a>
{% else %}
{{ entry.notBilledRate|money(currency) }} {{ entry.notBilledRate|money(currency) }}
{% endif %} </a>
</td> </td>
</tr> </tr>
{% endif %}
</table> </table>
</div> </div>
</div> </div>
{% if is_granted('budget', project) and (project.timeBudget > 0 or project.budget > 0) %} {% if view_revenue_tab and (project.timeBudget > 0 or project.budget > 0) %}
<div class="row"> <div class="row">
<div class="col-xs-12"> <div class="col-xs-12">
<table class="table table-hover dataTable"> <table class="table table-hover dataTable">
@@ -399,6 +404,7 @@
<div class="chart tab-pane" id="activity-chart"> <div class="chart tab-pane" id="activity-chart">
{{ _self.activity_tab(activities, entry.durationTotal, project.customer.currency, chartPrefix, view_revenue_tab) }} {{ _self.activity_tab(activities, entry.durationTotal, project.customer.currency, chartPrefix, view_revenue_tab) }}
</div> </div>
{% if see_users %}
<div class="chart tab-pane" id="user-chart"> <div class="chart tab-pane" id="user-chart">
<div class="row"> <div class="row">
<div class="col-xs-12 col-sm-9 col-md-8 col-lg-6"> <div class="col-xs-12 col-sm-9 col-md-8 col-lg-6">
@@ -450,6 +456,7 @@
</div> </div>
</div> </div>
</div> </div>
{% endif %}
</div> </div>
</div> </div>
{% endmacro %} {% endmacro %}