diff --git a/API_Endpoints.md b/API_Endpoints.md index a084bba..f7cb418 100644 --- a/API_Endpoints.md +++ b/API_Endpoints.md @@ -205,7 +205,7 @@ The following properties of every endpoint will be descibed in this file: "id": "Project Id" "name": "Project Name", "form_count": 5, - "allowed_origins": ["http://localhost", "https://savemyform.tk"], + "allowed_origins": ["http://localhost", "https://savemyform.in.net"], "date_created": "date-of-creation" } ] @@ -244,7 +244,7 @@ The following properties of every endpoint will be descibed in this file: "hasRecaptcha": true, "recaptchaKey": "User's project Recaptcha Key", "recaptchaSecret": "User's project Recaptcha Secret", - "allowedOrigins": ["http://localhost", "https://savemyform.tk"], + "allowedOrigins": ["http://localhost", "https://savemyform.in.net"], "collaborators": ["test1@test.com", "test2@test.com"], "recaptcha_token": "Google Recaptcha Token recieved from Google" } @@ -283,7 +283,7 @@ The following properties of every endpoint will be descibed in this file: "hasRecaptcha": true, "recaptchaKey": "User's project Recaptcha Key", "recaptchaSecret": "User's project Recaptcha Secret", - "allowedOrigins": ["http://localhost", "https://savemyform.tk"], + "allowedOrigins": ["http://localhost", "https://savemyform.in.net"], "form_count": 2, "forms":[ { @@ -309,7 +309,7 @@ The following properties of every endpoint will be descibed in this file: "hasRecaptcha": true, "recaptchaKey": "User's project Recaptcha Key", "recaptchaSecret": "User's project Recaptcha Secret", - "allowedOrigins": ["http://localhost", "https://savemyform.tk"], + "allowedOrigins": ["http://localhost", "https://savemyform.in.net"], "collaborators": ["test1@test.com", "test2@test.com"], "recaptcha_token": "Google Recaptcha Token recieved from Google", "password": "user's password" @@ -335,7 +335,7 @@ The following properties of every endpoint will be descibed in this file: "hasRecaptcha": true, "recaptchaKey": "User's project Recaptcha Key", "recaptchaSecret": "User's project Recaptcha Secret", - "allowedOrigins": ["http://localhost", "https://savemyform.tk"], + "allowedOrigins": ["http://localhost", "https://savemyform.in.net"], } ``` diff --git a/controllers/auth.controller.js b/controllers/auth.controller.js index 307fd79..1f799f6 100644 --- a/controllers/auth.controller.js +++ b/controllers/auth.controller.js @@ -14,7 +14,7 @@ const client = new OAuth2Client( process.env.GOOGLE_OAUTH_CLIENT_ID, process.env.GOOGLE_OAUTH_CLIENT_SECRET, process.env.ENV === 'prod' - ? 'https://savemyform.tk/signin/oauth' + ? 'https://savemyform.in.net/signin/oauth' : 'http://localhost:3000/signin/oauth', ); diff --git a/controllers/project.controller.js b/controllers/project.controller.js index f33de99..0bc09a7 100644 --- a/controllers/project.controller.js +++ b/controllers/project.controller.js @@ -124,30 +124,12 @@ export async function updateProject(req, res) { updatedProject.allowedOrigins = req.body.allowedOrigins; } - if (req.body.collaborators) { - if (req.body.collaborators.length > 5) { - return response_400( - res, - 'Number of collaborators cannot be greater than 5', - ); - } - inviteCollaborators( - req.body.collaborators, - projectId, - req.body.name, - req.user.name, - req.user.email, - ); - } - // updating the project details in DB const finalProject = await Project.findOneAndUpdate( { projectId: projectId }, updatedProject, { returnDocument: 'after', select: '-_id -forms' }, - ) - .populate({ path: 'owner', select: '-_id name email' }) - .populate({ path: 'collaborators', select: '-_id name email' }); + ).populate({ path: 'owner', select: '-_id name email' }); finalProject.is_owner = req.user.id === finalProject.owner; @@ -160,7 +142,10 @@ export async function updateProject(req, res) { export async function projectDashboard(req, res) { let project = await Project.findOne({ projectId: req.params.id }); if (!project) return response_400(res, 'No project with this id'); - let allow = project.collaborators.includes(req.user._id); + let allow = Collaborators.exists({ + email: req.user.email, + projectId: project._id, + }); if (!allow && String(project.owner) !== String(req.user._id)) return response_400(res, 'You cannot access this project'); @@ -168,7 +153,6 @@ export async function projectDashboard(req, res) { project = await Project.findOne({ projectId: req.params.id }) .populate('forms', 'formId name submission createdAt updatedAt -_id') .populate('owner', 'name email') - .populate('collaborators', 'name email -_id') .select('-_id -createdAt -updatedAt -__v'); project = project.toJSON(); project.is_owner = String(project.owner._id) === String(req.user._id); @@ -267,14 +251,13 @@ export async function updateCollaborator(req, res) { export async function updateCollaboratorStatus(req, res) { try { - if(req.body.userAccepted){ - let collaborator=await Collaborators.findById(req.body.collaboratorId); - collaborator.status='Accepted' + if (req.body.userAccepted) { + let collaborator = await Collaborators.findById(req.body.collaboratorId); + collaborator.status = 'Accepted'; collaborator.save(); - } - else{ + } else { await Collaborators.findByIdAndDelete(req.body.collaboratorId); - } + } } catch (error) { console.log(error); return response_500(res, 'Server error', error); diff --git a/controllers/user.controller.js b/controllers/user.controller.js index 7e1c4d2..18181b1 100644 --- a/controllers/user.controller.js +++ b/controllers/user.controller.js @@ -5,6 +5,7 @@ import { verifycaptcha } from '../utils/recaptcha.js'; import validator from 'validator'; import jwt from 'jsonwebtoken'; import User from '../models/user.model.js'; +import InvitedCollaborator from '../models/invitedCollaborators.model.js'; export function getVerificationLink(req, res) { if (req.user.verified) @@ -111,7 +112,19 @@ export async function dashboard(req, res) { options: { sort: { createdAt: -1 } }, select: 'projectId name forms allowedOrigins createdAt', }); + let collaboratedProjects = await InvitedCollaborator.find({ + status: 'Accepted', + email: req.user.email, + }) + .populate({ + path: 'projectId', + select: 'projectId name forms allowedOrigins createdAt', + }) + .toJSON(); user = await user.toJSON(); + collaboratedProjects.forEach((collabProjectObj) => { + user.projects.push(collabProjectObj.projectId); + }); user.project_count = user.projects.length; user.projects.map((project) => { project.date_created = project.createdAt; diff --git a/templates/collaborator.handlebars b/templates/collaborator.handlebars index 260bf90..bd7a281 100644 --- a/templates/collaborator.handlebars +++ b/templates/collaborator.handlebars @@ -1,170 +1,127 @@ - - +
- - - + + ++
You have been invited to the project{projectName} by - {userEmail}. + {userEmail}. Kindly click on the following link !
- - + + -+
If this does not work, copy and paste the following link in your web browser.
-- {{url}} +
+ {{url}}
+
We need to verify your email address. Kindly click on the following link !
- - + + -+
If this does not work, copy and paste the following link in your web browser.
-- {{url}} +
+ {{url}}
-- The verification request was generated on the ip address: {{ip}} +
+ The verification request was generated on the ip address: + {{ip}}