Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix admin 403 images #4565

Merged
merged 13 commits into from
Aug 23, 2021
2 changes: 2 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pipeline {
def disableDeploy = env.DISABLE_DEPLOY
def showQAPromoteCommand = env.SHOW_QA_PROMOTE_COMMAND
def qaBuildsSlackChannel = env.QA_BUILDS_SLACK_CHANNEL
def uploadsHost = env.UPLOADS_HOST

def habCommand = (
"/bin/bash scripts/hab-build-and-push.sh "
Expand All @@ -49,6 +50,7 @@ pipeline {
+ "\\\"${buildNumber}\\\" "
+ "\\\"${gitCommit}\\\" "
+ "\\\"${disableDeploy}\\\" "
+ "\\\"${uploadsHost}\\\" "
)
runCommand(habCommand)

Expand Down
6 changes: 3 additions & 3 deletions admin/src/react-components/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import PropTypes from "prop-types";
import { withStyles } from "@material-ui/core/styles";
import LaunchIcon from "@material-ui/icons/Launch";
import { getReticulumFetchUrl } from "hubs/src/utils/phoenix-utils";
import { getReticulumFetchUrl, getUploadsUrl } from "hubs/src/utils/phoenix-utils";
import { ReferenceField } from "react-admin";

const styles = {
Expand Down Expand Up @@ -39,7 +39,7 @@ ConditionalReferenceField.propTypes = {
};

const OwnedFileImageInternal = withStyles(styles)(({ record = {}, aspect = "wide", classes }) => {
const src = getReticulumFetchUrl(`/files/${record.owned_file_uuid}`);
const src = getUploadsUrl(`/files/${record.owned_file_uuid}`);
return <img src={src} className={classes[`ownedFileImageAspect_${aspect}`]} />;
});

Expand Down Expand Up @@ -67,7 +67,7 @@ function OwnedFileDownloadFieldInternal({ fileName, record, source }) {
return (
<a
download={fileName || true}
href={getReticulumFetchUrl(`/files/${record[source]}`)}
href={getUploadsUrl(`/files/${record[source]}`)}
target="_blank"
rel="noopener noreferrer"
>
Expand Down
3 changes: 2 additions & 1 deletion admin/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ module.exports = (env, argv) => {
ITA_SERVER: process.env.ITA_SERVER,
RETICULUM_SERVER: process.env.RETICULUM_SERVER,
CORS_PROXY_SERVER: process.env.CORS_PROXY_SERVER,
POSTGREST_SERVER: process.env.POSTGREST_SERVER
POSTGREST_SERVER: process.env.POSTGREST_SERVER,
UPLOADS_HOST: process.env.UPLOADS_HOST
})
})
]
Expand Down
2 changes: 2 additions & 0 deletions scripts/hab-build-and-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export GA_TRACKING_ID=$9
export BUILD_NUMBER=${10}
export GIT_COMMIT=${11}
export DISABLE_DEPLOY=${12}
export UPLOADS_HOST=${13}
export BUILD_VERSION="${BUILD_NUMBER} (${GIT_COMMIT})"

# Build the package, upload it, and start the service so we deploy to staging target.
Expand Down Expand Up @@ -53,6 +54,7 @@ cors_proxy_server = $CORS_PROXY_SERVER
non_cors_proxy_domains = $NON_CORS_PROXY_DOMAINS
sentry_dsn = $SENTRY_DSN
ga_tracking_id = $GA_TRACKING_ID
uploads_host = $UPLOADS_HOST
[deploy]
type = "$DEPLOY_TYPE"
Expand Down
3 changes: 2 additions & 1 deletion src/utils/configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ let isAdmin = false;
"SENTRY_DSN",
"GA_TRACKING_ID",
"SHORTLINK_DOMAIN",
"BASE_ASSETS_PATH"
"BASE_ASSETS_PATH",
"UPLOADS_HOST"
].forEach(x => {
const el = document.querySelector(`meta[name='env:${x.toLowerCase()}']`);
configs[x] = el ? el.getAttribute("content") : process.env[x];
Expand Down
6 changes: 6 additions & 0 deletions src/utils/phoenix-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ export function getReticulumFetchUrl(path, absolute = false, host = null, port =
}
}

export function getUploadsUrl(path, absolute = false, host = null, port = null) {
return configs.UPLOADS_HOST
? `https://${configs.UPLOADS_HOST}${port ? `:${port}` : ""}${path}`
: getReticulumFetchUrl(path, absolute, host, port);
}

export async function getReticulumMeta() {
if (!reticulumMeta) {
// Initially look up version based upon page, avoiding round-trip, otherwise fetch.
Expand Down
4 changes: 3 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ module.exports = async (env, argv) => {
BASE_ASSETS_PATH: "https://hubs.local:8080/",
RETICULUM_SERVER: "hubs.local:4000",
POSTGREST_SERVER: "",
ITA_SERVER: ""
ITA_SERVER: "",
UPLOADS_HOST: "https://hubs.local:4000"
});
}
}
Expand Down Expand Up @@ -643,6 +644,7 @@ module.exports = async (env, argv) => {
SENTRY_DSN: process.env.SENTRY_DSN,
GA_TRACKING_ID: process.env.GA_TRACKING_ID,
POSTGREST_SERVER: process.env.POSTGREST_SERVER,
UPLOADS_HOST: process.env.UPLOADS_HOST,
APP_CONFIG: appConfig
})
})
Expand Down