Skip to content
This repository was archived by the owner on Nov 5, 2025. It is now read-only.

Comments

Interface to create Bot user through Apps.engine#133

Closed
Cool-fire wants to merge 10 commits intoRocketChat:masterfrom
Cool-fire:create-user-bot
Closed

Interface to create Bot user through Apps.engine#133
Cool-fire wants to merge 10 commits intoRocketChat:masterfrom
Cool-fire:create-user-bot

Conversation

@Cool-fire
Copy link
Contributor

@Cool-fire Cool-fire commented Aug 20, 2019

changes made:

  • Added a new Interface IUserGenerate for creating user
  • Added IUserBuilder to create a user
  • Added a new Interface create in IUserBridge which accepts IUserGenerate

PR for implementation Rocket.Chat: Link

@codecov
Copy link

codecov bot commented Aug 20, 2019

Codecov Report

Merging #133 into master will increase coverage by 2.7%.
The diff coverage is 82.89%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/server/accessors/index.ts 100% <100%> (ø)
src/server/accessors/ModifyCreator.ts 63.51% <16.66%> (-9.51%) ⬇️
src/server/accessors/UserBuilder.ts 95.16% <95.16%> (ø)
src/server/errors/index.ts 100% <0%> (ø)
src/server/managers/index.ts 100% <0%> (ø)
src/server/marketplace/license/index.ts 100% <0%> (ø)
src/server/compiler/index.ts 100% <0%> (ø)
src/server/storage/index.ts 100% <0%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0d0af34...0ac4eef. Read the comment docs.

@Cool-fire
Copy link
Contributor Author

@d-gubert Please review

Copy link
Contributor

@graywolf336 graywolf336 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great. Is there any chance you can add some tests for the user builder?

@Cool-fire
Copy link
Contributor Author

sure @graywolf336 I will definitely add some test for user builder

@graywolf336
Copy link
Contributor

Thanks! I'll work with @d-gubert to see about getting this merged once you do.

@graywolf336
Copy link
Contributor

@Cool-fire let me know if you need help with anything

Copy link
Contributor

@graywolf336 graywolf336 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure @graywolf336 I will change that as you suggested :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you! 😄

private _finishUser(builder: IUserBuilder): Promise<string> {
const result = builder.getUser();
delete result.id;
return this.bridges.getUserBridge().create(result, this.appId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

throw new Error('The "name" property is required.');
}
if (!this.user.roles) {
throw new Error('The "roles" property is required.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We almost need a way for Apps to get fetch the roles from the Rocket.Chat system 🤔

getDisplayName(): string;

/**
* Sets the username for the user
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to add a warning here that the username must be unique.

*
* @param email the email address of the user
*/
setEmail(email: string): IUserBuilder;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The email provided here can not exist already in the system otherwise it will cause an error to arise.

@CLAassistant
Copy link

CLAassistant commented Oct 8, 2019

CLA assistant check
All committers have signed the CLA.

@Cool-fire Cool-fire requested a review from graywolf336 October 8, 2019 17:03
@wreiske
Copy link

wreiske commented Oct 8, 2019

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.

@Cool-fire
Copy link
Contributor Author

Cool-fire commented Oct 8, 2019

@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.

@graywolf336
Copy link
Contributor

@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?

@Cool-fire
Copy link
Contributor Author

@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.

@d-gubert
Copy link
Member

We've merged part of this implementation on #195, along with its Rocket.Chat counterpart.

Thanks again @Cool-fire ! 🤗

@d-gubert d-gubert closed this Feb 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants