Skip to content

Commit

Permalink
Revert "Web Lab: Environment-sensitive share URLs"
Browse files Browse the repository at this point in the history
  • Loading branch information
islemaster committed Dec 13, 2017
1 parent 3d326ff commit cc9a861
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 128 deletions.
2 changes: 1 addition & 1 deletion apps/src/StudioApp.js
Expand Up @@ -1404,7 +1404,7 @@ StudioApp.prototype.displayFeedback = function (options) {

try {
options.shareLink = (options.response && options.response.level_source) ||
project.getShareUrl();
(window.location.origin + project.getPathName());
} catch (e) {}

// Special test code for edit blocks.
Expand Down
8 changes: 7 additions & 1 deletion apps/src/code-studio/header.js
Expand Up @@ -153,7 +153,13 @@ header.build = function (scriptData, stageData, progressData, currentLevelId,

function shareProject() {
dashboard.project.save().then(() => {
const shareUrl = dashboard.project.getShareUrl();
var shareUrl;
if (appOptions.baseShareUrl) {
shareUrl = `${appOptions.baseShareUrl}/${dashboard.project.getCurrentId()}`;
} else {
const origin = location.protocol + '//' + location.host;
shareUrl = origin + dashboard.project.getPathName();
}

var i18n = window.dashboard.i18n;

Expand Down
42 changes: 2 additions & 40 deletions apps/src/code-studio/initApp/project.js
Expand Up @@ -134,14 +134,7 @@ var projects = module.exports = {
* This method is used so that it can be mocked for unit tests.
*/
getUrl() {
return this.getLocation().href;
},

/**
* This method exists to be mocked for unit tests.
*/
getLocation() {
return document.location;
return location.href;
},

/**
Expand Down Expand Up @@ -177,33 +170,6 @@ var projects = module.exports = {
return url + fragment + queryString;
},

/**
* Returns a share URL for the current project.
*
* Share URLs can vary by application environment and project type. For most
* project types the share URL is the same as the project edit and view URLs,
* but has no action appended to the project's channel ID.Weblab is a special
* case right now, because it shares projects to codeprojects.org.
*
* This function depends on the document location to determine both the
* current project id and the current application enviornmnet. It's unlikely
* to work if called when we're not on a project page.
*
* @returns {string} Fully-qualified share URL for the current project.
*/
getShareUrl() {
if (this.isWebLab()) {
const location = this.getLocation();
const re = /([-.]?studio)?\.?code.org/i;
const environmentKey = location.hostname.replace(re, '');
const subdomain = environmentKey.length > 0 ? `${environmentKey}.` : '';
const port = 'localhost' === environmentKey ? `:${location.port}` : '';
return `${location.protocol}//${subdomain}codeprojects.org${port}/${this.getCurrentId()}`;
} else {
return this.getProjectUrl();
}
},

getCurrentTimestamp() {
if (!current) {
return;
Expand Down Expand Up @@ -639,10 +605,6 @@ var projects = module.exports = {
}
},

isWebLab() {
return this.getStandaloneApp() === 'weblab';
},

canServerSideRemix() {
// The excluded app types need to make modifications to the project that
// apply to the remixed project, but should not be saved on the original
Expand Down Expand Up @@ -1232,7 +1194,7 @@ function fetchAbuseScoreAndPrivacyViolations(callback) {
deferredCallsToMake.push(new Promise(fetchPrivacyProfanityViolations));
} else if ((dashboard.project.getStandaloneApp() === 'applab') ||
(dashboard.project.getStandaloneApp() === 'gamelab') ||
(dashboard.project.isWebLab())) {
(dashboard.project.getStandaloneApp() === 'weblab')) {
deferredCallsToMake.push(new Promise(fetchSharingDisabled));
}
Promise.all(deferredCallsToMake).then(function () {
Expand Down
1 change: 1 addition & 0 deletions apps/src/weblab/WebLab.js
Expand Up @@ -95,6 +95,7 @@ WebLab.prototype.init = function (config) {
config.centerEmbedded = false;
config.wireframeShare = true;
config.noHowItWorks = true;
config.baseShareUrl = 'https://codeprojects.org';

config.afterClearPuzzle = config => {
return new Promise((resolve, reject) => {
Expand Down
86 changes: 0 additions & 86 deletions apps/test/unit/code-studio/initApp/projectTest.js
Expand Up @@ -47,92 +47,6 @@ describe('project.js', () => {
});
});

describe('project.getShareUrl', () => {
let fakeLocation;
const fakeProjectId = 'fake-project-id';

beforeEach(() => {
sinon.stub(project, 'getLocation').callsFake(() => fakeLocation);
sinon.stub(project, 'getCurrentId').returns(fakeProjectId);
});

afterEach(() => {
project.getCurrentId.restore();
project.getLocation.restore();
});

function setFakeLocation(url) {
fakeLocation = document.createElement('a');
fakeLocation.href = url;
}

[
'artist',
'playlab',
'applab',
'gamelab',
].forEach((standaloneApp) => {
describe(standaloneApp, () => {
beforeEach(() => sinon.stub(project, 'getStandaloneApp').returns(standaloneApp));
afterEach(() => project.getStandaloneApp.restore());

it('studio.code.org', () => {
setFakeLocation(`https://studio.code.org/projects/${standaloneApp}/${fakeProjectId}/edit`);
expect(project.getShareUrl())
.to.equal(`https://studio.code.org/projects/${standaloneApp}/${fakeProjectId}`);
});

it('test-studio.code.org', () => {
setFakeLocation(`https://test-studio.code.org/projects/${standaloneApp}/${fakeProjectId}/edit`);
expect(project.getShareUrl())
.to.equal(`https://test-studio.code.org/projects/${standaloneApp}/${fakeProjectId}`);
});
it('staging-studio.code.org', () => {
setFakeLocation(`https://staging-studio.code.org/projects/${standaloneApp}/${fakeProjectId}/edit`);
expect(project.getShareUrl())
.to.equal(`https://staging-studio.code.org/projects/${standaloneApp}/${fakeProjectId}`);
});

it('localhost-studio.code.org:3000', () => {
setFakeLocation(`http://localhost-studio.code.org:3000/projects/${standaloneApp}/${fakeProjectId}/edit`);
expect(project.getShareUrl())
.to.equal(`http://localhost-studio.code.org:3000/projects/${standaloneApp}/${fakeProjectId}`);
});
});
});

describe('weblab', () => {
beforeEach(() => sinon.stub(project, 'getStandaloneApp').returns('weblab'));
afterEach(() => project.getStandaloneApp.restore());

it('studio.code.org => codeprojects.org', () => {
setFakeLocation('https://studio.code.org/');
expect(project.getShareUrl()).to.equal(`https://codeprojects.org/${fakeProjectId}`);
});

it('test-studio.code.org => test.codeprojects.org', () => {
setFakeLocation('https://test-studio.code.org/');
expect(project.getShareUrl()).to.equal(`https://test.codeprojects.org/${fakeProjectId}`);
setFakeLocation('https://test.studio.code.org/');
expect(project.getShareUrl()).to.equal(`https://test.codeprojects.org/${fakeProjectId}`);
});

it('staging-studio.code.org => staging.codeprojects.org', () => {
setFakeLocation('https://staging-studio.code.org/');
expect(project.getShareUrl()).to.equal(`https://staging.codeprojects.org/${fakeProjectId}`);
setFakeLocation('https://staging.studio.code.org/');
expect(project.getShareUrl()).to.equal(`https://staging.codeprojects.org/${fakeProjectId}`);
});

it('localhost-studio.code.org:3000 => localhost.codeprojects.org:3000', () => {
setFakeLocation('http://localhost-studio.code.org:3000/');
expect(project.getShareUrl()).to.equal(`http://localhost.codeprojects.org:3000/${fakeProjectId}`);
setFakeLocation('http://localhost.studio.code.org:3000/');
expect(project.getShareUrl()).to.equal(`http://localhost.codeprojects.org:3000/${fakeProjectId}`);
});
});
});

describe('toggleMakerEnabled()', () => {
let sourceHandler;

Expand Down

0 comments on commit cc9a861

Please sign in to comment.