Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7eb134a

Browse files
committed
linting
fixed some actions that did not have bearer token auth update some ui packages
1 parent 1f97313 commit 7eb134a

10 files changed

Lines changed: 188 additions & 49 deletions

File tree

ui/package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"@storybook/addons": "^5.0.11",
1717
"@storybook/react": "^5.0.11",
1818
"babel-runtime": "^6.26.0",
19-
"tslint": "^5.7.0",
20-
"webpack-bundle-analyzer": "^3.0.3",
19+
"tslint": "^5.17.0",
20+
"webpack-bundle-analyzer": "^3.3.2",
2121
"webpack-cli": "^3.1.2",
2222
"webpack-dev-server": "^3.1.4",
2323
"webpack-hot-middleware": "^2.18.2"
@@ -41,18 +41,18 @@
4141
"@types/react-hot-loader": "^4.1.0",
4242
"@types/react-redux": "^7.0.9",
4343
"@types/react-router": "^5.0.0",
44-
"@types/react-router-dom": "^4.3.1",
45-
"@types/react-table": "^6.7.17",
46-
"@types/recompose": "^0.30.2",
47-
"@types/redux-devtools": "^3.0.38",
44+
"@types/react-router-dom": "^4.3.3",
45+
"@types/react-table": "^6.8.3",
46+
"@types/recompose": "^0.30.6",
47+
"@types/redux-devtools": "^3.0.46",
4848
"@types/semver": "^6.0.0",
49-
"@types/storybook__addon-actions": "^3.0.1",
49+
"@types/storybook__addon-actions": "^3.4.3",
5050
"@types/storybook__react": "^4.0.1",
51-
"@types/webpack": "^4.4.0",
52-
"@types/webpack-env": "^1.13.2",
51+
"@types/webpack": "^4.4.32",
52+
"@types/webpack-env": "^1.13.9",
5353
"@types/yup": "^0.26.1",
5454
"awesome-typescript-loader": "^5.0.0",
55-
"babel-loader": "^8.0.4",
55+
"babel-loader": "^8.0.6",
5656
"babel-plugin-lodash": "^3.3.4",
5757
"babel-preset-env": "^1.7.0",
5858
"byte-size": "^5.0.1",

ui/src/containers/LogoutPage.tsx

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import * as React from "react";
2+
3+
import {connect} from "react-redux";
4+
import {Redirect, RouteComponentProps, RouteProps} from "react-router";
5+
import {Grid, Card, Checkbox, Form, Header, Input, Message} from "semantic-ui-react";
6+
import * as actions from "../store/auth/actions";
7+
import {
8+
Formik,
9+
FormikActions,
10+
FormikProps,
11+
Form as FormikForm,
12+
Field,
13+
FieldProps,
14+
Label,
15+
withFormik,
16+
FormikBag
17+
} from "formik";
18+
import { Button } from "formik-semantic-ui";
19+
import {RootState} from "../reducers";
20+
import {ApiError} from "redux-api-middleware";
21+
import * as Yup from "yup";
22+
23+
interface IFormValues {
24+
email: string;
25+
password: string;
26+
}
27+
28+
interface IReduxDispatchProps {
29+
logout: actions.TokenActionRequestCreator;
30+
}
31+
32+
export interface ILogoutPageProps extends IReduxDispatchProps {
33+
apiError?: ApiError;
34+
access_token?: string;
35+
loading: boolean;
36+
}
37+
38+
export interface IRouteProps {
39+
from?: string;
40+
}
41+
42+
const UnconnectedLogoutPage: React.FC = (
43+
props: ILogoutPageProps & RouteComponentProps<IRouteProps>) => {
44+
45+
return (
46+
<Grid textAlign="center" style={{height: '100vh'}} verticalAlign="middle">
47+
<Grid.Column style={{maxWidth: 450}}>
48+
<Card>
49+
<Card.Content>
50+
<Card.Header>Logging Out</Card.Header>
51+
<Card.Description>
52+
Hold on while we log you out...
53+
</Card.Description>
54+
</Card.Content>
55+
</Card>
56+
</Grid.Column>}
57+
</Grid>
58+
);
59+
};
60+
61+
export const LogoutPage = connect(
62+
(state: RootState) => ({
63+
access_token: state.auth.access_token,
64+
apiError: state.auth.error,
65+
loading: state.auth.loading,
66+
}),
67+
{Logout: actions.logout})(UnconnectedLogoutPage);

ui/src/entry.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {DEPAccountsPage} from "./containers/settings/DEPAccountsPage";
2828
import {VPPAccountsPage} from "./containers/settings/VPPAccountsPage";
2929
import {SettingsPage} from "./containers/SettingsPage";
3030
import {LoginPage} from "./containers/LoginPage";
31+
import {LogoutPage} from "./containers/LogoutPage";
3132

3233
import "../sass/app.scss";
3334
import {ProfileUpload} from "./containers/ProfileUpload";
@@ -45,6 +46,7 @@ render(
4546
<Provider store={store}>
4647
<ConnectedRouter history={history}>
4748
<BareLayout exact path="/login" component={LoginPage} />
49+
<BareLayout exact path="/logout" component={LogoutPage} />
4850
<App>
4951
<NavigationLayout>
5052
<ProtectedRoute exact path="/" component={DashboardPage} />

ui/src/store/device/actions.ts

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ export const read: ReadActionRequest = (id: string, include?: string[]) => {
125125
return {
126126
[RSAA]: {
127127
endpoint: `/api/v1/devices/${id}?${inclusions}`,
128-
headers: JSONAPI_HEADERS,
128+
headers: (state: RootState) => ({
129+
...JSONAPI_HEADERS,
130+
Authorization: `Bearer ${state.auth.access_token}`,
131+
}),
129132
method: "GET",
130133
types: [
131134
DevicesActionTypes.READ_REQUEST,
@@ -182,7 +185,10 @@ export const push: PushActionRequest = (id: string | number) => {
182185
return {
183186
[RSAA]: {
184187
endpoint: `/api/v1/devices/${id}/push`,
185-
headers: JSON_HEADERS,
188+
headers: (state: RootState) => ({
189+
...JSONAPI_HEADERS,
190+
Authorization: `Bearer ${state.auth.access_token}`,
191+
}),
186192
method: "POST",
187193
types: [
188194
DevicesActionTypes.PUSH_REQUEST,
@@ -205,7 +211,10 @@ export const restart: RestartActionRequest = (deviceId: string | number) => {
205211
return {
206212
[RSAA]: {
207213
endpoint: `/api/v1/devices/${deviceId}/restart`,
208-
headers: JSON_HEADERS,
214+
headers: (state: RootState) => ({
215+
...JSONAPI_HEADERS,
216+
Authorization: `Bearer ${state.auth.access_token}`,
217+
}),
209218
method: "POST",
210219
types: [
211220
DevicesActionTypes.RESTART_REQUEST,
@@ -233,7 +242,10 @@ export const shutdown: ShutdownActionRequest = (id: string | number) => {
233242
return {
234243
[RSAA]: {
235244
endpoint: `/api/v1/devices/${id}/shutdown`,
236-
headers: JSON_HEADERS,
245+
headers: (state: RootState) => ({
246+
...JSONAPI_HEADERS,
247+
Authorization: `Bearer ${state.auth.access_token}`,
248+
}),
237249
method: "POST",
238250
types: [
239251
DevicesActionTypes.SHUTDOWN_REQUEST,
@@ -261,7 +273,10 @@ export const erase: EraseActionRequest = (id: string | number) => {
261273
return {
262274
[RSAA]: {
263275
endpoint: `/api/v1/devices/${id}/erase`,
264-
headers: JSON_HEADERS,
276+
headers: (state: RootState) => ({
277+
...JSONAPI_HEADERS,
278+
Authorization: `Bearer ${state.auth.access_token}`,
279+
}),
265280
method: "POST",
266281
types: [
267282
DevicesActionTypes.ERASE_REQUEST,
@@ -294,7 +309,10 @@ export const lock: LockActionRequest = (deviceId: string | number, pin?: string,
294309
pin,
295310
}),
296311
endpoint: `/api/v1/devices/${deviceId}/lock`,
297-
headers: JSON_HEADERS,
312+
headers: (state: RootState) => ({
313+
...JSONAPI_HEADERS,
314+
Authorization: `Bearer ${state.auth.access_token}`,
315+
}),
298316
method: "POST",
299317
types: [
300318
DevicesActionTypes.LOCK_REQUEST,
@@ -322,7 +340,10 @@ export const clearPasscode: ClearPasscodeActionRequest = (id: string | number) =
322340
return {
323341
[RSAA]: {
324342
endpoint: `/api/v1/devices/${id}/clear_passcode`,
325-
headers: JSON_HEADERS,
343+
headers: (state: RootState) => ({
344+
...JSONAPI_HEADERS,
345+
Authorization: `Bearer ${state.auth.access_token}`,
346+
}),
326347
method: "POST",
327348
types: [
328349
DevicesActionTypes.CLEARPASSCODE_REQUEST,
@@ -349,7 +370,10 @@ export const inventory: InventoryActionRequest = (id: string | number) => {
349370
return {
350371
[RSAA]: {
351372
endpoint: `/api/v1/devices/inventory/${id}`,
352-
headers: JSON_HEADERS,
373+
headers: (state: RootState) => ({
374+
...JSONAPI_HEADERS,
375+
Authorization: `Bearer ${state.auth.access_token}`,
376+
}),
353377
method: "GET",
354378
types: [
355379
DevicesActionTypes.INVENTORY_REQUEST,
@@ -377,7 +401,10 @@ export const test: TestActionRequest = (id: string | number) => {
377401
return {
378402
[RSAA]: {
379403
endpoint: `/api/v1/devices/test/${id}`,
380-
headers: JSON_HEADERS,
404+
headers: (state: RootState) => ({
405+
...JSONAPI_HEADERS,
406+
Authorization: `Bearer ${state.auth.access_token}`,
407+
}),
381408
method: "POST",
382409
types: [
383410
TEST_REQUEST,
@@ -400,7 +427,10 @@ export const commands = encodeJSONAPIChildIndexParameters((deviceId: string, que
400427
return ({
401428
[RSAA]: {
402429
endpoint: `/api/v1/devices/${deviceId}/commands?${queryParameters.join("&")}`,
403-
headers: JSONAPI_HEADERS,
430+
headers: (state: RootState) => ({
431+
...JSONAPI_HEADERS,
432+
Authorization: `Bearer ${state.auth.access_token}`,
433+
}),
404434
method: "GET",
405435
types: [
406436
DevicesActionTypes.COMMANDS_REQUEST,
@@ -433,7 +463,10 @@ export const patch: PatchActionRequest = (deviceId: string, values: Device) => {
433463
},
434464
}),
435465
endpoint: `/api/v1/devices/${deviceId}`,
436-
headers: JSONAPI_HEADERS,
466+
headers: (state: RootState) => ({
467+
...JSONAPI_HEADERS,
468+
Authorization: `Bearer ${state.auth.access_token}`,
469+
}),
437470
method: "PATCH",
438471
types: [
439472
DevicesActionTypes.PATCH_REQUEST,
@@ -457,7 +490,10 @@ export const postRelationship: PostRelationshipActionRequest = (id: string, rela
457490
[RSAA]: {
458491
body: JSON.stringify({ data }),
459492
endpoint: `/api/v1/devices/${id}/relationships/${relationship}`,
460-
headers: JSONAPI_HEADERS,
493+
headers: (state: RootState) => ({
494+
...JSONAPI_HEADERS,
495+
Authorization: `Bearer ${state.auth.access_token}`,
496+
}),
461497
method: "POST",
462498
types: [
463499
DevicesActionTypes.REL_POST_REQUEST,
@@ -478,7 +514,10 @@ export type RCPOST_FAILURE = typeof RCPOST_FAILURE;
478514
export type PostRelatedActionRequest = <TRelated>(parentId: string, relationship: DeviceRelationship, data: TRelated) => RSAAction<RCPOST_REQUEST, RCPOST_SUCCESS, RCPOST_FAILURE>;
479515
export type PostRelatedActionResponse = RSAAReadActionResponse<RCPOST_REQUEST, RCPOST_SUCCESS, RCPOST_FAILURE, JSONAPIDetailResponse<any, undefined>>;
480516

481-
export const postRelated: PostRelatedActionRequest = <TRelated>(parentId: string, relationship: DeviceRelationship, data: TRelated): RSAAction<RCPOST_REQUEST, RCPOST_SUCCESS, RCPOST_FAILURE> => {
517+
export const postRelated: PostRelatedActionRequest = <TRelated>(
518+
parentId: string,
519+
relationship: DeviceRelationship,
520+
data: TRelated): RSAAction<RCPOST_REQUEST, RCPOST_SUCCESS, RCPOST_FAILURE> => {
482521
return {
483522
[RSAA]: {
484523
body: JSON.stringify({ data: {
@@ -496,7 +535,10 @@ export const postRelated: PostRelatedActionRequest = <TRelated>(parentId: string
496535
type: relationship,
497536
} }),
498537
endpoint: `/api/v1/devices/${parentId}/${relationship}`,
499-
headers: JSONAPI_HEADERS,
538+
headers: (state: RootState) => ({
539+
...JSONAPI_HEADERS,
540+
Authorization: `Bearer ${state.auth.access_token}`,
541+
}),
500542
method: "POST",
501543
types: [
502544
RCPOST_REQUEST,
@@ -514,15 +556,24 @@ export type RPATCH_SUCCESS = typeof RPATCH_SUCCESS;
514556
export const RPATCH_FAILURE = "devices/RPATCH_FAILURE";
515557
export type RPATCH_FAILURE = typeof RPATCH_FAILURE;
516558

517-
export type PatchRelationshipActionRequest = (parentId: string, relationship: DeviceRelationship, data: JSONAPIRelationship[]) => RSAAction<RPATCH_REQUEST, RPATCH_SUCCESS, RPATCH_FAILURE>;
518-
export type PatchRelationshipActionResponse = RSAAReadActionResponse<RPATCH_REQUEST, RPATCH_SUCCESS, RPATCH_FAILURE, JSONAPIDetailResponse<Device, undefined>>;
559+
export type PatchRelationshipActionRequest = (
560+
parentId: string,
561+
relationship: DeviceRelationship,
562+
data: JSONAPIRelationship[]) => RSAAction<RPATCH_REQUEST, RPATCH_SUCCESS, RPATCH_FAILURE>;
519563

520-
export const patchRelationship: PatchRelationshipActionRequest = (id: string, relationship: DeviceRelationship, data: JSONAPIRelationship[]) => {
564+
export type PatchRelationshipActionResponse = RSAAReadActionResponse<
565+
RPATCH_REQUEST, RPATCH_SUCCESS, RPATCH_FAILURE, JSONAPIDetailResponse<Device, undefined>>;
566+
567+
export const patchRelationship: PatchRelationshipActionRequest = (
568+
id: string, relationship: DeviceRelationship, data: JSONAPIRelationship[]) => {
521569
return {
522570
[RSAA]: {
523571
body: JSON.stringify({ data }),
524572
endpoint: `/api/v1/devices/${id}/relationships/${relationship}`,
525-
headers: JSONAPI_HEADERS,
573+
headers: (state: RootState) => ({
574+
...JSONAPI_HEADERS,
575+
Authorization: `Bearer ${state.auth.access_token}`,
576+
}),
526577
method: "PATCH",
527578
types: [
528579
RPATCH_REQUEST,

ui/src/store/device/applications.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from "../json-api";
66
import {InstalledApplication} from "./types";
77
import {encodeJSONAPIChildIndexParameters} from "../../flask-rest-jsonapi";
8+
import {RootState} from "../../reducers";
89

910

1011
export type APPLICATIONS_REQUEST = 'devices/APPLICATIONS_REQUEST';
@@ -31,7 +32,10 @@ export const applications = encodeJSONAPIChildIndexParameters((device_id: string
3132
APPLICATIONS_SUCCESS,
3233
APPLICATIONS_FAILURE
3334
],
34-
headers: JSONAPI_HEADERS
35+
headers: (state: RootState) => ({
36+
...JSONAPI_HEADERS,
37+
Authorization: `Bearer ${state.auth.access_token}`,
38+
}),
3539
}
3640
});
3741
});

ui/src/store/device/available_os_updates_reducer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ const initialState: AvailableOSUpdatesState = {
2525

2626
type AvailableOSUpdatesAction = AvailableOSUpdatesActionResponse | OtherAction;
2727

28-
export function available_os_updates_reducer(state: AvailableOSUpdatesState = initialState, action: AvailableOSUpdatesAction): AvailableOSUpdatesState {
28+
export function available_os_updates_reducer(
29+
state: AvailableOSUpdatesState = initialState,
30+
action: AvailableOSUpdatesAction): AvailableOSUpdatesState {
2931
switch (action.type) {
3032
case UPDATES_SUCCESS:
3133
if (isJSONAPIErrorResponsePayload(action.payload)) {

ui/src/store/device/certificates.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from "../json-api";
77
import {InstalledCertificate} from "./types";
88
import {encodeJSONAPIChildIndexParameters} from "../../flask-rest-jsonapi";
9+
import {RootState} from "../../reducers";
910

1011

1112
export type CERTIFICATES_REQUEST = 'devices/CERTIFICATES_REQUEST';
@@ -28,7 +29,10 @@ export const certificates = encodeJSONAPIChildIndexParameters((device_id: string
2829
CERTIFICATES_SUCCESS,
2930
CERTIFICATES_FAILURE
3031
],
31-
headers: JSONAPI_HEADERS
32+
headers: (state: RootState) => ({
33+
...JSONAPI_HEADERS,
34+
Authorization: `Bearer ${state.auth.access_token}`,
35+
}),
3236
}
3337
});
3438
});

ui/src/store/device/installed_applications_reducer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ const initialState: InstalledApplicationsState = {
2424

2525
type InstalledCertificatesAction = InstalledApplicationsActionResponse | OtherAction;
2626

27-
export function installed_applications_reducer(state: InstalledApplicationsState = initialState, action: InstalledCertificatesAction): InstalledApplicationsState {
27+
export function installed_applications_reducer(
28+
state: InstalledApplicationsState = initialState,
29+
action: InstalledCertificatesAction): InstalledApplicationsState {
2830
switch (action.type) {
2931
case APPLICATIONS_SUCCESS:
3032
if (isJSONAPIErrorResponsePayload(action.payload)) {

0 commit comments

Comments
 (0)