From cdcb98382ab1272aa3f53db5fdcc0704f86ece19 Mon Sep 17 00:00:00 2001 From: uday-kalyan-s Date: Tue, 29 Oct 2024 00:01:29 +0530 Subject: [PATCH 01/11] added link to submissions page at govportal page --- templates/govportal/govportal.njk | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/govportal/govportal.njk b/templates/govportal/govportal.njk index 682218d7..e229dcdb 100644 --- a/templates/govportal/govportal.njk +++ b/templates/govportal/govportal.njk @@ -68,6 +68,7 @@ Add Poll Add Post View Newsletter Count + View Submissions {% endblock %} From c7be873be713206594a0e450055929786a61bd37 Mon Sep 17 00:00:00 2001 From: uday-kalyan-s Date: Tue, 29 Oct 2024 00:19:54 +0530 Subject: [PATCH 02/11] added getting submissions function to handler --- database/handler.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/database/handler.js b/database/handler.js index 967a7e16..48e5ad8b 100644 --- a/database/handler.js +++ b/database/handler.js @@ -362,6 +362,9 @@ async function getNewsletterCount () { return newsletterCounts; } +async function getSubmissions () { + return await Submission.find().lean(); +} module.exports = { createNewUser, From 8792a823582d231eb77b7e5cad7368af6f8c7159 Mon Sep 17 00:00:00 2001 From: uday-kalyan-s Date: Tue, 29 Oct 2024 00:20:45 +0530 Subject: [PATCH 03/11] exported function in handler --- database/handler.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/database/handler.js b/database/handler.js index 48e5ad8b..3bc4068d 100644 --- a/database/handler.js +++ b/database/handler.js @@ -399,5 +399,6 @@ module.exports = { addTeam, addSubmission, updateNewsletterCount, - getNewsletterCount + getNewsletterCount, + getSubmissions }; From bd2d0035c41c67a8445f5434ca7bdf9bc7768f00 Mon Sep 17 00:00:00 2001 From: uday-kalyan-s Date: Tue, 29 Oct 2024 00:38:47 +0530 Subject: [PATCH 04/11] added basic submissions-management template(near duplicate of post-management --- .../govportal/submissions-management.njk | 198 ++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 templates/govportal/submissions-management.njk diff --git a/templates/govportal/submissions-management.njk b/templates/govportal/submissions-management.njk new file mode 100644 index 00000000..35b6002d --- /dev/null +++ b/templates/govportal/submissions-management.njk @@ -0,0 +1,198 @@ +{% extends "govportal/govportal.njk" %} + +{% set thispage = 'Submission' %} +{% set pagetitle = 'Governor Portal | Submission Management' %} +{% set actionname = 'Submission Management' %} + +{% set scripts = ['https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js'] %} + +{% block actioncontent %} + + {% for submission in submissions %} +
+
+ {% for key, value in submission %} + {% if key != '_id' and key != '__v' and key != 'metadata' %} + {{ key | capitalize }}: {% if key != 'date' %} {{ value }} {% else %} {{ value | string | truncate(15, true, "") }} {% endif %}
+ {% endif %} + {% endfor %} +
+ +
+ +
+
+ {% endfor %} + +{% endblock %} + +{% block customcss %} + {{ super() }} + +{% endblock %} + +{% block customjs %} + +{% endblock %} From 3fbe0c28ab8ed0714719089adbdf430a56606a90 Mon Sep 17 00:00:00 2001 From: uday-kalyan-s Date: Tue, 29 Oct 2024 00:39:18 +0530 Subject: [PATCH 05/11] added get route for submission-management --- routes/govportal.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/routes/govportal.js b/routes/govportal.js index 8cbe55ec..92c1f890 100644 --- a/routes/govportal.js +++ b/routes/govportal.js @@ -8,9 +8,9 @@ router.use((req, res, next) => { }); if (!req.loggedIn) return res.loginRedirect(req, res); - if (!req.user.permissions.find(perm => perm === 'governor')) return res.status(403).renderFile('404.njk', { - message: 'Access denied. You do not have the required permission.' - }); + // if (!req.user.permissions.find(perm => perm === 'governor')) return res.status(403).renderFile('404.njk', { + // message: 'Access denied. You do not have the required permission.' + // }); next(); }); @@ -209,6 +209,11 @@ router.patch('/delete-option', async (req, res) => { } }); +router.get('/submission-management', async (req, res) => { + const submissions = await dbh.getSubmissions(); + return res.renderFile('govportal/submissions-management.njk', { submissions }); +}); + module.exports = { route: '/gov-portal', router From fd6b4dd81549f7cac84f92561ad2c84597970b1c Mon Sep 17 00:00:00 2001 From: uday-kalyan-s Date: Tue, 29 Oct 2024 00:53:29 +0530 Subject: [PATCH 06/11] added and exported deletion handler --- database/handler.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/database/handler.js b/database/handler.js index 3bc4068d..a2329cee 100644 --- a/database/handler.js +++ b/database/handler.js @@ -366,6 +366,11 @@ async function getSubmissions () { return await Submission.find().lean(); } +async function deleteSubmission (link) { + const sub = await Submission.findOneAndDelete({link: link}); + return sub; +} + module.exports = { createNewUser, getUser, @@ -400,5 +405,6 @@ module.exports = { addSubmission, updateNewsletterCount, getNewsletterCount, - getSubmissions + getSubmissions, + deleteSubmission }; From 2640af0d9454726455d89c88551a49a6f2dc9f2f Mon Sep 17 00:00:00 2001 From: uday-kalyan-s Date: Tue, 29 Oct 2024 00:55:05 +0530 Subject: [PATCH 07/11] fixed lint in handler --- database/handler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/handler.js b/database/handler.js index a2329cee..11d46f5e 100644 --- a/database/handler.js +++ b/database/handler.js @@ -367,7 +367,7 @@ async function getSubmissions () { } async function deleteSubmission (link) { - const sub = await Submission.findOneAndDelete({link: link}); + const sub = await Submission.findOneAndDelete({ link: link }); return sub; } From a0098150d8075f2639661fe6c492d8dc3a60d7dc Mon Sep 17 00:00:00 2001 From: uday-kalyan-s Date: Tue, 29 Oct 2024 00:55:47 +0530 Subject: [PATCH 08/11] added post route for deleting submission --- routes/govportal.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/routes/govportal.js b/routes/govportal.js index 92c1f890..170180ca 100644 --- a/routes/govportal.js +++ b/routes/govportal.js @@ -214,6 +214,17 @@ router.get('/submission-management', async (req, res) => { return res.renderFile('govportal/submissions-management.njk', { submissions }); }); +router.post('/submission-management', async (req, res) => { + const data = req.body.data; + let response; + try { + response = await dbh.deleteSubmission(data); + return res.send({ success: true, message: 'Successfully deleted post', response: response }); + } catch (e) { + return res.send({ success: false, message: 'Something Went Wrong' }); + } +}); + module.exports = { route: '/gov-portal', router From 7406a0bba6a6fd5bee9caf8bcefddb8482d0ccc6 Mon Sep 17 00:00:00 2001 From: uday-kalyan-s Date: Wed, 30 Oct 2024 20:32:55 +0530 Subject: [PATCH 09/11] submission management page added to nav --- templates/govportal/govportal.njk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/templates/govportal/govportal.njk b/templates/govportal/govportal.njk index e229dcdb..b9ec75f2 100644 --- a/templates/govportal/govportal.njk +++ b/templates/govportal/govportal.njk @@ -14,6 +14,9 @@ },{ href: 'newsletter', name: 'Newsletter' +},{ + href: 'submission', + name: 'submission' }] %} {% block navbar %} From 837594931813ccf3dd527c799f53c2f7bbdf776d Mon Sep 17 00:00:00 2001 From: Uday Kalyan S <65308101+uday-kalyan-s@users.noreply.github.com> Date: Wed, 30 Oct 2024 21:11:10 +0530 Subject: [PATCH 10/11] Update govportal.js --- routes/govportal.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/routes/govportal.js b/routes/govportal.js index 170180ca..2267c8a3 100644 --- a/routes/govportal.js +++ b/routes/govportal.js @@ -8,9 +8,9 @@ router.use((req, res, next) => { }); if (!req.loggedIn) return res.loginRedirect(req, res); - // if (!req.user.permissions.find(perm => perm === 'governor')) return res.status(403).renderFile('404.njk', { - // message: 'Access denied. You do not have the required permission.' - // }); + if (!req.user.permissions.find(perm => perm === 'governor')) return res.status(403).renderFile('404.njk', { + message: 'Access denied. You do not have the required permission.' + }); next(); }); From 4bd3f172737a69b816aea877884cb943dfedaba0 Mon Sep 17 00:00:00 2001 From: Uday Kalyan S <65308101+uday-kalyan-s@users.noreply.github.com> Date: Wed, 30 Oct 2024 21:12:23 +0530 Subject: [PATCH 11/11] convert Submission to title case in gov portal template --- templates/govportal/govportal.njk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/govportal/govportal.njk b/templates/govportal/govportal.njk index b9ec75f2..45d4f524 100644 --- a/templates/govportal/govportal.njk +++ b/templates/govportal/govportal.njk @@ -16,7 +16,7 @@ name: 'Newsletter' },{ href: 'submission', - name: 'submission' + name: 'Submission' }] %} {% block navbar %}