diff --git a/aurweb/models/user.py b/aurweb/models/user.py index bcb47754..1762f004 100644 --- a/aurweb/models/user.py +++ b/aurweb/models/user.py @@ -156,6 +156,18 @@ class User(Base): session.delete(self.session) 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): return "" % ( self.ID, str(self.AccountType), self.Username) diff --git a/test/test_user.py b/test/test_user.py index 06585207..9ab40801 100644 --- a/test/test_user.py +++ b/test/test_user.py @@ -9,7 +9,7 @@ import pytest import aurweb.auth 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.ban import Ban from aurweb.models.session import Session @@ -217,3 +217,35 @@ def test_user_as_dict(): assert data.get("Email") == user.Email # .as_dict() does not convert values to json-capable types. 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