Filter private info from public shares

This commit is contained in:
Tom Moor
2018-05-23 23:59:00 -07:00
parent 7eea1a90af
commit e538df0df3
8 changed files with 42 additions and 39 deletions

View File

@ -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 = '';

View File

@ -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,19 +274,20 @@ class DocumentScene extends React.Component<Props> {
readOnly={!this.isEditing} readOnly={!this.isEditing}
/> />
</MaxWidth> </MaxWidth>
{document && ( {document &&
<Actions !isShare && (
document={document} <Actions
isDraft={!document.publishedAt} document={document}
isEditing={this.isEditing} isDraft={!document.publishedAt}
isSaving={this.isSaving} isEditing={this.isEditing}
isPublishing={this.isPublishing} isSaving={this.isSaving}
savingIsDisabled={!document.allowSave} isPublishing={this.isPublishing}
history={this.props.history} savingIsDisabled={!document.allowSave}
onDiscard={this.onDiscard} history={this.props.history}
onSave={this.onSave} onDiscard={this.onDiscard}
/> onSave={this.onSave}
)} />
)}
</Flex> </Flex>
)} )}
</Container> </Container>

View File

@ -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"

View File

@ -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,

View File

@ -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 }),
}; };
}); });

View File

@ -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;

View File

@ -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 })
) )
); );
} }

View File

@ -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,39 +27,43 @@ 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.collection = await presentCollection(ctx, document.collection); data.pinned = !!document.pinnedById;
} data.collectionId = document.atlasId;
data.createdBy = presentUser(ctx, document.createdBy);
data.updatedBy = presentUser(ctx, document.updatedBy);
if (document.views && document.views.length === 1) { if (document.collection) {
data.views = document.views[0].count; data.collection = await presentCollection(ctx, document.collection);
data.firstViewedAt = document.views[0].createdAt; }
data.lastViewedAt = document.views[0].updatedAt;
} if (document.views && document.views.length === 1) {
data.views = document.views[0].count;
data.firstViewedAt = document.views[0].createdAt;
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: {