mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	fix: groups.updateCover
This commit is contained in:
		| @@ -368,8 +368,15 @@ SocketGroups.cover.update = async (socket, data) => { | |||||||
| 	if (!socket.uid) { | 	if (!socket.uid) { | ||||||
| 		throw new Error('[[error:no-privileges]]'); | 		throw new Error('[[error:no-privileges]]'); | ||||||
| 	} | 	} | ||||||
|  | 	if (data.file || (!data.imageData && !data.position)) { | ||||||
|  | 		throw new Error('[[error:invalid-data]]'); | ||||||
|  | 	} | ||||||
| 	await canModifyGroup(socket.uid, data.groupName); | 	await canModifyGroup(socket.uid, data.groupName); | ||||||
| 	return await groups.updateCover(socket.uid, data); | 	return await groups.updateCover(socket.uid, { | ||||||
|  | 		groupName: data.groupName, | ||||||
|  | 		imageData: data.imageData, | ||||||
|  | 		position: data.position, | ||||||
|  | 	}); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| SocketGroups.cover.remove = async (socket, data) => { | SocketGroups.cover.remove = async (socket, data) => { | ||||||
| @@ -378,7 +385,9 @@ SocketGroups.cover.remove = async (socket, data) => { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	await canModifyGroup(socket.uid, data.groupName); | 	await canModifyGroup(socket.uid, data.groupName); | ||||||
| 	await groups.removeCover(data); | 	await groups.removeCover({ | ||||||
|  | 		groupName: data.groupName, | ||||||
|  | 	}); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| async function canModifyGroup(uid, groupName) { | async function canModifyGroup(uid, groupName) { | ||||||
|   | |||||||
| @@ -1387,9 +1387,9 @@ describe('Groups', function () { | |||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		it('should fail if user is not logged in or not owner', function (done) { | 		it('should fail if user is not logged in or not owner', function (done) { | ||||||
| 			socketGroups.cover.update({ uid: 0 }, {}, function (err) { | 			socketGroups.cover.update({ uid: 0 }, { imageData: 'asd' }, function (err) { | ||||||
| 				assert.equal(err.message, '[[error:no-privileges]]'); | 				assert.equal(err.message, '[[error:no-privileges]]'); | ||||||
| 				socketGroups.cover.update({ uid: regularUid }, { groupName: 'Test' }, function (err) { | 				socketGroups.cover.update({ uid: regularUid }, { groupName: 'Test', imageData: 'asd' }, function (err) { | ||||||
| 					assert.equal(err.message, '[[error:no-privileges]]'); | 					assert.equal(err.message, '[[error:no-privileges]]'); | ||||||
| 					done(); | 					done(); | ||||||
| 				}); | 				}); | ||||||
| @@ -1404,7 +1404,7 @@ describe('Groups', function () { | |||||||
| 					type: 'image/png', | 					type: 'image/png', | ||||||
| 				}, | 				}, | ||||||
| 			}; | 			}; | ||||||
| 			socketGroups.cover.update({ uid: adminUid }, data, function (err, data) { | 			Groups.updateCover({ uid: adminUid }, data, function (err, data) { | ||||||
| 				assert.ifError(err); | 				assert.ifError(err); | ||||||
| 				Groups.getGroupFields('Test', ['cover:url'], function (err, groupData) { | 				Groups.getGroupFields('Test', ['cover:url'], function (err, groupData) { | ||||||
| 					assert.ifError(err); | 					assert.ifError(err); | ||||||
| @@ -1434,6 +1434,20 @@ describe('Groups', function () { | |||||||
| 			}); | 			}); | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
|  | 		it('should fail to upload group cover with invalid image', function (done) { | ||||||
|  | 			var data = { | ||||||
|  | 				groupName: 'Test', | ||||||
|  | 				file: { | ||||||
|  | 					path: imagePath, | ||||||
|  | 					type: 'image/png', | ||||||
|  | 				}, | ||||||
|  | 			}; | ||||||
|  | 			socketGroups.cover.update({ uid: adminUid }, data, function (err) { | ||||||
|  | 				assert.equal(err.message, '[[error:invalid-data]]'); | ||||||
|  | 				done(); | ||||||
|  | 			}); | ||||||
|  | 		}); | ||||||
|  |  | ||||||
| 		it('should fail to upload group cover with invalid image', function (done) { | 		it('should fail to upload group cover with invalid image', function (done) { | ||||||
| 			var data = { | 			var data = { | ||||||
| 				groupName: 'Test', | 				groupName: 'Test', | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user