0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 16:22:44 +00:00

Basic Google file permission checking

This commit is contained in:
G.Ambatte
2025-07-25 12:04:41 +12:00
parent b447d81b4c
commit 8e2abb9f78
2 changed files with 24 additions and 1 deletions

View File

@@ -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);
}
}

View File

@@ -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 });