Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Ban #240

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open

Ban #240

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
88b1841
Add endpoint for ban initialization
0nkery May 18, 2023
5af42da
Add NatsClient to AppContext
0nkery May 18, 2023
dcea306
Impl stage ban_intent
0nkery May 19, 2023
d2b9808
Add upsert query for ban account op
0nkery May 19, 2023
1776faf
Increase rustc version in Dockerfile
0nkery May 22, 2023
6159ced
Fix clippy
0nkery May 22, 2023
b1308c2
Impl ban_intent handler
0nkery May 22, 2023
6f849e6
Move migrations into single script
0nkery May 22, 2023
8b957b1
Update deps
0nkery May 23, 2023
b5ab3ab
WIP add nats consumer
0nkery May 23, 2023
7342ecd
Add nats consumer and ban handlers
0nkery May 24, 2023
f78b950
Rename fields + add missing pieces
0nkery May 25, 2023
b65b7dc
Publish BanRejected (almost)
0nkery May 25, 2023
b7ccd66
Use new event id format + re-arrange stage code a bit
0nkery May 25, 2023
92c57f9
Change op_id: Uuid -> i64
0nkery May 25, 2023
98d1882
Update src/app/error.rs
0nkery Jun 2, 2023
aa6bed0
Fix OperationFailed occurrences
0nkery Jun 2, 2023
33f3e5a
Apply suggestion from review
0nkery Jun 2, 2023
ca107f7
Update dependencies
mgrachev Jun 5, 2023
fffa90c
Bump `sqlx-cli` version to `0.6.3`
mgrachev Jun 5, 2023
6d56ac7
Merge pull request #243 from foxford/update-deps
mgrachev Jun 5, 2023
9a6c01b
Merge branch 'master' into ULMS-1896/ban
0nkery Jun 6, 2023
2458b56
Fix errors after updates
0nkery Jun 6, 2023
357c37e
Move transient/permanent errors to svc-nats-client
0nkery Jun 6, 2023
532de17
Fix fmt
0nkery Jun 6, 2023
57fa564
Use AgentId instead of AccountId for intent.sender
0nkery Jun 6, 2023
111d3dc
Fix clippy
0nkery Jun 6, 2023
47d0487
Use latest crates from crates.io
0nkery Jun 7, 2023
aecb21b
Add docs about ban endpoint
0nkery Jun 8, 2023
0610782
Add endpoint to get last ban operation id
0nkery Jun 8, 2023
2fc8ec8
Merge branch 'master' into ULMS-1896/ban
0nkery Jun 9, 2023
c4a5803
Update chart with nats config
0nkery Jun 13, 2023
94600c6
Fix config values
0nkery Jun 13, 2023
76666b1
Add trace
0nkery Jul 11, 2023
1004e14
Fix ban op upsert query
0nkery Jul 11, 2023
ea698f8
Merge branch 'master' into ULMS-1896/ban
0nkery Jul 14, 2023
c07fb5e
Avoid listing recordings whose author were banned during class
0nkery Jul 14, 2023
ad3e5a2
Add missing files
0nkery Jul 17, 2023
9ea0d24
Add tests for ban + refactor tests to use sqlx::test macro
0nkery Jul 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
977 changes: 700 additions & 277 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,19 @@ sqlx = { version = "0.6", features = [
"bigdecimal",
"runtime-tokio-native-tls",
] }
svc-agent = { version = "0.20", features = ["sqlx"] }
svc-agent = { version = "0.21", features = ["sqlx"] }
svc-authn = { version = "0.8", features = ["jose", "sqlx"] }
svc-authz = "0.12"
svc-error = { version = "0.5", features = [
svc-error = { version = "0.6", features = [
"svc-agent",
"svc-authn",
"svc-authz",
"sentry-extension",
"sqlx",
] }
svc-utils = { version = "0.7", features = ["log-middleware", "metrics-middleware", "cors-middleware", "authn-extractor"] }
svc-events = "0.11"
svc-nats-client = "0.8"
svc-utils = { version = "0.8", features = ["log-middleware", "metrics-middleware", "cors-middleware", "authn-extractor"] }
tokio = { version = "1.28", features = ["full"] }
tower = { version = "0.4", features = [ "timeout" ] }
tracing = "0.1"
Expand Down
20 changes: 20 additions & 0 deletions chart/templates/app-cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@ data:
{{- end }}
{{- end }}

{{- with .Values.nats }}
{{- println "" }}
[nats]
url = {{ .url | quote }}
creds = {{ .creds | quote }}
subscribe_durable.stream = {{ .subscribe_durable.stream | quote }}
subscribe_durable.consumer = {{ .subscribe_durable.consumer | quote }}
subscribe_durable.batch = {{ .subscribe_durable.batch }}
subscribe_durable.idle_heartbeat = {{ .subscribe_durable.idle_heartbeat | quote }}
{{- end }}

{{- with .Values.nats_consumer }}
{{- println "" }}
[nats_consumer]
suspend_interval = {{ .suspend_interval | quote }}
max_suspend_interval = {{ .max_suspend_interval | quote }}
suspend_sentry_interval = {{ .suspend_sentry_interval | quote }}
resubscribe_interval = {{ .resubscribe_interval | quote }}
{{- end }}

[storage]
{{- if .Values.app.storage }}
base_url = {{ .Values.app.storage.url | quote }}
Expand Down
3 changes: 3 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ clusterService:
http: 8080
metrics: 8888

nats: {}
nats_consumer: {}

tls:
secretName: tls-certificates

Expand Down
1 change: 1 addition & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
- [API](minigroups/api.md)
- [Classes API](classes/api.md)
- [Transcoding utils](utils/transcoding.md)
- [Ban](utils/ban.md)
42 changes: 42 additions & 0 deletions docs/src/utils/ban.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# API

All routes expect json payloads.

1. Get last ban operation id.
2. Send it in POST request along with other data.
If there's an error, return to 1.

### Routes
Route | Method | Short description
------------------------------- | ------ | ----------
/api/v1/account/:account_id/ban | POST | [Bans](#ban) media stream and collaboration for user
/api/v1/account/:account_id/ban | GET | [Gets](#get-last-ban-operation) last ban operation id for user

### Ban

Path variable | Type | Optional | Description
---------------------- | ----------- | -------- | --------------
account_id | string | | Account id we want to ban

JSON payload is required with following attributes:

Attribute | Type | Optional | Description
---------------------- | ----------- | -------- | --------------
last_seen_op_id | integer | | Last seen operation id which can be found by [GET request](#get-last-ban-operation)
ban | bool | | Ban/unban
class_id | uuid | | User should be banned in this particular classroom

Response: status 200 and empty payload or json object with an error description.

### Get last ban operation

Path variable | Type | Optional | Description
---------------------- | ----------- | -------- | --------------
account_id | string | | Account id we want to ban

No JSON payload is expected.

Response: status 200 and following payload or json object with an error description.

Attribute | Type | Optional | Description
last_seen_op_id | integer | | Last seen operation id which can be used later in POST request
8 changes: 8 additions & 0 deletions migrations/20230517104549_add_ban_account_op_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE IF NOT EXISTS ban_account_op (
user_account account_id PRIMARY KEY,
last_op_id bigint NOT NULL,
is_video_streaming_banned boolean NOT NULL DEFAULT false,
is_collaboration_banned boolean NOT NULL DEFAULT false
);

CREATE SEQUENCE IF NOT EXISTS ban_entity_seq_id;
11 changes: 11 additions & 0 deletions migrations/20230714081909_add_ban_history.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS ban_history (
target_account account_id NOT NULL,
class_id uuid NOT NULL,
banned_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
banned_operation_id BIGINT NOT NULL,
unbanned_at TIMESTAMPTZ,
unbanned_operation_id BIGINT,

FOREIGN KEY (class_id) REFERENCES class (id) ON DELETE CASCADE,
PRIMARY KEY (banned_operation_id)
);
Loading