import { SearchRulesQuery } from '../../types/rules';
import { Standards } from '../../types/security';
import { Dict, Rule, RuleActivation, RuleDetails, SnippetsByComponent } from '../../types/types';
-import { LoggedInUser, NoticeType, User } from '../../types/users';
+import { LoggedInUser, NoticeType, RestUser } from '../../types/users';
import {
addIssueComment,
bulkChangeIssues,
setIssueType,
} from '../issues';
import { getRuleDetails, searchRules } from '../rules';
-import { dismissNotice, getCurrentUser, searchUsers } from '../users';
+import { dismissNotice, getCurrentUser, getUsers } from '../users';
import { IssueData, mockIssuesList } from './data/issues';
import { mockRuleList } from './data/rules';
jest.mocked(searchIssues).mockImplementation(this.handleSearchIssues);
jest.mocked(searchIssueTags).mockImplementation(this.handleSearchIssueTags);
jest.mocked(searchRules).mockImplementation(this.handleSearchRules);
- jest.mocked(searchUsers).mockImplementation(this.handleSearchUsers);
+ jest.mocked(getUsers).mockImplementation(this.handleGetUsers);
jest.mocked(setIssueAssignee).mockImplementation(this.handleSetIssueAssignee);
jest.mocked(setIssueSeverity).mockImplementation(this.handleSetIssueSeverity);
jest.mocked(setIssueTags).mockImplementation(this.handleSetIssueTags);
);
};
- handleSearchUsers = () => {
- return this.reply({ paging: mockPaging(), users: [mockLoggedInUser() as unknown as User] });
+ handleGetUsers = () => {
+ return this.reply({
+ pageRestResponse: mockPaging(),
+ users: [mockLoggedInUser() as unknown as RestUser],
+ });
};
handleSearchIssueAuthors = () => {
} from '../../helpers/mocks/security-hotspots';
import { mockSourceLine } from '../../helpers/mocks/sources';
import { getStandards } from '../../helpers/security-standard';
-import { mockPaging, mockUser } from '../../helpers/testMocks';
+import { mockPaging, mockRestUser } from '../../helpers/testMocks';
import {
Hotspot,
HotspotAssignRequest,
HotspotResolution,
HotspotStatus,
} from '../../types/security-hotspots';
+import { RestUser } from '../../types/users';
import { getSources } from '../components';
import { getMeasures } from '../measures';
import {
getSecurityHotspots,
setSecurityHotspotStatus,
} from '../security-hotspots';
-import { searchUsers } from '../users';
+import { getUsers } from '../users';
const NUMBER_OF_LINES = 20;
jest.mocked(getSecurityHotspotList).mockImplementation(this.handleGetSecurityHotspotList);
jest.mocked(assignSecurityHotspot).mockImplementation(this.handleAssignSecurityHotspot);
jest.mocked(setSecurityHotspotStatus).mockImplementation(this.handleSetSecurityHotspotStatus);
- jest.mocked(searchUsers).mockImplementation(this.handleSearchUsers);
+ jest.mocked(getUsers).mockImplementation((p) => this.handleGetUsers(p));
jest.mocked(getSources).mockResolvedValue(
times(NUMBER_OF_LINES, (n) =>
mockSourceLine({
return Promise.resolve();
};
- handleSearchUsers = () => {
+ handleGetUsers: typeof getUsers<RestUser> = () => {
return this.reply({
users: [
- mockUser({ name: 'User John', login: 'user.john' }),
- mockUser({ name: 'User Doe', login: 'user.doe' }),
- mockUser({ name: 'User Foo', login: 'user.foo' }),
+ mockRestUser({ name: 'User John', login: 'user.john' }),
+ mockRestUser({ name: 'User Doe', login: 'user.doe' }),
+ mockRestUser({ name: 'User Foo', login: 'user.foo' }),
],
- paging: mockPaging(),
+ pageRestResponse: mockPaging(),
});
};
return getJSON('/api/users/identity_providers').catch(throwGlobalError);
}
-export function searchUsers(data: {
- p?: number;
- ps?: number;
- q?: string;
- managed?: boolean;
- lastConnectedAfter?: string;
- lastConnectedBefore?: string;
- slLastConnectedAfter?: string;
- slLastConnectedBefore?: string;
-}): Promise<{ paging: Paging; users: User[] }> {
- data.q = data.q || undefined;
- return getJSON('/api/users/search', data).catch(throwGlobalError);
-}
-
export function getUsers<T extends RestUserBase>(data: {
q: string;
active?: boolean;
import Avatar from '../../../components/ui/Avatar';
import { translate, translateWithParameters } from '../../../helpers/l10n';
import { Issue } from '../../../types/types';
-import { UserActive, isLoggedIn, isUserActive } from '../../../types/users';
+import { RestUser, isLoggedIn, isUserActive } from '../../../types/users';
import { searchAssignees } from '../utils';
// exported for test
inputId: string;
}
-function userToOption(user: UserActive) {
+function userToOption(user: RestUser) {
const userInfo = user.name || user.login;
return {
value: user.login,
isLoggedIn(currentUser) && issues.some((issue) => currentUser.login !== issue.assignee);
const defaultOptions = allowCurrentUserSelection
- ? [UNASSIGNED, userToOption(currentUser)]
+ ? [UNASSIGNED, userToOption(currentUser as unknown as RestUser)]
: [UNASSIGNED];
const controlLabel = assignee ? (
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { isArray } from 'lodash';
-import { searchUsers } from '../../api/users';
+import { getUsers } from '../../api/users';
import { formatMeasure } from '../../helpers/measures';
import {
cleanQuery,
import { MetricType } from '../../types/metrics';
import { SecurityStandard } from '../../types/security';
import { Dict, Issue, Paging, RawQuery } from '../../types/types';
-import { UserBase } from '../../types/users';
+import { RestUser } from '../../types/users';
const OWASP_ASVS_4_0 = 'owaspAsvs-4.0';
export const searchAssignees = (
query: string,
page = 1
-): Promise<{ paging: Paging; results: UserBase[] }> => {
- return searchUsers({ p: page, q: query }).then(({ paging, users }) => ({
- paging,
+): Promise<{ paging: Paging; results: RestUser[] }> => {
+ return getUsers<RestUser>({ pageIndex: page, q: query }).then(({ pageRestResponse, users }) => ({
+ paging: pageRestResponse,
results: users,
}));
};
import CodingRulesServiceMock from '../../../api/mocks/CodingRulesServiceMock';
import SecurityHotspotServiceMock from '../../../api/mocks/SecurityHotspotServiceMock';
import { getSecurityHotspots, setSecurityHotspotStatus } from '../../../api/security-hotspots';
-import { searchUsers } from '../../../api/users';
+import { getUsers } from '../../../api/users';
import { mockComponent } from '../../../helpers/mocks/component';
import { openHotspot, probeSonarLintServers } from '../../../helpers/sonarlint';
import { get, save } from '../../../helpers/storage';
await user.keyboard('User');
});
- expect(searchUsers).toHaveBeenLastCalledWith({ q: 'User' });
+ expect(getUsers).toHaveBeenLastCalledWith({ q: 'User' });
await user.keyboard('{Enter}');
expect(ui.successGlobalMessage.get()).toHaveTextContent(`hotspots.assign.success.User John`);
});
import * as React from 'react';
import { Options, SingleValue } from 'react-select';
import { assignSecurityHotspot } from '../../../api/security-hotspots';
-import { searchUsers } from '../../../api/users';
+import { getUsers } from '../../../api/users';
import { CurrentUserContext } from '../../../app/components/current-user/CurrentUserContext';
import Avatar from '../../../components/ui/Avatar';
import { addGlobalSuccessMessage } from '../../../helpers/globalMessages';
import { translate, translateWithParameters } from '../../../helpers/l10n';
import { Hotspot, HotspotResolution, HotspotStatus } from '../../../types/security-hotspots';
-import { isLoggedIn, isUserActive } from '../../../types/users';
+import { RestUser, isLoggedIn, isUserActive } from '../../../types/users';
interface Props {
hotspot: Hotspot;
query: string,
cb: (options: Options<LabelValueSelectOption<string>>) => void
) => {
- searchUsers({ q: query })
+ getUsers<RestUser>({ q: query })
.then((result) => {
const options: Array<LabelValueSelectOption<string>> = result.users
.filter(isUserActive)
import { LabelValueSelectOption, PopupZLevel, SearchSelectDropdown } from 'design-system';
import * as React from 'react';
import { Options, SingleValue } from 'react-select';
-import { searchUsers } from '../../../api/users';
+import { getUsers } from '../../../api/users';
import { CurrentUserContext } from '../../../app/components/current-user/CurrentUserContext';
import { translate, translateWithParameters } from '../../../helpers/l10n';
import { Issue } from '../../../types/types';
-import { isLoggedIn, isUserActive } from '../../../types/users';
+import { RestUser, isLoggedIn, isUserActive } from '../../../types/users';
import Avatar from '../../ui/Avatar';
interface Props {
query: string,
cb: (options: Options<LabelValueSelectOption<string>>) => void
) => {
- searchUsers({ q: query })
+ getUsers<RestUser>({ q: query })
.then((result) => {
const options: Array<LabelValueSelectOption<string>> = result.users
.filter(isUserActive)