mirror of https://github.com/portainer/portainer
fix(analytics): load public settings [EE-3590] (#7128)
parent
1551b02fde
commit
95f706aabe
|
@ -30,6 +30,19 @@ type publicSettingsResponse struct {
|
|||
KubeconfigExpiry string `example:"24h" default:"0"`
|
||||
// Whether team sync is enabled
|
||||
TeamSync bool `json:"TeamSync" example:"true"`
|
||||
|
||||
Edge struct {
|
||||
// Whether the device has been started in edge async mode
|
||||
AsyncMode bool
|
||||
// The ping interval for edge agent - used in edge async mode [seconds]
|
||||
PingInterval int `json:"PingInterval" example:"60"`
|
||||
// The snapshot interval for edge agent - used in edge async mode [seconds]
|
||||
SnapshotInterval int `json:"SnapshotInterval" example:"60"`
|
||||
// The command list interval for edge agent - used in edge async mode [seconds]
|
||||
CommandInterval int `json:"CommandInterval" example:"60"`
|
||||
// The check in interval for edge agent (in seconds) - used in non async mode [seconds]
|
||||
CheckinInterval int `example:"60"`
|
||||
}
|
||||
}
|
||||
|
||||
// @id SettingsPublic
|
||||
|
@ -61,6 +74,13 @@ func generatePublicSettings(appSettings *portainer.Settings) *publicSettingsResp
|
|||
KubeconfigExpiry: appSettings.KubeconfigExpiry,
|
||||
Features: appSettings.FeatureFlagSettings,
|
||||
}
|
||||
|
||||
publicSettings.Edge.AsyncMode = appSettings.Edge.AsyncMode
|
||||
publicSettings.Edge.PingInterval = appSettings.Edge.PingInterval
|
||||
publicSettings.Edge.SnapshotInterval = appSettings.Edge.SnapshotInterval
|
||||
publicSettings.Edge.CommandInterval = appSettings.Edge.CommandInterval
|
||||
publicSettings.Edge.CheckinInterval = appSettings.EdgeAgentCheckinInterval
|
||||
|
||||
//if OAuth authentication is on, compose the related fields from application settings
|
||||
if publicSettings.AuthenticationMethod == portainer.AuthenticationOAuth {
|
||||
publicSettings.OAuthLogoutURI = appSettings.OAuthSettings.LogoutURI
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import _ from 'lodash';
|
||||
|
||||
import { useSettings } from '@/portainer/settings/queries';
|
||||
import { usePublicSettings } from '@/portainer/settings/queries';
|
||||
|
||||
const categories = [
|
||||
'docker',
|
||||
|
@ -64,7 +64,9 @@ export function push(
|
|||
}
|
||||
|
||||
export function useAnalytics() {
|
||||
const telemetryQuery = useSettings((settings) => settings.EnableTelemetry);
|
||||
const telemetryQuery = usePublicSettings({
|
||||
select: (settings) => settings.EnableTelemetry,
|
||||
});
|
||||
|
||||
return { trackEvent: handleTrackEvent };
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@ import clsx from 'clsx';
|
|||
|
||||
import { isoDateFromTimestamp } from '@/portainer/filters/filters';
|
||||
import { Environment } from '@/portainer/environments/types';
|
||||
import { useSettings } from '@/portainer/settings/queries';
|
||||
import { Settings } from '@/portainer/settings/types';
|
||||
import { usePublicSettings } from '@/portainer/settings/queries';
|
||||
import { PublicSettingsViewModel } from '@/portainer/models/settings';
|
||||
|
||||
interface Props {
|
||||
showLastCheckInDate?: boolean;
|
||||
|
@ -58,7 +58,7 @@ export function EdgeIndicator({
|
|||
}
|
||||
|
||||
function useHasHeartbeat(environment: Environment, associated: boolean) {
|
||||
const settingsQuery = useSettings(undefined, associated);
|
||||
const settingsQuery = usePublicSettings({ enabled: associated });
|
||||
|
||||
if (!associated) {
|
||||
return false;
|
||||
|
@ -81,7 +81,10 @@ function useHasHeartbeat(environment: Environment, associated: boolean) {
|
|||
return false;
|
||||
}
|
||||
|
||||
function getCheckinInterval(environment: Environment, settings: Settings) {
|
||||
function getCheckinInterval(
|
||||
environment: Environment,
|
||||
settings: PublicSettingsViewModel
|
||||
) {
|
||||
const asyncMode = environment.Edge.AsyncMode;
|
||||
|
||||
if (asyncMode) {
|
||||
|
@ -104,7 +107,7 @@ function getCheckinInterval(environment: Environment, settings: Settings) {
|
|||
!environment.EdgeCheckinInterval ||
|
||||
environment.EdgeCheckinInterval === 0
|
||||
) {
|
||||
return settings.EdgeAgentCheckinInterval;
|
||||
return settings.Edge.CheckinInterval;
|
||||
}
|
||||
|
||||
return environment.EdgeCheckinInterval;
|
||||
|
|
|
@ -30,9 +30,9 @@ export function KubeconfigPrompt({
|
|||
const [page, setPage] = useState(1);
|
||||
const [pageLimit, setPageLimit] = usePaginationLimitState(storageKey);
|
||||
|
||||
const expiryQuery = usePublicSettings((settings) =>
|
||||
expiryMessage(settings.KubeconfigExpiry)
|
||||
);
|
||||
const expiryQuery = usePublicSettings({
|
||||
select: (settings) => expiryMessage(settings.KubeconfigExpiry),
|
||||
});
|
||||
|
||||
const { selection, toggle: toggleSelection, selectionSize } = useSelection();
|
||||
const { environments, totalCount } = useEnvironmentList({
|
||||
|
|
|
@ -34,6 +34,8 @@ export function PublicSettingsViewModel(settings) {
|
|||
this.EnableTelemetry = settings.EnableTelemetry;
|
||||
this.OAuthLogoutURI = settings.OAuthLogoutURI;
|
||||
this.KubeconfigExpiry = settings.KubeconfigExpiry;
|
||||
this.Features = settings.Features;
|
||||
this.Edge = new EdgeSettingsViewModel(settings.Edge);
|
||||
}
|
||||
|
||||
export function InternalAuthSettingsViewModel(data) {
|
||||
|
@ -75,3 +77,11 @@ export function OAuthSettingsViewModel(data) {
|
|||
this.SSO = data.SSO;
|
||||
this.LogoutURI = data.LogoutURI;
|
||||
}
|
||||
|
||||
export function EdgeSettingsViewModel(data = {}) {
|
||||
this.CheckinInterval = data.CheckinInterval;
|
||||
this.PingInterval = data.PingInterval;
|
||||
this.SnapshotInterval = data.SnapshotInterval;
|
||||
this.CommandInterval = data.CommandInterval;
|
||||
this.AsyncMode = data.AsyncMode;
|
||||
}
|
||||
|
|
|
@ -15,12 +15,17 @@ import {
|
|||
} from './settings.service';
|
||||
import { Settings } from './types';
|
||||
|
||||
export function usePublicSettings<T = PublicSettingsViewModel>(
|
||||
select?: (settings: PublicSettingsViewModel) => T
|
||||
) {
|
||||
export function usePublicSettings<T = PublicSettingsViewModel>({
|
||||
enabled,
|
||||
select,
|
||||
}: {
|
||||
select?: (settings: PublicSettingsViewModel) => T;
|
||||
enabled?: boolean;
|
||||
} = {}) {
|
||||
return useQuery(['settings', 'public'], () => getPublicSettings(), {
|
||||
select,
|
||||
...withError('Unable to retrieve public settings'),
|
||||
enabled,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@ interface Props {
|
|||
}
|
||||
|
||||
export function SettingsSidebar({ isAdmin }: Props) {
|
||||
const teamSyncQuery = usePublicSettings<boolean>(
|
||||
(settings) => settings.TeamSync
|
||||
);
|
||||
const teamSyncQuery = usePublicSettings<boolean>({
|
||||
select: (settings) => settings.TeamSync,
|
||||
});
|
||||
|
||||
const showUsersSection =
|
||||
!window.ddExtension && (isAdmin || teamSyncQuery.data);
|
||||
|
|
Loading…
Reference in New Issue