Skip to content

Commit

Permalink
Fix case sensitivity when checking user authorization (#184)
Browse files Browse the repository at this point in the history
* Fix case sensitivity when checking user authorization

* Remove console.log
  • Loading branch information
JunWei96 authored and ptvrajsk committed Sep 8, 2019
1 parent 1e8ca95 commit e000317
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/app/core/services/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class DataService {
// Formats the parsed information for easier app reading
parsedCSV.forEach(entry => {
if (entry[ROLE] === UserRole.Admin.toLowerCase()) {
admins[entry[NAME]] = {};
admins[entry[NAME].toLowerCase()] = {};
}
});

Expand Down Expand Up @@ -95,7 +95,7 @@ export class DataService {
}
const tutor = entry[NAME] in tutors ? tutors[entry[NAME]] : {};
tutor[entry[TEAM]] = 'true';
tutors[entry[NAME]] = tutor;
tutors[entry[NAME].toLowerCase()] = tutor;
});

return tutors;
Expand Down Expand Up @@ -126,7 +126,7 @@ export class DataService {
}
const newStudent = {};
newStudent[TEAM_ID] = entry[TEAM];
students[entry[NAME]] = newStudent;
students[entry[NAME].toLowerCase()] = newStudent;
});

return students;
Expand Down Expand Up @@ -154,7 +154,7 @@ export class DataService {
return;
}
const team = entry[TEAM] in teams ? teams[entry[TEAM]] : {};
team[entry[NAME]] = 'true';
team[entry[NAME].toLowerCase()] = 'true';
teams[entry[TEAM]] = team;
});

Expand Down Expand Up @@ -182,11 +182,11 @@ export class DataService {
// Formats the parsed information for easier app reading
parsedCSV.forEach(entry => {
if (entry[ROLE] === UserRole.Student.toLowerCase()) {
students[entry[NAME]] = 'true';
students[entry[NAME].toLowerCase()] = 'true';
} else if (entry[ROLE] === UserRole.Tutor.toLowerCase()) {
tutors[entry[NAME]] = 'true';
tutors[entry[NAME].toLowerCase()] = 'true';
} else if (entry[ROLE] === UserRole.Admin.toLowerCase()) {
admins[entry[NAME]] = 'true';
admins[entry[NAME].toLowerCase()] = 'true';
}
});

Expand Down
3 changes: 1 addition & 2 deletions src/app/core/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class UserService {
createUserModel(userLoginId: string): Observable<User> {
return this.dataService.getDataFile().pipe(
map((jsonData: {}) => {
this.currentUser = this.createUser(jsonData, userLoginId);
this.currentUser = this.createUser(jsonData, userLoginId.toLowerCase());
return this.currentUser;
}),
flatMap((user) => {
Expand All @@ -38,7 +38,6 @@ export class UserService {
private createUser(data: {}, userLoginId: string): User {
const userRole = this.parseUserRole(data, userLoginId);
switch (userRole) {

case UserRole.Student:
const teamId = data['students-allocation'][userLoginId]['teamId'];
const studentTeam = this.createTeamModel(data['team-structure'], teamId);
Expand Down

0 comments on commit e000317

Please sign in to comment.