Filter private info from public shares
This commit is contained in:
@ -32,7 +32,6 @@ class Document extends BaseModel {
|
|||||||
id: string;
|
id: string;
|
||||||
team: string;
|
team: string;
|
||||||
emoji: string;
|
emoji: string;
|
||||||
private: boolean = false;
|
|
||||||
starred: boolean = false;
|
starred: boolean = false;
|
||||||
pinned: boolean = false;
|
pinned: boolean = false;
|
||||||
text: string = '';
|
text: string = '';
|
||||||
|
@ -234,6 +234,7 @@ class DocumentScene extends React.Component<Props> {
|
|||||||
const document = this.document;
|
const document = this.document;
|
||||||
const titleFromState = location.state ? location.state.title : '';
|
const titleFromState = location.state ? location.state.title : '';
|
||||||
const titleText = document ? document.title : titleFromState;
|
const titleText = document ? document.title : titleFromState;
|
||||||
|
const isShare = match.params.shareId;
|
||||||
|
|
||||||
if (this.notFound) {
|
if (this.notFound) {
|
||||||
return <Search notFound />;
|
return <Search notFound />;
|
||||||
@ -273,7 +274,8 @@ class DocumentScene extends React.Component<Props> {
|
|||||||
readOnly={!this.isEditing}
|
readOnly={!this.isEditing}
|
||||||
/>
|
/>
|
||||||
</MaxWidth>
|
</MaxWidth>
|
||||||
{document && (
|
{document &&
|
||||||
|
!isShare && (
|
||||||
<Actions
|
<Actions
|
||||||
document={document}
|
document={document}
|
||||||
isDraft={!document.publishedAt}
|
isDraft={!document.publishedAt}
|
||||||
|
@ -34,7 +34,7 @@ class DocumentShare extends React.Component<Props> {
|
|||||||
<HelpText>
|
<HelpText>
|
||||||
The link below allows anyone to access a read-only version of the
|
The link below allows anyone to access a read-only version of the
|
||||||
document <strong>{document.title}</strong>. You can revoke this link
|
document <strong>{document.title}</strong>. You can revoke this link
|
||||||
at any point in the future.
|
in settings at any time.
|
||||||
</HelpText>
|
</HelpText>
|
||||||
<Input
|
<Input
|
||||||
type="text"
|
type="text"
|
||||||
|
@ -39,7 +39,6 @@ export type Document = {
|
|||||||
createdBy: User,
|
createdBy: User,
|
||||||
html: string,
|
html: string,
|
||||||
id: string,
|
id: string,
|
||||||
private: boolean,
|
|
||||||
starred: boolean,
|
starred: boolean,
|
||||||
views: number,
|
views: number,
|
||||||
team: string,
|
team: string,
|
||||||
|
@ -161,7 +161,9 @@ router.post('documents.info', auth({ required: false }), async ctx => {
|
|||||||
const { id, shareId } = ctx.body;
|
const { id, shareId } = ctx.body;
|
||||||
ctx.assertPresent(id || shareId, 'id or shareId is required');
|
ctx.assertPresent(id || shareId, 'id or shareId is required');
|
||||||
|
|
||||||
|
const isPublic = !!shareId;
|
||||||
let document;
|
let document;
|
||||||
|
|
||||||
if (shareId) {
|
if (shareId) {
|
||||||
const share = await Share.findById(shareId, {
|
const share = await Share.findById(shareId, {
|
||||||
include: [
|
include: [
|
||||||
@ -172,8 +174,6 @@ router.post('documents.info', auth({ required: false }), async ctx => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: REMOVE COLLECTION AND COLLABORATOR INFO
|
|
||||||
document = share.document;
|
document = share.document;
|
||||||
} else {
|
} else {
|
||||||
document = await Document.findById(id);
|
document = await Document.findById(id);
|
||||||
@ -181,7 +181,7 @@ router.post('documents.info', auth({ required: false }), async ctx => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
data: await presentDocument(ctx, document),
|
data: await presentDocument(ctx, document, { isPublic }),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -52,14 +52,14 @@ router.post('shares.create', auth(), async ctx => {
|
|||||||
const document = await Document.findById(id);
|
const document = await Document.findById(id);
|
||||||
authorize(user, 'share', document);
|
authorize(user, 'share', document);
|
||||||
|
|
||||||
const [share, created] = await Share.findOrCreate({
|
const [share] = await Share.findOrCreate({
|
||||||
where: {
|
where: {
|
||||||
documentId: document.id,
|
documentId: document.id,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
console.log('created', created);
|
|
||||||
share.user = user;
|
share.user = user;
|
||||||
share.document = document;
|
share.document = document;
|
||||||
|
|
||||||
|
@ -42,8 +42,7 @@ async function present(ctx: Object, collection: Collection) {
|
|||||||
if (collection.documents) {
|
if (collection.documents) {
|
||||||
data.recentDocuments = await Promise.all(
|
data.recentDocuments = await Promise.all(
|
||||||
collection.documents.map(
|
collection.documents.map(
|
||||||
async document =>
|
async document => await presentDocument(ctx, document)
|
||||||
await presentDocument(ctx, document, { includeCollaborators: true })
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,12 @@ import presentCollection from './collection';
|
|||||||
const Op = Sequelize.Op;
|
const Op = Sequelize.Op;
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
includeCollaborators?: boolean,
|
isPublic?: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
async function present(ctx: Object, document: Document, options: ?Options) {
|
async function present(ctx: Object, document: Document, options: ?Options) {
|
||||||
options = {
|
options = {
|
||||||
includeCollaborators: true,
|
isPublic: false,
|
||||||
...options,
|
...options,
|
||||||
};
|
};
|
||||||
ctx.cache.set(document.id, document);
|
ctx.cache.set(document.id, document);
|
||||||
@ -27,29 +27,34 @@ async function present(ctx: Object, document: Document, options: ?Options) {
|
|||||||
id: document.id,
|
id: document.id,
|
||||||
url: document.getUrl(),
|
url: document.getUrl(),
|
||||||
urlId: document.urlId,
|
urlId: document.urlId,
|
||||||
private: document.private,
|
|
||||||
title: document.title,
|
title: document.title,
|
||||||
text: document.text,
|
text: document.text,
|
||||||
emoji: document.emoji,
|
emoji: document.emoji,
|
||||||
createdAt: document.createdAt,
|
createdAt: document.createdAt,
|
||||||
createdBy: presentUser(ctx, document.createdBy),
|
createdBy: undefined,
|
||||||
updatedAt: document.updatedAt,
|
updatedAt: document.updatedAt,
|
||||||
updatedBy: presentUser(ctx, document.updatedBy),
|
updatedBy: undefined,
|
||||||
publishedAt: document.publishedAt,
|
publishedAt: document.publishedAt,
|
||||||
firstViewedAt: undefined,
|
firstViewedAt: undefined,
|
||||||
lastViewedAt: undefined,
|
lastViewedAt: undefined,
|
||||||
team: document.teamId,
|
team: document.teamId,
|
||||||
collaborators: [],
|
collaborators: [],
|
||||||
starred: !!(document.starred && document.starred.length),
|
starred: !!(document.starred && document.starred.length),
|
||||||
pinned: !!document.pinnedById,
|
|
||||||
revision: document.revisionCount,
|
revision: document.revisionCount,
|
||||||
collectionId: document.atlasId,
|
pinned: undefined,
|
||||||
|
collectionId: undefined,
|
||||||
collaboratorCount: undefined,
|
collaboratorCount: undefined,
|
||||||
collection: undefined,
|
collection: undefined,
|
||||||
views: undefined,
|
views: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (document.private && document.collection) {
|
if (!options.isPublic) {
|
||||||
|
data.pinned = !!document.pinnedById;
|
||||||
|
data.collectionId = document.atlasId;
|
||||||
|
data.createdBy = presentUser(ctx, document.createdBy);
|
||||||
|
data.updatedBy = presentUser(ctx, document.updatedBy);
|
||||||
|
|
||||||
|
if (document.collection) {
|
||||||
data.collection = await presentCollection(ctx, document.collection);
|
data.collection = await presentCollection(ctx, document.collection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +64,6 @@ async function present(ctx: Object, document: Document, options: ?Options) {
|
|||||||
data.lastViewedAt = document.views[0].updatedAt;
|
data.lastViewedAt = document.views[0].updatedAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.includeCollaborators) {
|
|
||||||
// This could be further optimized by using ctx.cache
|
// This could be further optimized by using ctx.cache
|
||||||
data.collaborators = await User.findAll({
|
data.collaborators = await User.findAll({
|
||||||
where: {
|
where: {
|
||||||
|
Reference in New Issue
Block a user