Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/containers/AdminScriptImport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ export default class AdminScriptImport extends Component {
</List>
);

renderGoogleClientEmail = () =>
window.GOOGLE_CLIENT_EMAIL ? (
<span>
Please share your Google Doc with <b>{window.GOOGLE_CLIENT_EMAIL}</b> before importing to Spoke
</span>
) : (
<span>
<b>ERROR</b>: Bad GOOGLE_SECRET<br/> Please contact your Administrator.
</span>
)


render() {
const url =
"https://github.com/StateVoicesNational/Spoke/blob/main/docs/HOWTO_IMPORT_GOOGLE_DOCS_SCRIPTS_TO_IMPORT.md";
Expand All @@ -73,6 +85,8 @@ export default class AdminScriptImport extends Component {
this document
</a>{" "}
for more details.
<br/><br/>
{this.renderGoogleClientEmail()}
</span>
}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/server/api/lib/import-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const textRegex = RegExp(".*[A-Za-z0-9]+.*");

const getDocument = async documentId => {
const auth = google.auth.fromJSON(JSON.parse(getConfig("GOOGLE_SECRET")));
auth.scopes = ["https://www.googleapis.com/auth/documents"];
auth.scopes = ["https://www.googleapis.com/auth/documents.readonly"];

const docs = google.docs({
version: "v1",
Expand Down
22 changes: 21 additions & 1 deletion src/server/middleware/render-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@ import { getProcessEnvTz, getProcessEnvDstReferenceTimezone } from "../../lib";

const canGoogleImport = hasConfig("GOOGLE_SECRET");

const googleClientEmail = () => {
let output;
if (canGoogleImport) {
try {
output = (JSON.parse((
process.env.GOOGLE_SECRET
.replace(/(\r\n|\n|\r)/gm, ""))) // new lines gum up parsing
.client_email)
.replaceAll(" ", "");
} catch (err) {
console.error(`
Google API failed to load client email.
Please check your GOOGLE_SECRET environment variable is intact: `,
err);
}
}
return (output || "");
};

const rollbarScript = process.env.ROLLBAR_CLIENT_TOKEN
? `<script>
var _rollbarConfig = {
Expand Down Expand Up @@ -136,7 +155,8 @@ export default function renderIndex(html, css, assetMap) {
)}';
window.ASSIGNMENT_CONTACTS_SIDEBAR=${getConfig(
"ASSIGNMENT_CONTACTS_SIDEBAR"
)}
)};
window.GOOGLE_CLIENT_EMAIL='${googleClientEmail()}';
window.OPT_OUT_PER_STATE=${getConfig("OPT_OUT_PER_STATE", null, {
truthy: true
})}
Expand Down