Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Prod] Add monitoring_integration feature flag, exclude courses that have been replaced from display, fix "start date before" filter bug #2486

Merged
merged 11 commits into from
Nov 15, 2024
Merged
2 changes: 1 addition & 1 deletion docs/logical_data_model.encoded

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/logical_data_model.puml
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@ enum enum_Users_flags {
anv_statistics
closed_goal_merge_override
manual_mark_goals_similar
monitoring_integration
quality_assurance_dashboard
regional_goal_dashboard
training_reports_dashboard
Expand Down
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ const FEATURE_FLAGS = [
'training_reports_dashboard',
'quality_assurance_dashboard',
'manual_mark_goals_similar',
'monitoring_integration',
];

const MAINTENANCE_CATEGORY = {
Expand Down
18 changes: 18 additions & 0 deletions src/migrations/20241114222525-add-monitoring-feature-flag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { prepMigration } = require('../lib/migration');

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface) {
await queryInterface.sequelize.transaction(async (transaction) => {
const sessionSig = __filename;
await prepMigration(queryInterface, transaction, sessionSig);
return queryInterface.sequelize.query(`
ALTER TYPE "enum_Users_flags" ADD VALUE IF NOT EXISTS 'monitoring_integration';
`);
});
},

async down() {
// no rollbacks
},
};
1 change: 0 additions & 1 deletion src/scopes/grants/activeWithin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export function activeBefore(dates) {
where: {
[Op.or]: scopes,
},
include: [],
};
}

Expand Down
21 changes: 13 additions & 8 deletions src/services/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ interface DecodedCSV {

export async function getAllCourses(where: WhereOptions = {}) {
return Course.findAll({
where,
where: {
...where,
mapsTo: null,
},
order: [['persistsOnUpload', 'ASC'], ['name', 'ASC']],
attributes: ['name', 'id'],
});
Expand All @@ -44,6 +47,12 @@ export async function csvImport(buffer: Buffer | string) {
const parsed = parse(buffer, { skipEmptyLines: true, columns: true });
let rowCount = 1;
let results;

const baseCourseScopes = {
persistsOnUpload: false, // We don't want to delete courses that persist on import.
mapsTo: null, // we only want to update courses that are not mapped to another course.
};

try {
results = await Promise.all(parsed.map(async (course: DecodedCSV) => {
// Trim unexpected chars.
Expand All @@ -62,6 +71,7 @@ export async function csvImport(buffer: Buffer | string) {

// Always trim leading and trailing spaces.
rawCourseName = rawCourseName.trim();
rawCourseName.replace('’', '\'');

// Remove all spaces and special characters from the course name.
const cleanCourseName = rawCourseName.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
Expand All @@ -74,10 +84,7 @@ export async function csvImport(buffer: Buffer | string) {
Sequelize.fn('lower', Sequelize.fn('regexp_replace', Sequelize.col('name'), '[^a-zA-Z0-9]', '', 'g')),
{ [Op.like]: cleanCourseName },
),
{
deletedAt: null,
persistsOnUpload: false, // We don't want to delete courses that persist on import.
},
baseCourseScopes,
],
},
});
Expand Down Expand Up @@ -111,7 +118,6 @@ export async function csvImport(buffer: Buffer | string) {
id: {
[Op.in]: existingCourses.map((c: ICourse) => c.id),
},
deletedAt: null,
},
});

Expand Down Expand Up @@ -141,8 +147,7 @@ export async function csvImport(buffer: Buffer | string) {
id: {
[Op.notIn]: importedCourseIds,
},
deletedAt: null,
persistsOnUpload: false,
...baseCourseScopes,
},
returning: true,
});
Expand Down
5 changes: 2 additions & 3 deletions src/widgets/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
Topic,
sequelize,
} from '../models';
import { mergeIncludes } from '../scopes';

export const getAllTopicsForWidget = async () => Topic.findAll({
attributes: ['id', 'name', 'deletedAt'],
Expand Down Expand Up @@ -82,13 +81,13 @@ export async function getAllRecipientsFiltered(scopes) {
required: true,
attributes: [],
where: scopes.grant.where,
include: mergeIncludes(scopes.grant.include, [
include: [
{
model: GrantReplacements,
as: 'replacedGrantReplacements',
attributes: [],
},
]),
],
},
],
});
Expand Down
Loading