mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-29 22:02:46 +00:00
Merge branch 'master' into Issue_1958
This commit is contained in:
@@ -24,9 +24,9 @@ const { splitTextStyleAndMetadata } = require('../shared/helpers.js');
|
||||
const sanitizeBrew = (brew, accessType)=>{
|
||||
brew._id = undefined;
|
||||
brew.__v = undefined;
|
||||
if(accessType !== 'edit'){
|
||||
if(accessType !== 'edit' && accessType !== 'shareAuthor') {
|
||||
brew.editId = undefined;
|
||||
}
|
||||
}
|
||||
return brew;
|
||||
};
|
||||
|
||||
@@ -308,7 +308,6 @@ app.get('/new/:id', asyncHandler(getBrew('share')), (req, res, next)=>{
|
||||
//Share Page
|
||||
app.get('/share/:id', asyncHandler(getBrew('share')), asyncHandler(async (req, res, next)=>{
|
||||
const { brew } = req;
|
||||
|
||||
req.ogMeta = { ...defaultMetaTags,
|
||||
title : req.brew.title || 'Untitled Brew',
|
||||
description : req.brew.description || 'No description.',
|
||||
@@ -327,7 +326,8 @@ app.get('/share/:id', asyncHandler(getBrew('share')), asyncHandler(async (req, r
|
||||
await HomebrewModel.increaseView({ shareId: brew.shareId });
|
||||
}
|
||||
};
|
||||
sanitizeBrew(req.brew, 'share');
|
||||
|
||||
brew.authors.includes(req.account?.username) ? sanitizeBrew(req.brew, 'shareAuthor') : sanitizeBrew(req.brew, 'share');
|
||||
splitTextStyleAndMetadata(req.brew);
|
||||
return next();
|
||||
}));
|
||||
@@ -373,7 +373,7 @@ app.get('/account', asyncHandler(async (req, res, next)=>{
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
data.uiItems = {
|
||||
data.accountDetails = {
|
||||
username : req.account.username,
|
||||
issued : req.account.issued,
|
||||
googleId : Boolean(req.account.googleId),
|
||||
|
||||
@@ -7,7 +7,9 @@ const config = require('./config.js');
|
||||
|
||||
let serviceAuth;
|
||||
if(!config.get('service_account')){
|
||||
console.log('No Google Service Account in config files - Google Drive integration will not be available.');
|
||||
const reset = '\x1b[0m'; // Reset to default style
|
||||
const yellow = '\x1b[33m'; // yellow color
|
||||
console.warn(`\n${yellow}No Google Service Account in config files - Google Drive integration will not be available.${reset}`);
|
||||
} else {
|
||||
const keys = typeof(config.get('service_account')) == 'string' ?
|
||||
JSON.parse(config.get('service_account')) :
|
||||
@@ -18,7 +20,7 @@ if(!config.get('service_account')){
|
||||
serviceAuth.scopes = ['https://www.googleapis.com/auth/drive'];
|
||||
} catch (err) {
|
||||
console.warn(err);
|
||||
console.log('Please make sure the Google Service Account is set up properly in your config files.');
|
||||
console.warn('Please make sure the Google Service Account is set up properly in your config files.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,10 @@ const api = {
|
||||
});
|
||||
stub = stub?.toObject();
|
||||
|
||||
if(stub?.lock?.locked && accessType != 'edit') {
|
||||
throw { HBErrorCode: '100', code: stub.lock.code, message: stub.lock.message, brewId: stub.shareId, brewTitle: stub.title };
|
||||
}
|
||||
|
||||
// If there is a google id, try to find the google brew
|
||||
if(!stubOnly && (googleId || stub?.googleId)) {
|
||||
let googleError;
|
||||
@@ -79,9 +83,9 @@ const api = {
|
||||
if(accessType === 'edit' && (authorsExist && !(isAuthor || isInvited))) {
|
||||
const accessError = { name: 'Access Error', status: 401 };
|
||||
if(req.account){
|
||||
throw { ...accessError, message: 'User is not an Author', HBErrorCode: '03', authors: stub.authors, brewTitle: stub.title, shareId: stub.shareId };
|
||||
throw { ...accessError, message: 'User is not an Author', HBErrorCode: '03', authors: stub.authors, brewTitle: stub.title, shareId: stub.shareId};
|
||||
}
|
||||
throw { ...accessError, message: 'User is not logged in', HBErrorCode: '04', authors: stub.authors, brewTitle: stub.title };
|
||||
throw { ...accessError, message: 'User is not logged in', HBErrorCode: '04', authors: stub.authors, brewTitle: stub.title, shareId: stub.shareId};
|
||||
}
|
||||
|
||||
// If after all of that we still don't have a brew, throw an exception
|
||||
|
||||
@@ -117,7 +117,7 @@ describe('Tests for api', ()=>{
|
||||
id : '123456789012345678901234567890123abcdefghijkl'
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
expect(googleId).toEqual('123456789012345678901234567890123');
|
||||
expect(id).toEqual('abcdefghijkl');
|
||||
});
|
||||
@@ -128,7 +128,7 @@ describe('Tests for api', ()=>{
|
||||
id : '123456789012345678901234567890123abcdefghij'
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
expect(googleId).toEqual('123456789012345678901234567890123');
|
||||
expect(id).toEqual('abcdefghij');
|
||||
});
|
||||
@@ -298,6 +298,18 @@ describe('Tests for api', ()=>{
|
||||
expect(model.get).toHaveBeenCalledWith({ shareId: '1' });
|
||||
expect(google.getGoogleBrew).toHaveBeenCalledWith('2', '1', 'share');
|
||||
});
|
||||
|
||||
it('access is denied to a locked brew', async()=>{
|
||||
const lockBrew = { title: 'test brew', shareId: '1', lock: { locked: true, code: 404, message: 'brew locked' } };
|
||||
model.get = jest.fn(()=>toBrewPromise(lockBrew));
|
||||
api.getId = jest.fn(()=>({ id: '1', googleId: undefined }));
|
||||
|
||||
const fn = api.getBrew('share', false);
|
||||
const req = { brew: {} };
|
||||
const next = jest.fn();
|
||||
|
||||
await expect(fn(req, null, next)).rejects.toEqual({ 'HBErrorCode': '100', 'brewId': '1', 'brewTitle': 'test brew', 'code': 404, 'message': 'brew locked' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('mergeBrewText', ()=>{
|
||||
|
||||
Reference in New Issue
Block a user