diff --git a/server/app.js b/server/app.js index 869fe6555..0e69484b0 100644 --- a/server/app.js +++ b/server/app.js @@ -318,6 +318,9 @@ app.get('/user/:username', async (req, res, next)=>{ // If stub matches file from Google, use Google metadata over stub metadata if(googleBrews && googleBrews.length > 0) { for (const brew of brews.filter((brew)=>brew.googleId)) { + const permissionCheck = await GoogleActions.checkPermissions(auth, brew); + brew.permissionCheck = permissionCheck; + const match = googleBrews.findIndex((b)=>b.editId === brew.editId); if(match !== -1) { brew.googleId = googleBrews[match].googleId; @@ -330,7 +333,7 @@ app.get('/user/:username', async (req, res, next)=>{ } //Remaining unstubbed google brews display current user as author - googleBrews = googleBrews.map((brew)=>({ ...brew, authors: [req.account.username] })); + googleBrews = googleBrews.map(async (brew)=>({ ...brew, authors: [req.account.username] })); brews = _.concat(brews, googleBrews); } } diff --git a/server/googleActions.js b/server/googleActions.js index bfa44c800..447d99874 100644 --- a/server/googleActions.js +++ b/server/googleActions.js @@ -264,6 +264,26 @@ const GoogleActions = { return obj.data.id; }, + checkPermissions : async (auth, brew)=>{ + if(!brew?.googleId) return; + const drive = googleDrive.drive({ version: 'v3', auth }); + + try { + const driveData = await drive.permissions.list({ fileId: brew.googleId }); + const permissionsList = driveData?.data?.permissions; + + if(permissionsList.some((permission)=>{ + return permission.id == 'anyoneWithLink' && permission.role == 'writer'; + })){ + return 1; + }; + } catch (err) { + return err.code; + } + + return 999; + }, + getGoogleBrew : async (auth = defaultAuth, id, accessId, accessType)=>{ const drive = googleDrive.drive({ version: 'v3', auth: auth });