Skip to content

Commit

Permalink
fix: prtoection against subscribing to yourself
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Sep 12, 2022
1 parent 4bbccba commit c0cfaaa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/controllers/fileStore.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export const deleteFile = async (req, res) => {
try {
await FileStore.deleteFileStoreItem(req.body.fileId);
res.status(200).json({
message: 'File deleted from filestore',
message:
'File will be delete from the filestore, but it will take a few mins to confirm.',
});
} catch (error) {
res.status(400).json({
Expand Down
9 changes: 8 additions & 1 deletion src/datalayer/persistance.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ const subscribeToStoreOnDataLayer = async (storeId) => {
return false;
}

const homeOrg = await Organization.getHomeOrg();

if ([homeOrg.orgUid, homeOrg.registryId].includes(storeId)) {
logger.info(`Cant subscribe to self: ${storeId}`);
return { success: true };
}

const subscriptions = await getSubscriptions();

if (subscriptions.includes(storeId)) {
Expand Down Expand Up @@ -463,7 +470,7 @@ const getSubscriptions = async () => {
const data = JSON.parse(response);

if (data.success) {
console.log('Your Subscriptions:', data.store_ids);
// console.log('Your Subscriptions:', data.store_ids);
return data.store_ids;
}

Expand Down
3 changes: 1 addition & 2 deletions src/datalayer/syncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ const getSubscribedStoreData = async (storeId, retry = 0) => {

const subscriptions = await dataLayer.getSubscriptions(storeId);
const alreadySubscribed = subscriptions.includes(storeId);
console.log('%%%%%%%%%%%%', alreadySubscribed);

if (!alreadySubscribed) {
logger.info(`No Subscription Found for ${storeId}, Subscribing...`);
Expand Down Expand Up @@ -297,7 +296,7 @@ const getStoreData = async (storeId, callback, onFail, retry = 0) => {
if (retry <= 10) {
const encodedData = await dataLayer.getStoreData(storeId);
if (_.isEmpty(encodedData?.keys_values)) {
await new Promise((resolve) => setTimeout(() => resolve(), 60000));
await new Promise((resolve) => setTimeout(() => resolve(), 120000));
return getStoreData(storeId, callback, onFail, retry + 1);
} else {
callback(decodeDataLayerResponse(encodedData));
Expand Down
2 changes: 0 additions & 2 deletions src/models/organizations/organizations.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,6 @@ class Organization extends Model {
console.log('Importing organization ' + orgUid);
const orgData = await datalayer.getSubscribedStoreData(orgUid);

console.log('!!!!!!!!!!!!', orgData);

if (!orgData.registryId) {
throw new Error(
'Currupted organization, no registryId on the datalayer, can not import',
Expand Down

0 comments on commit c0cfaaa

Please sign in to comment.