-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from hpi-schul-cloud/BC-7971-room-members
add docs form module room-member
- Loading branch information
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
docs/schulcloud-server/our nextjs modules/room-member-module/index.md
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,97 @@ | ||
# Room Member Module | ||
|
||
The Room Member module manages the association between users and rooms, handling permissions and roles within rooms. This module is designed to be injected into the Room module for managing user access and roles within rooms. | ||
|
||
## Model Relationships | ||
|
||
![Room Member Module Relationships](./p1.excalidraw.png) | ||
|
||
1. Room have one RoomMembers | ||
2. RoomMember have one UserGroup | ||
3. UserGroup have many Users | ||
4. Each User in UserGroup have Role | ||
|
||
This make room membership easy manage. Can give different roles to users in same room. | ||
|
||
|
||
### RoomMemberEntity | ||
|
||
The core entity of this module is the `RoomMemberEntity`, which represents a user's membership in a room. | ||
|
||
```typescript | ||
@Entity({ tableName: 'room-members' }) | ||
export class RoomMemberEntity extends BaseEntityWithTimestamps implements RoomMemberProps { | ||
@Property() | ||
@Index() | ||
roomId!: ObjectId; | ||
|
||
@OneToOne(() => GroupEntity, { owner: true, orphanRemoval: true }) | ||
userGroup!: GroupEntity; | ||
|
||
@Property({ persist: false }) | ||
domainObject: RoomMember | undefined; | ||
} | ||
``` | ||
|
||
The important part is the `userGroup` property. | ||
|
||
We store the the members using the `Group` module. | ||
Why? => Because that allows us to assign each user a separate role within the room. | ||
e.g. ROOM_EDITOR, ROOM_VIEWER, ... | ||
|
||
These roles are not related to the user's global role. | ||
|
||
### GroupEntity | ||
|
||
The `userGroup` property uses the `GroupEntity` from the Group module. This structure allows for multiple users to be associated with a room through a single group. | ||
|
||
```typescript | ||
class GroupEntity { | ||
id: EntityId; | ||
name: string; | ||
users: GroupUserEmbeddable[]; | ||
// other properties... | ||
} | ||
``` | ||
|
||
### GroupUserEmbeddable | ||
|
||
Each user in the group is represented by a `GroupUserEmbeddable`: | ||
|
||
```typescript | ||
class GroupUserEmbeddable { | ||
user: User; | ||
role: Role; | ||
} | ||
``` | ||
|
||
This structure allows for flexible assignment of roles to users within the context of a room. | ||
|
||
## Key Points | ||
|
||
1. The `RoomMemberEntity` doesn't directly store user IDs or roles. Instead, it uses a `GroupEntity` to manage this information. | ||
2. This design allows for easy management of multiple users and roles for a single room. | ||
3. The `roomId` is stored directly on the `RoomMemberEntity` for efficient querying of members for a specific room. | ||
4. The `domainObject` property facilitates the separation between the database entity and the domain object. This is an optimization to not loose the unit of work using mikro-orm. | ||
|
||
This structure provides a flexible and scalable way to manage room memberships, allowing for complex permission and role scenarios within rooms. | ||
|
||
## Service | ||
|
||
The `RoomMemberService` is a service for the `RoomMember` entity. It provides methods for creating, updating, and deleting `RoomMember` entities. | ||
|
||
```typescript | ||
class RoomMemberService { | ||
constructor(private readonly roomMembersRepo: RoomMemberRepo) {} | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
The `RoomMemberService` is designed to be injected into the `Room` module for managing user access and roles within rooms. | ||
|
||
## API | ||
|
||
There is no API for now. Member specific writes/reads can be implemented by adding an API to the RoomMember module. | ||
Like adding/removing users to a room. | ||
|
Binary file added
BIN
+244 KB
docs/schulcloud-server/our nextjs modules/room-member-module/p1.excalidraw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.