Skip to content

Commit

Permalink
feat: Add user profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
Paula-Kli committed Oct 20, 2023
1 parent 74e2137 commit 5c19b92
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 3 deletions.
34 changes: 34 additions & 0 deletions backend/capellacollab/projects/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,40 @@ def get_projects(
return projects


@router.get(
"/common/{user_id}", response_model=models.Project, tags=["Projects"]
)
def get_common_projects(
user_for_common_projects: users_models.DatabaseUser = fastapi.Depends(
users_injectables.get_existing_user
),
user: users_models.DatabaseUser = fastapi.Depends(
users_injectables.get_own_user
),
log: logging.LoggerAdapter = fastapi.Depends(
core_logging.get_request_logger
),
) -> list[models.DatabaseProject]:
current_users_projects = [
association.project
for association in user.projects
if not association.project.visibility == models.Visibility.INTERNAL
]
projects_for_common = [
association.project
for association in user_for_common_projects.projects
if not association.project.visibility == models.Visibility.INTERNAL
]

projects = [
project
for project in current_users_projects
if project in projects_for_common
]
log.info("Fetching the following projects: %s", projects)
return projects

Check warning on line 102 in backend/capellacollab/projects/routes.py

View check run for this annotation

Codecov / codecov/patch

backend/capellacollab/projects/routes.py#L101-L102

Added lines #L101 - L102 were not covered by tests


@router.patch(
"/{project_slug}",
response_model=models.Project,
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { EditProjectMetadataComponent } from 'src/app/projects/project-detail/ed
import { SessionComponent } from 'src/app/sessions/session/session.component';
import { PipelinesOverviewComponent } from 'src/app/settings/core/pipelines-overview/pipelines-overview.component';
import { BasicAuthTokenComponent } from 'src/app/users/basic-auth-token/basic-auth-token.component';
import { UsersProfileComponent } from 'src/app/users/users-profile/users-profile.component';
import { EventsComponent } from './events/events.component';
import { AuthComponent } from './general/auth/auth/auth.component';
import { AuthGuardService } from './general/auth/auth-guard/auth-guard.service';
Expand Down Expand Up @@ -442,6 +443,11 @@ const routes: Routes = [
data: { breadcrumb: 'Events' },
component: EventsComponent,
},
{
path: 'user',
data: { breadcrumb: (data: Data) => data?.user?.name || 'User' },
component: UsersProfileComponent,
},
{
path: 'tokens',
data: { breadcrumb: 'Tokens' },
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ import { T4CRepoDeletionDialogComponent } from './settings/modelsources/t4c-sett
import { T4CSettingsWrapperComponent } from './settings/modelsources/t4c-settings/t4c-settings-wrapper/t4c-settings-wrapper.component';
import { T4CSettingsComponent } from './settings/modelsources/t4c-settings/t4c-settings.component';
import { SettingsComponent } from './settings/settings.component';
import { UsersProfileComponent } from './users/users-profile/users-profile.component';

@NgModule({
declarations: [
Expand Down Expand Up @@ -223,6 +224,7 @@ import { SettingsComponent } from './settings/settings.component';
TriggerPipelineComponent,
UserSessionsWrapperComponent,
UserSettingsComponent,
UsersProfileComponent,
VersionComponent,
ViewLogsDialogComponent,
],
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/app/general/header/header.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
</a>
</div>
<mat-menu #profileMenu="matMenu">
<a
class="profileMenuButton"
mat-menu-item
routerLink="user"
[queryParams]="{ user_id: userService.user?.id }"
>
Profile <mat-icon>account_circle</mat-icon>
</a>
<a
*ngIf="userService.user?.role === 'administrator'"
class="profileMenuButton"
Expand Down Expand Up @@ -84,7 +92,7 @@
mat-raised-button
[matMenuTriggerFor]="profileMenu"
>
Profile <mat-icon>account_circle</mat-icon>
Menu <mat-icon>menu</mat-icon>
</button>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ <h2>Project members</h2>
)
"
>
<div class="flex">
<a
class="flex"
[routerLink]="['/user']"
[queryParams]="{ user_id: user.user.id }"
>
<div class="ml-0 mr-4 flex items-center">
<mat-icon class="my-auto !h-8 !w-8 text-3xl" mat-list-icon
>account_circle</mat-icon
Expand All @@ -63,7 +67,7 @@ <h2>Project members</h2>
{{ projectUserService.PERMISSIONS[user.permission] }}
</div>
</div>
</div>
</a>
<div class="ml-1 mr-0 flex items-center">
<button
mat-icon-button
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/app/projects/service/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ export class ProjectService {
});
}

loadCommonProjects(user_id: number): void {
this.http
.get<Project[]>(`${this.BACKEND_URL_PREFIX}/common/${user_id}`)
.subscribe({
next: (projects) => this._projects.next(projects),
error: () => this._projects.next(undefined),
});
}

loadProjectBySlug(slug: string): void {
this.http.get<Project>(`${this.BACKEND_URL_PREFIX}/${slug}`).subscribe({
next: (project) => this._project.next(project),
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/app/services/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export class UserService {
return this.http.get<User>(this.BACKEND_URL_PREFIX + user.id);
}

getUserById(user_id: number): Observable<User> {
return this.http.get<User>(this.BACKEND_URL_PREFIX + user_id);
}

getCurrentUser(): Observable<User> {
return this.http.get<User>(this.BACKEND_URL_PREFIX + 'current');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
* SPDX-FileCopyrightText: Copyright DB Netz AG and the capella-collab-manager contributors
* SPDX-License-Identifier: Apache-2.0
*/
25 changes: 25 additions & 0 deletions frontend/src/app/users/users-profile/users-profile.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
~ SPDX-FileCopyrightText: Copyright DB Netz AG and the capella-collab-manager contributors
~ SPDX-License-Identifier: Apache-2.0
-->

<h2>Profile of {{ user?.name }}</h2>

<div *ngIf="user?.id !== userService.user?.id">Common Projects</div>

<ng-container
*ngIf="(projectService.projects$ | async)?.length; else elseBlock"
>
<mat-card
*ngFor="let project of projectService.projects$ | async"
class="!ml-0 cursor-pointer"
[routerLink]="['/project', project.slug]"
>
<mat-card-content>
<b>{{ project.name }}</b
><br />
{{ project.description }}
</mat-card-content>
</mat-card>
</ng-container>
<ng-template #elseBlock>You do not have any common projects.</ng-template>
36 changes: 36 additions & 0 deletions frontend/src/app/users/users-profile/users-profile.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* SPDX-FileCopyrightText: Copyright DB Netz AG and the capella-collab-manager contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ProjectService } from 'src/app/projects/service/project.service';
import { User, UserService } from 'src/app/services/user/user.service';

@Component({
selector: 'app-users-profile',
templateUrl: './users-profile.component.html',
styleUrls: ['./users-profile.component.css'],
})
export class UsersProfileComponent implements OnInit {
user: User | undefined;
user_id: number | undefined;
constructor(
public userService: UserService,
public projectService: ProjectService,
private route: ActivatedRoute,
) {}

ngOnInit() {
this.route.queryParams.subscribe(
(params) => (this.user_id = params.user_id),
);
if (this.user_id) {
this.userService
.getUserById(this.user_id)
.subscribe((user) => (this.user = user));
}
this.projectService.loadCommonProjects(this.user_id!);
}
}

0 comments on commit 5c19b92

Please sign in to comment.