aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web
diff options
context:
space:
mode:
authorWouter Admiraal <wouter.admiraal@sonarsource.com>2019-06-27 14:49:52 +0200
committerSonarTech <sonartech@sonarsource.com>2019-06-28 20:21:11 +0200
commit43b337dc916cdda07a54355febad23028d639162 (patch)
treead52b1b9fd3ebba9cb4c2f9a7d796edcf5588b9f /server/sonar-web
parent2098582cd1c07e385b4a08943cd7b12a6b352a09 (diff)
downloadsonarqube-43b337dc916cdda07a54355febad23028d639162.tar.gz
sonarqube-43b337dc916cdda07a54355febad23028d639162.zip
SONAR-11723 Don't pass name and email values when updating a non-local user
Diffstat (limited to 'server/sonar-web')
-rw-r--r--server/sonar-web/src/main/js/apps/users/components/UserForm.tsx6
-rw-r--r--server/sonar-web/src/main/js/apps/users/components/__tests__/UserForm-test.tsx25
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<Props, State> {
};
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<UserForm['props']> = {}) {
return shallow(
<UserForm onClose={jest.fn()} onUpdateUsers={jest.fn()} user={mockUser()} {...props} />