-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement dashboard endpoints (#65)
- Loading branch information
1 parent
ba34e3e
commit 71ce307
Showing
43 changed files
with
653 additions
and
701 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Curator Content Platform | ||
|
||
Plugin for turning Strapi into a full-featured content platform. | ||
|
||
## Features | ||
|
||
- Audit logs | ||
- Dashboard (recently edited, user's drafts, etc.) | ||
- Versioning |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/strapi/server/config/index.ts → ...s/content-platform/server/config/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/content-platform/server/controllers/dashboard.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Strapi } from "@strapi/strapi"; | ||
|
||
export default ({ strapi }: { strapi: Strapi }) => ({ | ||
index() { | ||
return strapi.plugin("curator").service("dashboardService").getData(); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import dashboardController from "./dashboard.controller"; | ||
import secretsController from "./secrets.controller"; | ||
|
||
export default { | ||
secretsController, | ||
dashboardController, | ||
}; |
2 changes: 1 addition & 1 deletion
2
.../server/controllers/secrets-controller.ts → .../server/controllers/secrets.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { Strapi } from "@strapi/strapi"; | ||
|
||
export default ({ strapi }: { strapi: Strapi }) => ({ | ||
find() { | ||
index() { | ||
return strapi.plugin("curator").service("secretsService").getSecrets(); | ||
}, | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default {}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default [ | ||
{ | ||
method: "GET", | ||
path: "/secrets", | ||
handler: "secretsController.index", | ||
config: {}, | ||
}, | ||
{ | ||
method: "GET", | ||
path: "/dashboard", | ||
handler: "dashboardController.index", | ||
config: {}, | ||
}, | ||
]; |
93 changes: 93 additions & 0 deletions
93
packages/content-platform/server/services/dashboard.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { Strapi } from "@strapi/strapi"; | ||
import * as R from "ramda"; | ||
|
||
export default ({ strapi }: { strapi: Strapi }) => ({ | ||
async getData() { | ||
const ctx = strapi.requestContext.get(); | ||
|
||
const recent = await this.getRecent(ctx); | ||
const drafts = await this.getDrafts(ctx); | ||
|
||
return { recent, drafts }; | ||
}, | ||
/** | ||
* Get recently created or updated items. | ||
*/ | ||
async getRecent(ctx: any) { | ||
const user = ctx.state.user; | ||
const query = await strapi.entityService.findMany( | ||
"plugin::curator.curator-audit-log", | ||
{ | ||
sort: "updatedAt:DESC", | ||
filters: { | ||
subjectId: user.id, | ||
objectUid: { | ||
$startsWith: "api::", | ||
}, | ||
action: ["update", "create"], | ||
}, | ||
} | ||
); | ||
|
||
const distinct: Record<string, any>[] = R.uniqBy( | ||
R.props(["objectId", "objectUid"]), | ||
query as any[] | ||
).slice(0, 5); | ||
|
||
let results: any[] = []; | ||
|
||
for await (const item of distinct) { | ||
try { | ||
const data = await strapi.entityService.findOne( | ||
item.objectUid, | ||
item.objectId | ||
); | ||
|
||
results = [ | ||
...results, | ||
{ uid: item.objectUid, id: item.objectId, attributes: data ?? {} }, | ||
]; | ||
} catch (e) { | ||
console.warn(e); | ||
} | ||
} | ||
|
||
return results; | ||
}, | ||
|
||
/** | ||
* Get draft content created by the current user. | ||
*/ | ||
async getDrafts(ctx: any) { | ||
const user = ctx.state.user; | ||
|
||
const modelsWithDraftState = Object.values(strapi.contentTypes) | ||
.filter(R.path(["options", "draftAndPublish"])) | ||
.map<string>(R.prop<string>("uid")); | ||
|
||
let results: any[] = []; | ||
|
||
for await (const uid of modelsWithDraftState) { | ||
try { | ||
const data = (await strapi.entityService.findMany(uid as any, { | ||
sort: "updatedAt:DESC", | ||
filters: { | ||
createdBy: user.id, | ||
publishedAt: { | ||
$null: true, | ||
}, | ||
}, | ||
})) as any[]; | ||
|
||
results = [ | ||
...results, | ||
...data.map(({ id, ...attributes }) => ({ id, uid, attributes })), | ||
]; | ||
} catch (e) { | ||
console.warn(e); | ||
} | ||
} | ||
|
||
return results.slice(0, 10); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import secretsService from "./secrets.service"; | ||
import dashboardService from "./dashboard.service"; | ||
|
||
export default { | ||
secretsService, | ||
dashboardService, | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.