Feature: Team Collaboration
Relevant source files
The following files were used as context for generating this wiki page:
The Team Collaboration feature is a core component of Traduora, enabling multiple users to work together on translation projects. The system is built around a role-based access control (RBAC) mechanism where users can be invited to projects and assigned specific roles that define their permissions and capabilities within that project.
This feature allows project administrators to build a team, manage their access levels, and revoke access when necessary. The functionality encompasses inviting new members, viewing existing team members and pending invitations, modifying user roles, and removing users from a project.
Sources: README.md:21, api/test/project-user.e2e-spec.ts
Core Concepts
Team collaboration is managed on a per-project basis. Users are associated with projects through a ProjectUser relationship, which includes a role assignment.
Project Roles
There are three distinct roles a user can have within a project, each with a different level of permissions.
| Role | Description - |
|---|---|
Admin | Full control over the project. Can manage team members, edit project settings, and perform all actions available to lower roles. The user who creates a project is automatically assigned as an admin. - |
Editor | Can add/edit terms and translations. Can import and export translation files. Cannot manage team members or project settings. - |
Viewer | Read-only access. Can view terms and translations but cannot make any changes. - |
Sources: api/src/domain/http.ts:310, webapp/src/app/projects/projects.module.ts:44-48, api/test/project-user.e2e-spec.ts:43-54
Data Models
The collaboration feature is primarily supported by two data transfer objects (DTOs) in the API: ProjectUserDTO for existing members and ProjectInviteDto for pending invitations.
ProjectUserDTO
Represents a user who is a member of a project.
| Field | Type | Description |
|---|---|---|
id | string | The user's unique identifier. |
name | string | The user's name. |
email | string | The user's email address. |
role | ProjectRole | The user's role within the project. |
Sources: api/src/domain/http.ts:130-139
ProjectInviteDto
Represents a pending invitation for a user to join a project.
| Field | Type | Description |
|---|---|---|
id | string | The invite's unique identifier. |
status | InviteStatus | The status of the invitation. |
email | string | The email address of the invited user. |
role | ProjectRole | The role the user will have upon joining. |
Sources: api/src/domain/http.ts:141-150
Frontend: Team Overview Component
The user interface for managing a project's team is handled by the TeamOverviewComponent. This component is responsible for fetching and displaying the list of current project users and pending invitations.
The component is accessible via the /projects/:projectId/team route.
Sources: webapp/src/app/projects/projects.module.ts:42, webapp/src/app/projects/components/team-overview/team-overview.component.ts
Component Logic
- Initialization: On initialization (
ngOnInit), the component subscribes to the current project and dispatchesGetProjectUsersandGetProjectInvitesactions to fetch the team data from the API. - Data Display: It uses
projectUsers$andprojectInvites$observables to display the lists of members and invites, sorted for consistent presentation. - User Actions: It provides methods to handle user interactions from the template, such as updating a user's role or removing a user/invite. These methods dispatch the corresponding NGXS actions (
UpdateProjectUser,RemoveProjectUser, etc.).
Sources: webapp/src/app/projects/components/team-overview/team-overview.component.ts:48-52, webapp/src/app/projects/components/team-overview/team-overview.component.ts:60-77
The following diagram shows the data flow within the frontend for displaying the team.
This diagram illustrates how the TeamOverviewComponent fetches data via the NGXS store, which in turn communicates with the backend API.
Sources: webapp/src/app/projects/components/team-overview/team-overview.component.ts:48-52
API Endpoints
The backend provides a set of RESTful endpoints under /api/v1/projects/:projectId/ to manage users and invitations.
User Management
| Method | Endpoint | Description - |
|---|---|---|
GET | /users | Retrieves a list of all users associated with the project. Returns an array of ProjectUserDTO. - |
PATCH | /users/:userId | Updates a specific user's role in the project. The request body requires a role property. A user cannot edit or remove themselves. - |
DELETE | /users/:userId | Removes a user from the project. A user cannot remove themselves. If the user being deleted is the last admin of a project with other members, the action is disallowed to prevent orphaning the project. |
Sources: api/test/project-user.e2e-spec.ts:25-35, api/test/project-user.e2e-spec.ts:130-136, api/test/project-user.e2e-spec.ts:153-157, api/test/user.e2e-spec.ts:161-186
Invitation Management
| Method | Endpoint | Description - |
|---|---|---|
POST | /invites | Invites a user to the project by email. If the user already exists in the system, they are added to the project directly. Otherwise, a pending invite is created. The request body requires an email and a role. |
DELETE | /invites/:inviteId | Revokes a pending invitation. - |
Sources: api/test/project-user.e2e-spec.ts:38-54, webapp/src/app/projects/components/team-overview/team-overview.component.ts:75-77
User Role Update Flow
This diagram shows the sequence of events when an admin changes a team member's role.
This sequence illustrates the interaction between the frontend, the state management layer (NGXS), and the backend API to process a role change.
Sources: webapp/src/app/projects/components/team-overview/team-overview.component.ts:60-62, api/test/project-user.e2e-spec.ts:57-72
Conclusion
The Team Collaboration feature is integral to Traduora's workflow, providing a robust system for managing project contributors through role-based permissions. The architecture clearly separates frontend and backend concerns, with a well-defined API for user and invitation management. The frontend TeamOverviewComponent provides a centralized and intuitive interface for project admins to manage their team, ensuring that users have the appropriate level of access to contribute to translation projects effectively and securely.
Sources: README.md:21, webapp/src/app/projects/components/team-overview/team-overview.component.ts