mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-14 17:12:40 +00:00
Basic Google file permission checking
This commit is contained in:
@@ -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 stub matches file from Google, use Google metadata over stub metadata
|
||||||
if(googleBrews && googleBrews.length > 0) {
|
if(googleBrews && googleBrews.length > 0) {
|
||||||
for (const brew of brews.filter((brew)=>brew.googleId)) {
|
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);
|
const match = googleBrews.findIndex((b)=>b.editId === brew.editId);
|
||||||
if(match !== -1) {
|
if(match !== -1) {
|
||||||
brew.googleId = googleBrews[match].googleId;
|
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
|
//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);
|
brews = _.concat(brews, googleBrews);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -264,6 +264,26 @@ const GoogleActions = {
|
|||||||
return obj.data.id;
|
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)=>{
|
getGoogleBrew : async (auth = defaultAuth, id, accessId, accessType)=>{
|
||||||
const drive = googleDrive.drive({ version: 'v3', auth: auth });
|
const drive = googleDrive.drive({ version: 'v3', auth: auth });
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user