Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: invites regardless of registration type, invite privilege, groups to join on acceptance #8786

Merged
merged 16 commits into from Nov 16, 2020

Conversation

gasoved
Copy link
Collaborator

@gasoved gasoved commented Oct 23, 2020

Some notes:

Hidden groups are not included in the "groups to be joined" <select> to be consistent with the behavior in other places.


This leaves off joining of groups when the registration is completed by an approval (in approve-only registration mode), since it seems currently we can't distinguish a registration made through an invite link from one that is not. (Only mechanism for that right now is presence of an invite token.)

In approval flow, invite keys are not deleted, and it is assumed the user is coming from invite link even when it is not (added to the "Invitations" table at /admin/manage/registration).

In normal flow, invite-invitee "relationship" is deleted.

We can have a follow-up on this (like an invite accepted "flag", and tangentially, showing groups from invites in the "Invitations" table).

@CLAassistant
Copy link

CLAassistant commented Oct 23, 2020

CLA assistant check
All committers have signed the CLA.

@julianlam julianlam self-requested a review October 23, 2020 11:12
src/views/modals/invite.tpl Outdated Show resolved Hide resolved
public/src/admin/manage/users.js Outdated Show resolved Hide resolved
public/src/client/users.js Outdated Show resolved Hide resolved
@julianlam
Copy link
Member

julianlam commented Oct 23, 2020

Instead of introducing a new socket call, let's add a new route to the Write API.

Don't worry, this is a brand new feature that got merged last week, so it is not a surprise you did not know about it 😄

Step 1

Add a new route to src/routes/write/users.js, let's go with POST /invite

Step 2

Add the controller logic to src/controllers/write/users.js, Users.inviteUser

Note here that a lot of these controllers call out to methods in src/api/*.js. This is because we currently still support both socket.io and the write API, so the controller logic has to be organized in such a way that both methods can access.

In this case, this is a brand new route with no websocket variant (or rather, we're rewriting it to not be a socket call), so you do not need to put your logic into the src/api/users.js file. Just put it directly into this controllers file (src/controllers/users.js).

You'll note that the token generation/deletion controllers are done in this way. This is because there is no websocket equivalent.

Step 3

Rewrite your call so that instead of socket.emit, you call it via:

require(['api'], (api) => {
    api.post('/users/invite', { email, groups })   // pseudocode
        .then(() => { // do things... });
});

The api module automatically handles errors by calling app.alertError(), but if you want to handle errors yourself, add a .catch().

Slack me if you have questions!

@julianlam
Copy link
Member

It is ok to use socket.io for getInviteGroups... I think. I'd prefer it to be a GET but perhaps we can refactor it out later.

@gasoved gasoved force-pushed the invitesystem branch 3 times, most recently from 3309918 to 6ddea1f Compare October 30, 2020 14:35
src/routes/api.js Outdated Show resolved Hide resolved
@julianlam julianlam merged commit 3ccebf1 into NodeBB:master Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants