mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 17:08:53 +00:00
Fleet UI: [bug fix for release] Team admin and team maintainer can edit query (#14603)
This commit is contained in:
parent
436733763a
commit
c84ef31ed9
3 changed files with 33 additions and 5 deletions
|
|
@ -376,7 +376,7 @@ const AppProvider = ({ children }: Props): JSX.Element => {
|
|||
isTeamObserver: state.isTeamObserver,
|
||||
isTeamMaintainer: state.isTeamMaintainer,
|
||||
isTeamAdmin: state.isTeamAdmin,
|
||||
isTeamMaintainerOrTeamAdmin: state.isTeamMaintainer,
|
||||
isTeamMaintainerOrTeamAdmin: state.isTeamMaintainerOrTeamAdmin,
|
||||
isAnyTeamAdmin: state.isAnyTeamAdmin,
|
||||
isOnlyObserver: state.isOnlyObserver,
|
||||
isObserverPlus: state.isObserverPlus,
|
||||
|
|
|
|||
|
|
@ -49,11 +49,12 @@ const baseClass = "query-details-page";
|
|||
|
||||
const QueryDetailsPage = ({
|
||||
router,
|
||||
params: { id: paramsQueryId },
|
||||
params: { id: paramsQueryId, team_id: paramsTeamId },
|
||||
location,
|
||||
}: IQueryDetailsPageProps): JSX.Element => {
|
||||
const queryId = parseInt(paramsQueryId, 10);
|
||||
const queryParams = location.query;
|
||||
const teamId = parseInt(paramsTeamId, 10);
|
||||
|
||||
// Functions to avoid race conditions
|
||||
const serverSortBy: ISortOption[] = (() => {
|
||||
|
|
@ -74,6 +75,8 @@ const QueryDetailsPage = ({
|
|||
isAnyTeamObserverPlus,
|
||||
config,
|
||||
filteredQueriesPath,
|
||||
availableTeams,
|
||||
setCurrentTeam,
|
||||
} = useContext(AppContext);
|
||||
const {
|
||||
lastEditedQueryName,
|
||||
|
|
@ -151,6 +154,16 @@ const QueryDetailsPage = ({
|
|||
}
|
||||
);
|
||||
|
||||
// Used to set host's team in AppContext for RBAC action buttons
|
||||
useEffect(() => {
|
||||
if (storedQuery?.team_id) {
|
||||
const querysTeam = availableTeams?.find(
|
||||
(team) => team.id === storedQuery.team_id
|
||||
);
|
||||
setCurrentTeam(querysTeam);
|
||||
}
|
||||
}, [storedQuery]);
|
||||
|
||||
const isLoading = isStoredQueryLoading || isQueryReportLoading;
|
||||
const isApiError = storedQueryError || queryReportError;
|
||||
const isClipped =
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ const EditQueryPage = ({
|
|||
setLastEditedQueryPlatforms,
|
||||
setLastEditedQueryDiscardData,
|
||||
} = useContext(QueryContext);
|
||||
const { setConfig } = useContext(AppContext);
|
||||
const { setConfig, availableTeams, setCurrentTeam } = useContext(AppContext);
|
||||
const { renderFlash } = useContext(NotificationContext);
|
||||
|
||||
const [isLiveQueryRunnable, setIsLiveQueryRunnable] = useState(true);
|
||||
|
|
@ -145,6 +145,16 @@ const EditQueryPage = ({
|
|||
}
|
||||
);
|
||||
|
||||
// Used to set host's team in AppContext for RBAC actions
|
||||
useEffect(() => {
|
||||
if (storedQuery?.team_id) {
|
||||
const querysTeam = availableTeams?.find(
|
||||
(team) => team.id === storedQuery.team_id
|
||||
);
|
||||
setCurrentTeam(querysTeam);
|
||||
}
|
||||
}, [storedQuery]);
|
||||
|
||||
const detectIsFleetQueryRunnable = () => {
|
||||
statusAPI.live_query().catch(() => {
|
||||
setIsLiveQueryRunnable(false);
|
||||
|
|
@ -157,10 +167,15 @@ const EditQueryPage = ({
|
|||
const canEditExistingQuery =
|
||||
isGlobalAdmin || isGlobalMaintainer || isTeamMaintainerOrTeamAdmin;
|
||||
|
||||
if (queryId && queryId > 0 && !canEditExistingQuery) {
|
||||
if (
|
||||
!isStoredQueryLoading && // Confirms teamId for storedQuery before RBAC reroute
|
||||
queryId &&
|
||||
queryId > 0 &&
|
||||
!canEditExistingQuery
|
||||
) {
|
||||
router.push(PATHS.QUERY(queryId));
|
||||
}
|
||||
}, [queryId, isTeamMaintainerOrTeamAdmin]);
|
||||
}, [queryId, isTeamMaintainerOrTeamAdmin, isStoredQueryLoading]);
|
||||
|
||||
useEffect(() => {
|
||||
detectIsFleetQueryRunnable();
|
||||
|
|
|
|||
Loading…
Reference in a new issue