зеркало из https://github.com/mozilla/commonplace.git
Uplift url changes from fireplace (bug 975413)
See https://github.com/mozilla/fireplace/pull/384
This commit is contained in:
Родитель
f73d8ce49d
Коммит
08798c938e
|
@ -108,6 +108,9 @@ define('helpers',
|
|||
return _.clone(user.get_settings());
|
||||
},
|
||||
get_permission: user.get_permission,
|
||||
has_developed: user.has_developed,
|
||||
has_installed: user.has_installed,
|
||||
has_purchased: user.has_purchased,
|
||||
logged_in: user.logged_in
|
||||
};
|
||||
|
||||
|
@ -115,6 +118,8 @@ define('helpers',
|
|||
var helpers = {
|
||||
api: require('urls').api.url,
|
||||
apiParams: require('urls').api.params,
|
||||
anonApi: require('urls').api.unsigned.url,
|
||||
anonApiParams: require('urls').api.unsigned.params,
|
||||
url: require('urls').reverse,
|
||||
media: require('urls').media,
|
||||
|
||||
|
|
|
@ -43,16 +43,29 @@ define('urls',
|
|||
if (user.logged_in()) {
|
||||
args._user = user.get_token();
|
||||
}
|
||||
var blacklist = settings.api_param_blacklist || [];
|
||||
for (var key in args) {
|
||||
if (!args[key] || blacklist.indexOf(key) !== -1) {
|
||||
delete args[key];
|
||||
}
|
||||
}
|
||||
_removeBlacklistedParams(args);
|
||||
return require('utils').urlparams(out, args);
|
||||
};
|
||||
}
|
||||
|
||||
function _anonymousArgs(func) {
|
||||
return function() {
|
||||
var out = func.apply(this, arguments);
|
||||
var args = api_args();
|
||||
_removeBlacklistedParams(args);
|
||||
return require('utils').urlparams(out, args);
|
||||
};
|
||||
}
|
||||
|
||||
function _removeBlacklistedParams(args) {
|
||||
var blacklist = settings.api_param_blacklist || [];
|
||||
for (var key in args) {
|
||||
if (!args[key] || blacklist.indexOf(key) !== -1) {
|
||||
delete args[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function api(endpoint, args, params) {
|
||||
if (!(endpoint in api_endpoints)) {
|
||||
console.error('Invalid API endpoint: ' + endpoint);
|
||||
|
@ -86,7 +99,12 @@ define('urls',
|
|||
url: _userArgs(api),
|
||||
params: _userArgs(apiParams),
|
||||
sign: _userArgs(function(url) {return url;}),
|
||||
unsign: _anonymousArgs(function(url) {return url;}),
|
||||
unsigned: {
|
||||
url: _anonymousArgs(api),
|
||||
params: _anonymousArgs(apiParams)
|
||||
},
|
||||
base: {
|
||||
url: api,
|
||||
params: apiParams
|
||||
}
|
||||
|
|
|
@ -96,13 +96,25 @@ test('api url signage', function(done, fail) {
|
|||
capabilities: {firefoxOS: true, widescreen: function() { return false; }, touch: 'foo'},
|
||||
routes_api: {'homepage': '/foo/homepage'},
|
||||
routes_api_args: function() {return function() {return function() {return {foo: 'bar'};};};}, // Functions get pre-evaluated.
|
||||
settings: {api_url: 'api:'}
|
||||
settings: {api_url: 'api:'},
|
||||
user: {
|
||||
logged_in: function() { return true; },
|
||||
get_setting: function(x) {},
|
||||
get_token: function() { return 'mytoken';}
|
||||
}
|
||||
}, function(urls) {
|
||||
var homepage_url = urls.api.unsigned.url('homepage');
|
||||
var homepage_url, homepage_base_url = urls.api.base.url('homepage');
|
||||
|
||||
homepage_url = homepage_base_url;
|
||||
eq_(homepage_url, 'api:/foo/homepage');
|
||||
eq_(urls.api.sign(homepage_url), urls.api.url('homepage'));
|
||||
disincludes(homepage_url, 'foo=bar');
|
||||
contains(urls.api.sign(homepage_url), 'foo=bar');
|
||||
|
||||
homepage_url = urls.api.url('homepage');
|
||||
eq_(homepage_url, urls.api.sign(homepage_base_url));
|
||||
contains(homepage_url, '_user=mytoken');
|
||||
|
||||
homepage_url = urls.api.unsigned.url('homepage');
|
||||
eq_(homepage_url, urls.api.unsign(homepage_base_url));
|
||||
disincludes(homepage_url, '_user=mytoken');
|
||||
done();
|
||||
},
|
||||
fail
|
||||
|
|
Загрузка…
Ссылка в новой задаче