mirror of
https://github.com/outline/outline.git
synced 2026-11-27 07:58:51 +03:00
fix: More membership scopes
This commit is contained in:
1 parent
b5fad8cf1d
commit
cdafc3bb40
7 files changed
+44
-13
No files matched your search
@@ -72,11 +72,11 @@ export default class MembershipsStore extends BaseStore<Membership> {
|
||||
}
|
||||
|
||||
@action
|
||||
removeCollectionId(collectionId: string) {
|
||||
removeCollectionId = (collectionId: string) => {
|
||||
this.data.forEach((membership, key) => {
|
||||
if (key.includes(collectionId)) {
|
||||
this.remove(key);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -229,7 +229,9 @@ router.post('collections.export', auth(), async ctx => {
|
||||
ctx.assertUuid(id, 'id is required');
|
||||
|
||||
const user = ctx.state.user;
|
||||
const collection = await Collection.findByPk(id);
|
||||
const collection = await Collection.scope({
|
||||
method: ['withMembership', user.id],
|
||||
}).findByPk(id);
|
||||
authorize(user, 'export', collection);
|
||||
|
||||
const filePath = await archiveCollection(collection);
|
||||
|
||||
@@ -68,7 +68,7 @@ describe('#collections.list', async () => {
|
||||
});
|
||||
|
||||
describe('#collections.export', async () => {
|
||||
it('should require user to be a member', async () => {
|
||||
it('should now allow export of private collection not a member', async () => {
|
||||
const { user } = await seed();
|
||||
const collection = await buildCollection({
|
||||
private: true,
|
||||
@@ -81,6 +81,25 @@ describe('#collections.export', async () => {
|
||||
expect(res.status).toEqual(403);
|
||||
});
|
||||
|
||||
it('should allow export of private collection', async () => {
|
||||
const { user, collection } = await seed();
|
||||
collection.private = true;
|
||||
await collection.save();
|
||||
|
||||
await CollectionUser.create({
|
||||
createdById: user.id,
|
||||
collectionId: collection.id,
|
||||
userId: user.id,
|
||||
permission: 'read',
|
||||
});
|
||||
|
||||
const res = await server.post('/api/collections.export', {
|
||||
body: { token: user.getJwtToken(), id: collection.id },
|
||||
});
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
});
|
||||
|
||||
it('should require authentication', async () => {
|
||||
const res = await server.post('/api/collections.export');
|
||||
const body = await res.json();
|
||||
|
||||
@@ -457,7 +457,9 @@ router.post('documents.search', auth(), pagination(), async ctx => {
|
||||
if (collectionId) {
|
||||
ctx.assertUuid(collectionId, 'collectionId must be a UUID');
|
||||
|
||||
const collection = await Collection.findByPk(collectionId);
|
||||
const collection = await Collection.scope({
|
||||
method: ['withMembership', user.id],
|
||||
}).findByPk(collectionId);
|
||||
authorize(user, 'read', collection);
|
||||
}
|
||||
|
||||
|
||||
@@ -665,8 +665,9 @@ describe('#documents.search', async () => {
|
||||
});
|
||||
|
||||
it('should return documents for a specific private collection', async () => {
|
||||
const { user } = await seed();
|
||||
const collection = await buildCollection({ private: true });
|
||||
const { user, collection } = await seed();
|
||||
collection.private = true;
|
||||
await collection.save();
|
||||
|
||||
await CollectionUser.create({
|
||||
createdById: user.id,
|
||||
@@ -679,13 +680,14 @@ describe('#documents.search', async () => {
|
||||
title: 'search term',
|
||||
text: 'search term',
|
||||
teamId: user.teamId,
|
||||
collectionId: collection.id,
|
||||
});
|
||||
|
||||
const res = await server.post('/api/documents.search', {
|
||||
body: {
|
||||
token: user.getJwtToken(),
|
||||
query: 'search term',
|
||||
collectionId: document.collectionId,
|
||||
collectionId: collection.id,
|
||||
},
|
||||
});
|
||||
const body = await res.json();
|
||||
|
||||
+3
-1
@@ -53,7 +53,9 @@ if (process.env.WEBSOCKETS_ENABLED === 'true') {
|
||||
// allow the client to request to join rooms based on
|
||||
// new collections being created.
|
||||
socket.on('join', async event => {
|
||||
const collection = await Collection.findByPk(event.roomId);
|
||||
const collection = await Collection.scope({
|
||||
method: ['withMembership', user.id],
|
||||
}).findByPk(event.roomId);
|
||||
|
||||
if (can(user, 'read', collection)) {
|
||||
socket.join(`collection-${event.roomId}`);
|
||||
|
||||
@@ -303,14 +303,18 @@ Document.searchForUser = async (
|
||||
});
|
||||
|
||||
// Final query to get associated document data
|
||||
const documents = await Document.scope({
|
||||
method: ['withViews', user.id],
|
||||
}).findAll({
|
||||
const documents = await Document.scope(
|
||||
{
|
||||
method: ['withViews', user.id],
|
||||
},
|
||||
{
|
||||
method: ['withCollection', user.id],
|
||||
}
|
||||
).findAll({
|
||||
where: {
|
||||
id: map(results, 'id'),
|
||||
},
|
||||
include: [
|
||||
{ model: Collection, as: 'collection' },
|
||||
{ model: User, as: 'createdBy', paranoid: false },
|
||||
{ model: User, as: 'updatedBy', paranoid: false },
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user