From e809a50f05937d2b8d1ff8b9474588eb8a8c0b68 Mon Sep 17 00:00:00 2001 From: Kar Rui Lau Date: Fri, 4 Jun 2021 16:25:40 +0800 Subject: [PATCH] docs(script): add scripts to privatize all sp/rp student forms (#2073) --- .../private-rp-stud-forms.js | 45 +++++++++++++++++++ .../private-sp-stud-forms.js | 45 +++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 scripts/20210604_private-rp-sp-student-forms/private-rp-stud-forms.js create mode 100644 scripts/20210604_private-rp-sp-student-forms/private-sp-stud-forms.js diff --git a/scripts/20210604_private-rp-sp-student-forms/private-rp-stud-forms.js b/scripts/20210604_private-rp-sp-student-forms/private-rp-stud-forms.js new file mode 100644 index 0000000000..eb28bd9a90 --- /dev/null +++ b/scripts/20210604_private-rp-sp-student-forms/private-rp-stud-forms.js @@ -0,0 +1,45 @@ +/* eslint-disable */ + +// BEFORE +// A: Count number of forms belonging to RP students that are still public. +{ + let rpStudentUserIds = db.users.find({ email: /.+myrp\.edu\.sg$/i }).map(b => b._id) + db.forms.find({ admin: { $in: rpStudentUserIds }, status: 'PUBLIC' }).count() +} +// B: Count number of forms belonging to RP students that are private. +{ + let rpStudentUserIds = db.users.find({ email: /.+myrp\.edu\.sg$/i }).map(b => b._id) + db.forms.find({ admin: { $in: rpStudentUserIds }, status: 'PRIVATE' }).count() +} + +// UPDATE +// Number updated should be A +{ + let rpStudentUserIds = db.users.find({ email: /.+myrp\.edu\.sg$/i }).map(b => b._id) + let rpStudentFormIds = db.forms.find({ admin: { $in: rpStudentUserIds }, status: 'PUBLIC' }).map(b => b._id) + + db.forms.updateMany( + { + _id: { $in: rpStudentFormIds }, + }, + { + $set: { + status: 'PRIVATE', + }, + } + ) +} + +// AFTER +// Count number of forms belonging to RP students that are still public +// Should be 0 +{ + let rpStudentUserIds = db.users.find({ email: /.+myrp\.edu\.sg$/i }).map(b => b._id) + db.forms.find({ admin: { $in: rpStudentUserIds }, status: 'PUBLIC' }).count() +} +// Count number of forms belonging to RP students that are private. +// Should be A + B +{ + let rpStudentUserIds = db.users.find({ email: /.+myrp\.edu\.sg$/i }).map(b => b._id) + db.forms.find({ admin: { $in: rpStudentUserIds }, status: 'PRIVATE' }).count() +} \ No newline at end of file diff --git a/scripts/20210604_private-rp-sp-student-forms/private-sp-stud-forms.js b/scripts/20210604_private-rp-sp-student-forms/private-sp-stud-forms.js new file mode 100644 index 0000000000..ac3b2dac26 --- /dev/null +++ b/scripts/20210604_private-rp-sp-student-forms/private-sp-stud-forms.js @@ -0,0 +1,45 @@ +/* eslint-disable */ + +// BEFORE +// A: Count number of forms belonging to SP students that are still public. +{ + let spStudentUserIds = db.users.find({ email: /.+ichat\.sp\.edu\.sg$/i }).map(b => b._id) + db.forms.find({ admin: { $in: spStudentUserIds }, status: 'PUBLIC' }).count() +} +// B: Count number of forms belonging to SP students that are private. +{ + let spStudentUserIds = db.users.find({ email: /.+ichat\.sp\.edu\.sg$/i }).map(b => b._id) + db.forms.find({ admin: { $in: spStudentUserIds }, status: 'PRIVATE' }).count() +} + +// UPDATE +// Number updated should be A +{ + let spStudentUserIds = db.users.find({ email: /.+ichat\.sp\.edu\.sg$/i }).map(b => b._id) + let spStudentFormIds = db.forms.find({ admin: { $in: spStudentUserIds }, status: 'PUBLIC' }).map(b => b._id) + + db.forms.updateMany( + { + _id: { $in: spStudentFormIds }, + }, + { + $set: { + status: 'PRIVATE', + }, + } + ) +} + +// AFTER +// Count number of forms belonging to SP students that are still public +// Should be 0 +{ + let spStudentUserIds = db.users.find({ email: /.+ichat\.sp\.edu\.sg$/i }).map(b => b._id) + db.forms.find({ admin: { $in: spStudentUserIds }, status: 'PUBLIC' }).count() +} +// Count number of forms belonging to SP students that are private. +// Should be A + B +{ + let spStudentUserIds = db.users.find({ email: /.+ichat\.sp\.edu\.sg$/i }).map(b => b._id) + db.forms.find({ admin: { $in: spStudentUserIds }, status: 'PRIVATE' }).count() +}