@optimiser/common 1.0.393 → 1.0.395

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,6 +22,7 @@ export default class AwsServices {
22
22
  DeleteFile(Bucket: string, Key: string, id: string, db: mongo.Db): Promise<Error | AnyObjectInterface>;
23
23
  GetFile(BucketName: string, Region: string, FilePath: string): Promise<S3.GetObjectOutput>;
24
24
  getDownloadUrl(CDN: string, FilePath: string, FileName: string, action: string, expiry?: number): Promise<any>;
25
+ EncodeFileName(fileName: string): string;
25
26
  GetFileStream(CDN: string, Key: string, FileName: string): Promise<request.Request>;
26
27
  ChangesACL(BucketName: string, FilePath: string): Promise<S3.PutObjectAclOutput | aws.AWSError>;
27
28
  GetSignedUrl(BucketName: string, Region: string, FilePath: string): string;
@@ -144,7 +144,7 @@ var AwsServices = /** @class */ (function () {
144
144
  encodedurl = "".concat(CDN, "/").concat(FilePath);
145
145
  }
146
146
  else {
147
- FileName = FileName.replace(/[;]/g, "%3b").replace(/[,]/g, "%2c").replace(/[']/g, "%27"); //converting special character to UTF-8
147
+ FileName = this.EncodeFileName(FileName);
148
148
  encodedurl = "".concat(CDN, "/").concat(FilePath, "?response-content-disposition=").concat(encodeURIComponent("attachment;filename=" + FileName));
149
149
  }
150
150
  signingParams = {
@@ -164,6 +164,11 @@ var AwsServices = /** @class */ (function () {
164
164
  });
165
165
  });
166
166
  };
167
+ AwsServices.prototype.EncodeFileName = function (fileName) {
168
+ return fileName.split('').map(function (char) {
169
+ return /[A-Za-z0-9_\-\.]/.test(char) ? char : encodeURIComponent(char);
170
+ }).join('');
171
+ };
167
172
  AwsServices.prototype.GetFileStream = function (CDN, Key, FileName) {
168
173
  var _this = this;
169
174
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
@@ -4082,17 +4082,7 @@ function BroadCastEventToAllCompanyUsers(params) {
4082
4082
  data: eventItem.EventData,
4083
4083
  userId: usersData[i]._id.toString()
4084
4084
  };
4085
- //socketUtility.TriggerSockerEvent(req, usersData[i]._id.toString(), eventName, data);
4086
- params.event.CreateEvent(null, null, { SocketObj: socketObjectData }).then(function (socketResult) {
4087
- if (socketResult) {
4088
- console.log("Success");
4089
- }
4090
- else {
4091
- console.log('Notification failed to send.');
4092
- }
4093
- }).catch(function (socketErr) {
4094
- console.log('Notification failed to send due to error ==>', socketErr);
4095
- });
4085
+ params.socket.emit('sendNotification', { SocketObj: socketObjectData });
4096
4086
  }
4097
4087
  }
4098
4088
  }
@@ -5769,6 +5759,54 @@ function ValidateStateCountryField(_a) {
5769
5759
  });
5770
5760
  });
5771
5761
  }
5762
+ /*
5763
+ * This function is used to check user permission
5764
+ * @param1: permissionType, like Create/Modify/Delete/Import. permission type user has.
5765
+ * @param2: objectName, like Contact, Account etc
5766
+ * @param3:
5767
+ * @param4: db (database)
5768
+ * @param5: mdb (master DB)
5769
+ * Desc: allow user to procced, if he has access permission
5770
+ * Example: If user has Create/Modify/Delete/Import permission let him procceed else stop access.
5771
+ * Return: true/false
5772
+ */
5773
+ function checkAccessPermissions(permissionType, objectName, msp_d, db, mdb, next) {
5774
+ return __awaiter(this, void 0, void 0, function () {
5775
+ var response, isAllowed, data, _i, _a, item, error_9;
5776
+ return __generator(this, function (_b) {
5777
+ switch (_b.label) {
5778
+ case 0:
5779
+ _b.trys.push([0, 2, , 3]);
5780
+ return [4 /*yield*/, GetUserProfile(msp_d, db, mdb, next)];
5781
+ case 1:
5782
+ response = _b.sent();
5783
+ isAllowed = true;
5784
+ data = response === null || response === void 0 ? void 0 : response.data;
5785
+ if (data && data.Permissions.length > 0) {
5786
+ for (_i = 0, _a = data.Permissions; _i < _a.length; _i++) {
5787
+ item = _a[_i];
5788
+ if (item.ModuleID.toLowerCase() == objectName.toLowerCase()) {
5789
+ if (!item.Operations.includes(permissionType)) {
5790
+ isAllowed = false;
5791
+ if (item.Operations.includes('Create-Edit'))
5792
+ isAllowed = true;
5793
+ }
5794
+ }
5795
+ }
5796
+ }
5797
+ else if ((response === null || response === void 0 ? void 0 : response.message) != 'success') { // Else if was added by Shahzaib not to allow user to perform CRUD operation with inactive licence.
5798
+ isAllowed = false;
5799
+ }
5800
+ return [2 /*return*/, isAllowed];
5801
+ case 2:
5802
+ error_9 = _b.sent();
5803
+ console.error("Internal Error in checkAccessPermissions function : ".concat(error_9));
5804
+ return [3 /*break*/, 3];
5805
+ case 3: return [2 /*return*/];
5806
+ }
5807
+ });
5808
+ });
5809
+ }
5772
5810
  /**
5773
5811
  * Activity Mail Template Structure
5774
5812
  * @param {string} content It is html body content sent over mail
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimiser/common",
3
- "version": "1.0.393",
3
+ "version": "1.0.395",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {