Skip to content

Commit

Permalink
Merge pull request #142 from kata-ai/Release/2.6
Browse files Browse the repository at this point in the history
Release/2.6
  • Loading branch information
oktavianidewi authored Nov 19, 2019
2 parents 655391b + ed8bcc4 commit 879ccf9
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 143 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# CHANGELOG

## [2.6.0] - 2019/11/19
- Fix search user by username or email on`kata invite-member` and `kata impersonate`command ([#133](https://github.com/kata-ai/kata-cli/pull/133), [#139](https://github.com/kata-ai/kata-cli/pull/139))

## [2.5.0] - 2019/09/02
- Fix bug when switch to team durinng in impersonate mode ([#126](https://github.com/kata-ai/kata-cli/pull/126))
- Fix bug when switch to team during in impersonate mode ([#126](https://github.com/kata-ai/kata-cli/pull/126))
- Add feature to select project name inline ([#127](https://github.com/kata-ai/kata-cli/pull/127))
- Add handler to display notification message when error happened, instead of letting string quotes `''` pop up ([#128](https://github.com/kata-ai/kata-cli/pull/128))

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![NPM downloads](https://img.shields.io/npm/dm/kata-cli.svg?style=flat)](https://www.npmjs.com/package/kata-cli)

# Kata-CLI Overview and Command Reference
Kata Command Line Interface (Kata CLI) is a tool for creating bots with Kata Markup Language (Kata ML) and helps managing the bots with command line/shell of various operating systems. For more information, check our website [http://kata.ai/en](http://kata.ai/en).
Kata Command Line Interface (Kata CLI) is a tool for creating bot with Kata Markup Language (Kata ML) and helps managing the bots with command line/shell of various operating systems.

## Installing Kata-CLI
Install Kata-CLI using the npm package manager.
Expand Down Expand Up @@ -149,7 +149,7 @@ Commands | Functionalities

### Outdated Commands on Kata-CLI

Here are the list of outdated commands on version 2.4.0, please refer to [Changelog](Changelog.md) for the details.
Here are the list of outdated commands on version 2.4.0, please refer to [Changelog](CHANGELOG.md) for the details.

_List of Deprecated Command:_
- `kata add-channel <channelName>`
Expand Down Expand Up @@ -385,4 +385,4 @@ Is something missing/incorrect? Please let us know by contacting [email protected]
3. Code, and dont forget to add test after added new feature
4. Commit your branch and pull request to base `develop` branch
Happy contributing :)
Happy contributing :)
47 changes: 38 additions & 9 deletions components/users/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,28 @@ export default class Team extends Component {
public async addMember(username: string, options?: JsonObject) {
try {
const role = options.admin ? "teamAdmin" : "teamMember";
const { userInfo, teamInfo, teamMember, currentLogin } = await this.getInfo(username);
let firstLogin = this.helper.getProp("first_login") as JsonObject;

const { userInfo, teamInfo, teamMember, currentLogin } = await this.getInfo(
username,
(firstLogin.username).toString()
);

if (userInfo && userInfo.id) {
if (this.checkUser(userInfo.id, teamMember)) {
throw new Error(`User ${username} already on this team`);
}
const { response } = await this.helper.toPromise(this.api.teamApi, this.api.teamApi.teamsTeamIdUsersUserIdPost, teamInfo.id, userInfo.id, { roleId: role } );
const { response } = await this.helper.toPromise(
this.api.teamApi,
this.api.teamApi.teamsTeamIdUsersUserIdPost,
teamInfo.teamId,
userInfo.username,
{
roleId: role
});
if (!response.body) {
throw new Error("Error adding user to team: invalid roleId");
}

console.log(`Success register ${username} to ${currentLogin}`);
} else {
console.log(`User ${username} not found`);
Expand Down Expand Up @@ -63,7 +74,7 @@ export default class Team extends Component {
}
}

private async getInfo(username: string) {
private async getInfo(username: string, firstLoginUsername?: string) {
const currentLogin = this.helper.getProp("current_login") as string;
const currentUserType = this.helper.getProp("current_user_type") as string;

Expand All @@ -72,27 +83,44 @@ export default class Team extends Component {
}

const requestTeamData =
await this.helper.toPromise(this.api.userApi, this.api.userApi.usersUserIdGet, currentLogin);
await this.helper.toPromise(
this.api.userApi,
this.api.userApi.usersUserIdTeamsGet,
firstLoginUsername
);

let teamInfo: any;
if (requestTeamData.response && requestTeamData.response.body) {
teamInfo = requestTeamData.response.body;
const filterTeamBasedOnCurrentTeam = (requestTeamData.response.body).filter(
(singleTeam: any) => ( singleTeam.username == currentLogin ));
teamInfo = filterTeamBasedOnCurrentTeam[0];
} else {
throw new Error("Cannot add user to team");
}
// console.log('teamInfo ', teamInfo);

const requestUserData =
await this.helper.toPromise(this.api.userApi, this.api.userApi.usersUserIdGet, username);

await this.helper.toPromise(
this.api.userApi,
this.api.userApi.usersGetInfoKeyGet,
username
);

// console.log('requestUserData ', requestUserData);
let userInfo: any;
if (requestUserData && requestUserData.response) {
userInfo = requestUserData.response.body;
} else {
throw new Error("Cannot add user to team");
}

// console.log('userInfo ', userInfo);
const requestTeamMember =
await this.helper.toPromise(this.api.teamApi, this.api.teamApi.teamsTeamIdUsersGet, teamInfo.id);
await this.helper.toPromise(
this.api.teamApi,
this.api.teamApi.teamsTeamIdUsersGet,
teamInfo.teamId
);

let teamMember: any[];
if (requestTeamMember && requestTeamMember.response) {
Expand All @@ -101,6 +129,7 @@ export default class Team extends Component {
throw new Error("Cannot add user to team");
}

// console.log('teamMember ', teamMember);
return {
teamInfo,
userInfo,
Expand Down
41 changes: 19 additions & 22 deletions components/users/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,28 +307,22 @@ export default class User extends Component {
this.api.authApi.apiClient.defaultHeaders.Authorization = `Bearer ${currentToken}`;

// get admin token
// const currentToken: string = this.getToken({name: "admin"});
// console.log(currentToken);
this.api.authApi.apiClient.defaultHeaders.Authorization = `Bearer ${currentToken}`;

// get user id from username
const id: string = (await this.getUserInfo(userName)).id;
const name: string = (await this.getUserInfo(userName)).name;
const email: string = (await this.getUserInfo(userName)).email;

// const limit: number = 1;
// const { response } = await this.helper.toPromise(
// this.api.userApi, this.api.userApi.usersSearchGet, userName, limit
// );
// const users = response.body;
// const name: string = users.map( (user: any) => user.username )[0].toString();
// const id: string = users.map( (user: any) => user.userId )[0].toString();

if ( userName !== name ) {
throw new Error(`Sorry, username is not exist.`);
if ( name && email ) {
// userName is user collected input
if ( userName !== name && userName !== email ) {
throw new Error(`Sorry, username is not exist.`);
}
} else {
throw new Error(`Sorry, username is not valid.`);
}

// TODO : check tsc error kenapa?
// TODO : check message error tidak muncul, kenapa?


// impersonate function
const result = await this.helper.toPromise(
Expand Down Expand Up @@ -389,17 +383,20 @@ export default class User extends Component {

private async getUserInfo(userName: string) {
// get userId from currentlogin
const limit: number = 1;
const { response } = await this.helper.toPromise(
this.api.userApi,
this.api.userApi.usersSearchGet,
this.api.userApi.usersGetInfoKeyGet,
userName,
limit
);
const users = response.body;
const name: string = users.map( (user: any) => user.username )[0].toString();
const id: string = users.map( (user: any) => user.userId )[0].toString();
return { id, name };
const user = response.body;
const email: string = user.email ? user.email.toString() : "";
const name: string = user.username.toString();
const id: string = user.userId.toString();
return {
id,
name,
email,
};
}

private async getNewPasswordData(): Promise<JsonObject> {
Expand Down
22 changes: 15 additions & 7 deletions lib/components/users/team.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 19 additions & 19 deletions lib/components/users/user.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 879ccf9

Please sign in to comment.