From 29ce4814742c0cc2591934a30acadb596fb89c67 Mon Sep 17 00:00:00 2001 From: deligence-dharmendra Date: Tue, 30 Jan 2018 15:31:25 +0530 Subject: [PATCH 01/49] Fixed REST API: (organizations) verify DB operation outcome before sending --- apinf_packages/organizations/server/api.js | 48 +++++++++++++++++-- .../organizations/server/methods.js | 27 +++++++---- 2 files changed, 61 insertions(+), 14 deletions(-) diff --git a/apinf_packages/organizations/server/api.js b/apinf_packages/organizations/server/api.js index ba9a4ba989..888f21a7c2 100644 --- a/apinf_packages/organizations/server/api.js +++ b/apinf_packages/organizations/server/api.js @@ -182,6 +182,9 @@ ManagementV1.addRoute('organizations', { 403: { description: 'User does not have permission', }, + 500: { + description: 'Internal server error', + }, }, security: [ { @@ -314,6 +317,11 @@ ManagementV1.addRoute('organizations', { const organizationId = Organizations.insert(organizationData); + // If insert failed, stop and send response + if (!organizationId) { + return errorMessagePayload(500, 'Insert organization failed. Organization not created'); + } + return { statusCode: 201, body: { @@ -437,6 +445,9 @@ ManagementV1.addRoute('organizations/:id', { 404: { description: 'Organization is not found', }, + 500: { + description: 'Internal server error', + }, }, security: [ { @@ -586,7 +597,12 @@ ManagementV1.addRoute('organizations/:id', { } // Update Organization document - Organizations.update(organizationId, { $set: organizationData }); + const result = Organizations.update(organizationId, { $set: organizationData }); + + // Check if organiztions update failed + if (result === 0) { + return errorMessagePayload(500, 'Organization update failed'); + } return { statusCode: 200, @@ -622,6 +638,9 @@ ManagementV1.addRoute('organizations/:id', { 404: { description: 'Organization is not found', }, + 500: { + description: 'Internal server error', + }, }, security: [ { @@ -652,7 +671,11 @@ ManagementV1.addRoute('organizations/:id', { } // Remove Organization document - Meteor.call('removeOrganization', organization._id); + const result = Meteor.call('removeOrganization', organization._id); + + if (result === 0) { + return errorMessagePayload(500, 'Organization removing failed.'); + } return { statusCode: 204, @@ -861,6 +884,9 @@ ManagementV1.addRoute('organizations/:id/managers', { }, }, }, + 500: { + description: 'Internal server error', + }, }, security: [ { @@ -872,6 +898,7 @@ ManagementV1.addRoute('organizations/:id/managers', { action () { // Get data from body parameters const bodyParams = this.bodyParams; + // Get ID of Organization // Note! It can not be checked here, if this parameter is not provided, // because in that case the parameters are shifted and endpoint is not found at all. @@ -914,7 +941,13 @@ ManagementV1.addRoute('organizations/:id/managers', { } // Update Organization manager list - Organizations.update(organizationId, { $push: { managerIds: newManager._id } }); + const result = Organizations.update(organizationId, + { $push: { managerIds: newManager._id } }); + + // If organiztions update failed + if (result === 0) { + return errorMessagePayload(500, 'Organization update failed'); + } // Do not include password in response const options = {}; @@ -1123,6 +1156,9 @@ ManagementV1.addRoute('organizations/:id/managers/:managerId', { 404: { description: 'Organization is not found', }, + 500: { + description: 'Internal server error', + }, }, security: [ { @@ -1173,7 +1209,11 @@ ManagementV1.addRoute('organizations/:id/managers/:managerId', { } // Remove user from organization manager list - Meteor.call('removeOrganizationManager', organizationId, removeManagerId); + const result = Meteor.call('removeOrganizationManager', organizationId, removeManagerId); + + if (result === 0) { + return errorMessagePayload(500, 'Removing manager id from organization failed.'); + } return { statusCode: 204, diff --git a/apinf_packages/organizations/server/methods.js b/apinf_packages/organizations/server/methods.js index d340b3bf30..54af26294f 100644 --- a/apinf_packages/organizations/server/methods.js +++ b/apinf_packages/organizations/server/methods.js @@ -97,11 +97,13 @@ Meteor.methods({ check(userId, String); // Remove User ID from managers array - Organizations.update({ _id: organizationId }, + const result = Organizations.update({ _id: organizationId }, { $pull: { managerIds: userId }, } ); + + return result; }, removeUserFromAllOrganizations (userId) { // Make sure userId is an String @@ -137,18 +139,23 @@ Meteor.methods({ removeOrganization (organizationId) { check(organizationId, String); // Remove organization document - Organizations.remove(organizationId); + const result = Organizations.remove(organizationId); - // Get all organizationApis links with current organization ID - const organizationApis = OrganizationApis.find({ organizationId }).fetch(); + // Make sure Organization removed + if (result) { + // Get all organizationApis links with current organization ID + const organizationApis = OrganizationApis.find({ organizationId }).fetch(); - // Get array with all IDs of found document - const organizationApisIDs = _.map(organizationApis, (link) => { - return link._id; - }); + // Get array with all IDs of found document + const organizationApisIDs = _.map(organizationApis, (link) => { + return link._id; + }); + + // Remove organizationApi links + OrganizationApis.remove({ _id: { $in: organizationApisIDs } }); + } - // Remove organizationApi links - OrganizationApis.remove({ _id: { $in: organizationApisIDs } }); + return result; }, getOrganizationProfile (slug) { // Make sure slug is a string From 3f38fc7ff2400faa354a7db4ff3a97cf9cc1dc73 Mon Sep 17 00:00:00 2001 From: Daria Voytova Date: Tue, 30 Jan 2018 17:07:12 +0300 Subject: [PATCH 02/49] Change message type from warning to error --- apinf_packages/organizations/client/managers/form/autoform.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apinf_packages/organizations/client/managers/form/autoform.js b/apinf_packages/organizations/client/managers/form/autoform.js index 81b7e5cd54..306e83a53f 100644 --- a/apinf_packages/organizations/client/managers/form/autoform.js +++ b/apinf_packages/organizations/client/managers/form/autoform.js @@ -26,7 +26,7 @@ AutoForm.hooks({ const message = TAPi18n.__('organizationManagerForm_emailNotRegistered_errorText'); // Warn manager that user email is not registered - sAlert.warning(message); + sAlert.error(message); } if (errorType === 'manager-already-exist') { @@ -34,7 +34,7 @@ AutoForm.hooks({ const message = TAPi18n.__('organizationManagerForm_managerAlreadyExist_errorText'); // Warn manager that manager is already exist - sAlert.warning(message); + sAlert.error(message); } }, }, From 9c8742d31e360a16924b8154f4db27dd14a625cb Mon Sep 17 00:00:00 2001 From: Daria Voytova Date: Wed, 31 Jan 2018 15:26:00 +0300 Subject: [PATCH 03/49] Add Organization manager to API by using username #3344 --- apinf_packages/core/lib/i18n/en.i18n.json | 2 +- .../client/managers/form/autoform.js | 16 +++---- .../client/managers/form/form.html | 4 +- .../client/managers/form/schema.js | 3 +- .../organizations/server/methods.js | 44 +++++++++---------- 5 files changed, 33 insertions(+), 36 deletions(-) diff --git a/apinf_packages/core/lib/i18n/en.i18n.json b/apinf_packages/core/lib/i18n/en.i18n.json index 6b13fcaba9..573af53a55 100644 --- a/apinf_packages/core/lib/i18n/en.i18n.json +++ b/apinf_packages/core/lib/i18n/en.i18n.json @@ -502,7 +502,7 @@ "organizationLogo_resumable_acceptedExtensions": "Only .jpg, .jpeg, .png and .gif file formats are allowed.", "organizationManagersList_title": "Managers", "organizationManagerForm_successMessage": "New manager added.", - "organizationManagerForm_emailNotRegistered_errorText": "Email address not currently registered.", + "organizationManagerForm_userNotRegistered_errorText": "User not currently registered.", "organizationNoApis_text_noConnectedApis": "The organization doesn't have any connected APIs.", "organizationNoApis_text_useButton": "You can connect one via button \"Connect API to Organization\"", "organizationNoFeaturedApis_text_noFeaturedApis": "The organization doesn't have any featured APIs.", diff --git a/apinf_packages/organizations/client/managers/form/autoform.js b/apinf_packages/organizations/client/managers/form/autoform.js index 306e83a53f..83e862c946 100644 --- a/apinf_packages/organizations/client/managers/form/autoform.js +++ b/apinf_packages/organizations/client/managers/form/autoform.js @@ -21,20 +21,20 @@ AutoForm.hooks({ // Get error type string from error object const errorType = error.error; - if (errorType === 'email-not-registered') { - // Get 'email not registered' error message translation - const message = TAPi18n.__('organizationManagerForm_emailNotRegistered_errorText'); + if (errorType === 'user-not-registered') { + // Get error message translation + const message = TAPi18n.__('organizationManagerForm_userNotRegistered_errorText'); - // Warn manager that user email is not registered - sAlert.error(message); + // Display error + sAlert.error(message, { timeout: 'none' }); } if (errorType === 'manager-already-exist') { - // Get 'manager already exist' error message translation + // Get error message translation const message = TAPi18n.__('organizationManagerForm_managerAlreadyExist_errorText'); - // Warn manager that manager is already exist - sAlert.error(message); + // Display error + sAlert.error(message, { timeout: 'none' }); } }, }, diff --git a/apinf_packages/organizations/client/managers/form/form.html b/apinf_packages/organizations/client/managers/form/form.html index 56e477565a..be6f2d3241 100644 --- a/apinf_packages/organizations/client/managers/form/form.html +++ b/apinf_packages/organizations/client/managers/form/form.html @@ -15,9 +15,9 @@

id="organizationManagerForm" class="form-inline" type="method" - meteormethod="addOrganizationManagerByEmail"}} + meteormethod="addOrganizationManager"}} - {{> afQuickField name='email' id="manager-email" }} + {{> afQuickField name='user' id="manager" }} {{> afQuickField name='organizationId' value=organization._id type="hidden" }}