aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--it/it-tests/src/test/java/it/organization/OrganizationMembershipTest.java1
-rw-r--r--server/sonar-web/src/main/js/api/user_groups.js23
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/actions.js34
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/components/OrganizationGroupCheckbox.js4
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/components/OrganizationMembers.js7
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationGroupCheckbox-test.js.snap2
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationMembers-test.js.snap6
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/components/forms/AddMemberForm.js1
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/components/forms/ManageMemberGroupsForm.js14
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/components/forms/__tests__/__snapshots__/AddMemberForm-test.js.snap1
-rw-r--r--server/sonar-web/src/main/js/apps/users/components/UsersSelectSearch.js10
11 files changed, 57 insertions, 46 deletions
diff --git a/it/it-tests/src/test/java/it/organization/OrganizationMembershipTest.java b/it/it-tests/src/test/java/it/organization/OrganizationMembershipTest.java
index 4f6dbe6cc15..0b05b0ef264 100644
--- a/it/it-tests/src/test/java/it/organization/OrganizationMembershipTest.java
+++ b/it/it-tests/src/test/java/it/organization/OrganizationMembershipTest.java
@@ -223,7 +223,6 @@ public class OrganizationMembershipTest {
}
@Test
- @Ignore("To be fixed by SONAR-8994")
public void admin_can_manage_groups() {
String orgKey = createOrganization();
userRule.createUser("foo", "pwd");
diff --git a/server/sonar-web/src/main/js/api/user_groups.js b/server/sonar-web/src/main/js/api/user_groups.js
index becfdb9c8a0..de515f119b0 100644
--- a/server/sonar-web/src/main/js/api/user_groups.js
+++ b/server/sonar-web/src/main/js/api/user_groups.js
@@ -20,24 +20,23 @@
//@flow
import { getJSON, post } from '../helpers/request';
-export function searchUsersGroups(query?: string, organization?: string) {
+export function searchUsersGroups(
+ data: { f?: string, organization?: string, p?: number, ps?: number, q?: string }
+) {
const url = '/api/user_groups/search';
- const data: { q?: string, organization?: string } = {};
- if (query) {
- data.q = query;
- }
- if (organization) {
- data.organization = organization;
- }
return getJSON(url, data);
}
-export function addUserToGroup(groupId: string, login: string) {
+export function addUserToGroup(
+ data: { id?: string, name?: string, login?: string, organization?: string }
+) {
const url = '/api/user_groups/add_user';
- return post(url, { id: groupId, login });
+ return post(url, data);
}
-export function removeUserFromGroup(groupId: string, login: string) {
+export function removeUserFromGroup(
+ data: { id?: string, name?: string, login?: string, organization?: string }
+) {
const url = '/api/user_groups/remove_user';
- return post(url, { id: groupId, login });
+ return post(url, data);
}
diff --git a/server/sonar-web/src/main/js/apps/organizations/actions.js b/server/sonar-web/src/main/js/apps/organizations/actions.js
index a67d6103e3e..db5727bdd36 100644
--- a/server/sonar-web/src/main/js/apps/organizations/actions.js
+++ b/server/sonar-web/src/main/js/apps/organizations/actions.js
@@ -59,11 +59,11 @@ export const fetchOrganization = (key: string): Function =>
);
};
-export const fetchOrganizationGroups = (key: string): Function =>
+export const fetchOrganizationGroups = (organization: string): Function =>
(dispatch: Function): Promise<*> => {
- return searchUsersGroups('', key).then(
+ return searchUsersGroups({ organization }).then(
response => {
- dispatch(actions.receiveOrganizationGroups(key, response.groups));
+ dispatch(actions.receiveOrganizationGroups(organization, response.groups));
},
onFail(dispatch)
);
@@ -166,24 +166,26 @@ export const removeOrganizationMember = (key: string, member: Member) =>
};
export const updateOrganizationMemberGroups = (
+ organization: Organization,
member: Member,
add: Array<string>,
remove: Array<string>
) =>
(dispatch: Function) => {
+ dispatch(
+ receiveUser({
+ ...member,
+ groupCount: (member.groupCount || 0) + add.length - remove.length
+ })
+ );
const promises = [
- ...add.map(id => addUserToGroup(id, member.login)),
- ...remove.map(id => removeUserFromGroup(id, member.login))
+ ...add.map(name =>
+ addUserToGroup({ name, login: member.login, organization: organization.key })),
+ ...remove.map(name =>
+ removeUserFromGroup({ name, login: member.login, organization: organization.key }))
];
- return Promise.all(promises).then(
- () => {
- dispatch(
- receiveUser({
- ...member,
- groupCount: (member.groupCount || 0) + add.length - remove.length
- })
- );
- },
- onFail(dispatch)
- );
+ return Promise.all(promises).catch(error => {
+ dispatch(receiveUser(member));
+ onFail(dispatch)(error);
+ });
};
diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationGroupCheckbox.js b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationGroupCheckbox.js
index ffe6fc463ce..3324cc4ec77 100644
--- a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationGroupCheckbox.js
+++ b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationGroupCheckbox.js
@@ -32,11 +32,11 @@ export default class OrganizationGroupCheckbox extends React.PureComponent {
props: Props;
onCheck = (checked: boolean) => {
- this.props.onCheck(this.props.group.id, checked);
+ this.props.onCheck(this.props.group.name, checked);
};
toggleCheck = () => {
- this.props.onCheck(this.props.group.id, !this.props.checked);
+ this.props.onCheck(this.props.group.name, !this.props.checked);
};
render() {
diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationMembers.js b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationMembers.js
index b4448548149..49eac0e3fa7 100644
--- a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationMembers.js
+++ b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationMembers.js
@@ -39,6 +39,7 @@ type Props = {
addOrganizationMember: (organizationKey: string, member: Member) => void,
removeOrganizationMember: (organizationKey: string, member: Member) => void,
updateOrganizationMemberGroups: (
+ organization: Organization,
member: Member,
add: Array<string>,
remove: Array<string>
@@ -71,6 +72,10 @@ export default class OrganizationMembers extends React.PureComponent {
this.props.removeOrganizationMember(this.props.organization.key, member);
};
+ updateMemberGroups = (member: Member, add: Array<string>, remove: Array<string>) => {
+ this.props.updateOrganizationMemberGroups(this.props.organization, member, add, remove);
+ };
+
render() {
const { organization, status, members } = this.props;
return (
@@ -89,7 +94,7 @@ export default class OrganizationMembers extends React.PureComponent {
organizationGroups={this.props.organizationGroups}
organization={organization}
removeMember={this.removeMember}
- updateMemberGroups={this.props.updateOrganizationMemberGroups}
+ updateMemberGroups={this.updateMemberGroups}
/>
{status.total != null &&
<ListFooter
diff --git a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationGroupCheckbox-test.js.snap b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationGroupCheckbox-test.js.snap
index 2ecdb53cf0d..5ee947cf614 100644
--- a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationGroupCheckbox-test.js.snap
+++ b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationGroupCheckbox-test.js.snap
@@ -16,7 +16,7 @@ exports[`test should be able to toggle check 1`] = `
exports[`test should be able to toggle check 2`] = `
Array [
Array [
- "7",
+ "professionals",
false,
],
]
diff --git a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationMembers-test.js.snap b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationMembers-test.js.snap
index bcd0da07201..ccec13399d5 100644
--- a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationMembers-test.js.snap
+++ b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationMembers-test.js.snap
@@ -29,7 +29,8 @@ exports[`test should not render actions for non admin 1`] = `
"name": "Foo",
}
}
- removeMember={[Function]} />
+ removeMember={[Function]}
+ updateMemberGroups={[Function]} />
<ListFooter
count={2}
loadMore={[Function]}
@@ -80,7 +81,8 @@ exports[`test should render actions for admin 1`] = `
"name": "Foo",
}
}
- removeMember={[Function]} />
+ removeMember={[Function]}
+ updateMemberGroups={[Function]} />
<ListFooter
count={2}
loadMore={[Function]}
diff --git a/server/sonar-web/src/main/js/apps/organizations/components/forms/AddMemberForm.js b/server/sonar-web/src/main/js/apps/organizations/components/forms/AddMemberForm.js
index c478be943d5..f1fafe1a2e0 100644
--- a/server/sonar-web/src/main/js/apps/organizations/components/forms/AddMemberForm.js
+++ b/server/sonar-web/src/main/js/apps/organizations/components/forms/AddMemberForm.js
@@ -78,6 +78,7 @@ export default class AddMemberForm extends React.PureComponent {
<div className="modal-large-field">
<label>{translate('users.search_description')}</label>
<UsersSelectSearch
+ autoFocus={true}
selectedUser={this.state.selectedMember}
excludedUsers={this.props.memberLogins}
searchUsers={searchUsers}
diff --git a/server/sonar-web/src/main/js/apps/organizations/components/forms/ManageMemberGroupsForm.js b/server/sonar-web/src/main/js/apps/organizations/components/forms/ManageMemberGroupsForm.js
index 14243d37f04..4021f1a5ade 100644
--- a/server/sonar-web/src/main/js/apps/organizations/components/forms/ManageMemberGroupsForm.js
+++ b/server/sonar-web/src/main/js/apps/organizations/components/forms/ManageMemberGroupsForm.js
@@ -60,13 +60,13 @@ export default class ManageMemberGroupsForm extends React.PureComponent {
loadUserGroups = () => {
this.setState({ loading: true });
getUserGroups(this.props.member.login, this.props.organization.key).then(response => {
- this.setState({ loading: false, userGroups: keyBy(response.groups, 'id') });
+ this.setState({ loading: false, userGroups: keyBy(response.groups, 'name') });
});
};
- isGroupSelected = (groupId: string) => {
+ isGroupSelected = (groupName: string) => {
if (this.state.userGroups) {
- const group = this.state.userGroups[groupId] || {};
+ const group = this.state.userGroups[groupName] || {};
if (group.status) {
return group.status === 'add';
} else {
@@ -76,17 +76,17 @@ export default class ManageMemberGroupsForm extends React.PureComponent {
return false;
};
- onCheck = (groupId: string, checked: boolean) => {
+ onCheck = (groupName: string, checked: boolean) => {
this.setState((prevState: State) => {
const userGroups = prevState.userGroups || {};
- const group = userGroups[groupId] || {};
+ const group = userGroups[groupName] || {};
let status = '';
if (group.selected && !checked) {
status = 'remove';
} else if (!group.selected && checked) {
status = 'add';
}
- return { userGroups: { ...userGroups, [groupId]: { ...group, status } } };
+ return { userGroups: { ...userGroups, [groupName]: { ...group, status } } };
});
};
@@ -125,7 +125,7 @@ export default class ManageMemberGroupsForm extends React.PureComponent {
<OrganizationGroupCheckbox
key={group.id}
group={group}
- checked={this.isGroupSelected(group.id)}
+ checked={this.isGroupSelected(group.name)}
onCheck={this.onCheck}
/>
))}
diff --git a/server/sonar-web/src/main/js/apps/organizations/components/forms/__tests__/__snapshots__/AddMemberForm-test.js.snap b/server/sonar-web/src/main/js/apps/organizations/components/forms/__tests__/__snapshots__/AddMemberForm-test.js.snap
index 8cae5645817..51167b86dcd 100644
--- a/server/sonar-web/src/main/js/apps/organizations/components/forms/__tests__/__snapshots__/AddMemberForm-test.js.snap
+++ b/server/sonar-web/src/main/js/apps/organizations/components/forms/__tests__/__snapshots__/AddMemberForm-test.js.snap
@@ -36,6 +36,7 @@ exports[`test should render and open the modal 2`] = `
users.search_description
</label>
<UsersSelectSearch
+ autoFocus={true}
excludedUsers={
Array [
"admin",
diff --git a/server/sonar-web/src/main/js/apps/users/components/UsersSelectSearch.js b/server/sonar-web/src/main/js/apps/users/components/UsersSelectSearch.js
index 4fdecd3935e..96cc5da6e53 100644
--- a/server/sonar-web/src/main/js/apps/users/components/UsersSelectSearch.js
+++ b/server/sonar-web/src/main/js/apps/users/components/UsersSelectSearch.js
@@ -35,16 +35,17 @@ export type Option = {
};
type Props = {
- selectedUser?: Option,
+ autoFocus?: boolean,
excludedUsers: Array<string>,
+ handleValueChange: (Option) => void,
searchUsers: (string, number) => Promise<*>,
- handleValueChange: (Option) => void
+ selectedUser?: Option
};
type State = {
- searchResult: Array<Option>,
isLoading: boolean,
- search: string
+ search: string,
+ searchResult: Array<Option>
};
const LIST_SIZE = 10;
@@ -88,6 +89,7 @@ export default class UsersSelectSearch extends React.PureComponent {
: translate('no_results');
return (
<Select
+ autofocus={this.props.autoFocus}
className="Select-big"
options={this.state.searchResult}
isLoading={this.state.isLoading}