Sửa lỗi quyền chia sẻ và hiển thị lên map ở các liên kết chéo
This commit is contained in:
@@ -36,11 +36,25 @@ router.get('/assets/view/:assetId', verifyReferer, optionalAuth, async (req, res
|
||||
} else {
|
||||
const isTokenValid = scene.shareToken && (!scene.shareTokenExpires || new Date() < scene.shareTokenExpires);
|
||||
const userEmail = req.user ? req.user.email : null;
|
||||
const hasAccess = scene.privacy === 'public' ||
|
||||
let hasAccess = scene.privacy === 'public' ||
|
||||
(scene.privacy === 'member' && req.user && (scene.sharedWith.includes(req.user._id) || (userEmail && scene.sharedEmails.includes(userEmail)))) ||
|
||||
(req.user && scene.createdBy.toString() === req.user._id.toString()) ||
|
||||
(scene.privacy === 'shared' && req.query.token === scene.shareToken && isTokenValid);
|
||||
|
||||
// [BRIDGE ACCESS LOGIC]
|
||||
// Áp dụng tương tự cho Asset để đảm bảo hiển thị được ảnh khi di chuyển liên kết chéo
|
||||
if (!hasAccess && req.query.token) {
|
||||
const potentialParents = await Hotspot.find({ target_scene_id: scene._id }).distinct('parent_scene_id');
|
||||
if (potentialParents.length > 0) {
|
||||
const authorizedParentExists = await Scene.exists({
|
||||
_id: { $in: potentialParents },
|
||||
shareToken: req.query.token,
|
||||
$or: [{ shareTokenExpires: null }, { shareTokenExpires: { $gt: new Date() } }]
|
||||
});
|
||||
if (authorizedParentExists) hasAccess = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasAccess) return res.status(403).json({ message: 'Access denied' });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user