mirror of
https://github.com/outline/outline.git
synced 2025-12-21 10:39:41 -06:00
Update API responses to 204 (#10441)
* shares.info * subscriptions and pins to 204
This commit is contained in:
@@ -37,6 +37,9 @@ export default class PinsStore extends Store<Pin> {
|
||||
documentId,
|
||||
collectionId,
|
||||
});
|
||||
if (!res) {
|
||||
return;
|
||||
}
|
||||
invariant(res?.data, "Data should be available");
|
||||
return this.add(res.data);
|
||||
} catch (err) {
|
||||
|
||||
@@ -34,6 +34,9 @@ export default class SubscriptionsStore extends Store<Subscription> {
|
||||
|
||||
try {
|
||||
const res = await client.post(`/${this.apiEndpoint}.info`, options);
|
||||
if (!res) {
|
||||
return;
|
||||
}
|
||||
invariant(res?.data, "Data should be available");
|
||||
return this.add(res.data);
|
||||
} catch (err) {
|
||||
|
||||
@@ -227,7 +227,7 @@ describe("#pins.info", () => {
|
||||
expect(pin.data.collectionId).toEqual(document.collectionId);
|
||||
});
|
||||
|
||||
it("should throw 404 if no pin found", async () => {
|
||||
it("should return 204 if no pin for input", async () => {
|
||||
const user = await buildUser();
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
@@ -242,7 +242,7 @@ describe("#pins.info", () => {
|
||||
},
|
||||
});
|
||||
|
||||
expect(res.status).toEqual(404);
|
||||
expect(res.status).toEqual(204);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -77,9 +77,13 @@ router.post(
|
||||
createdById: user.id,
|
||||
teamId: user.teamId,
|
||||
},
|
||||
rejectOnEmpty: true,
|
||||
});
|
||||
|
||||
if (!pin) {
|
||||
ctx.response.status = 204;
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
data: presentPin(pin),
|
||||
policies: presentPolicies(user, [pin]),
|
||||
|
||||
@@ -655,6 +655,20 @@ describe("#shares.info", () => {
|
||||
expect(body.data.shares[0].id).toBe(share.id);
|
||||
expect(body.data.shares[0].published).toBe(true);
|
||||
});
|
||||
it("should allow reading share by documentId", async () => {
|
||||
const user = await buildUser();
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
const res = await server.post("/api/shares.info", {
|
||||
body: {
|
||||
token: user.getJwtToken(),
|
||||
documentId: document.id,
|
||||
},
|
||||
});
|
||||
expect(res.status).toEqual(204);
|
||||
});
|
||||
it("should return share for parent document with includeChildDocuments=true", async () => {
|
||||
const user = await buildUser();
|
||||
const collection = await buildCollection({
|
||||
|
||||
@@ -102,25 +102,31 @@ router.post(
|
||||
throw AuthenticationError("Authentication required");
|
||||
}
|
||||
|
||||
const { share, parentShare } = await loadShareWithParent({
|
||||
collectionId,
|
||||
documentId,
|
||||
user,
|
||||
});
|
||||
try {
|
||||
const { share, parentShare } = await loadShareWithParent({
|
||||
collectionId,
|
||||
documentId,
|
||||
user,
|
||||
});
|
||||
|
||||
const shares = [share, parentShare].filter(Boolean) as Share[];
|
||||
const shares = [share, parentShare].filter(Boolean) as Share[];
|
||||
if (!shares.length) {
|
||||
throw NotFoundError();
|
||||
}
|
||||
|
||||
if (!shares.length) {
|
||||
ctx.response.status = 204;
|
||||
return;
|
||||
ctx.body = {
|
||||
data: {
|
||||
shares: shares.map((s) => presentShare(s, user.isAdmin ?? false)),
|
||||
},
|
||||
policies: presentPolicies(user, shares),
|
||||
};
|
||||
} catch (err) {
|
||||
if (err.id === "not_found") {
|
||||
ctx.response.status = 204;
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
data: {
|
||||
shares: shares.map((s) => presentShare(s, user.isAdmin ?? false)),
|
||||
},
|
||||
policies: presentPolicies(user, shares),
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -300,7 +300,7 @@ describe("#subscriptions.info", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("should throw 404 if no subscription found", async () => {
|
||||
it("should return 204 if no subscription for input", async () => {
|
||||
const author = await buildUser();
|
||||
const subscriber = await buildUser({ teamId: author.teamId });
|
||||
const document = await buildDocument({
|
||||
@@ -316,7 +316,7 @@ describe("#subscriptions.info", () => {
|
||||
},
|
||||
});
|
||||
|
||||
expect(res.status).toEqual(404);
|
||||
expect(res.status).toEqual(204);
|
||||
});
|
||||
|
||||
it("should not allow outsiders to gain info about a subscription", async () => {
|
||||
|
||||
@@ -98,9 +98,13 @@ router.post(
|
||||
// There can be only one subscription with these props.
|
||||
const subscription = await Subscription.findOne({
|
||||
where,
|
||||
rejectOnEmpty: true,
|
||||
});
|
||||
|
||||
if (!subscription) {
|
||||
ctx.response.status = 204;
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.body = {
|
||||
data: presentSubscription(subscription),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user