Commit 4e5314cc authored by oleg.pahhomov's avatar oleg.pahhomov

Revert "SA0140-537 | remove user check from find user widget"

This reverts commit efca98c7
parent 81d7ace5
......@@ -5,5 +5,4 @@ public interface DashboardWidgetCustomRepository {
boolean existsByAppUserWidget(Long appUser, Long widget);
boolean existsByAppUserAndDashboardAndWidget(Long appUser, Long dashboard, Long widget);
}
package ee.stat.dashboard.service.widget.widget;
import ee.stat.dashboard.config.security.StatUser;
import ee.stat.dashboard.model.dashboard.Dashboard;
import ee.stat.dashboard.model.widget.back.Widget;
import ee.stat.dashboard.repository.DashboardWidgetRepository;
import ee.stat.dashboard.repository.WidgetRepository;
import ee.stat.dashboard.service.dashboard.DashboardFinder;
import ee.stat.dashboard.service.dashboard.DashboardServiceCache;
import ee.stat.dashboard.util.StatBadRequestException;
import ee.stat.dashboard.util.StatNotFoundRequestException;
import lombok.AllArgsConstructor;
......@@ -34,12 +36,12 @@ public class WidgetFinder {
return widgetRepository.findById(id).orElseThrow(()-> new StatBadRequestException(widget_is_not_existing));
}
public Widget findWidget(Long id, Long dashboardId) {
public Widget findWidget(Long id, Long dashboardId, StatUser user) {
Dashboard dashboard = dashboardFinder.findById(dashboardId);
if (dashboard.getUserType().isAdmin()) {
existsAdminWidget(id, dashboardId);
} else {
existsUserWidget(id, dashboardId);
existsUserWidget(id, dashboardId, user);
}
Widget widget = findWidgetByIdFromCache(id);
mustBeVisible(widget);
......@@ -50,8 +52,11 @@ public class WidgetFinder {
return widgetServiceCache.findById(id).orElseThrow(() -> new StatBadRequestException(widget_is_not_existing));
}
private void existsUserWidget(Long widgetId, Long dashboardId) {
if (!dashboardWidgetRepository.existsByDashboardAndWidget(dashboardId, widgetId)) {
private void existsUserWidget(Long widgetId, Long dashboardId, StatUser user) {
if (user == null) {
throw new StatNotFoundRequestException(my_dashboard_must_have_user);
}
if (!dashboardWidgetRepository.existsByAppUserAndDashboardAndWidget(user.getId(), dashboardId, widgetId)) {
throw new StatNotFoundRequestException(my_dashboard_does_not_exist);
}
}
......
......@@ -52,7 +52,7 @@ public class WidgetService {
public WidgetResponse findById(Long id, Long dashboardId, Long ehakId, Language lang, String graphType,
StatUser user, Map<String, String> params, FilterType filterType) {
Widget widget = widgetFinder.findWidget(id, dashboardId);
Widget widget = widgetFinder.findWidget(id, dashboardId, user);
return mapWidget(widget, dashboardId, ehakId, lang, graphType, user, params, filterType);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment