-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#705 implement member-detail component (without delete and edit).
+ set isWriteable for teams correctly in user requests
- Loading branch information
1 parent
e4de052
commit 734215e
Showing
14 changed files
with
193 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
|
||
import static ch.puzzle.okr.TestHelper.defaultTeam; | ||
import static ch.puzzle.okr.TestHelper.defaultUserWithTeams; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
|
@@ -22,6 +22,8 @@ public class UserAuthorizationServiceTest { | |
UserBusinessService userBusinessService; | ||
@Mock | ||
AuthorizationService authorizationService; | ||
@Mock | ||
TeamAuthorizationService teamAuthorizationService; | ||
@InjectMocks | ||
private UserAuthorizationService userAuthorizationService; | ||
|
||
|
@@ -30,16 +32,31 @@ public class UserAuthorizationServiceTest { | |
|
||
private final AuthorizationUser authorizationUser = new AuthorizationUser( | ||
defaultUserWithTeams(1L, List.of(defaultTeam(adminTeamId)), List.of(defaultTeam(memberTeamId)))); | ||
User user = User.Builder.builder().withId(5L).withFirstname("firstname").withLastname("lastname") | ||
.withEmail("[email protected]").build(); | ||
User user = defaultUserWithTeams(1L, List.of(defaultTeam(adminTeamId), defaultTeam(memberTeamId)), List.of()); | ||
User user2 = defaultUserWithTeams(2L, List.of(), List.of(defaultTeam(adminTeamId), defaultTeam(memberTeamId))); | ||
|
||
@Test | ||
void getAllUsersShouldReturnAllUsers() { | ||
List<User> userList = List.of(user, user); | ||
when(authorizationService.getAuthorizationUser()).thenReturn(authorizationUser); | ||
List<User> userList = List.of(user, user2); | ||
when(userBusinessService.getAllUsers()).thenReturn(userList); | ||
when(teamAuthorizationService.isUserWriteAllowed(adminTeamId)).thenReturn(true); | ||
when(teamAuthorizationService.isUserWriteAllowed(memberTeamId)).thenReturn(false); | ||
|
||
List<User> users = userAuthorizationService.getAllUsers(); | ||
assertEquals(userList, users); | ||
} | ||
|
||
@Test | ||
void getAllUsers_shouldSetTeamWritableCorrectly() { | ||
List<User> userList = List.of(user, user2); | ||
when(userBusinessService.getAllUsers()).thenReturn(userList); | ||
when(teamAuthorizationService.isUserWriteAllowed(adminTeamId)).thenReturn(true); | ||
when(teamAuthorizationService.isUserWriteAllowed(memberTeamId)).thenReturn(false); | ||
|
||
List<User> users = userAuthorizationService.getAllUsers(); | ||
assertTrue(users.get(0).getUserTeamList().get(0).getTeam().isWriteable()); | ||
assertFalse(users.get(0).getUserTeamList().get(1).getTeam().isWriteable()); | ||
assertTrue(users.get(1).getUserTeamList().get(0).getTeam().isWriteable()); | ||
assertFalse(users.get(1).getUserTeamList().get(1).getTeam().isWriteable()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,7 @@ void shouldReturnSingleUserWhenFindingOwnerByValidId() { | |
.withEmail("[email protected]").build(); | ||
Mockito.when(userPersistenceService.findById(any())).thenReturn(owner); | ||
|
||
User returnedUser = userBusinessService.getOwnerById(1L); | ||
User returnedUser = userBusinessService.getUserById(1L); | ||
|
||
assertEquals(1L, returnedUser.getId()); | ||
assertEquals("Bob", returnedUser.getFirstname()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
41 changes: 40 additions & 1 deletion
41
frontend/src/app/team-management/member-detail/member-detail.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,42 @@ | ||
<div class="w-100" cdkTrapFocus cdkTrapFocusAutoCapture="true" [attr.data-testId]="'side-panel'"> | ||
<p>test</p> | ||
<div *ngIf="user$ | async as user; else spinner"> | ||
<div class="w-100"> | ||
<h2> | ||
{{ getFullNameFromUser(user) }} | ||
<span *ngIf="selectedUserIsLoggedInUser">(ich)</span> | ||
</h2> | ||
</div> | ||
<div class="w-100"> | ||
<table mat-table [dataSource]="user.userTeamList" class="okr-table"> | ||
<ng-container matColumnDef="name"> | ||
<th mat-header-cell *matHeaderCellDef>Name</th> | ||
<td mat-cell *matCellDef="let element">{{ element.team.name }}</td> | ||
</ng-container> | ||
<ng-container matColumnDef="role"> | ||
<th mat-header-cell *matHeaderCellDef>Rolle</th> | ||
<td mat-cell *matCellDef="let element"> | ||
<div class="role"> | ||
<span>{{ getRole(element) }}</span> | ||
<button mat-icon-button (click)="editTeamMembership(element, user)" *ngIf="isEditable(element)"> | ||
<mat-icon class="d-flex justify-content-center align-items-center">edit</mat-icon> | ||
</button> | ||
</div> | ||
</td> | ||
</ng-container> | ||
<ng-container matColumnDef="delete"> | ||
<th mat-header-cell *matHeaderCellDef></th> | ||
<td mat-cell *matCellDef="let element"> | ||
<button *ngIf="isDeletable(element, user)" mat-icon-button (click)="removeTeamMembership(element, user)"> | ||
<mat-icon class="d-flex justify-content-center align-items-center">delete</mat-icon> | ||
</button> | ||
</td> | ||
</ng-container> | ||
<tr mat-row *matHeaderRowDef="displayedColumns"></tr> | ||
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
<ng-template #spinner> | ||
<app-spinner text="Member wird geladen..."></app-spinner> | ||
</ng-template> |
13 changes: 13 additions & 0 deletions
13
frontend/src/app/team-management/member-detail/member-detail.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
:host { | ||
width: 100%; | ||
} | ||
|
||
.mat-column-delete { | ||
width: 20px; | ||
} | ||
|
||
.role { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
} |
65 changes: 61 additions & 4 deletions
65
frontend/src/app/team-management/member-detail/member-detail.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,75 @@ | ||
import {Component, OnInit} from '@angular/core'; | ||
import { Component, OnInit, ViewChild } from '@angular/core'; | ||
import { UserService } from '../../services/user.service'; | ||
import { mergeMap, Observable, tap } from 'rxjs'; | ||
import { getFullNameFromUser, User } from '../../shared/types/model/User'; | ||
import { ActivatedRoute, ParamMap } from '@angular/router'; | ||
import { Team } from '../../shared/types/model/Team'; | ||
import { UserTeam } from '../../shared/types/model/UserTeam'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
import { MatTable } from '@angular/material/table'; | ||
|
||
@Component({ | ||
selector: 'app-member-detail', | ||
templateUrl: './member-detail.component.html', | ||
styleUrl: './member-detail.component.css' | ||
styleUrl: './member-detail.component.scss', | ||
}) | ||
export class MemberDetailComponent implements OnInit { | ||
@ViewChild(MatTable) table!: MatTable<User[]>; | ||
|
||
user$: Observable<User> | undefined; | ||
teams: Team[] = []; | ||
selectedUserIsLoggedInUser: boolean = false; | ||
readonly displayedColumns = ['name', 'role', 'delete']; | ||
|
||
readonly getFullNameFromUser = getFullNameFromUser; | ||
|
||
constructor( | ||
) { | ||
} | ||
private readonly userService: UserService, | ||
private readonly route: ActivatedRoute, | ||
private readonly translateService: TranslateService, | ||
) {} | ||
ngOnInit(): void { | ||
this.user$ = this.route.paramMap.pipe( | ||
mergeMap((params) => { | ||
const id = this.getIdFromParams(params); | ||
return this.userService.getUserById(id); | ||
}), | ||
tap((user) => this.setSelectedUserIsLoggedinUser(user)), | ||
); | ||
} | ||
|
||
private setSelectedUserIsLoggedinUser(selectedUser: User) { | ||
this.selectedUserIsLoggedInUser = selectedUser.id === this.userService.getCurrentUser().id; | ||
} | ||
|
||
private getIdFromParams(params: ParamMap): number { | ||
const id = params.get('id'); | ||
if (!id) { | ||
throw Error('member id is undefined'); | ||
} | ||
return parseInt(id); | ||
} | ||
|
||
getRole(userTeam: UserTeam): string { | ||
if (userTeam.isTeamAdmin) { | ||
return this.translateService.instant('USER_ROLE.TEAM_ADMIN'); | ||
} | ||
return this.translateService.instant('USER_ROLE.TEAM_MEMBER'); | ||
} | ||
|
||
removeTeamMembership(userTeam: UserTeam, user: User) { | ||
alert('not implemented'); | ||
} | ||
|
||
editTeamMembership(userTeam: UserTeam, user: User) { | ||
alert('not implemented'); | ||
} | ||
|
||
isEditable(userTeam: UserTeam) { | ||
return userTeam.team.isWriteable; | ||
} | ||
|
||
isDeletable(userTeam: UserTeam, user: User): boolean { | ||
return this.isEditable(userTeam) || this.selectedUserIsLoggedInUser; | ||
} | ||
} |