Skip to content

Commit

Permalink
Merge pull request #47 from alkem-io/develop
Browse files Browse the repository at this point in the history
Release to add matrix admin service; tidy up logic for working with power levels in rooms
  • Loading branch information
techsmyth authored Jul 6, 2024
2 parents 8ac6ef5 + e77cd6c commit 8791a67
Show file tree
Hide file tree
Showing 25 changed files with 666 additions and 246 deletions.
29 changes: 25 additions & 4 deletions service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,30 @@ Execute the following command from the workspace root:

## Explainer

The way syncing works with Matrix SDK client is that you see the rooms in the MatrixClient that you are a member of.
This service uses the Matrix JS SDK to create a client for user.

For the way we use it this can mean that the admin account can potentially have a lot of rooms that it is a member of, and hence take a long time to sync.
This is done in two ways:

To address this, an admin account is only added as a member at the moment that it needs to read the room. This does mean the sync time will increase over time, but it
is then trivial to go to a new admin account and have that gradually join the rooms that are needed.
- there is an elevated admin user that is used to create rooms
- each Alkemio user for sending messages to a room

The Matrix Client created for a user knows about all rooms **that the user is a member of**. This is key: if the user is not a member of a room then the client does not know about that room.

For this reason the resulting setup is that the admin user ends up being a member of many rooms, as the user is added to rooms to allow reading from the room. This means that the admin user can potentially take a long time to sync up.

To address this, an admin account is only added as a member at the moment that it needs to read the room. This does mean the sync time will increase over time.
However it is then trivial to go to a new admin account and have that gradually join the rooms that are needed.

### Usage of power levels

Each room has a state. This state specifies what is the power level needed for particular actions. And crucially what is the power level that is assigned to new members of the room.

The way Alkemio uses rooms is that new members of a room get a power level that is high enough so that they can delete / carry out other actions on the room.

In rooms created before mid-2024, the users_default power level was set to zero. This meant that they cannot delete messages. After this point the default power level for new users in a room is set to 100 so that they can carry out all actions.

The power levels in rooms will need to be tidied up before the rooms in Matrix could be exposed outside of the cluster.

References:

- https://spec.matrix.org/v1.3/client-server-api/#room-events and then search for "m.room.power_levels"
2 changes: 1 addition & 1 deletion service/matrix-adapter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ matrix:

admin:
# The admin account that is created / used to administer the regular users on the Synapse server
username: ${SYNAPSE_ADMIN_USERNAME}:matrixadmin@alkem.io
username: ${SYNAPSE_ADMIN_USERNAME}:matrixadmin2@alkem.io
password: ${SYNAPSE_ADMIN_PASSWORD}:change_me_now

30 changes: 30 additions & 0 deletions service/message_samples/updateRoomStateForAdminRooms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { MatrixAdminEventUpdateRoomStateForAdminRoomsInput } from '../src/services/matrix-admin/dto/matrix.admin.dto.event.update.room.state.for.admin.rooms';

const messageBody: CmdMatrixAdminEventResetAdminRoomsInput = {
pattern: 'updateRoomStateForAdminRooms',
payload: {
adminEmail: "[email protected]",
adminPassword: "change_me_now",
powerLevel: {
users_default: 50,
redact: 0
}
}
}

// {
// "pattern": "updateRoomStateForAdminRooms",
// "data": {
// "adminEmail": "[email protected]",
// "adminPassword": "change_me_now",
// "powerLevel": {
// "users_default": 50,
// "redact": 0
// }
// }
// }

export class CmdMatrixAdminEventResetAdminRoomsInput {
pattern: string;
payload: MatrixAdminEventUpdateRoomStateForAdminRoomsInput;
}
2 changes: 1 addition & 1 deletion service/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alkemio-matrix-adapter",
"version": "0.4.3",
"version": "0.4.4",
"description": "Alkemio Matrix Adapter service",
"author": "Alkemio Foundation",
"private": false,
Expand Down
2 changes: 2 additions & 0 deletions service/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import configuration from './config/configuration';
import { HttpExceptionsFilter } from './core';
import { BootstrapModule } from './core/bootstrap/bootstrap.module';
import { CommunicationAdapterModule } from './services/communication-adapter/communication-adapter.module';
import { MatrixAdminModule } from './services/matrix-admin/matrix.admin.module';

@Module({
imports: [
Expand All @@ -22,6 +23,7 @@ import { CommunicationAdapterModule } from './services/communication-adapter/com
}),
BootstrapModule,
CommunicationAdapterModule,
MatrixAdminModule,
HealthModule,
],
providers: [
Expand Down
2 changes: 2 additions & 0 deletions service/src/common/enums/logging.context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export enum LogContext {
BOOTSTRAP = 'bootstrap',
EVENTS = 'events',
COMMUNICATION = 'communication',
MATRIX_ADMIN = 'matrix-admin',
MATRIX_ADMIN_EVENTS = 'matrix-admin-events',
MATRIX = 'matrix',
UNSPECIFIED = 'not_specified',
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MatrixRoomAdapterModule } from '@services/matrix/adapter-room/matrix.ro
import { MatrixAgentModule } from '@services/matrix/agent/matrix.agent.module';
import { MatrixUserAdapterModule } from '@services/matrix/adapter-user/matrix.user.adapter.module';
import { CommunicationAdapter } from './communication.adapter';
import { CommunicationAdminUserModule } from '../communication-admin-user/communication.admin.user.module';

@Module({
imports: [
Expand All @@ -13,6 +14,7 @@ import { CommunicationAdapter } from './communication.adapter';
MatrixRoomAdapterModule,
MatrixAgentModule,
MatrixAgentPoolModule,
CommunicationAdminUserModule,
],
providers: [CommunicationAdapter],
exports: [CommunicationAdapter],
Expand Down
Loading

0 comments on commit 8791a67

Please sign in to comment.