@@ -53,14 +53,17 @@ pub fn doc(operation: TransformOperation) -> TransformOperation {
53
53
operation
54
54
. id ( "deactivateUser" )
55
55
. summary ( "Deactivate a user" )
56
- . description ( "Calling this endpoint will lock and deactivate the user, preventing them from doing any action.
57
- This invalidates any existing session, and will ask the homeserver to make them leave all rooms." )
56
+ . description (
57
+ "Calling this endpoint will deactivate the user, preventing them from doing any action.
58
+ This invalidates any existing session, and will ask the homeserver to make them leave all rooms." ,
59
+ )
58
60
. tag ( "user" )
59
61
. response_with :: < 200 , Json < SingleResponse < User > > , _ > ( |t| {
60
62
// In the samples, the third user is the one locked
61
63
let [ _alice, _bob, charlie, ..] = User :: samples ( ) ;
62
64
let id = charlie. id ( ) ;
63
- let response = SingleResponse :: new ( charlie, format ! ( "/api/admin/v1/users/{id}/deactivate" ) ) ;
65
+ let response =
66
+ SingleResponse :: new ( charlie, format ! ( "/api/admin/v1/users/{id}/deactivate" ) ) ;
64
67
t. description ( "User was deactivated" ) . example ( response)
65
68
} )
66
69
. response_with :: < 404 , RouteError , _ > ( |t| {
@@ -78,15 +81,13 @@ pub async fn handler(
78
81
id : UlidPathParam ,
79
82
) -> Result < Json < SingleResponse < User > > , RouteError > {
80
83
let id = * id;
81
- let mut user = repo
84
+ let user = repo
82
85
. user ( )
83
86
. lookup ( id)
84
87
. await ?
85
88
. ok_or ( RouteError :: NotFound ( id) ) ?;
86
89
87
- if user. locked_at . is_none ( ) {
88
- user = repo. user ( ) . lock ( & clock, user) . await ?;
89
- }
90
+ let user = repo. user ( ) . deactivate ( & clock, user) . await ?;
90
91
91
92
info ! ( %user. id, "Scheduling deactivation of user" ) ;
92
93
repo. queue_job ( )
@@ -132,12 +133,18 @@ mod tests {
132
133
response. assert_status ( StatusCode :: OK ) ;
133
134
let body: serde_json:: Value = response. json ( ) ;
134
135
135
- // The locked_at timestamp should be the same as the current time
136
+ // The deactivated_at timestamp should be the same as the current time
136
137
assert_eq ! (
137
- body[ "data" ] [ "attributes" ] [ "locked_at " ] ,
138
+ body[ "data" ] [ "attributes" ] [ "deactivated_at " ] ,
138
139
serde_json:: json!( state. clock. now( ) )
139
140
) ;
140
141
142
+ // Deactivating the user should not lock it
143
+ assert_eq ! (
144
+ body[ "data" ] [ "attributes" ] [ "locked_at" ] ,
145
+ serde_json:: Value :: Null
146
+ ) ;
147
+
141
148
// Make sure to run the jobs in the queue
142
149
state. run_jobs_in_queue ( ) . await ;
143
150
@@ -156,7 +163,7 @@ mod tests {
156
163
"attributes": {
157
164
"username": "alice",
158
165
"created_at": "2022-01-16T14:40:00Z",
159
- "locked_at": "2022-01-16T14:40:00Z" ,
166
+ "locked_at": null ,
160
167
"deactivated_at": "2022-01-16T14:40:00Z",
161
168
"admin": false
162
169
},
@@ -196,10 +203,16 @@ mod tests {
196
203
response. assert_status ( StatusCode :: OK ) ;
197
204
let body: serde_json:: Value = response. json ( ) ;
198
205
199
- // The locked_at timestamp should be different from the current time
206
+ // The deactivated_at timestamp should be the same as the current time
207
+ assert_eq ! (
208
+ body[ "data" ] [ "attributes" ] [ "deactivated_at" ] ,
209
+ serde_json:: json!( state. clock. now( ) )
210
+ ) ;
211
+
212
+ // The deactivated_at timestamp should be different from the locked_at timestamp
200
213
assert_ne ! (
214
+ body[ "data" ] [ "attributes" ] [ "deactivated_at" ] ,
201
215
body[ "data" ] [ "attributes" ] [ "locked_at" ] ,
202
- serde_json:: json!( state. clock. now( ) )
203
216
) ;
204
217
205
218
// Make sure to run the jobs in the queue
0 commit comments