mirror of
https://github.com/ansible/awx.git
synced 2026-05-14 04:47:44 -02:30
Use organization api to create users
This ensures that the user will be related to the chosen organization when it is created.
This commit is contained in:
@@ -15,6 +15,10 @@ class Organizations extends InstanceGroupsMixin(NotificationsMixin(Base)) {
|
|||||||
readTeams(id, params) {
|
readTeams(id, params) {
|
||||||
return this.http.get(`${this.baseUrl}${id}/teams/`, { params });
|
return this.http.get(`${this.baseUrl}${id}/teams/`, { params });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createUser(id, data) {
|
||||||
|
return this.http.post(`${this.baseUrl}${id}/users/`, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Organizations;
|
export default Organizations;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { useHistory } from 'react-router-dom';
|
|||||||
import { Card, PageSection } from '@patternfly/react-core';
|
import { Card, PageSection } from '@patternfly/react-core';
|
||||||
import { CardBody } from '../../../components/Card';
|
import { CardBody } from '../../../components/Card';
|
||||||
import UserForm from '../shared/UserForm';
|
import UserForm from '../shared/UserForm';
|
||||||
import { UsersAPI } from '../../../api';
|
import { OrganizationsAPI } from '../../../api';
|
||||||
|
|
||||||
function UserAdd() {
|
function UserAdd() {
|
||||||
const [formSubmitError, setFormSubmitError] = useState(null);
|
const [formSubmitError, setFormSubmitError] = useState(null);
|
||||||
@@ -11,10 +11,11 @@ function UserAdd() {
|
|||||||
|
|
||||||
const handleSubmit = async values => {
|
const handleSubmit = async values => {
|
||||||
setFormSubmitError(null);
|
setFormSubmitError(null);
|
||||||
|
const { organization, ...userValues } = values;
|
||||||
try {
|
try {
|
||||||
const {
|
const {
|
||||||
data: { id },
|
data: { id },
|
||||||
} = await UsersAPI.create(values);
|
} = await OrganizationsAPI.createUser(organization, userValues);
|
||||||
history.push(`/users/${id}/details`);
|
history.push(`/users/${id}/details`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setFormSubmitError(error);
|
setFormSubmitError(error);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
waitForElement,
|
waitForElement,
|
||||||
} from '../../../../testUtils/enzymeHelpers';
|
} from '../../../../testUtils/enzymeHelpers';
|
||||||
import UserAdd from './UserAdd';
|
import UserAdd from './UserAdd';
|
||||||
import { UsersAPI } from '../../../api';
|
import { OrganizationsAPI } from '../../../api';
|
||||||
|
|
||||||
jest.mock('../../../api');
|
jest.mock('../../../api');
|
||||||
let wrapper;
|
let wrapper;
|
||||||
@@ -16,7 +16,7 @@ describe('<UserAdd />', () => {
|
|||||||
await act(async () => {
|
await act(async () => {
|
||||||
wrapper = mountWithContexts(<UserAdd />);
|
wrapper = mountWithContexts(<UserAdd />);
|
||||||
});
|
});
|
||||||
UsersAPI.create.mockResolvedValueOnce({ data: {} });
|
OrganizationsAPI.createUser.mockResolvedValueOnce({ data: {} });
|
||||||
const updatedUserData = {
|
const updatedUserData = {
|
||||||
username: 'sysadmin',
|
username: 'sysadmin',
|
||||||
email: 'sysadmin@ansible.com',
|
email: 'sysadmin@ansible.com',
|
||||||
@@ -30,7 +30,11 @@ describe('<UserAdd />', () => {
|
|||||||
await act(async () => {
|
await act(async () => {
|
||||||
wrapper.find('UserForm').prop('handleSubmit')(updatedUserData);
|
wrapper.find('UserForm').prop('handleSubmit')(updatedUserData);
|
||||||
});
|
});
|
||||||
expect(UsersAPI.create).toHaveBeenCalledWith(updatedUserData);
|
|
||||||
|
const { organization, ...userData } = updatedUserData;
|
||||||
|
expect(OrganizationsAPI.createUser.mock.calls).toEqual([
|
||||||
|
[organization, userData],
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should navigate to users list when cancel is clicked', async () => {
|
test('should navigate to users list when cancel is clicked', async () => {
|
||||||
@@ -58,7 +62,7 @@ describe('<UserAdd />', () => {
|
|||||||
is_superuser: true,
|
is_superuser: true,
|
||||||
is_system_auditor: false,
|
is_system_auditor: false,
|
||||||
};
|
};
|
||||||
UsersAPI.create.mockResolvedValueOnce({
|
OrganizationsAPI.createUser.mockResolvedValueOnce({
|
||||||
data: {
|
data: {
|
||||||
id: 5,
|
id: 5,
|
||||||
...userData,
|
...userData,
|
||||||
|
|||||||
Reference in New Issue
Block a user