Skip to content

Commit

Permalink
Fix for dashboard navigation and email links (#2248)
Browse files Browse the repository at this point in the history
* Changes to show all survey results to superusers

* removing hard coded values

* fixing linting

* splitting to seperate end points

* Handle no data error for graphs

* adding new nodata component

* adding new email for submission response

* fixing linting and testing

* Upgrades to Issue Tracking Table

* removing try catch

* Fixing dashboard navigation and email links

* excluding comments for unpublished engagement
  • Loading branch information
VineetBala-AOT authored Sep 25, 2023
1 parent 805bf24 commit 48bcfca
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 28 deletions.
4 changes: 2 additions & 2 deletions met-api/src/met_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ class _Config(): # pylint: disable=too-few-public-methods
ENGAGEMENT_PATH_SLUG = os.getenv('ENGAGEMENT_PATH_SLUG', '/{slug}')
# engagement dashboard path is used to pass the survey result to the public user.
# The link is changed such that public user can access the comments page from the email and not the dashboard.
ENGAGEMENT_DASHBOARD_PATH = os.getenv('ENGAGEMENT_DASHBOARD_PATH', '/engagements/{engagement_id}/comments')
ENGAGEMENT_DASHBOARD_PATH_SLUG = os.getenv('ENGAGEMENT_DASHBOARD_PATH_SLUG', '/{slug}/comments')
ENGAGEMENT_DASHBOARD_PATH = os.getenv('ENGAGEMENT_DASHBOARD_PATH', '/engagements/{engagement_id}/comments/public')
ENGAGEMENT_DASHBOARD_PATH_SLUG = os.getenv('ENGAGEMENT_DASHBOARD_PATH_SLUG', '/{slug}/comments/public')
USER_MANAGEMENT_PATH = os.getenv('USER_MANAGEMENT_PATH', '/usermanagement')
SITE_URL = os.getenv('SITE_URL')

Expand Down
9 changes: 6 additions & 3 deletions met-api/src/met_api/models/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def get_comments_by_survey_id_paginated(cls, survey_id, pagination_options: Pagi
return page.items, page.total

@classmethod
def get_accepted_comments_by_survey_id_where_engagement_closed_paginated(
cls, survey_id, pagination_options: PaginationOptions):
def get_accepted_comments_by_survey_id_paginated(
cls, survey_id, pagination_options: PaginationOptions, search_text=''):
"""Get comments for closed engagements."""
query = db.session.query(Comment)\
.join(Submission, Submission.id == Comment.submission_id)\
Expand All @@ -103,10 +103,13 @@ def get_accepted_comments_by_survey_id_where_engagement_closed_paginated(
and_(
Comment.survey_id == survey_id,
CommentStatusModel.id == CommentStatus.Approved.value,
Engagement.status_id == EngagementStatus.Closed.value,
Engagement.status_id != EngagementStatus.Unpublished.value,
ReportSetting.display == true()
))

if search_text:
query = query.filter(Comment.text.ilike('%' + search_text + '%'))

query = query.order_by(Comment.id.desc())

no_pagination_options = not pagination_options or not pagination_options.page or not pagination_options.size
Expand Down
16 changes: 3 additions & 13 deletions met-api/src/met_api/services/comment_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,9 @@ def can_view_unapproved_comments(survey_id: int) -> bool:
@classmethod
def get_comments_paginated(cls, survey_id, pagination_options: PaginationOptions, search_text=''):
"""Get comments paginated."""
can_view_unapproved_comments = CommentService.can_view_unapproved_comments(survey_id)

if not can_view_unapproved_comments:
comment_schema = CommentSchema(many=True, only=('text', 'submission_date'))
items, total = Comment.get_accepted_comments_by_survey_id_where_engagement_closed_paginated(
survey_id, pagination_options)
else:
comment_schema = CommentSchema(many=True)
items, total = Comment.get_comments_by_survey_id_paginated(
survey_id,
pagination_options,
search_text,
)
comment_schema = CommentSchema(many=True, only=('text', 'submission_date'))
items, total = Comment.get_accepted_comments_by_survey_id_paginated(
survey_id, pagination_options, search_text)
return {
'items': comment_schema.dump(items),
'total': total
Expand Down
8 changes: 6 additions & 2 deletions met-cron/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ class _Config(): # pylint: disable=too-few-public-methods
# front end endpoints
SITE_URL = os.getenv('SITE_URL')
# needed for close out emails for met api
ENGAGEMENT_DASHBOARD_PATH = os.getenv('ENGAGEMENT_DASHBOARD_PATH', '/engagements/{engagement_id}/comments')
ENGAGEMENT_DASHBOARD_PATH_SLUG = os.getenv('ENGAGEMENT_DASHBOARD_PATH_SLUG', '/{slug}/comments')
ENGAGEMENT_DASHBOARD_PATH = os.getenv('ENGAGEMENT_DASHBOARD_PATH', '/engagements/{engagement_id}/comments/public')
ENGAGEMENT_DASHBOARD_PATH_SLUG = os.getenv('ENGAGEMENT_DASHBOARD_PATH_SLUG', '/{slug}/comments/public')
# needed for publish emails for met api
ENGAGEMENT_VIEW_PATH = os.getenv('ENGAGEMENT_VIEW_PATH', '/engagements/{engagement_id}/view')
ENGAGEMENT_VIEW_PATH_SLUG = os.getenv('ENGAGEMENT_VIEW_PATH_SLUG', '/{slug}')
Expand All @@ -140,6 +140,10 @@ class _Config(): # pylint: disable=too-few-public-methods
PUBLISH_ENGAGEMENT_EMAIL_TEMPLATE_ID = os.getenv('PUBLISH_ENGAGEMENT_EMAIL_TEMPLATE_ID')
PUBLISH_ENGAGEMENT_EMAIL_SUBJECT = os.getenv('PUBLISH_ENGAGEMENT_EMAIL_SUBJECT', 'Share your feedback')

# EAO is a single Tenant Environment where EAO is the only env and should be set to True
# This flag decides if additonal tenant based checks has to be carried or not
IS_SINGLE_TENANT_ENVIRONMENT = os.getenv('IS_SINGLE_TENANT_ENVIRONMENT', 'False').lower() == 'true'

# Closing Soon Email Service
ENGAGEMENT_CLOSING_SOON_EMAIL_TEMPLATE_ID = os.getenv('ENGAGEMENT_CLOSING_SOON_EMAIL_TEMPLATE_ID')
ENGAGEMENT_CLOSING_SOON_EMAIL_SUBJECT = os.getenv('ENGAGEMENT_CLOSING_SOON_EMAIL_SUBJECT',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import { useAppSelector, useAppDispatch } from 'hooks';
import { SubmissionStatus } from 'constants/engagementStatus';
import { openNotificationModal } from 'services/notificationModalService/notificationModalSlice';

export const CommentsBlock = () => {
interface CommentsBlockProps {
dashboardType: string;
}

export const CommentsBlock: React.FC<CommentsBlockProps> = ({ dashboardType }) => {
const { slug } = useParams();
const { engagement, isEngagementLoading } = useContext(CommentViewContext);
const navigate = useNavigate();
Expand All @@ -19,7 +23,7 @@ export const CommentsBlock = () => {
const handleViewDashboard = () => {
/* check to ensure that users with role access_dashboard can access the dashboard while engagement not closed*/
if (canAccessDashboard) {
navigate(`/engagements/${engagement?.id}/dashboard`);
navigate(`/engagements/${engagement?.id}/dashboard/${dashboardType}`);
return;
}

Expand All @@ -42,7 +46,7 @@ export const CommentsBlock = () => {
return;
}

navigate(`${basePath}/dashboard`);
navigate(`${basePath}/dashboard/public`);
};

if (isEngagementLoading || !engagement) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react';
import { useParams } from 'react-router-dom';
import { Grid } from '@mui/material';
import { CommentBanner } from './CommentBanner';
import CommentsBlock from './CommentsBlock';

export const EngagementComments = () => {
const { dashboardType } = useParams<{ dashboardType: string }>();
return (
<Grid container direction="row" justifyContent="flex-start" alignItems="flex-start">
<Grid item xs={12}>
Expand All @@ -18,7 +20,7 @@ export const EngagementComments = () => {
alignItems="flex-end"
m={{ lg: '1em 8em 2em 3em', xs: '1em' }}
>
<CommentsBlock />
<CommentsBlock dashboardType={dashboardType ? dashboardType : 'public'} />
</Grid>
</Grid>
);
Expand Down
2 changes: 1 addition & 1 deletion met-web/src/components/publicDashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Dashboard = () => {
};

const handleReadComments = () => {
navigate(`${basePath}/comments`);
navigate(`${basePath}/comments/${dashboardType}`);
};

const handlePdfExportProgress = (progress: number) => {
Expand Down
2 changes: 1 addition & 1 deletion met-web/src/routes/AuthenticatedRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const AuthenticatedRoutes = () => {
<Route path="/engagements/:engagementId/form" element={<EngagementForm />} />
</Route>
<Route path="/engagements/:engagementId/view" element={<EngagementView />} />
<Route path="/engagements/:engagementId/comments" element={<EngagementComments />} />
<Route path="/engagements/:engagementId/comments/:dashboardType" element={<EngagementComments />} />
<Route path="/engagements/:engagementId/dashboard/:dashboardType" element={<PublicDashboard />} />

<Route element={<AuthGate allowedRoles={[USER_ROLES.VIEW_FEEDBACKS]} />}>
Expand Down
4 changes: 2 additions & 2 deletions met-web/src/routes/UnauthenticatedRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const UnauthenticatedRoutes = () => {
<Route path="/:slug" element={<EngagementView />} />
<Route path="/engagements/:engagementId/dashboard/:dashboardType" element={<PublicDashboard />} />
<Route path="/:slug/dashboard/:dashboardType" element={<PublicDashboard />} />
<Route path="/engagements/:engagementId/comments" element={<EngagementComments />} />
<Route path="/:slug/comments" element={<EngagementComments />} />
<Route path="/engagements/:engagementId/comments/:dashboardType" element={<EngagementComments />} />
<Route path="/:slug/comments/:dashboardType" element={<EngagementComments />} />
<Route path="/engagements/:engagementId/edit/:token" element={<EditSurvey />} />
<Route path="/:slug/edit/:token" element={<EditSurvey />} />
<Route path="/surveys/submit/:surveyId/:token" element={<SurveySubmit />} />
Expand Down

0 comments on commit 48bcfca

Please sign in to comment.