Merge pull request #4680 from FinnStutzenstein/unifyUrlsPrefixes

Added beginning slash to all request urls
This commit is contained in:
Finn Stutzenstein 2019-05-13 14:49:51 +02:00 committed by GitHub
commit af717fe018
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 22 additions and 22 deletions

View File

@ -26,7 +26,7 @@ export class DataSendService {
* @param model The model to create. * @param model The model to create.
*/ */
public async createModel(model: BaseModel): Promise<Identifiable> { public async createModel(model: BaseModel): Promise<Identifiable> {
const restPath = `rest/${model.collectionString}/`; const restPath = `/rest/${model.collectionString}/`;
return await this.httpService.post<Identifiable>(restPath, model); return await this.httpService.post<Identifiable>(restPath, model);
} }
@ -36,7 +36,7 @@ export class DataSendService {
* @param model The model that is meant to be changed. * @param model The model that is meant to be changed.
*/ */
public async updateModel(model: BaseModel): Promise<void> { public async updateModel(model: BaseModel): Promise<void> {
const restPath = `rest/${model.collectionString}/${model.id}/`; const restPath = `/rest/${model.collectionString}/${model.id}/`;
await this.httpService.put(restPath, model); await this.httpService.put(restPath, model);
} }
@ -46,7 +46,7 @@ export class DataSendService {
* @param model The model to partially update. * @param model The model to partially update.
*/ */
public async partialUpdateModel(model: BaseModel): Promise<void> { public async partialUpdateModel(model: BaseModel): Promise<void> {
const restPath = `rest/${model.collectionString}/${model.id}/`; const restPath = `/rest/${model.collectionString}/${model.id}/`;
await this.httpService.patch(restPath, model); await this.httpService.patch(restPath, model);
} }
@ -56,7 +56,7 @@ export class DataSendService {
* @param model the model that shall be deleted. * @param model the model that shall be deleted.
*/ */
public async deleteModel(model: BaseModel): Promise<void> { public async deleteModel(model: BaseModel): Promise<void> {
const restPath = `rest/${model.collectionString}/${model.id}/`; const restPath = `/rest/${model.collectionString}/${model.id}/`;
await this.httpService.delete(restPath); await this.httpService.delete(restPath);
} }
} }

View File

@ -79,6 +79,10 @@ export class HttpService {
} }
let url = path + formatQueryParams(queryParams); let url = path + formatQueryParams(queryParams);
if (url[0] !== '/') {
console.warn(`Please prefix the URL "${url}" with a slash.`);
url = '/' + url;
}
if (this.OSStatus.isPrioritizedClient) { if (this.OSStatus.isPrioritizedClient) {
url = '/prioritize' + url; url = '/prioritize' + url;
} }

View File

@ -94,9 +94,8 @@ export class TimeTravelService {
* @returns the full history on the given date * @returns the full history on the given date
*/ */
private async getHistoryData(history: History): Promise<HistoryData[]> { private async getHistoryData(history: History): Promise<HistoryData[]> {
const historyUrl = '/core/history/';
const queryParams = { timestamp: Math.ceil(+history.unixtime) }; const queryParams = { timestamp: Math.ceil(+history.unixtime) };
return this.httpService.get<HistoryData[]>(environment.urlPrefix + historyUrl, null, queryParams); return this.httpService.get<HistoryData[]>(`${environment.urlPrefix}/core/history/`, null, queryParams);
} }
/** /**

View File

@ -158,6 +158,6 @@ export class SpeakerRepositoryService {
* @param suffix the desired speaker action * @param suffix the desired speaker action
*/ */
private getRestUrl(itemId: number, suffix: SpeakerAction): string { private getRestUrl(itemId: number, suffix: SpeakerAction): string {
return `rest/agenda/item/${itemId}/${suffix}/`; return `/rest/agenda/item/${itemId}/${suffix}/`;
} }
} }

View File

@ -266,7 +266,7 @@ export class ConfigRepositoryService extends BaseRepository<ViewConfig, Config>
updatedConfig.patchValues(viewConfig.config); updatedConfig.patchValues(viewConfig.config);
updatedConfig.patchValues(config); updatedConfig.patchValues(config);
// TODO: Use datasendService, if it can switch correctly between put, post and patch // TODO: Use datasendService, if it can switch correctly between put, post and patch
await this.http.put('rest/' + updatedConfig.collectionString + '/' + updatedConfig.key + '/', updatedConfig); await this.http.put(`/rest/${updatedConfig.collectionString}/${updatedConfig.key}/`, updatedConfig);
} }
/** /**

View File

@ -109,7 +109,7 @@ export class HistoryRepositoryService extends BaseRepository<ViewHistory, Histor
* Sends a post-request to delete history objects * Sends a post-request to delete history objects
*/ */
public async delete(): Promise<void> { public async delete(): Promise<void> {
const restPath = 'rest/core/history/clear_history/'; const restPath = '/rest/core/history/clear_history/';
await this.httpService.post(restPath); await this.httpService.post(restPath);
} }

View File

