Interface to create Bot user through Apps.engine#133
Interface to create Bot user through Apps.engine#133Cool-fire wants to merge 10 commits intoRocketChat:masterfrom Cool-fire:create-user-bot
Conversation
Codecov Report
@@ Coverage Diff @@
## master #133 +/- ##
=========================================
+ Coverage 55.4% 58.11% +2.7%
=========================================
Files 68 77 +9
Lines 2397 2583 +186
Branches 360 366 +6
=========================================
+ Hits 1328 1501 +173
- Misses 1069 1082 +13
Continue to review full report at Codecov.
|
|
@d-gubert Please review |
graywolf336
left a comment
There was a problem hiding this comment.
Looking great. Is there any chance you can add some tests for the user builder?
|
sure @graywolf336 I will definitely add some test for user builder |
|
Thanks! I'll work with @d-gubert to see about getting this merged once you do. |
|
@Cool-fire let me know if you need help with anything |
There was a problem hiding this comment.
A few quality of developer experience and improvements, but overall a fantastic pull request and something we have been needing. Along with the requested changes, can you fix the merge conflicts? We separated out the accessor definitions into individual files instead of all being in one.
| @@ -0,0 +1,12 @@ | |||
| export interface IUserGenerate { | |||
There was a problem hiding this comment.
I'm not 100% certain about this interface name. What is the main reason for not putting this on the existing user? What about extending the IUser interface so that it accepts everything else along with the new fields that are just for when creating a user?
There was a problem hiding this comment.
@graywolf336 The main reason for not extending the IUser is that there are some fields which are non-nullable like lastLoginAt, createdAt which I felt are to be extended unnecessarily while creating, So I have created a new Interface which is meant for the only generation of a user.
There was a problem hiding this comment.
Great point, I see the validity in it now. Then I think we should change the name of the interface to something like IUserCreation, what do you think?
There was a problem hiding this comment.
sure @graywolf336 I will change that as you suggested :)
| private _finishUser(builder: IUserBuilder): Promise<string> { | ||
| const result = builder.getUser(); | ||
| delete result.id; | ||
| return this.bridges.getUserBridge().create(result, this.appId); |
There was a problem hiding this comment.
Almost wonder if we should do a check to ensure the user doesn't exist by the username, email, etc before we proceed to create the user that way we can gracefully handle the error instead of letting Rocket.Chat handle the error for us.
There was a problem hiding this comment.
Yes, @graywolf336 it would be better if we can check a user exists by username, email..etc but I couldn't find a way to check whether it exists from apps-engine. Anyways I think the server handles the case where a user exists gracefully throwing the reason for the error in logs.
There was a problem hiding this comment.
Then let's create it that way we can throw custom errors. The Apps Engine is an abstraction away from Rocket.Chat since the internals of Rocket.Chat can change at any point in time and we want the Apps Engine to be stable and consistent. Thus I would rather us do the extra work that way it is not a guessing game for App developers of what will happen and instead they can know up front. Does that make sense?
src/server/accessors/UserBuilder.ts
Outdated
| throw new Error('The "name" property is required.'); | ||
| } | ||
| if (!this.user.roles) { | ||
| throw new Error('The "roles" property is required.'); |
There was a problem hiding this comment.
We almost need a way for Apps to get fetch the roles from the Rocket.Chat system 🤔
src/definition/accessors/IModify.ts
Outdated
| getDisplayName(): string; | ||
|
|
||
| /** | ||
| * Sets the username for the user |
There was a problem hiding this comment.
Might want to add a warning here that the username must be unique.
src/definition/accessors/IModify.ts
Outdated
| * | ||
| * @param email the email address of the user | ||
| */ | ||
| setEmail(email: string): IUserBuilder; |
There was a problem hiding this comment.
The email provided here can not exist already in the system otherwise it will cause an error to arise.
|
Would it be possible to add the ability for an app to edit a user, as well as create it? That would be amazing! Please, and thank you :) I'd like to be able to modify user roles from the apps-engine. |
|
@graywolf336 can you please review the PR, I think I have added necessary tests for UserBuilder and resolved merge conflicts. Please let me know if any changes are needed. |
|
@Cool-fire will do, probably will be tomorrow or Thursday before I can. Based upon your experience with this, how hard would it be to implement what @wreiske requested? |
|
@graywolf336 I think this pr gives the apps ability to create users. And I think it would be simple to make an interface like IUserModifier which has the ability to edit a user details but I think we have to look take a look on permissions to edit a user roles since I think that can be only done by an admin or the same user, I am wondering if the app developers have to use an admin role user to edit other user details. |
|
We've merged part of this implementation on #195, along with its Rocket.Chat counterpart. Thanks again @Cool-fire ! 🤗 |
changes made:
PR for implementation Rocket.Chat: Link