Skip to content

Commit

Permalink
fix: do not included deleted items in dashboard recent
Browse files Browse the repository at this point in the history
  • Loading branch information
StructuralRealist committed Sep 15, 2023
1 parent ced7d09 commit 65d0c93
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/content-platform/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@curatorjs/content-platform",
"version": "0.2.0",
"version": "0.2.1",
"description": "Curator plugin for Strapi.",
"main": "strapi-server.js",
"strapi": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function versioningLifecycle(strapi: Strapi) {
*/
const throttleTime = R.unless(
(value) => typeof value === "number",
R.always(DEFAULT_THROTTLE)
R.always(DEFAULT_THROTTLE),
)(R.prop<number>("throttle", config)) as number;
/*
* Make sure versions cannot be updated.
Expand Down Expand Up @@ -69,13 +69,13 @@ export default function versioningLifecycle(strapi: Strapi) {
([key, attribute]: [string, any]) =>
attribute.writable !== false &&
attribute.type !== "relation" &&
!NON_VERSIONED_FIELDS.includes(key)
!NON_VERSIONED_FIELDS.includes(key),
)
.map<string>(R.head)
: Object.entries(event.model.attributes)
.filter(
([_, attribute]: [string, any]) =>
attribute.pluginOptions?.versioning
attribute.pluginOptions?.versioning,
)
.map<string>(R.head);

Expand All @@ -85,7 +85,7 @@ export default function versioningLifecycle(strapi: Strapi) {
if (id && !R.isEmpty(fields)) {
const current = await strapi.entityService.findOne(
event.model.uid as any,
id
id,
);
/*
* If for some reason we cannot get the current entity there is no
Expand All @@ -106,12 +106,12 @@ export default function versioningLifecycle(strapi: Strapi) {
objectId: id,
objectUid: event.model.uid,
},
}
},
)) as any[];

const hasChanges = !R.equals(
R.pick(fields, current),
R.pick(fields, data)
R.pick(fields, data),
);

const published =
Expand All @@ -129,7 +129,7 @@ export default function versioningLifecycle(strapi: Strapi) {
version: lastVersion[0] ? lastVersion[0].version + 1 : 1,
content: R.when(
R.always(published),
R.assoc("published", published)
R.assoc("published", published),
)(R.pick(fields, current)),
createdBy: data.updatedBy || data.createdBy,
},
Expand Down
16 changes: 9 additions & 7 deletions packages/content-platform/server/services/dashboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ export default ({ strapi }: { strapi: Strapi }) => ({
},
action: ["update", "create"],
},
}
},
);

const distinct: Record<string, any>[] = R.uniqBy(
R.props(["objectId", "objectUid"]),
query as any[]
query as any[],
).slice(0, 5);

let results: any[] = [];
Expand All @@ -40,13 +40,15 @@ export default ({ strapi }: { strapi: Strapi }) => ({
try {
const data = await strapi.entityService.findOne(
item.objectUid,
item.objectId
item.objectId,
);

results = [
...results,
{ uid: item.objectUid, id: item.objectId, attributes: data ?? {} },
];
if (data) {
results = [
...results,
{ uid: item.objectUid, id: item.objectId, attributes: data },
];
}
} catch (e) {
console.warn(e);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/content-platform/server/services/secrets.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ export default ({ strapi }: { strapi: Strapi }) => ({
const ctx = strapi.requestContext.get();
const userRoles = ctx.state.user.roles.map(({ id }: { id: number }) => id);
const isAdmin = ctx.state.user.roles.some(
R.whereEq({ code: "strapi-super-admin" })
R.whereEq({ code: "strapi-super-admin" }),
);
const query = await strapi.entityService.findMany(
"plugin::curator.curator-secret",
{
filters: isAdmin ? undefined : { roles: userRoles },
}
},
);

return (
query?.reduce(
(
result: Record<string, string>,
{ key, value }: { key: string; value: string }
{ key, value }: { key: string; value: string },
) => ({
...result,
[key]: value,
}),
{}
{},
) ?? {}
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default ({ strapi }: { strapi: Strapi }) => ({
R.whereEq({
subject: params.uid,
action: `plugin::content-manager.explorer.read`,
})
}),
);

if (!hasPermission) {
Expand Down Expand Up @@ -56,7 +56,7 @@ export default ({ strapi }: { strapi: Strapi }) => ({
$eq: params.uid,
},
},
}
},
);

const count = await strapi.entityService.count(
Expand All @@ -70,7 +70,7 @@ export default ({ strapi }: { strapi: Strapi }) => ({
$eq: params.uid,
},
},
}
},
);

return {
Expand All @@ -82,7 +82,7 @@ export default ({ strapi }: { strapi: Strapi }) => ({
},
results: Array.isArray(entities)
? entities.map(
R.pick(["id", "content", "version", "createdAt", "createdBy"])
R.pick(["id", "content", "version", "createdAt", "createdBy"]),
)
: [],
};
Expand Down

0 comments on commit 65d0c93

Please sign in to comment.