Commit c8909520 authored by OlegPahhomov's avatar OlegPahhomov

SA0140-572 | make my-dashboard visible for a quest

parent e7fcb8fc
......@@ -4,5 +4,4 @@ public interface DashboardWidgetCustomRepository {
boolean existsByAppUserWidget(Long appUser, Long widget);
boolean existsByAppUserAndDashboardAndWidget(Long appUser, Long dashboard, Long widget);
}
......@@ -20,19 +20,4 @@ public class DashboardWidgetCustomRepositoryImpl implements DashboardWidgetCusto
.setParameter("widget", widget)
.getSingleResult();
}
@Override
public boolean existsByAppUserAndDashboardAndWidget(Long appUser, Long dashboard, Long widget) {
return (boolean) entityManager.createNativeQuery("" +
"select case when count(1) > 0 then true else false end\n" +
"from dashboard d\n" +
" join dashboard_widget dw on d.id = dw.dashboard\n" +
"where d.app_user = :appUser\n" +
" and dw.widget = :widget \n" +
" and dw.dashboard = :dashboard")
.setParameter("appUser", appUser)
.setParameter("dashboard", dashboard)
.setParameter("widget", widget)
.getSingleResult();
}
}
......@@ -23,15 +23,17 @@ public class DashboardFinder {
private DashboardServiceCache dashboardServiceCache;
public Dashboard findValidDashboard(Long id, StatUser user) {
public Dashboard findValidDashboardForViewing(Long id) {
Dashboard dashboard = findById(id);
mustBeVisible(dashboard);
ifTypeIsUserUsersMustMatch(user, dashboard);
return dashboard;
}
public Dashboard dashboardForSaveWidgets(Long id, StatUser user) {
return findValidDashboard(id, user);
Dashboard dashboard = findById(id);
mustBeVisible(dashboard);
ifTypeIsUserUsersMustMatch(user, dashboard);
return dashboard;
}
public Dashboard findValidDashboardForPinning(Long id, PinningStrategy pinning) {
......
......@@ -32,7 +32,7 @@ public class DashboardService {
}
public DashboardResponse findById(Long id, Language lang, StatUser user) {
Dashboard dashboard = dashboardFinder.findValidDashboard(id, user);
Dashboard dashboard = dashboardFinder.findValidDashboardForViewing(id);
return map(dashboard, lang, user);
}
......
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;
import org.springframework.stereotype.Service;
import static ee.stat.dashboard.util.ErrorCode.*;
import static ee.stat.dashboard.util.ErrorCode.my_dashboard_does_not_exist;
import static ee.stat.dashboard.util.ErrorCode.widget_is_hidden;
import static ee.stat.dashboard.util.ErrorCode.widget_is_not_existing;
import static ee.stat.dashboard.util.ErrorCode.widget_is_not_existing_or_added_to_dashboard;
import static ee.stat.dashboard.util.ResponseUtil.badRequest;
@Service
@AllArgsConstructor
......@@ -36,12 +34,12 @@ public class WidgetFinder {
return widgetRepository.findById(id).orElseThrow(()-> new StatBadRequestException(widget_is_not_existing));
}
public Widget findWidget(Long id, Long dashboardId, StatUser user) {
public Widget findWidgetForViewing(Long id, Long dashboardId) {
Dashboard dashboard = dashboardFinder.findById(dashboardId);
if (dashboard.getUserType().isAdmin()) {
existsAdminWidget(id, dashboardId);
} else {
existsUserWidget(id, dashboardId, user);
existsUserWidget(id, dashboardId);
}
Widget widget = findWidgetByIdFromCache(id);
mustBeVisible(widget);
......@@ -52,11 +50,8 @@ public class WidgetFinder {
return widgetServiceCache.findById(id).orElseThrow(() -> new StatBadRequestException(widget_is_not_existing));
}
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)) {
private void existsUserWidget(Long widgetId, Long dashboardId) {
if (!dashboardWidgetRepository.existsByDashboardAndWidget(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, user);
Widget widget = widgetFinder.findWidgetForViewing(id, dashboardId);
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