Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Ley
synapse
Commits
eea12437
Unverified
Commit
eea12437
authored
4 years ago
by
Richard van der Hoff
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix type information on `assert_*_is_admin` methods (#7645)
These things don't return Deferreds.
parent
b4f8dcb4
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
changelog.d/7645.misc
+1
-0
1 addition, 0 deletions
changelog.d/7645.misc
synapse/api/auth.py
+4
-4
4 additions, 4 deletions
synapse/api/auth.py
synapse/rest/admin/_base.py
+14
-19
14 additions, 19 deletions
synapse/rest/admin/_base.py
with
19 additions
and
23 deletions
changelog.d/7645.misc
0 → 100644
+
1
−
0
View file @
eea12437
Fix type information on `assert_*_is_admin` methods.
This diff is collapsed.
Click to expand it.
synapse/api/auth.py
+
4
−
4
View file @
eea12437
...
@@ -510,16 +510,16 @@ class Auth(object):
...
@@ -510,16 +510,16 @@ class Auth(object):
request
.
authenticated_entity
=
service
.
sender
request
.
authenticated_entity
=
service
.
sender
return
defer
.
succeed
(
service
)
return
defer
.
succeed
(
service
)
def
is_server_admin
(
self
,
user
)
:
async
def
is_server_admin
(
self
,
user
:
UserID
)
->
bool
:
"""
Check if the given user is a local server admin.
"""
Check if the given user is a local server admin.
Args:
Args:
user
(UserID)
: user to check
user: user to check
Returns:
Returns:
bool:
True if the user is an admin
True if the user is an admin
"""
"""
return
self
.
store
.
is_server_admin
(
user
)
return
await
self
.
store
.
is_server_admin
(
user
)
def
compute_auth_events
(
def
compute_auth_events
(
self
,
event
,
current_state_ids
:
StateMap
[
str
],
for_verification
:
bool
=
False
,
self
,
event
,
current_state_ids
:
StateMap
[
str
],
for_verification
:
bool
=
False
,
...
...
This diff is collapsed.
Click to expand it.
synapse/rest/admin/_base.py
+
14
−
19
View file @
eea12437
...
@@ -15,7 +15,11 @@
...
@@ -15,7 +15,11 @@
import
re
import
re
import
twisted.web.server
import
synapse.api.auth
from
synapse.api.errors
import
AuthError
from
synapse.api.errors
import
AuthError
from
synapse.types
import
UserID
def
historical_admin_path_patterns
(
path_regex
):
def
historical_admin_path_patterns
(
path_regex
):
...
@@ -55,41 +59,32 @@ def admin_patterns(path_regex: str):
...
@@ -55,41 +59,32 @@ def admin_patterns(path_regex: str):
return
patterns
return
patterns
async
def
assert_requester_is_admin
(
auth
,
request
):
async
def
assert_requester_is_admin
(
auth
:
synapse
.
api
.
auth
.
Auth
,
request
:
twisted
.
web
.
server
.
Request
)
->
None
:
"""
Verify that the requester is an admin user
"""
Verify that the requester is an admin user
WARNING: MAKE SURE YOU YIELD ON THE RESULT!
Args:
Args:
auth (synapse.api.auth.Auth):
auth: api.auth.Auth singleton
request (twisted.web.server.Request): incoming request
request: incoming request
Returns:
Deferred
Raises:
Raises:
AuthError if the requester is not a
n
admin
AuthError if the requester is not a
server
admin
"""
"""
requester
=
await
auth
.
get_user_by_req
(
request
)
requester
=
await
auth
.
get_user_by_req
(
request
)
await
assert_user_is_admin
(
auth
,
requester
.
user
)
await
assert_user_is_admin
(
auth
,
requester
.
user
)
async
def
assert_user_is_admin
(
auth
,
user_id
)
:
async
def
assert_user_is_admin
(
auth
:
synapse
.
api
.
auth
.
Auth
,
user_id
:
UserID
)
->
None
:
"""
Verify that the given user is an admin user
"""
Verify that the given user is an admin user
WARNING: MAKE SURE YOU YIELD ON THE RESULT!
Args:
Args:
auth (synapse.api.auth.Auth):
auth: api.auth.Auth singleton
user_id (UserID):
user_id: user to check
Returns:
Deferred
Raises:
Raises:
AuthError if the user is not a
n
admin
AuthError if the user is not a
server
admin
"""
"""
is_admin
=
await
auth
.
is_server_admin
(
user_id
)
is_admin
=
await
auth
.
is_server_admin
(
user_id
)
if
not
is_admin
:
if
not
is_admin
:
raise
AuthError
(
403
,
"
You are not a server admin
"
)
raise
AuthError
(
403
,
"
You are not a server admin
"
)
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