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
9 changes: 3 additions & 6 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ if (appName && validAppNames.indexOf(appName) === -1) {

const amoCDN = 'https://addons.cdn.mozilla.net';
const apiHost = 'https://addons.mozilla.org';
const apiBase = `${apiHost}/api/v3`;
const startLoginUrl = `${apiBase}/internal/accounts/login/start/`;


module.exports = {
Expand All @@ -42,19 +40,18 @@ module.exports = {
// The CDN host for AMO.
amoCDN,
apiHost,
apiBase,
startLoginUrl,
apiPath: '/api/v3',

// The keys listed here will be exposed on the client.
// Since by definition client-side code is public these config keys
// must not contain sensitive data.
clientConfigKeys: [
'apiBase',
'apiHost',
'apiPath',
'cookieName',
'cookieMaxAge',
'isDeployed',
'isDevelopment',
'startLoginUrl',
],

// Content security policy.
Expand Down
4 changes: 0 additions & 4 deletions config/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

const amoCDN = 'https://addons-dev-cdn.allizom.org';
const apiHost = 'https://addons-dev.allizom.org';
const apiBase = `${apiHost}/api/v3`;
const startLoginUrl = `${apiBase}/internal/accounts/login/start/`;


module.exports = {
apiHost,
apiBase,
amoCDN,
startLoginUrl,

// Content security policy.
CSP: {
Expand Down
4 changes: 0 additions & 4 deletions config/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@ const webpackServerPort = 3001;
const webpackHost = `${webpackServerHost}:${webpackServerPort}`;
const apiHost = 'https://addons-dev.allizom.org';
const amoCDN = 'https://addons-dev-cdn.allizom.org';
const apiBase = `${apiHost}/api/v3`;
const startLoginUrl = `${apiBase}/internal/accounts/login/start/`;


module.exports = {

apiHost,
amoCDN,

isDeployed: false,
isDevelopment: true,

serverPort: 3000,
startLoginUrl,
webpackServerHost,
webpackServerPort,
webpackHost,
Expand Down
4 changes: 0 additions & 4 deletions config/stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

const amoCDN = 'https://addons-stage-cdn.allizom.org';
const apiHost = 'https://addons.allizom.org';
const apiBase = `${apiHost}/api/v3`;
const startLoginUrl = `${apiBase}/internal/accounts/login/start/`;


module.exports = {
apiHost,
apiBase,
amoCDN,
startLoginUrl,

// Content security policy.
CSP: {
Expand Down
9 changes: 7 additions & 2 deletions src/core/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import config from 'config';

import 'isomorphic-fetch';

const API_BASE = config.get('apiBase');
const API_BASE = `${config.get('apiHost')}${config.get('apiPath')}`;

const addon = new Schema('addons', {idAttribute: 'slug'});

Expand Down Expand Up @@ -45,10 +45,11 @@ function callApi({endpoint, schema, params, auth = false, state = {}, method = '
export function search({ api, page, query }) {
// TODO: Get the language from the server.
return callApi({
endpoint: 'addons/search',
endpoint: 'internal/addons/search',
schema: {results: arrayOf(addon)},
params: {q: query, lang: 'en-US', page},
state: api,
auth: true,
});
}

Expand All @@ -72,3 +73,7 @@ export function login({ api, code, state }) {
credentials: true,
});
}

export function startLoginUrl() {
return `${API_BASE}/internal/accounts/login/start/`;
}
4 changes: 2 additions & 2 deletions src/core/components/LoginPage/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { PropTypes } from 'react';

import config from 'config';
import { startLoginUrl } from 'core/api';
import { gettext as _ } from 'core/utils';

export default class LoginPage extends React.Component {
Expand All @@ -17,7 +17,7 @@ export default class LoginPage extends React.Component {
{message || _('You must be logged in to access this page.')}
</p>
<p>
<a className="button" href={config.get('startLoginUrl')}>
<a className="button" href={startLoginUrl()}>
{_('Login')}
</a>
</p>
Expand Down
3 changes: 2 additions & 1 deletion src/core/server/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ export function runServer({listen = true, app = appName} = {}) {
reject(err);
}
log.info(`🔥 Addons-frontend server is running [ENV:${env}] [APP:${app}] ` +
`[isDevelopment:${isDevelopment}] [isDeployed:${isDeployed}]`);
`[isDevelopment:${isDevelopment}] [isDeployed:${isDeployed}] ` +
`[apiHost:${config.get('apiHost')}] [apiPath:${config.get('apiPath')}]`);
log.info(`👁 Open your browser at http://${host}:${port} to view it.`);
resolve(server);
});
Expand Down
17 changes: 10 additions & 7 deletions src/search/containers/AddonPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import NotFound from 'core/components/NotFound';

import './style.scss';

const editRegExpHelper = new RegExp('/firefox/addon/');
const editRegExpPath = '/developers/addon/';
function editUrl(viewUrl) {
return `${viewUrl.replace(editRegExpHelper, editRegExpPath)}edit`;
function siteLink(url, text) {
return <a href={url} target="_blank">{text}</a>;
}

class AddonPage extends React.Component {
Expand All @@ -28,8 +26,9 @@ class AddonPage extends React.Component {
const items = [
[addon.type, 'type'],
[addon.status, 'status'],
[<a href={addon.url} target="_blank">{_('View on site')}</a>, 'url'],
[<a href={editUrl(addon.url)} target="_blank">{_('Edit on site')}</a>, 'edit'],
[siteLink(addon.url, _('View on site')), 'url'],
[siteLink(addon.edit_url, _('Edit on site')), 'edit'],
[siteLink(addon.review_url, _('View on editors')), 'editors'],
];
if (addon.homepage) {
items.push([
Expand Down Expand Up @@ -69,7 +68,11 @@ class AddonPage extends React.Component {
return (
<div className="addon--current-version">
<h2>{_('Current version')}</h2>
{this.dataBar([[version.version, 'version']], 'version-info')}
{this.dataBar([
[version.version, 'version'],
[siteLink(version.url, _('View on site')), 'view'],
[siteLink(version.edit_url, _('Edit on site')), 'edit'],
], 'version-info')}
<h3>{_('Files')}</h3>
<ul>
{version.files.map((file) => (
Expand Down
3 changes: 2 additions & 1 deletion tests/client/core/api/test_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ describe('api', () => {
it('sets the lang, limit, page and query', () => {
// FIXME: This shouldn't fail if the args are in a different order.
mockWindow.expects('fetch')
.withArgs('https://addons.mozilla.org/api/v3/addons/search/?q=foo&lang=en-US&page=3')
.withArgs(
'https://addons.mozilla.org/api/v3/internal/addons/search/?q=foo&lang=en-US&page=3')
.once()
.returns(mockResponse());
return api.search({query: 'foo', page: 3}).then(() => mockWindow.verify());
Expand Down
5 changes: 3 additions & 2 deletions tests/client/core/components/TestLoginPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import { renderIntoDocument } from 'react-addons-test-utils';
import { findDOMNode } from 'react-dom';

import config from 'config';
import LoginPage from 'core/components/LoginPage';

describe('<LoginPage />', () => {
Expand Down Expand Up @@ -32,7 +31,9 @@ describe('<LoginPage />', () => {
it('has a button to the login URL', () => {
const root = render();
const loginLink = root.querySelector('a');
assert.equal(loginLink.href, config.get('startLoginUrl'));
assert.equal(
loginLink.href,
'https://addons.mozilla.org/api/v3/internal/accounts/login/start/');
assert.equal(loginLink.textContent, 'Login');
});
});
12 changes: 8 additions & 4 deletions tests/client/search/containers/TestAddonPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ describe('AddonPage', () => {
tags: [],
type: 'Extension',
url: 'https://addons.mozilla.org/firefox/addon/my-addon/',
edit_url: 'https://addons.mozilla.org/developers/addon/my-addon/edit',
review_url: 'https://addons.mozilla.org/en-US/editors/review/1865',
};

function render({props, state}) {
Expand All @@ -39,6 +41,8 @@ describe('AddonPage', () => {
tags: ['foo-tag', 'bar-tag'],
current_version: {
version: '2.5-beta.1',
url: 'https://a.m.org/versions/2.5-beta.1',
edit_url: 'https://a.m.org/versions/2.5-beta.1/edit',
files: [
{
id: 54321,
Expand Down Expand Up @@ -80,8 +84,8 @@ describe('AddonPage', () => {
const infoText = info.map((infum) => infum.textContent);
assert.deepEqual(
infoText,
['Extension', 'Fully Reviewed', 'View on site', 'Edit on site', 'View homepage',
'Email support', 'View support site']);
['Extension', 'Fully Reviewed', 'View on site', 'Edit on site', 'View on editors',
'View homepage', 'Email support', 'View support site']);
});

it('renders the AMO page as a link', () => {
Expand Down Expand Up @@ -129,7 +133,7 @@ describe('AddonPage', () => {
const version = Array
.from(root.querySelector('.addon--version-info').childNodes)
.map((infum) => infum.textContent);
assert.deepEqual(version, ['2.5-beta.1']);
assert.deepEqual(version, ['2.5-beta.1', 'View on site', 'Edit on site']);
});

it('renders the file info', () => {
Expand All @@ -150,7 +154,7 @@ describe('AddonPage', () => {
const infoText = info.map((infum) => infum.textContent);
assert.deepEqual(
infoText,
['Extension', 'Fully Reviewed', 'View on site', 'Edit on site']);
['Extension', 'Fully Reviewed', 'View on site', 'Edit on site', 'View on editors']);
});

it('does not render the tags', () => {
Expand Down