Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
ab71589c
Commit
ab71589c
authored
8 years ago
by
Erik Johnston
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #903 from matrix-org/erikj/deactivate_user
Feature: Add deactivate account admin API
parents
aac546c9
f328d95c
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
synapse/rest/client/v1/admin.py
+26
-0
26 additions, 0 deletions
synapse/rest/client/v1/admin.py
synapse/storage/_base.py
+5
-0
5 additions, 0 deletions
synapse/storage/_base.py
synapse/storage/registration.py
+9
-0
9 additions, 0 deletions
synapse/storage/registration.py
with
40 additions
and
0 deletions
synapse/rest/client/v1/admin.py
+
26
−
0
View file @
ab71589c
...
...
@@ -77,6 +77,32 @@ class PurgeMediaCacheRestServlet(ClientV1RestServlet):
defer
.
returnValue
((
200
,
ret
))
class
DeactivateAccountRestServlet
(
ClientV1RestServlet
):
PATTERNS
=
client_path_patterns
(
"
/admin/deactivate/(?P<target_user_id>[^/]*)
"
)
def
__init__
(
self
,
hs
):
self
.
store
=
hs
.
get_datastore
()
super
(
DeactivateAccountRestServlet
,
self
).
__init__
(
hs
)
@defer.inlineCallbacks
def
on_POST
(
self
,
request
,
target_user_id
):
UserID
.
from_string
(
target_user_id
)
requester
=
yield
self
.
auth
.
get_user_by_req
(
request
)
is_admin
=
yield
self
.
auth
.
is_server_admin
(
requester
.
user
)
if
not
is_admin
:
raise
AuthError
(
403
,
"
You are not a server admin
"
)
# FIXME: Theoretically there is a race here wherein user resets password
# using threepid.
yield
self
.
store
.
user_delete_access_tokens
(
target_user_id
)
yield
self
.
store
.
user_delete_threepids
(
target_user_id
)
yield
self
.
store
.
user_set_password_hash
(
target_user_id
,
None
)
defer
.
returnValue
((
200
,
{}))
def
register_servlets
(
hs
,
http_server
):
WhoisRestServlet
(
hs
).
register
(
http_server
)
PurgeMediaCacheRestServlet
(
hs
).
register
(
http_server
)
DeactivateAccountRestServlet
(
hs
).
register
(
http_server
)
This diff is collapsed.
Click to expand it.
synapse/storage/_base.py
+
5
−
0
View file @
ab71589c
...
...
@@ -807,6 +807,11 @@ class SQLBaseStore(object):
if
txn
.
rowcount
>
1
:
raise
StoreError
(
500
,
"
more than one row matched
"
)
def
_simple_delete
(
self
,
table
,
keyvalues
,
desc
):
return
self
.
runInteraction
(
desc
,
self
.
_simple_delete_txn
,
table
,
keyvalues
)
@staticmethod
def
_simple_delete_txn
(
txn
,
table
,
keyvalues
):
sql
=
"
DELETE FROM %s WHERE %s
"
%
(
...
...
This diff is collapsed.
Click to expand it.
synapse/storage/registration.py
+
9
−
0
View file @
ab71589c
...
...
@@ -384,6 +384,15 @@ class RegistrationStore(SQLBaseStore):
defer
.
returnValue
(
ret
[
'
user_id
'
])
defer
.
returnValue
(
None
)
def
user_delete_threepids
(
self
,
user_id
):
return
self
.
_simple_delete
(
"
user_threepids
"
,
keyvalues
=
{
"
user_id
"
:
user_id
,
},
desc
=
"
user_delete_threepids
"
,
)
@defer.inlineCallbacks
def
count_all_users
(
self
):
"""
Counts all users registered on the homeserver.
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment