Skip to content

Commit

Permalink
Merge branch 'hotfix/1.1.2' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
hauke96 committed Oct 1, 2020
2 parents 4754989 + 831c520 commit 9681242
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-task-manager",
"version": "1.1.1",
"version": "1.1.2",
"scripts": {
"ng": "ng",
"dev": "ng serve --watch",
Expand Down
4 changes: 2 additions & 2 deletions client/src/app/project/all-projects.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/r
import { Project } from './project.material';
import { ProjectService } from './project.service';
import { Observable } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { catchError, share, tap } from 'rxjs/operators';
import { HttpErrorResponse } from '@angular/common/http';
import { NotificationService } from '../common/notification.service';

Expand All @@ -16,7 +16,7 @@ export class AllProjectsResolver implements Resolve<Project[]> {
}

resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Project[]> {
return this.projectService.getProjects().pipe(
return this.projectService.getProjects().pipe(tap(p => console.log(p)),
catchError((e: HttpErrorResponse) => {
this.notificationService.addError($localize`:@@ERROR_LOAD_PROJECTS:Could not load projects`);
throw e;
Expand Down
24 changes: 18 additions & 6 deletions client/src/app/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ export class UserService {
const url = environment.osm_api_url + '/users?users=' + uncachedUsers.join(',');

// TODO handle case of removed account: Here a comma separated list of users will return a 404 when one UID doesn't exist anymore
return this.http.get(url, {responseType: 'text'}).pipe(
// The users API support JSON
return this.http.get(url, {headers: {ContentType: 'application/json'}}).pipe(
map(result => {
const loadedUsers = this.extractUserFromXmlAttributes(result, 'user', 'display_name', 'id');
const loadedUsers = this.extractUserFromJsonResult(result);
loadedUsers.forEach(u => this.cache.set(u.uid, u));
return cachedUsers.concat(loadedUsers);
})
Expand All @@ -40,12 +41,13 @@ export class UserService {
return of(cachedUser);
}

// Unfortunately these endpoints to not support JSON as response format
const changesetUrl = environment.osm_api_url + '/changesets?display_name=' + userName;
const notesUrl = environment.osm_api_url + '/notes/search?display_name=' + userName;

return this.http.get(changesetUrl, {responseType: 'text'}).pipe(
return this.http.get(changesetUrl, {responseType: 'text', headers: {ContentType: 'application/xml'}}).pipe(
map(result => {
const user = this.extractUserFromXmlAttributes(result, 'changeset', 'user', 'uid')[0];
const user = this.extractUserFromXmlResult(result, 'changeset', 'user', 'uid')[0];
if (!user) {
throw new Error('User \'' + userName + '\' not found in changesets');
}
Expand All @@ -58,7 +60,7 @@ export class UserService {
console.error(e);

// Second try, this time via the notes API
return this.http.get(notesUrl, {responseType: 'text'}).pipe(
return this.http.get(notesUrl, {responseType: 'text', headers: {ContentType: 'application/xml'}}).pipe(
map(result => {
const user = this.extractDataFromComment(result, userName);
if (!user) {
Expand All @@ -73,7 +75,7 @@ export class UserService {
}

// Takes the name of a XML-node (e.g. "user" or "changeset" and finds the according attribute
private extractUserFromXmlAttributes(xmlString: string, nodeQualifier: string, nameQualifier: string, idQualifier: string): User[] {
private extractUserFromXmlResult(xmlString: string, nodeQualifier: string, nameQualifier: string, idQualifier: string): User[] {
if (window.DOMParser) {
const parser = new DOMParser();
const xmlDoc = parser.parseFromString('' + xmlString, 'application/xml');
Expand All @@ -91,6 +93,16 @@ export class UserService {
return null;
}

private extractUserFromJsonResult(result: any): User[] {
const users = [];
for (const u of result.users) {
const name = u?.user?.display_name;
const uid = u?.user?.id;
users.push(new User(name, '' + uid));
}
return users;
}

private extractDataFromComment(xmlString: string, userName: string): User {
if (window.DOMParser) {
const parser = new DOMParser();
Expand Down
2 changes: 1 addition & 1 deletion server/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

const (
VERSION = "1.1.1"
VERSION = "1.1.2"
)

func GetParam(param string, r *http.Request) (string, error) {
Expand Down

0 comments on commit 9681242

Please sign in to comment.