Skip to content

Commit

Permalink
AAP-20935: Console: Use correct Admin Dashboard URL (#839)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Anstis <[email protected]>
  • Loading branch information
manstis and manstis authored Feb 26, 2024
1 parent 21733c0 commit df63b72
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 14 deletions.
5 changes: 5 additions & 0 deletions ansible_wisdom/main/settings/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@
# WCA_SECRET_DUMMY_SECRETS=1009103:valid,11009104:not-valid
WCA_SECRET_DUMMY_SECRETS = os.getenv("WCA_SECRET_DUMMY_SECRETS", "")
WCA_CLIENT_BACKEND_TYPE = os.getenv("WCA_CLIENT_BACKEND_TYPE", "dummy") # or wcaclient

# "Schema 2" Telemetry Admin Dashboard URL
TELEMETRY_ADMIN_DASHBOARD_URL = (
"https://console.stage.redhat.com/ansible/lightspeed-admin-dashboard"
)
3 changes: 3 additions & 0 deletions ansible_wisdom/main/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@

SESSION_ENGINE = "django.contrib.sessions.backends.cache"
SESSION_CACHE_ALIAS = "default"

# "Schema 2" Telemetry Admin Dashboard URL
TELEMETRY_ADMIN_DASHBOARD_URL = "https://console.redhat.com/ansible/lightspeed-admin-dashboard"
2 changes: 2 additions & 0 deletions ansible_wisdom/main/templates/console/console.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
<div id="user_name" hidden>{{user_name}}</div>
<!-- Flag whether Telemetry settings is supported -->
<div id="telemetry_schema_2_enabled" hidden>{{telemetry_schema_2_enabled}}</div>
<!-- Admin Dashboard URL -->
<div id="telemetry_schema_2_admin_dashboard_url" hidden>{{telemetry_schema_2_admin_dashboard_url}}</div>
{% endblock content %}
5 changes: 5 additions & 0 deletions ansible_wisdom/main/tests/test_console_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ def test_extra_data_telemetry_feature_enabled(self, LDClient, *args):
context = response.context_data
# The default setting for tests is True
self.assertTrue(context['telemetry_schema_2_enabled'])
self.assertEqual(
context['telemetry_schema_2_admin_dashboard_url'],
'https://console.stage.redhat.com/ansible/lightspeed-admin-dashboard',
)

@override_settings(LAUNCHDARKLY_SDK_KEY='dummy_key')
@patch.object(feature_flags, 'LDClient')
Expand All @@ -101,3 +105,4 @@ def test_extra_data_telemetry__feature_disabled(self, LDClient, *args):
self.assertIsInstance(response.context_data, dict)
context = response.context_data
self.assertFalse(context['telemetry_schema_2_enabled'])
self.assertIsNone(context.get('telemetry_schema_2_admin_dashboard_url'))
9 changes: 8 additions & 1 deletion ansible_wisdom/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,12 @@ def get_context_data(self, **kwargs):
context["rh_org_has_subscription"] = user.rh_org_has_subscription
organization = user.organization
if organization:
context["telemetry_schema_2_enabled"] = organization.is_schema_2_telemetry_enabled
is_schema_2_telemetry_enabled = organization.is_schema_2_telemetry_enabled
context["telemetry_schema_2_enabled"] = is_schema_2_telemetry_enabled

if is_schema_2_telemetry_enabled:
context[
"telemetry_schema_2_admin_dashboard_url"
] = settings.TELEMETRY_ADMIN_DASHBOARD_URL

return context
1 change: 1 addition & 0 deletions ansible_wisdom_console_react/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
<script type="module" src="/src/index.tsx"></script>
<div id="user_name" hidden>development-user</div>
<div id="telemetry_schema_2_enabled" hidden>true</div>
<div id="telemetry_schema_2_admin_dashboard_url" hidden>https://console.redhat.com/ansible/lightspeed-admin-dashboard</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"TelemetryManageUsage": "Manage telemetry usage",
"TelemetryManageUsageDescription": "Telemetry data is used to enable app usage and the ",
"TelemetryManageUsageAdminDashboardURLText": "admin dashboard.",
"TelemetryManageUsageAdminDashboardURL": "http://www.redhat.com",
"TelemetryManageUsageLearnMoreURLText": "Learn more about how Ansible Lightspeed uses data. ",
"TelemetryManageUsageLearnMoreURL": "https://access.redhat.com/documentation/en-us/red_hat_ansible_lightspeed_with_ibm_watsonx_code_assistant/2.x_latest/html/red_hat_ansible_lightspeed_with_ibm_watsonx_code_assistant_user_guide/lightspeed-intro#training-data_lightspeed-intro",
"TelemetryOptInLabel": "Admin dashboard telemetry data.",
Expand Down
7 changes: 4 additions & 3 deletions ansible_wisdom_console_react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import { PageApp } from "./PageApp";
export interface AppProps {
readonly userName: string;
readonly telemetryOptEnabled: boolean;
readonly adminDashboardUrl: string;
}

export function App(props: AppProps) {
const { t } = useTranslation();
const { userName, telemetryOptEnabled } = props;
const { userName, telemetryOptEnabled, adminDashboardUrl } = props;

const navigationItems = useMemo<PageNavigationItem[]>(() => {
const items = [
Expand All @@ -29,7 +30,7 @@ export function App(props: AppProps) {
// Telemetry
label: t("Telemetry"),
path: "telemetry",
element: <TelemetrySettings />,
element: <TelemetrySettings adminDashboardUrl={adminDashboardUrl} />,
});
}
return [
Expand All @@ -40,7 +41,7 @@ export function App(props: AppProps) {
children: items,
},
];
}, [t, telemetryOptEnabled]);
}, [t, telemetryOptEnabled, adminDashboardUrl]);

