mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
add User.is_elevated()
This one returns true if the user is either a Trusted User or a Developer. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
b59601a8b7
commit
c006386079
2 changed files with 14 additions and 0 deletions
|
@ -165,6 +165,15 @@ class User(Base):
|
||||||
aurweb.models.account_type.TRUSTED_USER_AND_DEV_ID
|
aurweb.models.account_type.TRUSTED_USER_AND_DEV_ID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def is_elevated(self):
|
||||||
|
""" A User is 'elevated' when they have either a
|
||||||
|
Trusted User or Developer AccountType. """
|
||||||
|
return self.AccountType.ID in {
|
||||||
|
aurweb.models.account_type.TRUSTED_USER_ID,
|
||||||
|
aurweb.models.account_type.DEVELOPER_ID,
|
||||||
|
aurweb.models.account_type.TRUSTED_USER_AND_DEV_ID,
|
||||||
|
}
|
||||||
|
|
||||||
def can_edit_user(self, user):
|
def can_edit_user(self, user):
|
||||||
""" Can this account record edit the target user? It must either
|
""" Can this account record edit the target user? It must either
|
||||||
be the target user or a user with enough permissions to do so.
|
be the target user or a user with enough permissions to do so.
|
||||||
|
|
|
@ -214,6 +214,11 @@ def test_user_credential_types():
|
||||||
assert aurweb.auth.developer(user)
|
assert aurweb.auth.developer(user)
|
||||||
assert aurweb.auth.trusted_user_or_dev(user)
|
assert aurweb.auth.trusted_user_or_dev(user)
|
||||||
|
|
||||||
|
# Some model authorization checks.
|
||||||
|
assert user.is_elevated()
|
||||||
|
assert user.is_trusted_user()
|
||||||
|
assert user.is_developer()
|
||||||
|
|
||||||
|
|
||||||
def test_user_json():
|
def test_user_json():
|
||||||
data = json.loads(user.json())
|
data = json.loads(user.json())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue