|
| 1 | +import TableView from 'dashboard/TableView.react'; |
| 2 | +import Button from 'components/Button/Button.react'; |
| 3 | +import EmptyState from 'components/EmptyState/EmptyState.react'; |
| 4 | +import React from 'react'; |
| 5 | +import Toolbar from 'components/Toolbar/Toolbar.react'; |
| 6 | +import styles from './Security.scss'; |
| 7 | +import Parse from 'parse'; |
| 8 | +import TableHeader from 'components/Table/TableHeader.react'; |
| 9 | + |
| 10 | +export default class Security extends TableView { |
| 11 | + constructor() { |
| 12 | + super(); |
| 13 | + this.section = 'App Settings'; |
| 14 | + this.subsection = 'Security'; |
| 15 | + this.state = { |
| 16 | + loading: false, |
| 17 | + data: {}, |
| 18 | + error: '', |
| 19 | + }; |
| 20 | + } |
| 21 | + |
| 22 | + componentWillMount() { |
| 23 | + this.reload(); |
| 24 | + } |
| 25 | + |
| 26 | + componentWillReceiveProps(nextProps, nextContext) { |
| 27 | + if (this.context !== nextContext) { |
| 28 | + this.reload(); |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + renderToolbar() { |
| 33 | + return ( |
| 34 | + <Toolbar section="Settings" subsection="Security"> |
| 35 | + <Button color="white" value="Reload" onClick={() => this.reload()} /> |
| 36 | + </Toolbar> |
| 37 | + ); |
| 38 | + } |
| 39 | + |
| 40 | + renderRow(security) { |
| 41 | + return ( |
| 42 | + <tr key={JSON.stringify(security)}> |
| 43 | + <td className={styles.tableData} style={security.header ? {fontWeight: 'bold'} : {}} width={'20%'}> |
| 44 | + {security.check} |
| 45 | + </td> |
| 46 | + <td className={styles.tableData} width={'5%'}> |
| 47 | + {security.i !== undefined ? '' : (security.status === 'success' ? '✅' : '❌')} |
| 48 | + </td> |
| 49 | + <td className={styles.tableData} width={'37.5%'}> |
| 50 | + {security.issue} |
| 51 | + </td> |
| 52 | + <td className={styles.tableData} width={'37.5%'}> |
| 53 | + {security.solution} |
| 54 | + </td> |
| 55 | + </tr> |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + renderHeaders() { |
| 60 | + return [ |
| 61 | + <TableHeader width={20} key="Check"> |
| 62 | + Check |
| 63 | + </TableHeader>, |
| 64 | + <TableHeader width={5} key="Status"> |
| 65 | + Status |
| 66 | + </TableHeader>, |
| 67 | + <TableHeader width={37.5} key="Issue"> |
| 68 | + Issue |
| 69 | + </TableHeader>, |
| 70 | + <TableHeader width={37.5} key="Solution"> |
| 71 | + Solution |
| 72 | + </TableHeader>, |
| 73 | + ]; |
| 74 | + } |
| 75 | + |
| 76 | + renderEmpty() { |
| 77 | + return <EmptyState title="Security" description={<span>{this.state.error}</span>} icon="gears" cta="Reload" action={() => this.reload()} />; |
| 78 | + } |
| 79 | + |
| 80 | + tableData() { |
| 81 | + const data = []; |
| 82 | + if (this.state.data.state) { |
| 83 | + data.push({ |
| 84 | + check: 'Overall status', |
| 85 | + status: this.state.data.state, |
| 86 | + header: true |
| 87 | + }), |
| 88 | + data.push({i: -1}) |
| 89 | + } |
| 90 | + for (let i = 0; i < this.state.data?.groups?.length; i++) { |
| 91 | + const group = this.state.data.groups[i] |
| 92 | + data.push({ |
| 93 | + check: group.name, |
| 94 | + status: group.state, |
| 95 | + issue: '', |
| 96 | + solution: '', |
| 97 | + header: true |
| 98 | + }); |
| 99 | + for (const check of group.checks) { |
| 100 | + data.push({ |
| 101 | + check: check.title, |
| 102 | + status: check.state, |
| 103 | + issue: check.warning, |
| 104 | + solution: check.solution, |
| 105 | + }); |
| 106 | + } |
| 107 | + if (i !== this.state.data.groups.length - 1) { |
| 108 | + data.push({i}); |
| 109 | + } |
| 110 | + } |
| 111 | + return data; |
| 112 | + } |
| 113 | + |
| 114 | + async reload() { |
| 115 | + if (!this.context.enableSecurityChecks) { |
| 116 | + this.setState({ error: 'Enable Dashboard option `enableSecurityChecks` to run security check.' }); |
| 117 | + return; |
| 118 | + } |
| 119 | + this.setState({ loading: true }); |
| 120 | + const result = await Parse._request('GET', 'security', {}, { useMasterKey: true }).catch((e) => { |
| 121 | + this.setState({ error: e?.message || e }); |
| 122 | + }); |
| 123 | + this.setState({ loading: false, data: result?.report || {} }); |
| 124 | + } |
| 125 | +} |
0 commit comments