Skip to content

Commit

Permalink
Merge pull request #5328 from 3drepo/ISSUE_5287
Browse files Browse the repository at this point in the history
Issue 5287- Endpoints to get the md5 hash of the original model file
  • Loading branch information
carmenfan authored Jan 21, 2025
2 parents c3edb60 + 53480b5 commit 5beeb9e
Show file tree
Hide file tree
Showing 16 changed files with 850 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,11 @@ Revision.serialiseRevisionArray = (req, res) => {
respond(req, res, templates.ok, { revisions });
};

Revision.serialiseRevision = (req, res) => {
const rev = req.outputData;
const revision = serialiseRevision(rev);

respond(req, res, templates.ok, revision);
};

module.exports = Revision;
6 changes: 6 additions & 0 deletions backend/src/v5/models/fileRefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,10 @@ FileRefs.removeRefsByQuery = (teamspace, collection, query) => db.deleteMany(
teamspace, collectionName(collection), query,
);

FileRefs.updateRef = async (teamspace, collection, query, action) => {
await db.updateOne(
teamspace, collectionName(collection), query, action,
);
};

module.exports = FileRefs;
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
*/

const { addModelToProject, getProjectById, removeModelFromProject } = require('../../../../../models/projectSettings');
const { getLatestRevision, getRevisionByIdOrTag } = require('../../../../../models/revisions');
const { hasProjectAdminPermissions, isTeamspaceAdmin } = require('../../../../../utils/permissions/permissions');
const { USERS_DB_NAME } = require('../../../../../models/users.constants');
const { addModel } = require('../../../../../models/modelSettings');
const { getFavourites } = require('../../../../../models/users');
const { getMD5FileHash } = require('../../../../../services/filesManager');
const { modelTypes } = require('../../../../../models/modelSettings.constants');
const { removeModelData } = require('../../../../../utils/helper/models');

const ModelList = {};
Expand Down Expand Up @@ -50,11 +53,43 @@ ModelList.getModelList = async (teamspace, project, user, modelSettings) => {
return modelSettings.flatMap(({ _id, name, permissions: modelPerms }) => {
const perm = modelPerms ? modelPerms.find((entry) => entry.user === user) : undefined;
return (!isAdmin && !perm)
? [] : { _id,
? [] : {
_id,
name,
role: isAdmin ? USERS_DB_NAME : perm.permission,
isFavourite: favourites.includes(_id) };
isFavourite: favourites.includes(_id),
};
});
};

ModelList.getModelMD5Hash = async (teamspace, container, revision) => {
let rev;

if (revision) {
rev = await getRevisionByIdOrTag(
teamspace, container, modelTypes.CONTAINER, revision,
{ rFile: 1, timestamp: 1, fileSize: 1, tag: 1 },
{ includeVoid: false });
} else {
rev = await getLatestRevision(
teamspace, container, modelTypes.CONTAINER,
{ rFile: 1, timestamp: 1, fileSize: 1, tag: 1 });
}

if (!rev.rFile?.length) return {};

const { tag, timestamp } = rev;
const filename = rev.rFile[0];
const { hash, size } = await getMD5FileHash(teamspace, `${container}.history`, filename);

return {
container,
tag,
timestamp,
hash,
filename,
size,
};
};

module.exports = ModelList;
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

const { addModel, deleteModel, getModelList } = require('./commons/modelList');
const { addModel, deleteModel, getModelList, getModelMD5Hash } = require('./commons/modelList');
const { appendFavourites, deleteFavourites } = require('./commons/favourites');
const { getContainerById, getContainers, updateModelSettings } = require('../../../../models/modelSettings');
const { getLatestRevision, getRevisionByIdOrTag, getRevisionCount, getRevisionFormat, getRevisions, updateRevisionStatus } = require('../../../../models/revisions');
Expand Down Expand Up @@ -133,4 +133,6 @@ Containers.updateSettings = updateModelSettings;
Containers.getSettings = (teamspace, container) => getContainerById(teamspace,
container, { corID: 0, account: 0, permissions: 0 });

Containers.getRevisionMD5Hash = getModelMD5Hash;

module.exports = Containers;
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@

const { addModel, deleteModel, getModelList } = require('./commons/modelList');
const { appendFavourites, deleteFavourites } = require('./commons/favourites');
const { getFederationById, getFederations, updateModelSettings } = require('../../../../models/modelSettings');
const { getContainers, getFederationById, getFederations, updateModelSettings } = require('../../../../models/modelSettings');
const Comments = require('./commons/tickets.comments');
const Groups = require('./commons/groups');
const TicketGroups = require('./commons/tickets.groups');
const Tickets = require('./commons/tickets');
const Views = require('./commons/views');
const { getLatestRevision } = require('../../../../models/revisions');
const { getModelMD5Hash } = require('./commons/modelList');
const { getOpenTicketsCount } = require('./commons/tickets');
const { getProjectById } = require('../../../../models/projectSettings');
const { hasReadAccessToContainer } = require('../../../../utils/permissions/permissions');
const { modelTypes } = require('../../../../models/modelSettings.constants');
const { queueFederationUpdate } = require('../../../../services/modelProcessing');

Expand Down Expand Up @@ -75,7 +77,7 @@ const getLastUpdatesFromModels = async (teamspace, models) => {
}

return lastUpdates.length ? lastUpdates.sort((a, b) => b.timestamp
- a.timestamp)[0].timestamp : undefined;
- a.timestamp)[0].timestamp : undefined;
};

Federations.getFederationStats = async (teamspace, project, federation) => {
Expand Down Expand Up @@ -107,4 +109,31 @@ Federations.updateSettings = updateModelSettings;
Federations.getSettings = (teamspace, federation) => getFederationById(teamspace,
federation, { corID: 0, account: 0, permissions: 0, subModels: 0, federate: 0 });

Federations.getMD5Hash = async (teamspace, project, federation, user) => {
const { subModels: containers } = await getFederationById(teamspace, federation, { subModels: 1 });

if (containers) {
const containerWithMetadata = await getContainers(
teamspace,
containers.map((container) => container._id),
{ _id: 1, name: 1, permissions: 1 });

const listOfPromises = containerWithMetadata.map(
async (container) => {
const hasAccess = await hasReadAccessToContainer(teamspace, project, container._id, user);
if (hasAccess) {
return getModelMD5Hash(teamspace, container._id);
}
return undefined;
},
);

const promiseResponses = await Promise.allSettled(listOfPromises);
const responses = promiseResponses.flatMap(({ status, value }) => (status === 'fulfilled' && value ? value : []));

return responses;
}
return [];
};

module.exports = Federations;
Loading

0 comments on commit 5beeb9e

Please sign in to comment.