Merge pull request #1913 from opf/fix/15314-fix-hyperagent-relative-url-root

15314 Teach HALAPIResource (Hyperagent) to handle relative root path
pull/1914/head
ulferts 10 years ago
commit 7c8eb5de30
  1. 2
      app/assets/javascripts/angular/api/hal-api-resource.js
  2. 4
      app/assets/javascripts/angular/helpers/components/path-helper.js
  3. 3
      app/assets/javascripts/angular/openproject-app.js
  4. 2
      app/assets/javascripts/angular/work_packages/controllers/details-tab-overview-controller.js
  5. 56
      karma/tests/api/hal-api-resource-test.js

@ -12,7 +12,7 @@ angular.module('openproject.api')
setup: function(uri) {
HALAPIResource.configure();
return new Hyperagent.Resource({
url: PathHelper.apiV3 + '/' + uri,
url: PathHelper.appBasePath + PathHelper.apiV3 + '/' + uri,
});
}
};

@ -34,7 +34,9 @@ angular.module('openproject.helpers')
apiV2: '/api/v2',
apiExperimental: '/api/experimental',
apiV3: '/api/v3',
staticBase: window.appBasePath ? window.appBasePath : '',
appBasePath: window.appBasePath ? window.appBasePath : '',
staticBase: appBasePath,
activityFromPath: function(projectIdentifier, from) {
var link = '/activity';

@ -145,6 +145,9 @@ openprojectApp
$httpProvider.defaults.headers.common['X-CSRF-TOKEN'] = jQuery('meta[name=csrf-token]').attr('content'); // TODO find a more elegant way to keep the session alive
// prepend a given base path to requests performed via $http
//
// NOTE: this does not apply to Hyperagent-based queries, which instead use
// jQuery's AJAX implementation.
$httpProvider.interceptors.push(function ($q) {
return {
'request': function (config) {

@ -45,6 +45,7 @@ angular.module('openproject.workPackages.controllers')
'USER_FIELDS',
'CustomFieldHelper',
'WorkPackagesHelper',
'PathHelper',
'UserService',
'HookService',
'$q',
@ -58,6 +59,7 @@ angular.module('openproject.workPackages.controllers')
USER_FIELDS,
CustomFieldHelper,
WorkPackagesHelper,
PathHelper,
UserService,
HookService,
$q) {

@ -30,12 +30,23 @@
describe('HALAPIResource', function() {
var HALAPIResource;
beforeEach(module('openproject.api', 'openproject.helpers'));
var HALAPIResource, testPathHelper;
beforeEach(module('openproject.api'));
beforeEach(inject(function(_HALAPIResource_){
HALAPIResource = _HALAPIResource_;
}));
beforeEach(function() {
testPathHelper = {
apiV3: '/api/v3',
appBasePath: ''
};
module(function($provide) {
$provide.value('PathHelper', testPathHelper);
});
inject(function(_HALAPIResource_) {
HALAPIResource = _HALAPIResource_;
});
});
describe('setup', function() {
var workPackageUri = 'work_packages/1';
@ -50,12 +61,35 @@ describe('HALAPIResource', function() {
resourceFunction = sinon.stub(Hyperagent, 'Resource').returns(apiResource);
}));
beforeEach(inject(function() {
HALAPIResource.setup(workPackageUri);
}))
afterEach(function() {
resourceFunction.restore();
});
describe('with default (empty) base path', function() {
beforeEach(inject(function() {
HALAPIResource.setup(workPackageUri);
}));
it('makes an api setup call', function() {
expect(resourceFunction).to.have.been.calledWith({
url: "/api/v3/" + workPackageUri
});
})
});
describe('with custom appBasePath', function() {
beforeEach(inject(function() {
testPathHelper.appBasePath = '/whitelabel';
HALAPIResource.setup(workPackageUri);
}));
it('makes an api setup call', function() {
expect(resourceFunction).to.have.been.calledWith({
url: "/whitelabel/api/v3/" + workPackageUri
});
})
});
it('makes an api setup call', function() {
expect(resourceFunction).to.have.been.calledWith({ url: "/api/v3/" + workPackageUri });
})
});
});

Loading…
Cancel
Save