Commit efca98c7 authored by oleg.pahhomov's avatar oleg.pahhomov

SA0140-537 | remove user check from find user widget

parent 3b5ddc53
...@@ -5,4 +5,5 @@ public interface DashboardWidgetCustomRepository { ...@@ -5,4 +5,5 @@ public interface DashboardWidgetCustomRepository {
boolean existsByAppUserWidget(Long appUser, Long widget); boolean existsByAppUserWidget(Long appUser, Long widget);
boolean existsByAppUserAndDashboardAndWidget(Long appUser, Long dashboard, Long widget); boolean existsByAppUserAndDashboardAndWidget(Long appUser, Long dashboard, Long widget);
} }
package ee.stat.dashboard.service.widget.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.dashboard.Dashboard;
import ee.stat.dashboard.model.widget.back.Widget; import ee.stat.dashboard.model.widget.back.Widget;
import ee.stat.dashboard.repository.DashboardWidgetRepository; import ee.stat.dashboard.repository.DashboardWidgetRepository;
import ee.stat.dashboard.repository.WidgetRepository; import ee.stat.dashboard.repository.WidgetRepository;
import ee.stat.dashboard.service.dashboard.DashboardFinder; 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.StatBadRequestException;
import ee.stat.dashboard.util.StatNotFoundRequestException; import ee.stat.dashboard.util.StatNotFoundRequestException;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
...@@ -36,12 +34,12 @@ public class WidgetFinder { ...@@ -36,12 +34,12 @@ public class WidgetFinder {
return widgetRepository.findById(id).orElseThrow(()-> new StatBadRequestException(widget_is_not_existing)); return widgetRepository.findById(id).orElseThrow(()-> new StatBadRequestException(widget_is_not_existing));
} }
public Widget findWidget(Long id, Long dashboardId, StatUser user) { public Widget findWidget(Long id, Long dashboardId) {
Dashboard dashboard = dashboardFinder.findById(dashboardId); Dashboard dashboard = dashboardFinder.findById(dashboardId);
if (dashboard.getUserType().isAdmin()) { if (dashboard.getUserType().isAdmin()) {
existsAdminWidget(id, dashboardId); existsAdminWidget(id, dashboardId);
} else { } else {
existsUserWidget(id, dashboardId, user); existsUserWidget(id, dashboardId);
} }
Widget widget = findWidgetByIdFromCache(id); Widget widget = findWidgetByIdFromCache(id);
mustBeVisible(widget); mustBeVisible(widget);
...@@ -52,11 +50,8 @@ public class WidgetFinder { ...@@ -52,11 +50,8 @@ public class WidgetFinder {
return widgetServiceCache.findById(id).orElseThrow(() -> new StatBadRequestException(widget_is_not_existing)); return widgetServiceCache.findById(id).orElseThrow(() -> new StatBadRequestException(widget_is_not_existing));
} }
private void existsUserWidget(Long widgetId, Long dashboardId, StatUser user) { private void existsUserWidget(Long widgetId, Long dashboardId) {
if (user == null) { if (!dashboardWidgetRepository.existsByDashboardAndWidget(dashboardId, widgetId)) {
throw new StatNotFoundRequestException(my_dashboard_must_have_user);
}
if (!dashboardWidgetRepository.existsByAppUserAndDashboardAndWidget(user.getId(), dashboardId, widgetId)) {
throw new StatNotFoundRequestException(my_dashboard_does_not_exist); throw new StatNotFoundRequestException(my_dashboard_does_not_exist);
} }
} }
......
...@@ -52,7 +52,7 @@ public class WidgetService { ...@@ -52,7 +52,7 @@ public class WidgetService {
public WidgetResponse findById(Long id, Long dashboardId, Long ehakId, Language lang, String graphType, public WidgetResponse findById(Long id, Long dashboardId, Long ehakId, Language lang, String graphType,
StatUser user, Map<String, String> params, FilterType filterType) { StatUser user, Map<String, String> params, FilterType filterType) {
Widget widget = widgetFinder.findWidget(id, dashboardId, user); Widget widget = widgetFinder.findWidget(id, dashboardId);
return mapWidget(widget, dashboardId, ehakId, lang, graphType, user, params, filterType); 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