mirror of
https://github.com/filecoin-project/slate.git
synced 2024-11-22 21:45:56 +03:00
fix for private slates not showing
This commit is contained in:
parent
16650b6f15
commit
cc19234634
@ -3,6 +3,7 @@ import * as Serializers from "~/node_common/serializers";
|
||||
import * as Strings from "~/common/strings";
|
||||
|
||||
export default async (req, res) => {
|
||||
const id = Utilities.getIdFromCookie(req);
|
||||
let slate;
|
||||
if (req.body.data.id) {
|
||||
slate = await Data.getSlateById({ id: req.body.data.id });
|
||||
@ -20,7 +21,7 @@ export default async (req, res) => {
|
||||
}
|
||||
slate = Serializers.slate(slate);
|
||||
|
||||
if (!slate.data.public && slate.data.ownerId !== req.body.data.id) {
|
||||
if (!slate.data.public && slate.data.ownerId !== id) {
|
||||
return res.status(403).send({
|
||||
decorator: "SLATE_PRIVATE_ACCESS_DENIED",
|
||||
error: true,
|
||||
|
@ -253,104 +253,6 @@ class SlatePage extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
fetchSlate = async () => {
|
||||
const { user: username, slate: slatename, cid } = this.props.page;
|
||||
|
||||
if (!this.props.data && (!username || !slatename)) {
|
||||
this.setState({ notFound: true });
|
||||
return;
|
||||
}
|
||||
|
||||
//NOTE(martina): look for the slate in the user's slates
|
||||
let slate;
|
||||
if (this.props.data?.id) {
|
||||
for (let s of this.props.viewer.slates) {
|
||||
if (this.props.data.id && this.props.data.id === s.id) {
|
||||
slate = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (slatename && username === this.props.viewer.username) {
|
||||
for (let s of this.props.viewer.slates) {
|
||||
if (username && slatename === s.slatename) {
|
||||
slate = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!slate) {
|
||||
Events.dispatchMessage({ message: "We're having trouble fetching that slate right now." });
|
||||
this.setState({ notFound: true });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (slate) {
|
||||
window.history.replaceState(
|
||||
{ ...window.history.state, data: slate },
|
||||
"Slate",
|
||||
`/${this.props.viewer.username}/${slate.slatename}`
|
||||
);
|
||||
}
|
||||
|
||||
if (!slate) {
|
||||
let query;
|
||||
if (username && slatename) {
|
||||
query = { username, slatename };
|
||||
} else if (this.props.data && this.props.data.id) {
|
||||
query = { id: this.props.data.id };
|
||||
}
|
||||
let response;
|
||||
if (query) {
|
||||
response = await Actions.getSerializedSlate(query);
|
||||
}
|
||||
if (response?.decorator == "SLATE_PRIVATE_ACCESS_DENIED") {
|
||||
this.setState({ accessDenied: true });
|
||||
return;
|
||||
}
|
||||
if (Events.hasError(response)) {
|
||||
this.setState({ notFound: true });
|
||||
return;
|
||||
}
|
||||
slate = response.data;
|
||||
window.history.replaceState(
|
||||
{ ...window.history.state, data: slate },
|
||||
"Slate",
|
||||
`/${response.data.user.username}/${response.data.slatename}`
|
||||
);
|
||||
}
|
||||
|
||||
this.props.onUpdateData({ data: slate });
|
||||
|
||||
let index = -1;
|
||||
let page = this.props.page;
|
||||
if (page?.fileId || page?.cid || page?.index || !Strings.isEmpty(cid)) {
|
||||
if (page?.index) {
|
||||
index = page.index;
|
||||
} else {
|
||||
let index = slate.data.objects.findIndex((object) => object.cid === this.props.cid);
|
||||
if (index !== -1) {
|
||||
}
|
||||
for (let i = 0; i < slate.data.objects.length; i++) {
|
||||
let obj = slate.data.objects[i];
|
||||
if (
|
||||
(obj.cid && (obj.cid === cid || obj.cid === page?.cid)) ||
|
||||
(obj.id && obj.id === page?.fileId)
|
||||
) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (index !== -1) {
|
||||
Events.dispatchCustomEvent({
|
||||
name: "slate-global-open-carousel",
|
||||
detail: { index },
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
_handleFollow = () => {
|
||||
this.setState({ isFollowing: !this.state.isFollowing });
|
||||
Actions.createSubscription({
|
||||
|
Loading…
Reference in New Issue
Block a user