Skip to content

Commit

Permalink
feat: add endpoint to invite users (#343)
Browse files Browse the repository at this point in the history
Co-authored-by: yoko <25644062+sidemt@users.noreply.github.com>
  • Loading branch information
ojeytonwilliams and sidemt authored Nov 27, 2023
1 parent 839a7c3 commit 35f62de
Show file tree
Hide file tree
Showing 8 changed files with 387 additions and 5 deletions.
45 changes: 40 additions & 5 deletions apps/backend/config/sync/admin-role.strapi-super-admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,27 @@
"codeinjection_head",
"codeinjection_foot",
"slug_id"
]
],
"locales": ["en"]
},
"conditions": []
},
{
"action": "plugin::content-manager.explorer.delete",
"actionParameters": {},
"subject": "api::post.post",
"properties": {},
"properties": {
"locales": ["en"]
},
"conditions": []
},
{
"action": "plugin::content-manager.explorer.publish",
"actionParameters": {},
"subject": "api::post.post",
"properties": {},
"properties": {
"locales": ["en"]
},
"conditions": []
},
{
Expand All @@ -57,7 +62,8 @@
"codeinjection_head",
"codeinjection_foot",
"slug_id"
]
],
"locales": ["en"]
},
"conditions": []
},
Expand All @@ -79,7 +85,8 @@
"codeinjection_head",
"codeinjection_foot",
"slug_id"
]
],
"locales": ["en"]
},
"conditions": []
},
Expand Down Expand Up @@ -483,6 +490,34 @@
"properties": {},
"conditions": []
},
{
"action": "plugin::i18n.locale.create",
"actionParameters": {},
"subject": null,
"properties": {},
"conditions": []
},
{
"action": "plugin::i18n.locale.delete",
"actionParameters": {},
"subject": null,
"properties": {},
"conditions": []
},
{
"action": "plugin::i18n.locale.read",
"actionParameters": {},
"subject": null,
"properties": {},
"conditions": []
},
{
"action": "plugin::i18n.locale.update",
"actionParameters": {},
"subject": null,
"properties": {},
"conditions": []
},
{
"action": "plugin::upload.assets.copy-link",
"actionParameters": {},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{
"key": "plugin_content_manager_configuration_content_types::plugin::i18n.locale",
"value": {
"uid": "plugin::i18n.locale",
"settings": {
"bulkable": true,
"filterable": true,
"searchable": true,
"pageSize": 10,
"mainField": "name",
"defaultSortBy": "name",
"defaultSortOrder": "ASC"
},
"metadatas": {
"id": {
"edit": {},
"list": {
"label": "id",
"searchable": true,
"sortable": true
}
},
"name": {
"edit": {
"label": "name",
"description": "",
"placeholder": "",
"visible": true,
"editable": true
},
"list": {
"label": "name",
"searchable": true,
"sortable": true
}
},
"code": {
"edit": {
"label": "code",
"description": "",
"placeholder": "",
"visible": true,
"editable": true
},
"list": {
"label": "code",
"searchable": true,
"sortable": true
}
},
"createdAt": {
"edit": {
"label": "createdAt",
"description": "",
"placeholder": "",
"visible": false,
"editable": true
},
"list": {
"label": "createdAt",
"searchable": true,
"sortable": true
}
},
"updatedAt": {
"edit": {
"label": "updatedAt",
"description": "",
"placeholder": "",
"visible": false,
"editable": true
},
"list": {
"label": "updatedAt",
"searchable": true,
"sortable": true
}
},
"createdBy": {
"edit": {
"label": "createdBy",
"description": "",
"placeholder": "",
"visible": false,
"editable": true,
"mainField": "firstname"
},
"list": {
"label": "createdBy",
"searchable": true,
"sortable": true
}
},
"updatedBy": {
"edit": {
"label": "updatedBy",
"description": "",
"placeholder": "",
"visible": false,
"editable": true,
"mainField": "firstname"
},
"list": {
"label": "updatedBy",
"searchable": true,
"sortable": true
}
}
},
"layouts": {
"list": ["id", "name", "code", "createdAt"],
"edit": [
[
{
"name": "name",
"size": 6
},
{
"name": "code",
"size": 6
}
]
]
}
},
"type": "object",
"environment": null,
"tag": null
}
3 changes: 3 additions & 0 deletions apps/backend/config/sync/user-role.authenticated.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
{
"action": "plugin::users-permissions.auth.changePassword"
},
{
"action": "plugin::users-permissions.auth.invitation"
},
{
"action": "plugin::users-permissions.role.find"
},
Expand Down
39 changes: 39 additions & 0 deletions apps/backend/src/extensions/users-permissions/strapi-server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const DASHBOARD_URL = process.env.DASHBOARD_URL ?? "http://localhost:3000";

module.exports = (plugin) => {
plugin.controllers.user.updateMe = async (ctx) => {
if (!ctx.state.user || !ctx.state.user.id) {
Expand Down Expand Up @@ -25,6 +27,7 @@ module.exports = (plugin) => {
});
};

// TODO: find out if unshift is necessary or push will work.
plugin.routes["content-api"].routes.unshift({
method: "PUT",
path: "/users/me",
Expand All @@ -35,5 +38,41 @@ module.exports = (plugin) => {
},
});

plugin.controllers.auth.invitation = async (ctx) => {
if (!ctx.state.user || !ctx.state.user.id) {
return (ctx.response.status = 401);
}

const { email } = await strapi
.query("plugin::users-permissions.user")
.update({
where: { id: ctx.request.params.id },
data: {
provider: "auth0",
password: null,
},
});

await strapi.plugins.email.services.email.send({
to: email,
from: "support@freecodecamp.org",
subject: "Invitation Link",
text: `Here is your invitation link: ${DASHBOARD_URL}/api/auth/signin`,
});

ctx.response.status = 200;
ctx.response.body = {
status: "success",
};
};
plugin.routes["content-api"].routes.unshift({
method: "PUT",
path: "/auth/invitation/:id",
handler: "auth.invitation",
config: {
prefix: "",
policies: [],
},
});
return plugin;
};
1 change: 1 addition & 0 deletions apps/backend/tests/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ it("strapi is defined", () => {
});

require("./user");
require("./auth");
require("./custom-post");
require("./post");
Loading

0 comments on commit 35f62de

Please sign in to comment.