select intiator in filters when you don't have permission to search users.

This commit is contained in:
Dan 2023-03-13 11:50:18 -04:00
parent 91679845dd
commit ce4eb56a60
4 changed files with 61 additions and 19 deletions

View File

@ -15,4 +15,4 @@ if app.config["ENV"] != "production":
app.register_blueprint(proxy_blueprint) app.register_blueprint(proxy_blueprint)
if __name__ == "__main__": if __name__ == "__main__":
app.run(host="localhost", port=5000) app.run(host="localhost", port=7004)

View File

@ -272,6 +272,7 @@ def process_instance_list_for_me(
with_relation_to_me=True, with_relation_to_me=True,
report_columns=report_columns, report_columns=report_columns,
report_filter_by=report_filter_by, report_filter_by=report_filter_by,
process_initiator_username=process_initiator_username,
) )

View File

@ -37,6 +37,7 @@ import {
modifyProcessIdentifierForPathParam, modifyProcessIdentifierForPathParam,
refreshAtInterval, refreshAtInterval,
} from '../helpers'; } from '../helpers';
import { useUriListForPermissions } from '../hooks/UriListForPermissions';
import PaginationForTable from './PaginationForTable'; import PaginationForTable from './PaginationForTable';
import 'react-datepicker/dist/react-datepicker.css'; import 'react-datepicker/dist/react-datepicker.css';
@ -56,6 +57,7 @@ import {
ReportFilter, ReportFilter,
User, User,
ErrorForDisplay, ErrorForDisplay,
PermissionsToCheck,
} from '../interfaces'; } from '../interfaces';
import ProcessModelSearch from './ProcessModelSearch'; import ProcessModelSearch from './ProcessModelSearch';
import ProcessInstanceReportSearch from './ProcessInstanceReportSearch'; import ProcessInstanceReportSearch from './ProcessInstanceReportSearch';
@ -63,6 +65,8 @@ import ProcessInstanceListDeleteReport from './ProcessInstanceListDeleteReport';
import ProcessInstanceListSaveAsReport from './ProcessInstanceListSaveAsReport'; import ProcessInstanceListSaveAsReport from './ProcessInstanceListSaveAsReport';
import { Notification } from './Notification'; import { Notification } from './Notification';
import useAPIError from '../hooks/UseApiError'; import useAPIError from '../hooks/UseApiError';
import { usePermissionFetcher } from '../hooks/PermissionService';
import { Can } from '../contexts/Can';
const REFRESH_INTERVAL = 5; const REFRESH_INTERVAL = 5;
const REFRESH_TIMEOUT = 600; const REFRESH_TIMEOUT = 600;
@ -107,6 +111,13 @@ export default function ProcessInstanceListTable({
const navigate = useNavigate(); const navigate = useNavigate();
const { addError, removeError } = useAPIError(); const { addError, removeError } = useAPIError();
const { targetUris } = useUriListForPermissions();
const permissionRequestData: PermissionsToCheck = {
[targetUris.userSearch]: ['GET'],
};
const { ability } = usePermissionFetcher(permissionRequestData);
const canSearchUsers: boolean = ability.can('GET', targetUris.userSearch);
const [processInstances, setProcessInstances] = useState([]); const [processInstances, setProcessInstances] = useState([]);
const [reportMetadata, setReportMetadata] = useState<ReportMetadata | null>(); const [reportMetadata, setReportMetadata] = useState<ReportMetadata | null>();
const [pagination, setPagination] = useState<PaginationObject | null>(null); const [pagination, setPagination] = useState<PaginationObject | null>(null);
@ -167,6 +178,9 @@ export default function ProcessInstanceListTable({
useState<string[]>([]); useState<string[]>([]);
const [processInitiatorSelection, setProcessInitiatorSelection] = const [processInitiatorSelection, setProcessInitiatorSelection] =
useState<User | null>(null); useState<User | null>(null);
const [processInitiatorText, setProcessInitiatorText] =
useState<string | null>(null);
const lastRequestedInitatorSearchTerm = useRef<string>(); const lastRequestedInitatorSearchTerm = useRef<string>();
const dateParametersToAlwaysFilterBy: dateParameters = useMemo(() => { const dateParametersToAlwaysFilterBy: dateParameters = useMemo(() => {
@ -202,7 +216,7 @@ export default function ProcessInstanceListTable({
}; };
const searchForProcessInitiator = (inputText: string) => { const searchForProcessInitiator = (inputText: string) => {
if (inputText) { if (inputText && canSearchUsers) {
lastRequestedInitatorSearchTerm.current = inputText; lastRequestedInitatorSearchTerm.current = inputText;
HttpService.makeCallToBackend({ HttpService.makeCallToBackend({
path: `/users/search?username_prefix=${inputText}`, path: `/users/search?username_prefix=${inputText}`,
@ -590,8 +604,11 @@ export default function ProcessInstanceListTable({
if (processInitiatorSelection) { if (processInitiatorSelection) {
queryParamString += `&process_initiator_username=${processInitiatorSelection.username}`; queryParamString += `&process_initiator_username=${processInitiatorSelection.username}`;
} else if (processInitiatorText) {
queryParamString += `&process_initiator_username=${processInitiatorText}`;
} }
const reportColumnsBase64 = encodeBase64(JSON.stringify(reportColumns())); const reportColumnsBase64 = encodeBase64(JSON.stringify(reportColumns()));
queryParamString += `&report_columns=${reportColumnsBase64}`; queryParamString += `&report_columns=${reportColumnsBase64}`;
const reportFilterByBase64 = encodeBase64(JSON.stringify(reportFilterBy())); const reportFilterByBase64 = encodeBase64(JSON.stringify(reportFilterBy()));
@ -1077,6 +1094,15 @@ export default function ProcessInstanceListTable({
/> />
</Column> </Column>
<Column md={4}> <Column md={4}>
<Can
I="GET"
a={targetUris.userSearch}
ability={ability}
passThrough
>
{(hasAccess: boolean) => {
if (hasAccess) {
return (
<ComboBox <ComboBox
onInputChange={searchForProcessInitiator} onInputChange={searchForProcessInitiator}
onChange={(event: any) => { onChange={(event: any) => {
@ -1091,10 +1117,25 @@ export default function ProcessInstanceListTable({
} }
return null; return null;
}} }}
placeholder="Starting typing username" placeholder="Start typing username"
titleText="Process Initiator" titleText="Process Initiator"
selectedItem={processInitiatorSelection} selectedItem={processInitiatorSelection}
/> />
);
} else {
return (
<TextInput
id="process-instance-initiator-search"
placeholder="Enter username"
labelText="Process Initiator"
onChange={(event: any) =>
setProcessInitiatorText(event.target.value)
}
/>
);
}
}}
</Can>
</Column> </Column>
<Column md={4}>{processStatusSearch()}</Column> <Column md={4}>{processStatusSearch()}</Column>
</Grid> </Grid>
@ -1248,7 +1289,6 @@ export default function ProcessInstanceListTable({
</td> </td>
); );
} }
console.log(column.accessor);
if (column.accessor === 'process_model_display_name') { if (column.accessor === 'process_model_display_name') {
const pmStyle = { background: 'rgba(0, 0, 0, .02)' }; const pmStyle = { background: 'rgba(0, 0, 0, .02)' };
return ( return (

View File

@ -29,6 +29,7 @@ export const useUriListForPermissions = () => {
processModelPublishPath: `/v1.0/process-models/${params.process_model_id}/publish`, processModelPublishPath: `/v1.0/process-models/${params.process_model_id}/publish`,
processModelShowPath: `/v1.0/process-models/${params.process_model_id}`, processModelShowPath: `/v1.0/process-models/${params.process_model_id}`,
secretListPath: `/v1.0/secrets`, secretListPath: `/v1.0/secrets`,
userSearch: `/v1.0/users/search`,
}; };
}, [params]); }, [params]);