Merge pull request #6345 from mabashian/5964-apiv1-hard-coding

Replaced all hard-coded api/v1 references with dynamic references or with v2
This commit is contained in:
Michael Abashian 2017-05-25 17:15:36 -04:00 committed by GitHub
commit 32f8c0bfaf
36 changed files with 64 additions and 70 deletions

View File

@ -61,7 +61,7 @@ export default ['$scope', '$rootScope',
if ($rootScope.current_user && $rootScope.current_user.is_superuser) {
$scope.canShareCredential = true;
} else {
Rest.setUrl(`/api/v1/users/${$rootScope.current_user.id}/admin_of_organizations`);
Rest.setUrl(GetBasePath('users') + `${$rootScope.current_user.id}/admin_of_organizations`);
Rest.get()
.success(function(data) {
$scope.canShareCredential = (data.count) ? true : false;

View File

@ -431,7 +431,7 @@ export default ['i18n', function(i18n) {
dataTipWatch: 'permissionsTooltip',
awToolTipTabEnabledInEditMode: true,
dataPlacement: 'right',
basePath: 'api/v1/credentials/{{$stateParams.credential_id}}/access_list/',
basePath: 'api/v2/credentials/{{$stateParams.credential_id}}/access_list/',
search: {
order_by: 'username'
},

View File

@ -55,7 +55,7 @@ export default ['$scope', '$rootScope', '$location',
if ($rootScope.current_user && $rootScope.current_user.is_superuser) {
$scope.canShareCredential = true;
} else {
Rest.setUrl(`/api/v1/users/${$rootScope.current_user.id}/admin_of_organizations`);
Rest.setUrl(GetBasePath('users') + `${$rootScope.current_user.id}/admin_of_organizations`);
Rest.get()
.success(function(data) {
$scope.canShareCredential = (data.count) ? true : false;

View File

@ -30,14 +30,10 @@ export default
// smartStatus?, launchUrl, editUrl, name
scope.templates = _.map(list, function(template){ return {
recent_jobs: template.summary_fields.recent_jobs,
launch_url: template.url,
edit_url: template.url.replace('api/v1', '#'),
name: template.name,
id: template.id,
type: template.type
}; });
scope.snapRows = (list.length < 4);
}
scope.isSuccessful = function (status) {

View File

@ -29,14 +29,12 @@ export default
// detailsUrl, status, name, time
scope.jobs = _.map(list, function(job){
return {
detailsUrl: job.type && job.type === 'workflow_job' ? job.url.replace("api/v1/workflow_jobs", "#/workflows") : job.url.replace("api/v1", "#"),
detailsUrl: job.type && job.type === 'workflow_job' ? job.url.replace(/api\/v\d+\/workflow_jobs/, "#/workflows") : job.url.replace(/api\/v\d+/, "#"),
status: job.status,
name: job.name,
id: job.id,
time: $filter('longDate')(job.finished)
}; });
scope.snapRows = (list.length < 4);
}
scope.isSuccessful = function (status) {

View File

@ -23,7 +23,7 @@ export default ['$scope', '$rootScope','Wait',
ProcessErrors($scope, data, status, null, { hdr: 'Error!', msg: 'Failed to get dashboard host graph data: ' + status });
});
Rest.setUrl("api/v1/unified_jobs?order_by=-finished&page_size=5&finished__isnull=false&type=workflow_job,job");
Rest.setUrl(GetBasePath("unified_jobs") + "?order_by=-finished&page_size=5&finished__isnull=false&type=workflow_job,job");
Rest.get()
.success(function (data) {
$scope.dashboardJobsListData = data.results;
@ -99,7 +99,7 @@ export default ['$scope', '$rootScope','Wait',
.error(function (data, status) {
ProcessErrors($scope, data, status, null, { hdr: 'Error!', msg: 'Failed to get dashboard: ' + status });
});
Rest.setUrl("api/v1/unified_jobs?order_by=-finished&page_size=5&finished__isnull=false&type=workflow_job,job");
Rest.setUrl(GetBasePath("unified_jobs") + "?order_by=-finished&page_size=5&finished__isnull=false&type=workflow_job,job");
Rest.get()
.success(function (data) {
data = data.results;

View File

@ -112,7 +112,7 @@ export default ['i18n', 'InventoryCompletedJobsList', function(i18n, InventoryCo
name: 'permissions',
awToolTip: i18n._('Please save before assigning permissions'),
dataPlacement: 'top',
basePath: 'api/v1/inventories/{{$stateParams.smartinventory_id}}/access_list/',
basePath: 'api/v2/inventories/{{$stateParams.smartinventory_id}}/access_list/',
type: 'collection',
title: i18n._('Permissions'),
iterator: 'permission',

View File

@ -1,5 +1,5 @@
export default ['jobData', 'jobDataOptions', 'jobLabels', 'jobFinished', 'count', '$scope', 'ParseTypeChange', 'ParseVariableString', 'jobResultsService', 'eventQueue', '$compile', '$log', 'Dataset', '$q', 'QuerySet', '$rootScope', 'moment', '$stateParams', 'i18n', 'fieldChoices', 'fieldLabels', 'workflowResultsService', 'statusSocket',
function(jobData, jobDataOptions, jobLabels, jobFinished, count, $scope, ParseTypeChange, ParseVariableString, jobResultsService, eventQueue, $compile, $log, Dataset, $q, QuerySet, $rootScope, moment, $stateParams, i18n, fieldChoices, fieldLabels, workflowResultsService, statusSocket) {
export default ['jobData', 'jobDataOptions', 'jobLabels', 'jobFinished', 'count', '$scope', 'ParseTypeChange', 'ParseVariableString', 'jobResultsService', 'eventQueue', '$compile', '$log', 'Dataset', '$q', 'QuerySet', '$rootScope', 'moment', '$stateParams', 'i18n', 'fieldChoices', 'fieldLabels', 'workflowResultsService', 'statusSocket', 'GetBasePath',
function(jobData, jobDataOptions, jobLabels, jobFinished, count, $scope, ParseTypeChange, ParseVariableString, jobResultsService, eventQueue, $compile, $log, Dataset, $q, QuerySet, $rootScope, moment, $stateParams, i18n, fieldChoices, fieldLabels, workflowResultsService, statusSocket, GetBasePath) {
var toDestroy = [];
var cancelRequests = false;
var runTimeElapsedTimer = null;
@ -49,7 +49,7 @@ function(jobData, jobDataOptions, jobLabels, jobFinished, count, $scope, ParseTy
var getTowerLink = function(key) {
if(key === 'schedule') {
if($scope.job.related.schedule) {
return '/#/templates/job_template/' + $scope.job.job_template + '/schedules' + $scope.job.related.schedule.split('api/v1/schedules')[1];
return '/#/templates/job_template/' + $scope.job.job_template + '/schedules' + $scope.job.related.schedule.split(/api\/v\d+\/schedules/)[1];
}
else {
return null;
@ -66,7 +66,7 @@ function(jobData, jobDataOptions, jobLabels, jobFinished, count, $scope, ParseTy
else {
if ($scope.job.related[key]) {
return '/#/' + $scope.job.related[key]
.split('api/v1/')[1];
.split(/api\/v\d+\//)[1];
} else {
return null;
}
@ -132,7 +132,7 @@ function(jobData, jobDataOptions, jobLabels, jobFinished, count, $scope, ParseTy
// return a promise from the options request with the permission type choices (including adhoc) as a param
var fieldChoice = fieldChoices({
$scope: $scope,
url: 'api/v1/unified_jobs/',
url: GetBasePath('unified_jobs'),
field: 'type'
});

View File

@ -505,7 +505,7 @@
<a ng-show="job.status === 'failed' ||
job.status === 'successful' ||
job.status === 'canceled'"
href="/api/v1/jobs/{{ job.id }}/stdout?format=txt_download">
href="/api/v2/jobs/{{ job.id }}/stdout?format=txt_download">
<button class="StandardOut-actionButton"
aw-tool-tip="{{ standardOutTooltip }}"
data-tip-watch="standardOutTooltip"

View File

@ -152,7 +152,7 @@ export default
getUser: function () {
return $http({
method: 'GET',
url: '/api/v1/me/',
url: GetBasePath('me'),
headers: {
'Authorization': 'Token ' + this.getToken(),
"X-Auth-Token": 'Token ' + this.getToken()

View File

@ -38,10 +38,10 @@
*
* When the the login button is clicked, the following occurs:
*
* - Call Authorization.retrieveToken(username, password) - sends a POST request to /api/v1/authtoken to get a new token value.
* - Call Authorization.retrieveToken(username, password) - sends a POST request to /api/v2/authtoken to get a new token value.
* - Call Authorization.setToken(token, expires) to store the token and exipration time in a session cookie.
* - Start the expiration timer by calling the init() method of [js/shared/Timer.js](/static/docs/api/shared.function:Timer)
* - Get user informaton by calling Authorization.getUser() - sends a GET request to /api/v1/me
* - Get user informaton by calling Authorization.getUser() - sends a GET request to /api/v2/me
* - Store user information in the session cookie by calling Authorization.setUser().
* - Get the Tower license by calling ConfigService.getConfig() - sends a GET request to /api/vi/config
* - Stores the license object in memory by calling CheckLicense.test(). This adds the Tower version and a tested flag to the license object. The tested flag is initially set to false. Additionally, the pendoService and FeaturesService are called to initiate the other startup services of Tower

View File

@ -15,7 +15,7 @@ export default ['$window', '$scope', 'thirdPartySignOnService',
function ($window, $scope, thirdPartySignOnService) {
thirdPartySignOnService(
{scope: $scope, url: "api/v1/auth/"}).then(function (data) {
{scope: $scope, url: "api/v2/auth/"}).then(function (data) {
if (data && data.options && data.options.length > 0) {
$scope.thirdPartyLoginSupported = true;
$scope.loginItems = data.options;

View File

@ -57,7 +57,7 @@ export default ['NotificationsList', 'i18n',
name: 'users',
dataPlacement: 'top',
awToolTip: i18n._('Please save before adding users'),
basePath: 'api/v1/organizations/{{$stateParams.organization_id}}/access_list/',
basePath: 'api/v2/organizations/{{$stateParams.organization_id}}/access_list/',
search: {
order_by: 'username'
},

View File

@ -225,7 +225,7 @@ export default ['i18n', 'NotificationsList', function(i18n, NotificationsList) {
awToolTip: i18n._('Please save before assigning permissions'),
djangoModel: 'access_list',
dataPlacement: 'top',
basePath: 'api/v1/projects/{{$stateParams.project_id}}/access_list/',
basePath: 'api/v2/projects/{{$stateParams.project_id}}/access_list/',
search: {
order_by: 'username'
},

View File

@ -19,8 +19,8 @@
* Note that $http will automaticall encode the URL, replacing spaces and special characters with appropriate %hex codes. Example URL values might include:
*
* ```
* /api/v1/inventories/9/
* /api/v1/credentials/?name=SSH Key&kind=ssh
* /api/v2/inventories/9/
* /api/v2/credentials/?name=SSH Key&kind=ssh
* ```
*
* When constructing the URL be sure to use the GetBasePath() method found in js/shared/Utilities.js. GetBasePath uses the response objects from /api and

View File

@ -339,7 +339,7 @@ export default
return qs.search(path, $stateParams[`${list.iterator}_search`]);
}
],
ParentObject: [() =>{return {endpoint:'/api/v1/schedules'}; }],
ParentObject: ['GetBasePath', (GetBasePath) =>{return {endpoint:GetBasePath('schedules')}; }],
UnifiedJobsOptions: ['Rest', 'GetBasePath', '$stateParams', '$q',
function(Rest, GetBasePath, $stateParams, $q) {
Rest.setUrl(GetBasePath('unified_jobs'));

View File

@ -13,8 +13,8 @@ export default {
},
resolve: {
orgAdmin:
['$rootScope', 'ProcessErrors', 'Rest',
function($rootScope, ProcessErrors, Rest){
['$rootScope', 'ProcessErrors', 'Rest', 'GetBasePath',
function($rootScope, ProcessErrors, Rest, GetBasePath){
return $rootScope.loginConfig.promise.then(function () {
if($rootScope.current_user.related.admin_of_organizations){
@ -22,7 +22,7 @@ export default {
if ($rootScope.current_user.is_superuser) {
return true;
} else {
Rest.setUrl(`/api/v1/users/${$rootScope.current_user.id}/admin_of_organizations`);
Rest.setUrl(GetBasePath('users') + `${$rootScope.current_user.id}/admin_of_organizations`);
return Rest.get().then(function(data){
if(data.data.count){
return true;

View File

@ -63,7 +63,7 @@ angular.module('ApiLoader', ['Utilities'])
.factory('GetBasePath', ['$rootScope', 'Store', 'LoadBasePaths', 'Empty',
function ($rootScope, Store, LoadBasePaths, Empty) {
return function (set) {
// use /api/v1/ results to construct API URLs.
// use /api/v2/ results to construct API URLs.
if (Empty($rootScope.defaultUrls)) {
// browser refresh must have occurred. load from local storage
if (Store('api')) {

View File

@ -130,7 +130,7 @@
<button class="StandardOut-actionButton" aw-tool-tip="{{ toggleStdoutFullscreenTooltip }}" data-tip-watch="toggleStdoutFullscreenTooltip" data-placement="top" ng-class="{'StandardOut-actionButton--active': stdoutFullScreen}" ng-click="toggleStdoutFullscreen()">
<i class="fa fa-arrows-alt"></i>
</button>
<a href="/api/v1/ad_hoc_commands/{{ job.id }}/stdout?format=txt_download">
<a href="/api/v2/ad_hoc_commands/{{ job.id }}/stdout?format=txt_download">
<button class="StandardOut-actionButton" aw-tool-tip="{{'Download Output'|translate}}" data-placement="top">
<i class="fa fa-download"></i>
</button>

View File

@ -124,7 +124,7 @@
<button class="StandardOut-actionButton" aw-tool-tip="{{ toggleStdoutFullscreenTooltip }}" data-tip-watch="toggleStdoutFullscreenTooltip" data-placement="top" ng-class="{'StandardOut-actionButton--active': stdoutFullScreen}"ng-click="toggleStdoutFullscreen()">
<i class="fa fa-arrows-alt"></i>
</button>
<a href="/api/v1/inventory_updates/{{ job.id }}/stdout?format=txt_download">
<a href="/api/v2/inventory_updates/{{ job.id }}/stdout?format=txt_download">
<button class="StandardOut-actionButton" aw-tool-tip="{{'Download Output'|translate}}" data-placement="top">
<i class="fa fa-download"></i>
</button>

View File

@ -98,7 +98,7 @@
<button class="StandardOut-actionButton" aw-tool-tip="{{ toggleStdoutFullscreenTooltip }}" data-tip-watch="toggleStdoutFullscreenTooltip" data-placement="top" ng-class="{'StandardOut-actionButton--active': stdoutFullScreen}"ng-click="toggleStdoutFullscreen()">
<i class="fa fa-arrows-alt"></i>
</button>
<a href="/api/v1/project_updates/{{ job.id }}/stdout?format=txt_download">
<a href="/api/v2/project_updates/{{ job.id }}/stdout?format=txt_download">
<button class="StandardOut-actionButton" aw-tool-tip="{{'Download Output'|translate}}" data-placement="top">
<i class="fa fa-download"></i>
</button>

View File

@ -87,7 +87,7 @@ export default ['$scope', '$rootScope', '$stateParams', 'TeamForm', 'Rest',
$scope.convertApiUrl = function(str) {
if (str) {
return str.replace("api/v1", "#");
return str.replace(/api\/v\d+/, "#");
} else {
return null;
}

View File

@ -67,7 +67,7 @@ export default ['i18n', function(i18n) {
name: 'users',
dataPlacement: 'top',
awToolTip: i18n._('Please save before adding users'),
basePath: 'api/v1/teams/{{$stateParams.team_id}}/access_list/',
basePath: 'api/v2/teams/{{$stateParams.team_id}}/access_list/',
search: {
order_by: 'username'
},
@ -104,7 +104,7 @@ export default ['i18n', function(i18n) {
},
permissions: {
name: 'permissions',
basePath: 'api/v1/teams/{{$stateParams.team_id}}/roles/',
basePath: 'api/v2/teams/{{$stateParams.team_id}}/roles/',
search: {
page_size: '10',
// @todo ask about name field / serializer on this endpoint

View File

@ -11,7 +11,7 @@ export default ['i18n', function(i18n) {
awToolTip: i18n._('Please save and run a job to view'),
dataPlacement: 'top',
name: 'completed_jobs',
basePath: 'api/v1/job_templates/{{$stateParams.job_template_id}}/jobs/?or__status=successful&or__status=failed&or__status=error&or__status=canceled',
basePath: 'api/v2/job_templates/{{$stateParams.job_template_id}}/jobs/?or__status=successful&or__status=failed&or__status=error&or__status=canceled',
iterator: 'completed_job',
editTitle: i18n._('COMPLETED JOBS'),
index: false,

View File

@ -426,7 +426,7 @@ function(NotificationsList, CompletedJobsList, i18n) {
name: 'permissions',
awToolTip: i18n._('Please save before assigning permissions'),
dataPlacement: 'top',
basePath: 'api/v1/job_templates/{{$stateParams.job_template_id}}/access_list/',
basePath: 'api/v2/job_templates/{{$stateParams.job_template_id}}/access_list/',
search: {
order_by: 'username'
},

View File

@ -137,7 +137,7 @@
callback: 'choicesReadyVerbosity'
});
Rest.setUrl('api/v1/labels');
Rest.setUrl(GetBasePath('labels'));
Rest.get()
.success(function (data) {
$scope.labelOptions = data.results

View File

@ -351,7 +351,7 @@ export default
callback: 'choicesReady'
});
Rest.setUrl('api/v1/labels');
Rest.setUrl(GetBasePath('labels'));
Wait("start");
Rest.get()
.success(function (data) {

View File

@ -108,7 +108,7 @@ export default ['NotificationsList', 'i18n', function(NotificationsList, i18n) {
name: 'permissions',
awToolTip: i18n._('Please save before assigning permissions'),
dataPlacement: 'top',
basePath: 'api/v1/workflow_job_templates/{{$stateParams.workflow_job_template_id}}/access_list/',
basePath: 'api/v2/workflow_job_templates/{{$stateParams.workflow_job_template_id}}/access_list/',
search: {
order_by: 'username'
},

View File

@ -47,7 +47,7 @@ export default [
templateType: 'workflow_job_template'
});
Rest.setUrl('api/v1/labels');
Rest.setUrl(GetBasePath('labels'));
Wait("start");
Rest.get()
.success(function (data) {

View File

@ -128,7 +128,7 @@ export default ['$scope', '$rootScope', '$stateParams', 'UserForm', 'Rest',
$scope.convertApiUrl = function(str) {
if (str) {
return str.replace("api/v1", "#");
return str.replace(/api\/v\d+/, "#");
} else {
return null;
}

View File

@ -119,7 +119,7 @@ export default ['i18n', function(i18n) {
organizations: {
name: 'organizations',
awToolTip: i18n._('Please save before assigning to organizations'),
basePath: 'api/v1/users/{{$stateParams.user_id}}/organizations',
basePath: 'api/v2/users/{{$stateParams.user_id}}/organizations',
emptyListText: i18n._('Please add user to an Organization.'),
search: {
page_size: '10'
@ -147,7 +147,7 @@ export default ['i18n', function(i18n) {
teams: {
name: 'teams',
awToolTip: i18n._('Please save before assigning to teams'),
basePath: 'api/v1/users/{{$stateParams.user_id}}/teams',
basePath: 'api/v2/users/{{$stateParams.user_id}}/teams',
search: {
page_size: '10'
},
@ -172,7 +172,7 @@ export default ['i18n', function(i18n) {
},
permissions: {
name: 'permissions',
basePath: 'api/v1/users/{{$stateParams.user_id}}/roles/',
basePath: 'api/v2/users/{{$stateParams.user_id}}/roles/',
search: {
page_size: '10',
order_by: 'id'

View File

@ -10,7 +10,7 @@ export default ['workflowData', 'workflowResultsService', 'workflowDataOptions',
var getTowerLink = function(key) {
if(key === 'schedule') {
if($scope.workflow.related.schedule) {
return '/#/templates/workflow_job_template/' + $scope.workflow.workflow_job_template + '/schedules' + $scope.workflow.related.schedule.split('api/v1/schedules')[1];
return '/#/templates/workflow_job_template/' + $scope.workflow.workflow_job_template + '/schedules' + $scope.workflow.related.schedule.split(/api\/v\d+\/schedules/)[1];
}
else {
return null;
@ -19,7 +19,7 @@ export default ['workflowData', 'workflowResultsService', 'workflowDataOptions',
else {
if ($scope.workflow.related[key]) {
return '/#/' + $scope.workflow.related[key]
.split('api/v1/')[1];
.split(/api\/v\d+\//)[1];
} else {
return null;
}

View File

@ -20,7 +20,7 @@ describe('Service: InventoryManageService', () => {
spyOn(InventoryManageService, 'error');
});
it('InventoryManageService.getInventory should handle errors', () => {
Rest.expectGET('/api/v1/inventory:id/').respond(400, {});
Rest.expectGET('/api/v2/inventory:id/').respond(400, {});
Rest.flush();
expect(InventoryManageService.error).toHaveBeenCalled();
});

View File

@ -198,12 +198,12 @@ describe('Controller: jobResultsController', () => {
describe('getTowerLinks()', () => {
beforeEach(() => {
jobData.related = {
"created_by": "api/v1/users/12",
"inventory": "api/v1/inventories/12",
"project": "api/v1/projects/12",
"credential": "api/v1/credentials/12",
"cloud_credential": "api/v1/credentials/13",
"network_credential": "api/v1/credentials/14",
"created_by": "api/v2/users/12",
"inventory": "api/v2/inventories/12",
"project": "api/v2/projects/12",
"credential": "api/v2/credentials/12",
"cloud_credential": "api/v2/credentials/13",
"network_credential": "api/v2/credentials/14",
};
jobData.summary_fields.inventory = {

View File

@ -60,8 +60,8 @@ describe('Service: QuerySet', () => {
describe('fn search', () => {
let pattern = /\/api\/v1\/inventories\/(.+)\/groups\/*/,
endpoint = '/api/v1/inventories/1/groups/',
let pattern = /\/api\/v2\/inventories\/(.+)\/groups\/*/,
endpoint = '/api/v2/inventories/1/groups/',
params = {
or__name: 'borg',
or__description__icontains: 'assimilate'
@ -72,7 +72,7 @@ describe('Service: QuerySet', () => {
.expectGET(pattern)
.respond(200, {});
QuerySet.search(endpoint, params).then((data) =>{
expect(data.config.url).toEqual('/api/v1/inventories/1/groups/?or__name=borg&or__description__icontains=assimilate');
expect(data.config.url).toEqual('/api/v2/inventories/1/groups/?or__name=borg&or__description__icontains=assimilate');
});
$httpBackend.flush();
});

View File

@ -1,17 +1,17 @@
export default {
"id": 109,
"type": "workflow_job",
"url": "/api/v1/workflow_jobs/109/",
"url": "/api/v2/workflow_jobs/109/",
"related": {
"created_by": "/api/v1/users/1/",
"unified_job_template": "/api/v1/workflow_job_templates/27/",
"workflow_job_template": "/api/v1/workflow_job_templates/27/",
"notifications": "/api/v1/workflow_jobs/109/notifications/",
"workflow_nodes": "/api/v1/workflow_jobs/109/workflow_nodes/",
"labels": "/api/v1/workflow_jobs/109/labels/",
"activity_stream": "/api/v1/workflow_jobs/109/activity_stream/",
"relaunch": "/api/v1/workflow_jobs/109/relaunch/",
"cancel": "/api/v1/workflow_jobs/109/cancel/"
"created_by": "/api/v2/users/1/",
"unified_job_template": "/api/v2/workflow_job_templates/27/",
"workflow_job_template": "/api/v2/workflow_job_templates/27/",
"notifications": "/api/v2/workflow_jobs/109/notifications/",
"workflow_nodes": "/api/v2/workflow_jobs/109/workflow_nodes/",
"labels": "/api/v2/workflow_jobs/109/labels/",
"activity_stream": "/api/v2/workflow_jobs/109/activity_stream/",
"relaunch": "/api/v2/workflow_jobs/109/relaunch/",
"cancel": "/api/v2/workflow_jobs/109/cancel/"
},
"summary_fields": {
"workflow_job_template": {