Skip to content

Commit

Permalink
Participant can see its own fights
Browse files Browse the repository at this point in the history
  • Loading branch information
softwaremagico committed Jun 20, 2024
1 parent ae3acef commit cdae4d6
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 26 deletions.
38 changes: 20 additions & 18 deletions frontend/src/app/interceptors/logged-in.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,32 @@ export class LoggedInService {
}

userLoginPageDependingOnRoles(context: string, params: string): boolean {
debugger
if (this.loginService.getJwtValue()) {
//Participant users must redirect to their statistcs.
if (localStorage.getItem('account') == 'participant' && !context.startsWith('/participants/statistics')) {
if (localStorage.getItem('account') == 'participant'
&& (!context.startsWith('/participants/statistics') && !context.startsWith('/participants/fights'))) {
this.router.navigate(['/participants/statistics']);
} else if (localStorage.getItem('account') == 'guest' && !context.startsWith('/tournaments/fights')) {
this.router.navigate(['/tournaments/fights']);
}
this.loginService.getUserRoles().subscribe((_roles: String[]): void => {
if (_roles.includes("viewer") || _roles.includes("editor") || _roles.includes("admin")) {
// Do nothing and navigate as usual.
} else if (_roles.includes("guest")) {
//Gets last tournament and redirects to fight list.
this.tournamentService.getLastUnlockedTournament().subscribe((_tournament: Tournament): void => {
//Path '/tournaments/fights' and '/fights/championship' does not call LoggedInService to avoid redirect loops.
if (_tournament) {
this.router.navigate(['/tournaments/fights'], {state: {tournamentId: _tournament.id}});
} else {
this.router.navigate(['/login']);
}
});
} else if (_roles.includes("participant")) {
this.router.navigate(['/participants/statistics']);
}
});
// this.loginService.getUserRoles().subscribe((_roles: String[]): void => {
// if (_roles.includes("viewer") || _roles.includes("editor") || _roles.includes("admin")) {
// // Do nothing and navigate as usual.
// } else if (_roles.includes("guest")) {
// //Gets last tournament and redirects to fight list.
// this.tournamentService.getLastUnlockedTournament().subscribe((_tournament: Tournament): void => {
// //Path '/tournaments/fights' and '/fights/championship' does not call LoggedInService to avoid redirect loops.
// if (_tournament) {
// this.router.navigate(['/tournaments/fights'], {state: {tournamentId: _tournament.id}});
// } else {
// this.router.navigate(['/login']);
// }
// });
// } else if (_roles.includes("participant")) {
// this.router.navigate(['/participants/statistics']);
// }
// });
return true;
}
return this.whiteListedPages.includes(context);
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/app/services/rbac/activity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ export class ActivityService {
RbacActivity.CHECK_TOURNAMENT_BRACKETS,
RbacActivity.READ_TEAMS_RANKINGS,
RbacActivity.READ_COMPETITORS_RANKINGS,
RbacActivity.CAN_LOGOUT
RbacActivity.CAN_LOGOUT,
RbacActivity.VIEW_PARTICIPANT_FIGHTS,
RbacActivity.VIEW_PARTICIPANT_STATISTICS
];
}

Expand Down
1 change: 1 addition & 0 deletions frontend/src/app/services/rbac/rbac.activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export enum RbacActivity {
UPLOAD_TOURNAMENT_ACCREDITATION = 'UPLOAD_TOURNAMENT_ACCREDITATION',
UPLOAD_TOURNAMENT_PHOTO = 'UPLOAD_TOURNAMENT_PHOTO',
VIEW_TOURNAMENT_STATISTICS = 'VIEW_TOURNAMENT_STATISTICS',
VIEW_PARTICIPANT_STATISTICS = 'VIEW_PARTICIPANT_STATISTICS',
VIEW_PARTICIPANT_FIGHTS = 'VIEW_PARTICIPANT_FIGHTS',

READ_ALL_ROLES = 'READ_ALL_ROLES',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<div class="fights-table">
<div class="upper-menu">
<div class="cell">
<button (click)="goBackToUsers()"
*ngIf="(RbacActivity.READ_ALL_TOURNAMENTS | rbac : this.rbacService.getActivities())"
<button (click)="goBackToStatistics()"
*ngIf="(RbacActivity.VIEW_PARTICIPANT_STATISTICS | rbac : this.rbacService.getActivities())"
[matTooltipShowDelay]="500"
mat-button
matTooltip="{{'back' | translate}}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ export class ParticipantFightListComponent extends RbacBasedComponent implements
if (state['participantId'] && !isNaN(Number(state['participantId']))) {
this.participantId = Number(state['participantId']);
} else {
this.goBackToUsers();
this.goBackToStatistics();
}
}
}

goBackToUsers(): void {
goBackToStatistics(): void {
this.router.navigate(['/participants/statistics'], {state: {participantId: this.participantId}});
}

ngOnInit(): void {
if (this.participantId) {
this.initializeData();
} else {
this.goBackToUsers();
this.goBackToStatistics();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<basic-table [basicTableData]="basicTableData" [disableRow]="disableRow"></basic-table>
<div class="bottom-menu">
<button (click)="openStatistics()"
*ngIf="(RbacActivity.VIEW_TOURNAMENT_STATISTICS | rbac : this.rbacService.getActivities())"
*ngIf="(RbacActivity.VIEW_PARTICIPANT_STATISTICS | rbac : this.rbacService.getActivities())"
[disabled]="!basicTableData.selectedElement" [matTooltipShowDelay]="500"
color="primary" mat-button
matTooltip="{{'titleStatistics' | translate}}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@

app-achievement-wall {
margin-top: 10px;
width: 270px;
width: 275px;
height: 245px;
}

Expand Down

0 comments on commit cdae4d6

Please sign in to comment.