mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
add User.is_trusted_user() and User.is_developer()
Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
ef4a7308ee
commit
d606ebc0f1
2 changed files with 45 additions and 1 deletions
|
@ -156,6 +156,18 @@ class User(Base):
|
||||||
session.delete(self.session)
|
session.delete(self.session)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
def is_trusted_user(self):
|
||||||
|
return self.AccountType.ID in {
|
||||||
|
aurweb.models.account_type.TRUSTED_USER_ID,
|
||||||
|
aurweb.models.account_type.TRUSTED_USER_AND_DEV_ID
|
||||||
|
}
|
||||||
|
|
||||||
|
def is_developer(self):
|
||||||
|
return self.AccountType.ID in {
|
||||||
|
aurweb.models.account_type.DEVELOPER_ID,
|
||||||
|
aurweb.models.account_type.TRUSTED_USER_AND_DEV_ID
|
||||||
|
}
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<User(ID='%s', AccountType='%s', Username='%s')>" % (
|
return "<User(ID='%s', AccountType='%s', Username='%s')>" % (
|
||||||
self.ID, str(self.AccountType), self.Username)
|
self.ID, str(self.AccountType), self.Username)
|
||||||
|
|
|
@ -9,7 +9,7 @@ import pytest
|
||||||
import aurweb.auth
|
import aurweb.auth
|
||||||
import aurweb.config
|
import aurweb.config
|
||||||
|
|
||||||
from aurweb.db import create, query
|
from aurweb.db import commit, create, query
|
||||||
from aurweb.models.account_type import AccountType
|
from aurweb.models.account_type import AccountType
|
||||||
from aurweb.models.ban import Ban
|
from aurweb.models.ban import Ban
|
||||||
from aurweb.models.session import Session
|
from aurweb.models.session import Session
|
||||||
|
@ -217,3 +217,35 @@ def test_user_as_dict():
|
||||||
assert data.get("Email") == user.Email
|
assert data.get("Email") == user.Email
|
||||||
# .as_dict() does not convert values to json-capable types.
|
# .as_dict() does not convert values to json-capable types.
|
||||||
assert isinstance(data.get("RegistrationTS"), datetime)
|
assert isinstance(data.get("RegistrationTS"), datetime)
|
||||||
|
|
||||||
|
|
||||||
|
def test_user_is_trusted_user():
|
||||||
|
tu_type = query(AccountType,
|
||||||
|
AccountType.AccountType == "Trusted User").first()
|
||||||
|
user.AccountType = tu_type
|
||||||
|
commit()
|
||||||
|
assert user.is_trusted_user() is True
|
||||||
|
|
||||||
|
# Do it again with the combined role.
|
||||||
|
tu_type = query(
|
||||||
|
AccountType,
|
||||||
|
AccountType.AccountType == "Trusted User & Developer").first()
|
||||||
|
user.AccountType = tu_type
|
||||||
|
commit()
|
||||||
|
assert user.is_trusted_user() is True
|
||||||
|
|
||||||
|
|
||||||
|
def test_user_is_developer():
|
||||||
|
dev_type = query(AccountType,
|
||||||
|
AccountType.AccountType == "Developer").first()
|
||||||
|
user.AccountType = dev_type
|
||||||
|
commit()
|
||||||
|
assert user.is_developer() is True
|
||||||
|
|
||||||
|
# Do it again with the combined role.
|
||||||
|
dev_type = query(
|
||||||
|
AccountType,
|
||||||
|
AccountType.AccountType == "Trusted User & Developer").first()
|
||||||
|
user.AccountType = dev_type
|
||||||
|
commit()
|
||||||
|
assert user.is_developer() is True
|
||||||
|
|
Loading…
Add table
Reference in a new issue