return (
<PageApp
Expand Down
12 changes: 10 additions & 2 deletions ansible_wisdom_console_react/src/TelemetrySettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ import { useTelemetry } from "./hooks/useTelemetryAPI";
import { BusyButton } from "./BusyButton";
import { Alerts, AlertsHandle } from "./Alerts";

export function TelemetrySettings() {
export interface TelemetrySettingsProps {
readonly adminDashboardUrl: string;
}

export function TelemetrySettings(props: TelemetrySettingsProps) {
const { t } = useTranslation();
const { adminDashboardUrl } = props;

const [telemetry, setTelemetry] = useState<Telemetry>({
status: "NOT_ASKED",
Expand Down Expand Up @@ -141,7 +146,10 @@ export function TelemetrySettings() {
<Text component={"h3"}>{t("TelemetryManageUsage")}</Text>
<Text component={"p"}>
{t("TelemetryManageUsageDescription")}
<a href={t("TelemetryManageUsageAdminDashboardURL")}>
<a
data-testid={"telemetry-settings__admin_dashboard_url"}
href={adminDashboardUrl}
>
{t("TelemetryManageUsageAdminDashboardURLText")}
</a>
</Text>
Expand Down
8 changes: 7 additions & 1 deletion ansible_wisdom_console_react/src/__tests__/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import { App } from "../App";
describe("App", () => {
it("Rendering::With Username", async () => {
window.history.pushState({}, "Test page", "/console");
render(<App userName={"Batman"} telemetryOptEnabled={true} />);
render(
<App
userName={"Batman"}
telemetryOptEnabled={true}
adminDashboardUrl={"http://admin_dashboard-url/"}
/>,
);
const accountMenu = await screen.findByTestId("page-masthead-dropdown");
expect(accountMenu).toBeInTheDocument();
expect(accountMenu).toHaveTextContent("Batman");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ describe("TelemetrySettings", () => {

it("Loading", async () => {
(axios.get as jest.Mock).mockResolvedValue({ optOut: "false" });
render(<TelemetrySettings />);
render(
<TelemetrySettings adminDashboardUrl={"http://admin_dashboard-url/"} />,
);
expect(axios.get as jest.Mock).toBeCalledWith(API_TELEMETRY_PATH);
expect(
await screen.findByTestId("telemetry-settings__telemetry-loading"),
Expand All @@ -24,7 +26,9 @@ describe("TelemetrySettings", () => {

it("Loaded::Found", async () => {
(axios.get as jest.Mock).mockResolvedValue({ data: { optOut: true } });
render(<TelemetrySettings />);
render(
<TelemetrySettings adminDashboardUrl={"http://admin_dashboard-url/"} />,
);
expect(axios.get as jest.Mock).toBeCalledWith(API_TELEMETRY_PATH);
expect(
await screen.findByTestId("telemetry-settings__opt_in_radiobutton"),
Expand All @@ -43,13 +47,21 @@ describe("TelemetrySettings", () => {
expect(cancelButton).toBeInTheDocument();
expect(saveButton.disabled).toBeFalsy();
expect(cancelButton.disabled).toBeTruthy();

const adminDashboardUrl: HTMLAnchorElement = await screen.findByTestId(
"telemetry-settings__admin_dashboard_url",
);
expect(adminDashboardUrl).toBeInTheDocument();
expect(adminDashboardUrl.href).toEqual("http://admin_dashboard-url/");
});

it("Click::Save::Success", async () => {
(axios.get as jest.Mock).mockResolvedValue({ data: { optOut: false } });
(axios.post as jest.Mock).mockResolvedValue({});

render(<TelemetrySettings />);
render(
<TelemetrySettings adminDashboardUrl={"http://admin_dashboard-url/"} />,
);

// Check initial settings
let optInRadioButton: HTMLInputElement = await screen.findByTestId(
Expand Down Expand Up @@ -100,7 +112,9 @@ describe("TelemetrySettings", () => {
(axios.get as jest.Mock).mockResolvedValue({ data: { optOut: false } });
(axios.post as jest.Mock).mockRejectedValue({ response: { status: 500 } });

render(<TelemetrySettings />);
render(
<TelemetrySettings adminDashboardUrl={"http://admin_dashboard-url/"} />,
);

// Emulate click on "Opt Out" radio button
const optOutRadioButton: HTMLInputElement = await screen.findByTestId(
Expand Down Expand Up @@ -128,7 +142,9 @@ describe("TelemetrySettings", () => {
it("Click::Cancel", async () => {
(axios.get as jest.Mock).mockResolvedValue({ data: { optOut: false } });

render(<TelemetrySettings />);
render(
<TelemetrySettings adminDashboardUrl={"http://admin_dashboard-url/"} />,
);

// Check initial settings
let optInRadioButton: HTMLInputElement = await screen.findByTestId(
Expand Down
9 changes: 8 additions & 1 deletion ansible_wisdom_console_react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ const telemetrySchema2EnabledInnerText = document.getElementById(
)?.innerText;
const telemetrySchema2Enabled =
telemetrySchema2EnabledInnerText?.toLowerCase() === "true";
const adminDashboardUrl =
document.getElementById("telemetry_schema_2_admin_dashboard_url")
?.innerText ?? "";

createRoot(document.getElementById("root") as HTMLElement).render(
<StrictMode>
<App userName={userName} telemetryOptEnabled={telemetrySchema2Enabled} />
<App
userName={userName}
telemetryOptEnabled={telemetrySchema2Enabled}
adminDashboardUrl={adminDashboardUrl}
/>
</StrictMode>,
);

1 comment on commit df63b72

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ClamAV Virus Definition DB Files:
----
total 228212
-rw-r--r--  1 root root 170479789 Feb 26 06:07 main.cvd
-rw-r--r--  1 root root        69 Feb 26 06:07 freshclam.dat
-rw-r--r--  1 root root  62887086 Feb 26 06:07 daily.cvd
-rw-r--r--  1 root root    291965 Feb 26 06:07 bytecode.cvd
drwxr-xr-x 16 root root      4096 Feb 26 19:53 ..
drwxr-xr-x  2 root root      4096 Feb 26 19:53 .
----
File: /var/lib/clamav/bytecode.cvd
Build time: 22 Feb 2023 16:33 -0500
Version: 334
Signatures: 91
Functionality level: 90
Builder: anvilleg
MD5: 0464067a252b1e937012ad34e811065f
Digital signature: urVBCbhJcz8v6i1E6HedDwa8TxBHnJknqg7SE+6JWBtovATpw8MWwS+kvGAi//x5u0LIFwhPvUsgEBBeFiZE0QTTWazOhJ/LfKJK+nODqha6cTvaQdKl2rSbEOv6grv7UONV8eKi383Wv07wfSNYp+lPNpt0QmejKb1TMHAYTA
Verification OK.
----
File: /var/lib/clamav/daily.cvd
Build time: 25 Feb 2024 04:29 -0500
Version: 27196
Signatures: 2054014
Functionality level: 90
Builder: raynman
MD5: 7f0c3cf76d7ef208d74c5557e00e2bc0
Digital signature: Vy3FG4hCth4kqHqa5PPaxWlQ4Q3YOil5fjKYzQrOjrOSY7lZtX7U1zFoOkHEy0RkbTV9MO/8/8qd5OjPLlyOE8gRaivmOv6w4GIcBLl7KKg8EcAmhki3ebX1N2z3TPIkft5sXhBtIJZUM6A78R6LC6exZ0PpKLcNd9IS+pXQSnb
Verification OK.
----
File: /var/lib/clamav/main.cvd
Build time: 16 Sep 2021 08:32 -0400
Version: 62
Signatures: 6647427
Functionality level: 90
Builder: sigmgr
MD5: 137eccce31aacb21b5a98bb8c21cefd6
Digital signature: twaJBls8V5q64R7QY10AatEtPNuPWoVoxTaNO1jpBg7s5jIMMXpitgG1000YLp6rb0TWkEKjRqxneGTxuxWaWm7XBjsgwX2BRWh/y4fhs7uyImdKRLzQ5y8e2EkSChegF/i8clqfn+1qetq9j4gbktJ3JZpOXPoHlyr2Dv9S/Bg
Verification OK.
----
Scanning Results:
ClamAV 1.0.5/27196/Sun Feb 25 09:29:27 2024
LibClamAV Warning: Max file-size was set to 4194304000 bytes. Unfortunately, scanning files greater than 2147483647 bytes (2 GiB - 1) is not supported.

----------- SCAN SUMMARY -----------
Known viruses: 8685882
Engine version: 1.0.5
Scanned directories: 30964
Scanned files: 190046
Infected files: 0
Data scanned: 6455.49 MB
Data read: 3413.39 MB (ratio 1.89:1)
Time: 2350.026 sec (39 m 10 s)
Start Date: 2024:02:26 19:56:01
End Date:   2024:02:26 20:35:11

Please sign in to comment.