From 43b337dc916cdda07a54355febad23028d639162 Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Thu, 27 Jun 2019 14:49:52 +0200 Subject: [PATCH] SONAR-11723 Don't pass name and email values when updating a non-local user --- .../js/apps/users/components/UserForm.tsx | 6 +++-- .../components/__tests__/UserForm-test.tsx | 25 ++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/users/components/UserForm.tsx b/server/sonar-web/src/main/js/apps/users/components/UserForm.tsx index bc46891136a..6fa6ff036b2 100644 --- a/server/sonar-web/src/main/js/apps/users/components/UserForm.tsx +++ b/server/sonar-web/src/main/js/apps/users/components/UserForm.tsx @@ -117,11 +117,13 @@ export default class UserForm extends React.PureComponent { }; handleUpdateUser = () => { + const { user } = this.props; + this.setState({ submitting: true }); updateUser({ - email: this.state.email, + email: user!.local ? this.state.email : undefined, login: this.state.login, - name: this.state.name, + name: user!.local ? this.state.name : undefined, scmAccount: uniq(this.state.scmAccounts) }).then(() => { this.props.onUpdateUsers(); diff --git a/server/sonar-web/src/main/js/apps/users/components/__tests__/UserForm-test.tsx b/server/sonar-web/src/main/js/apps/users/components/__tests__/UserForm-test.tsx index e8b487d50c5..e4c4871d783 100644 --- a/server/sonar-web/src/main/js/apps/users/components/__tests__/UserForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/users/components/__tests__/UserForm-test.tsx @@ -29,6 +29,10 @@ jest.mock('../../../../api/users', () => ({ updateUser: jest.fn().mockResolvedValue({}) })); +beforeEach(() => { + jest.clearAllMocks(); +}); + it('should render correctly', () => { expect(shallowRender().dive()).toMatchSnapshot(); expect(shallowRender({ user: undefined }).dive()).toMatchSnapshot(); @@ -86,7 +90,7 @@ it('should correctly create a new user', () => { }); }); -it('should correctly update a user', () => { +it('should correctly update a local user', () => { const email = 'foo@bar.ch'; const login = 'foo'; const name = 'Foo'; @@ -103,6 +107,25 @@ it('should correctly update a user', () => { }); }); +it('should correctly update a non-local user', () => { + const email = 'foo@bar.ch'; + const login = 'foo'; + const name = 'Foo'; + const scmAccounts = ['gh', 'bitbucket']; + const wrapper = shallowRender({ + user: mockUser({ email, local: false, login, name, scmAccounts }) + }).dive(); + + submit(wrapper.find('form')); + + expect(updateUser).toBeCalledWith( + expect.not.objectContaining({ + email, + name + }) + ); +}); + function shallowRender(props: Partial = {}) { return shallow( -- 2.39.5