@ -66,9 +66,8 @@ export class MediafileRepositoryService extends BaseRepository<ViewMediafile, Me
* @returns the promise to a new mediafile. * @returns the promise to a new mediafile.
*/ */
public async uploadFile(file: FormData): Promise<Identifiable> { public async uploadFile(file: FormData): Promise<Identifiable> {
const restPath = `rest/mediafiles/mediafile/`;
const emptyHeader = new HttpHeaders(); const emptyHeader = new HttpHeaders();
return this.httpService.post<Identifiable>(restPath, file, {}, emptyHeader); return this.httpService.post<Identifiable>('`/rest/mediafiles/mediafile/', file, {}, emptyHeader);
} }
/** /**

View File

@ -77,8 +77,7 @@ export class CategoryRepositoryService extends BaseRepository<ViewCategory, Cate
* @param motionIds the list of motion ids on this category * @param motionIds the list of motion ids on this category
*/ */
public async numberMotionsInCategory(category: Category, motionIds: number[]): Promise<void> { public async numberMotionsInCategory(category: Category, motionIds: number[]): Promise<void> {
const collectionString = 'rest/motions/category/' + category.id + '/numbering/'; await this.httpService.post(`/rest/motions/category/${category.id}/numbering/`, { motions: motionIds });
await this.httpService.post(collectionString, { motions: motionIds });
} }
/** /**
@ -88,8 +87,7 @@ export class CategoryRepositoryService extends BaseRepository<ViewCategory, Cate
* @param motionIds the list of motion ids on this category * @param motionIds the list of motion ids on this category
*/ */
public async sortMotionsInCategory(category: Category, motionIds: number[]): Promise<void> { public async sortMotionsInCategory(category: Category, motionIds: number[]): Promise<void> {
const collectionString = 'rest/motions/category/' + category.id + '/sort/'; await this.httpService.post(`/rest/motions/category/${category.id}/sort/`, { motions: motionIds });
await this.httpService.post(collectionString, { motions: motionIds });
} }
/** /**

View File

@ -90,7 +90,7 @@ export class MotionCommentSectionRepositoryService extends BaseRepository<
* Updates the comment. Saves it on the server. * Updates the comment. Saves it on the server.
*/ */
private async updateComment(motion: ViewMotion, section: ViewMotionCommentSection, comment: string): Promise<void> { private async updateComment(motion: ViewMotion, section: ViewMotionCommentSection, comment: string): Promise<void> {
return await this.http.post(`rest/motions/motion/${motion.id}/manage_comments/`, { return await this.http.post(`/rest/motions/motion/${motion.id}/manage_comments/`, {
section_id: section.id, section_id: section.id,
comment: comment comment: comment
}); });
@ -100,6 +100,6 @@ export class MotionCommentSectionRepositoryService extends BaseRepository<
* Deletes a comment from the server * Deletes a comment from the server
*/ */
private async deleteComment(motion: ViewMotion, section: ViewMotionCommentSection): Promise<void> { private async deleteComment(motion: ViewMotion, section: ViewMotionCommentSection): Promise<void> {
return await this.http.delete(`rest/motions/motion/${motion.id}/manage_comments/`, { section_id: section.id }); return await this.http.delete(`/rest/motions/motion/${motion.id}/manage_comments/`, { section_id: section.id });
} }
} }

View File

@ -29,7 +29,7 @@ export class WorkflowRepositoryService extends BaseRepository<ViewWorkflow, Work
/** /**
* The url to state on rest * The url to state on rest
*/ */
private restStateUrl = 'rest/motions/state/'; private restStateUrl = '/rest/motions/state/';
/** /**
* Creates a WorkflowRepository * Creates a WorkflowRepository

View File

@ -116,7 +116,7 @@ export class UserRepositoryService extends BaseRepository<ViewUser, User> {
const data = newEntries.map(entry => { const data = newEntries.map(entry => {
return { ...entry.newEntry.user, importTrackId: entry.importTrackId }; return { ...entry.newEntry.user, importTrackId: entry.importTrackId };
}); });
const response = (await this.httpService.post(`rest/users/user/mass_import/`, { users: data })) as { const response = (await this.httpService.post(`/rest/users/user/mass_import/`, { users: data })) as {
detail: string; detail: string;
importedTrackIds: number[]; importedTrackIds: number[];
}; };

View File

@ -60,7 +60,7 @@ export class MediaManageService {
* @param action determines the action * @param action determines the action
*/ */
public async setAs(file: ViewMediafile, action: string): Promise<void> { public async setAs(file: ViewMediafile, action: string): Promise<void> {
const restPath = `rest/core/config/${action}/`; const restPath = `/rest/core/config/${action}/`;
const config = this.getMediaConfig(action); const config = this.getMediaConfig(action);
const path = config.path !== file.downloadUrl ? file.downloadUrl : ''; const path = config.path !== file.downloadUrl ? file.downloadUrl : '';

View File

@ -95,9 +95,9 @@ export class PersonalNoteService {
*/ */
private async savePersonalNoteObject(pnObject: Partial<PersonalNoteObject>): Promise<void> { private async savePersonalNoteObject(pnObject: Partial<PersonalNoteObject>): Promise<void> {
if (!pnObject.id) { if (!pnObject.id) {
await this.http.post('rest/users/personal-note/', pnObject); await this.http.post('/rest/users/personal-note/', pnObject);
} else { } else {
await this.http.put(`rest/users/personal-note/${pnObject.id}/`, pnObject); await this.http.put(`/rest/users/personal-note/${pnObject.id}/`, pnObject);
} }
} }
} }