mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
housekeep: TU rename - code changes
Renaming of symbols. Functions, variables, values, DB values, etc. Basically everything that is not user-facing. This only covers "Trusted User" things: tests, comments, etc. will covered in a following commit.
This commit is contained in:
parent
9eda6a42c6
commit
1e6282eafe
30 changed files with 223 additions and 163 deletions
|
@ -71,7 +71,7 @@ class AnonymousUser:
|
|||
return False
|
||||
|
||||
@staticmethod
|
||||
def is_trusted_user():
|
||||
def is_package_maintainer():
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
|
@ -205,7 +205,7 @@ def account_type_required(one_of: set):
|
|||
|
||||
@router.get('/some_route')
|
||||
@auth_required(True)
|
||||
@account_type_required({"Trusted User", "Trusted User & Developer"})
|
||||
@account_type_required({"Package Maintainer", "Package Maintainer & Developer"})
|
||||
async def some_route(request: fastapi.Request):
|
||||
return Response()
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from aurweb.models.account_type import (
|
||||
DEVELOPER_ID,
|
||||
TRUSTED_USER_AND_DEV_ID,
|
||||
TRUSTED_USER_ID,
|
||||
PACKAGE_MAINTAINER_AND_DEV_ID,
|
||||
PACKAGE_MAINTAINER_ID,
|
||||
USER_ID,
|
||||
)
|
||||
from aurweb.models.user import User
|
||||
|
@ -35,42 +35,44 @@ TU_LIST_VOTES = 20
|
|||
TU_VOTE = 21
|
||||
PKGBASE_MERGE = 29
|
||||
|
||||
user_developer_or_trusted_user = set(
|
||||
[USER_ID, TRUSTED_USER_ID, DEVELOPER_ID, TRUSTED_USER_AND_DEV_ID]
|
||||
user_developer_or_package_maintainer = set(
|
||||
[USER_ID, PACKAGE_MAINTAINER_ID, DEVELOPER_ID, PACKAGE_MAINTAINER_AND_DEV_ID]
|
||||
)
|
||||
trusted_user_or_dev = set([TRUSTED_USER_ID, DEVELOPER_ID, TRUSTED_USER_AND_DEV_ID])
|
||||
developer = set([DEVELOPER_ID, TRUSTED_USER_AND_DEV_ID])
|
||||
trusted_user = set([TRUSTED_USER_ID, TRUSTED_USER_AND_DEV_ID])
|
||||
package_maintainer_or_dev = set(
|
||||
[PACKAGE_MAINTAINER_ID, DEVELOPER_ID, PACKAGE_MAINTAINER_AND_DEV_ID]
|
||||
)
|
||||
developer = set([DEVELOPER_ID, PACKAGE_MAINTAINER_AND_DEV_ID])
|
||||
package_maintainer = set([PACKAGE_MAINTAINER_ID, PACKAGE_MAINTAINER_AND_DEV_ID])
|
||||
|
||||
cred_filters = {
|
||||
PKGBASE_FLAG: user_developer_or_trusted_user,
|
||||
PKGBASE_NOTIFY: user_developer_or_trusted_user,
|
||||
PKGBASE_VOTE: user_developer_or_trusted_user,
|
||||
PKGREQ_FILE: user_developer_or_trusted_user,
|
||||
ACCOUNT_CHANGE_TYPE: trusted_user_or_dev,
|
||||
ACCOUNT_EDIT: trusted_user_or_dev,
|
||||
ACCOUNT_LAST_LOGIN: trusted_user_or_dev,
|
||||
ACCOUNT_LIST_COMMENTS: trusted_user_or_dev,
|
||||
ACCOUNT_SEARCH: trusted_user_or_dev,
|
||||
COMMENT_DELETE: trusted_user_or_dev,
|
||||
COMMENT_UNDELETE: trusted_user_or_dev,
|
||||
COMMENT_VIEW_DELETED: trusted_user_or_dev,
|
||||
COMMENT_EDIT: trusted_user_or_dev,
|
||||
COMMENT_PIN: trusted_user_or_dev,
|
||||
PKGBASE_ADOPT: trusted_user_or_dev,
|
||||
PKGBASE_SET_KEYWORDS: trusted_user_or_dev,
|
||||
PKGBASE_DELETE: trusted_user_or_dev,
|
||||
PKGBASE_EDIT_COMAINTAINERS: trusted_user_or_dev,
|
||||
PKGBASE_DISOWN: trusted_user_or_dev,
|
||||
PKGBASE_LIST_VOTERS: trusted_user_or_dev,
|
||||
PKGBASE_UNFLAG: trusted_user_or_dev,
|
||||
PKGREQ_CLOSE: trusted_user_or_dev,
|
||||
PKGREQ_LIST: trusted_user_or_dev,
|
||||
TU_ADD_VOTE: trusted_user,
|
||||
TU_LIST_VOTES: trusted_user_or_dev,
|
||||
TU_VOTE: trusted_user,
|
||||
PKGBASE_FLAG: user_developer_or_package_maintainer,
|
||||
PKGBASE_NOTIFY: user_developer_or_package_maintainer,
|
||||
PKGBASE_VOTE: user_developer_or_package_maintainer,
|
||||
PKGREQ_FILE: user_developer_or_package_maintainer,
|
||||
ACCOUNT_CHANGE_TYPE: package_maintainer_or_dev,
|
||||
ACCOUNT_EDIT: package_maintainer_or_dev,
|
||||
ACCOUNT_LAST_LOGIN: package_maintainer_or_dev,
|
||||
ACCOUNT_LIST_COMMENTS: package_maintainer_or_dev,
|
||||
ACCOUNT_SEARCH: package_maintainer_or_dev,
|
||||
COMMENT_DELETE: package_maintainer_or_dev,
|
||||
COMMENT_UNDELETE: package_maintainer_or_dev,
|
||||
COMMENT_VIEW_DELETED: package_maintainer_or_dev,
|
||||
COMMENT_EDIT: package_maintainer_or_dev,
|
||||
COMMENT_PIN: package_maintainer_or_dev,
|
||||
PKGBASE_ADOPT: package_maintainer_or_dev,
|
||||
PKGBASE_SET_KEYWORDS: package_maintainer_or_dev,
|
||||
PKGBASE_DELETE: package_maintainer_or_dev,
|
||||
PKGBASE_EDIT_COMAINTAINERS: package_maintainer_or_dev,
|
||||
PKGBASE_DISOWN: package_maintainer_or_dev,
|
||||
PKGBASE_LIST_VOTERS: package_maintainer_or_dev,
|
||||
PKGBASE_UNFLAG: package_maintainer_or_dev,
|
||||
PKGREQ_CLOSE: package_maintainer_or_dev,
|
||||
PKGREQ_LIST: package_maintainer_or_dev,
|
||||
TU_ADD_VOTE: package_maintainer,
|
||||
TU_LIST_VOTES: package_maintainer_or_dev,
|
||||
TU_VOTE: package_maintainer,
|
||||
ACCOUNT_EDIT_DEV: developer,
|
||||
PKGBASE_MERGE: trusted_user_or_dev,
|
||||
PKGBASE_MERGE: package_maintainer_or_dev,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@ def feed_initial_data(conn):
|
|||
aurweb.schema.AccountTypes.insert(),
|
||||
[
|
||||
{"ID": 1, "AccountType": "User"},
|
||||
{"ID": 2, "AccountType": "Trusted User"},
|
||||
{"ID": 2, "AccountType": "Package Maintainer"},
|
||||
{"ID": 3, "AccountType": "Developer"},
|
||||
{"ID": 4, "AccountType": "Trusted User & Developer"},
|
||||
{"ID": 4, "AccountType": "Package Maintainer & Developer"},
|
||||
],
|
||||
)
|
||||
conn.execute(
|
||||
|
|
|
@ -2,21 +2,21 @@ from aurweb import schema
|
|||
from aurweb.models.declarative import Base
|
||||
|
||||
USER = "User"
|
||||
TRUSTED_USER = "Trusted User"
|
||||
PACKAGE_MAINTAINER = "Package Maintainer"
|
||||
DEVELOPER = "Developer"
|
||||
TRUSTED_USER_AND_DEV = "Trusted User & Developer"
|
||||
PACKAGE_MAINTAINER_AND_DEV = "Package Maintainer & Developer"
|
||||
|
||||
USER_ID = 1
|
||||
TRUSTED_USER_ID = 2
|
||||
PACKAGE_MAINTAINER_ID = 2
|
||||
DEVELOPER_ID = 3
|
||||
TRUSTED_USER_AND_DEV_ID = 4
|
||||
PACKAGE_MAINTAINER_AND_DEV_ID = 4
|
||||
|
||||
# Map string constants to integer constants.
|
||||
ACCOUNT_TYPE_ID = {
|
||||
USER: USER_ID,
|
||||
TRUSTED_USER: TRUSTED_USER_ID,
|
||||
PACKAGE_MAINTAINER: PACKAGE_MAINTAINER_ID,
|
||||
DEVELOPER: DEVELOPER_ID,
|
||||
TRUSTED_USER_AND_DEV: TRUSTED_USER_AND_DEV_ID,
|
||||
PACKAGE_MAINTAINER_AND_DEV: PACKAGE_MAINTAINER_AND_DEV_ID,
|
||||
}
|
||||
|
||||
# Reversed ACCOUNT_TYPE_ID mapping.
|
||||
|
|
|
@ -157,25 +157,25 @@ class User(Base):
|
|||
with db.begin():
|
||||
db.delete(self.session)
|
||||
|
||||
def is_trusted_user(self):
|
||||
def is_package_maintainer(self):
|
||||
return self.AccountType.ID in {
|
||||
aurweb.models.account_type.TRUSTED_USER_ID,
|
||||
aurweb.models.account_type.TRUSTED_USER_AND_DEV_ID,
|
||||
aurweb.models.account_type.PACKAGE_MAINTAINER_ID,
|
||||
aurweb.models.account_type.PACKAGE_MAINTAINER_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,
|
||||
aurweb.models.account_type.PACKAGE_MAINTAINER_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.PACKAGE_MAINTAINER_ID,
|
||||
aurweb.models.account_type.DEVELOPER_ID,
|
||||
aurweb.models.account_type.TRUSTED_USER_AND_DEV_ID,
|
||||
aurweb.models.account_type.PACKAGE_MAINTAINER_AND_DEV_ID,
|
||||
}
|
||||
|
||||
def can_edit_user(self, target: "User") -> bool:
|
||||
|
|
|
@ -187,7 +187,7 @@ def pkgbase_merge_instance(
|
|||
|
||||
# Log this out for accountability purposes.
|
||||
logger.info(
|
||||
f"Trusted User '{request.user.Username}' merged "
|
||||
f"Package Maintainer '{request.user.Username}' merged "
|
||||
f"'{pkgbasename}' into '{target.Name}'."
|
||||
)
|
||||
|
||||
|
|
|
@ -7,13 +7,13 @@ from . import (
|
|||
accounts,
|
||||
auth,
|
||||
html,
|
||||
package_maintainer,
|
||||
packages,
|
||||
pkgbase,
|
||||
requests,
|
||||
rpc,
|
||||
rss,
|
||||
sso,
|
||||
trusted_user,
|
||||
)
|
||||
|
||||
"""
|
||||
|
@ -28,7 +28,7 @@ APP_ROUTES = [
|
|||
packages,
|
||||
pkgbase,
|
||||
requests,
|
||||
trusted_user,
|
||||
package_maintainer,
|
||||
rss,
|
||||
rpc,
|
||||
sso,
|
||||
|
|
|
@ -184,9 +184,9 @@ def make_account_form_context(
|
|||
lambda e: request.user.AccountTypeID >= e[0],
|
||||
[
|
||||
(at.USER_ID, f"Normal {at.USER}"),
|
||||
(at.TRUSTED_USER_ID, at.TRUSTED_USER),
|
||||
(at.PACKAGE_MAINTAINER_ID, at.PACKAGE_MAINTAINER),
|
||||
(at.DEVELOPER_ID, at.DEVELOPER),
|
||||
(at.TRUSTED_USER_AND_DEV_ID, at.TRUSTED_USER_AND_DEV),
|
||||
(at.PACKAGE_MAINTAINER_AND_DEV_ID, at.PACKAGE_MAINTAINER_AND_DEV),
|
||||
],
|
||||
)
|
||||
)
|
||||
|
@ -520,7 +520,9 @@ async def account_comments(request: Request, username: str):
|
|||
|
||||
@router.get("/accounts")
|
||||
@requires_auth
|
||||
@account_type_required({at.TRUSTED_USER, at.DEVELOPER, at.TRUSTED_USER_AND_DEV})
|
||||
@account_type_required(
|
||||
{at.PACKAGE_MAINTAINER, at.DEVELOPER, at.PACKAGE_MAINTAINER_AND_DEV}
|
||||
)
|
||||
async def accounts(request: Request):
|
||||
context = make_context(request, "Accounts")
|
||||
return render_template(request, "account/search.html", context)
|
||||
|
@ -529,7 +531,9 @@ async def accounts(request: Request):
|
|||
@router.post("/accounts")
|
||||
@handle_form_exceptions
|
||||
@requires_auth
|
||||
@account_type_required({at.TRUSTED_USER, at.DEVELOPER, at.TRUSTED_USER_AND_DEV})
|
||||
@account_type_required(
|
||||
{at.PACKAGE_MAINTAINER, at.DEVELOPER, at.PACKAGE_MAINTAINER_AND_DEV}
|
||||
)
|
||||
async def accounts_post(
|
||||
request: Request,
|
||||
O: int = Form(default=0), # Offset
|
||||
|
@ -564,9 +568,9 @@ async def accounts_post(
|
|||
# Convert parameter T to an AccountType ID.
|
||||
account_types = {
|
||||
"u": at.USER_ID,
|
||||
"t": at.TRUSTED_USER_ID,
|
||||
"t": at.PACKAGE_MAINTAINER_ID,
|
||||
"d": at.DEVELOPER_ID,
|
||||
"td": at.TRUSTED_USER_AND_DEV_ID,
|
||||
"td": at.PACKAGE_MAINTAINER_AND_DEV_ID,
|
||||
}
|
||||
account_type_id = account_types.get(T, None)
|
||||
|
||||
|
|
|
@ -11,7 +11,10 @@ from aurweb import aur_logging, db, l10n, models, time
|
|||
from aurweb.auth import creds, requires_auth
|
||||
from aurweb.exceptions import handle_form_exceptions
|
||||
from aurweb.models import User
|
||||
from aurweb.models.account_type import TRUSTED_USER_AND_DEV_ID, TRUSTED_USER_ID
|
||||
from aurweb.models.account_type import (
|
||||
PACKAGE_MAINTAINER_AND_DEV_ID,
|
||||
PACKAGE_MAINTAINER_ID,
|
||||
)
|
||||
from aurweb.templates import make_context, make_variable_context, render_template
|
||||
|
||||
router = APIRouter()
|
||||
|
@ -33,25 +36,25 @@ ADDVOTE_SPECIFICS = {
|
|||
}
|
||||
|
||||
|
||||
def populate_trusted_user_counts(context: dict[str, Any]) -> None:
|
||||
def populate_package_maintainer_counts(context: dict[str, Any]) -> None:
|
||||
tu_query = db.query(User).filter(
|
||||
or_(
|
||||
User.AccountTypeID == TRUSTED_USER_ID,
|
||||
User.AccountTypeID == TRUSTED_USER_AND_DEV_ID,
|
||||
User.AccountTypeID == PACKAGE_MAINTAINER_ID,
|
||||
User.AccountTypeID == PACKAGE_MAINTAINER_AND_DEV_ID,
|
||||
)
|
||||
)
|
||||
context["trusted_user_count"] = tu_query.count()
|
||||
context["package_maintainer_count"] = tu_query.count()
|
||||
|
||||
# In case any records have a None InactivityTS.
|
||||
active_tu_query = tu_query.filter(
|
||||
or_(User.InactivityTS.is_(None), User.InactivityTS == 0)
|
||||
)
|
||||
context["active_trusted_user_count"] = active_tu_query.count()
|
||||
context["active_package_maintainer_count"] = active_tu_query.count()
|
||||
|
||||
|
||||
@router.get("/tu")
|
||||
@requires_auth
|
||||
async def trusted_user(
|
||||
async def package_maintainer(
|
||||
request: Request,
|
||||
coff: int = 0, # current offset
|
||||
cby: str = "desc", # current by
|
||||
|
@ -63,7 +66,7 @@ async def trusted_user(
|
|||
if not request.user.has_credential(creds.TU_LIST_VOTES):
|
||||
return RedirectResponse("/", status_code=HTTPStatus.SEE_OTHER)
|
||||
|
||||
context = make_context(request, "Trusted User")
|
||||
context = make_context(request, "Package Maintainer")
|
||||
|
||||
current_by, past_by = cby, pby
|
||||
current_off, past_off = coff, poff
|
||||
|
@ -129,7 +132,7 @@ async def trusted_user(
|
|||
context["current_by_next"] = "asc" if current_by == "desc" else "desc"
|
||||
context["past_by_next"] = "asc" if past_by == "desc" else "desc"
|
||||
|
||||
populate_trusted_user_counts(context)
|
||||
populate_package_maintainer_counts(context)
|
||||
|
||||
context["q"] = {
|
||||
"coff": current_off,
|
||||
|
@ -178,11 +181,11 @@ def render_proposal(
|
|||
|
||||
@router.get("/tu/{proposal}")
|
||||
@requires_auth
|
||||
async def trusted_user_proposal(request: Request, proposal: int):
|
||||
async def package_maintainer_proposal(request: Request, proposal: int):
|
||||
if not request.user.has_credential(creds.TU_LIST_VOTES):
|
||||
return RedirectResponse("/tu", status_code=HTTPStatus.SEE_OTHER)
|
||||
|
||||
context = await make_variable_context(request, "Trusted User")
|
||||
context = await make_variable_context(request, "Package Maintainer")
|
||||
proposal = int(proposal)
|
||||
|
||||
voteinfo = (
|
||||
|
@ -221,13 +224,13 @@ async def trusted_user_proposal(request: Request, proposal: int):
|
|||
@router.post("/tu/{proposal}")
|
||||
@handle_form_exceptions
|
||||
@requires_auth
|
||||
async def trusted_user_proposal_post(
|
||||
async def package_maintainer_proposal_post(
|
||||
request: Request, proposal: int, decision: str = Form(...)
|
||||
):
|
||||
if not request.user.has_credential(creds.TU_LIST_VOTES):
|
||||
return RedirectResponse("/tu", status_code=HTTPStatus.SEE_OTHER)
|
||||
|
||||
context = await make_variable_context(request, "Trusted User")
|
||||
context = await make_variable_context(request, "Package Maintainer")
|
||||
proposal = int(proposal) # Make sure it's an int.
|
||||
|
||||
voteinfo = (
|
||||
|
@ -285,7 +288,7 @@ async def trusted_user_proposal_post(
|
|||
|
||||
@router.get("/addvote")
|
||||
@requires_auth
|
||||
async def trusted_user_addvote(
|
||||
async def package_maintainer_addvote(
|
||||
request: Request, user: str = str(), type: str = "add_tu", agenda: str = str()
|
||||
):
|
||||
if not request.user.has_credential(creds.TU_ADD_VOTE):
|
||||
|
@ -308,7 +311,7 @@ async def trusted_user_addvote(
|
|||
@router.post("/addvote")
|
||||
@handle_form_exceptions
|
||||
@requires_auth
|
||||
async def trusted_user_addvote_post(
|
||||
async def package_maintainer_addvote_post(
|
||||
request: Request,
|
||||
user: str = Form(default=str()),
|
||||
type: str = Form(default=str()),
|
||||
|
@ -364,7 +367,7 @@ async def trusted_user_addvote_post(
|
|||
timestamp = time.utcnow()
|
||||
|
||||
# Active TU types we filter for.
|
||||
types = {TRUSTED_USER_ID, TRUSTED_USER_AND_DEV_ID}
|
||||
types = {PACKAGE_MAINTAINER_ID, PACKAGE_MAINTAINER_AND_DEV_ID}
|
||||
|
||||
# Create a new TUVoteInfo (proposal)!
|
||||
with db.begin():
|
|
@ -3,7 +3,11 @@ from sqlalchemy import func
|
|||
from aurweb import config, db, time
|
||||
from aurweb.cache import db_count_cache, db_query_cache
|
||||
from aurweb.models import PackageBase, PackageRequest, RequestType, User
|
||||
from aurweb.models.account_type import TRUSTED_USER_AND_DEV_ID, TRUSTED_USER_ID, USER_ID
|
||||
from aurweb.models.account_type import (
|
||||
PACKAGE_MAINTAINER_AND_DEV_ID,
|
||||
PACKAGE_MAINTAINER_ID,
|
||||
USER_ID,
|
||||
)
|
||||
from aurweb.models.package_request import (
|
||||
ACCEPTED_ID,
|
||||
CLOSED_ID,
|
||||
|
@ -22,7 +26,7 @@ HOMEPAGE_COUNTERS = [
|
|||
"year_old_updated",
|
||||
"never_updated",
|
||||
"user_count",
|
||||
"trusted_user_count",
|
||||
"package_maintainer_count",
|
||||
]
|
||||
REQUEST_COUNTERS = [
|
||||
"total_requests",
|
||||
|
@ -32,7 +36,7 @@ REQUEST_COUNTERS = [
|
|||
"rejected_requests",
|
||||
]
|
||||
PROMETHEUS_USER_COUNTERS = [
|
||||
("trusted_user_count", "tu"),
|
||||
("package_maintainer_count", "package_maintainer"),
|
||||
("regular_user_count", "user"),
|
||||
]
|
||||
PROMETHEUS_PACKAGE_COUNTERS = [
|
||||
|
@ -92,12 +96,12 @@ class Statistics:
|
|||
# Users
|
||||
case "user_count":
|
||||
query = self.user_query
|
||||
case "trusted_user_count":
|
||||
case "package_maintainer_count":
|
||||
query = self.user_query.filter(
|
||||
User.AccountTypeID.in_(
|
||||
(
|
||||
TRUSTED_USER_ID,
|
||||
TRUSTED_USER_AND_DEV_ID,
|
||||
PACKAGE_MAINTAINER_ID,
|
||||
PACKAGE_MAINTAINER_AND_DEV_ID,
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
|
@ -220,7 +220,7 @@ def invalid_account_type(
|
|||
raise ValidationError([error])
|
||||
|
||||
logger.debug(
|
||||
f"Trusted User '{request.user.Username}' has "
|
||||
f"Package Maintainer '{request.user.Username}' has "
|
||||
f"modified '{user.Username}' account's type to"
|
||||
f" {name}."
|
||||
)
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
"""Rename TU to Package Maintainer
|
||||
|
||||
Revision ID: 6a64dd126029
|
||||
Revises: c5a6a9b661a0
|
||||
Create Date: 2023-09-01 13:48:15.315244
|
||||
|
||||
"""
|
||||
from aurweb import db
|
||||
from aurweb.models import AccountType
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "6a64dd126029"
|
||||
down_revision = "c5a6a9b661a0"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
# AccountTypes
|
||||
# ID 2 -> Trusted User / Package Maintainer
|
||||
# ID 4 -> Trusted User & Developer / Package Maintainer & Developer
|
||||
|
||||
|
||||
def upgrade():
|
||||
with db.begin():
|
||||
tu = db.query(AccountType).filter(AccountType.ID == 2).first()
|
||||
tudev = db.query(AccountType).filter(AccountType.ID == 4).first()
|
||||
|
||||
tu.AccountType = "Package Maintainer"
|
||||
tudev.AccountType = "Package Maintainer & Developer"
|
||||
|
||||
|
||||
def downgrade():
|
||||
with db.begin():
|
||||
tu = db.query(AccountType).filter(AccountType.ID == 2).first()
|
||||
tudev = db.query(AccountType).filter(AccountType.ID == 4).first()
|
||||
|
||||
tu.AccountType = "Trusted User"
|
||||
tudev.AccountType = "Trusted User & Developer"
|
|
@ -4,7 +4,7 @@
|
|||
<option value="unflag">{{ "Unflag Out-of-date" | tr }}</option>
|
||||
<option value="adopt">{{ "Adopt Packages" | tr }}</option>
|
||||
<option value="disown">{{ "Disown Packages" | tr }}</option>
|
||||
{% if request.user.is_trusted_user() or request.user.is_developer() %}
|
||||
{% if request.user.is_package_maintainer() or request.user.is_developer() %}
|
||||
<option value="delete">{{ "Delete Packages" | tr }}</option>
|
||||
{% endif %}
|
||||
<option value="notify">{{ "Notify" | tr }}</option>
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
<td class="stat-desc">
|
||||
{{ "Trusted Users" | tr }}
|
||||
</td>
|
||||
<td>{{ trusted_user_count }}</td>
|
||||
<td>{{ package_maintainer_count }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
<tbody>
|
||||
<tr>
|
||||
<td>{{ "Total" | tr }} {{ "Trusted Users" | tr }}:</td>
|
||||
<td>{{ trusted_user_count }}</td>
|
||||
<td>{{ package_maintainer_count }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ "Active" | tr }} {{ "Trusted Users" | tr }}:</td>
|
||||
<td>{{ active_trusted_user_count }}</td>
|
||||
<td>{{ active_package_maintainer_count }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
@ -17,9 +17,9 @@ from aurweb.db import create, query
|
|||
from aurweb.models.accepted_term import AcceptedTerm
|
||||
from aurweb.models.account_type import (
|
||||
DEVELOPER_ID,
|
||||
TRUSTED_USER,
|
||||
TRUSTED_USER_AND_DEV_ID,
|
||||
TRUSTED_USER_ID,
|
||||
PACKAGE_MAINTAINER,
|
||||
PACKAGE_MAINTAINER_AND_DEV_ID,
|
||||
PACKAGE_MAINTAINER_ID,
|
||||
USER_ID,
|
||||
AccountType,
|
||||
)
|
||||
|
@ -98,7 +98,7 @@ def user() -> User:
|
|||
@pytest.fixture
|
||||
def tu_user(user: User):
|
||||
with db.begin():
|
||||
user.AccountTypeID = TRUSTED_USER_AND_DEV_ID
|
||||
user.AccountTypeID = PACKAGE_MAINTAINER_AND_DEV_ID
|
||||
yield user
|
||||
|
||||
|
||||
|
@ -661,7 +661,7 @@ def test_get_account_edit_tu_as_tu(client: TestClient, tu_user: User):
|
|||
"""Test edit get route of another TU as a TU."""
|
||||
with db.begin():
|
||||
user2 = create_user("test2")
|
||||
user2.AccountTypeID = at.TRUSTED_USER_ID
|
||||
user2.AccountTypeID = at.PACKAGE_MAINTAINER_ID
|
||||
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
endpoint = f"/account/{user2.Username}/edit"
|
||||
|
@ -672,10 +672,10 @@ def test_get_account_edit_tu_as_tu(client: TestClient, tu_user: User):
|
|||
assert response.status_code == int(HTTPStatus.OK)
|
||||
|
||||
# Verify that we have an account type selection and that the
|
||||
# "{at.TRUSTED_USER}" option is selected.
|
||||
# "{at.PACKAGE_MAINTAINER}" option is selected.
|
||||
root = parse_root(response.text)
|
||||
atype = root.xpath('//select[@id="id_type"]/option[@selected="selected"]')
|
||||
expected = at.TRUSTED_USER
|
||||
expected = at.PACKAGE_MAINTAINER
|
||||
assert atype[0].text.strip() == expected
|
||||
|
||||
username = root.xpath('//input[@id="id_username"]')[0]
|
||||
|
@ -836,7 +836,7 @@ def test_post_account_edit_type_as_dev(client: TestClient, tu_user: User):
|
|||
def test_post_account_edit_invalid_type_as_tu(client: TestClient, tu_user: User):
|
||||
with db.begin():
|
||||
user2 = create_user("test_tu")
|
||||
tu_user.AccountTypeID = at.TRUSTED_USER_ID
|
||||
tu_user.AccountTypeID = at.PACKAGE_MAINTAINER_ID
|
||||
|
||||
cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
endpoint = f"/account/{user2.Username}/edit"
|
||||
|
@ -861,8 +861,8 @@ def test_post_account_edit_invalid_type_as_tu(client: TestClient, tu_user: User)
|
|||
|
||||
|
||||
def test_post_account_edit_dev(client: TestClient, tu_user: User):
|
||||
# Modify our user to be a "Trusted User & Developer"
|
||||
name = "Trusted User & Developer"
|
||||
# Modify our user to be a "Package Maintainer & Developer"
|
||||
name = "Package Maintainer & Developer"
|
||||
tu_or_dev = query(AccountType, AccountType.AccountType == name).first()
|
||||
with db.begin():
|
||||
user.AccountType = tu_or_dev
|
||||
|
@ -1004,7 +1004,7 @@ def test_post_account_edit_suspend_unauthorized(client: TestClient, user: User):
|
|||
|
||||
def test_post_account_edit_inactivity(client: TestClient, user: User):
|
||||
with db.begin():
|
||||
user.AccountTypeID = TRUSTED_USER_ID
|
||||
user.AccountTypeID = PACKAGE_MAINTAINER_ID
|
||||
assert not user.Suspended
|
||||
|
||||
cookies = {"AURSID": user.login(Request(), "testPassword")}
|
||||
|
@ -1033,7 +1033,7 @@ def test_post_account_edit_inactivity(client: TestClient, user: User):
|
|||
|
||||
def test_post_account_edit_suspended(client: TestClient, user: User):
|
||||
with db.begin():
|
||||
user.AccountTypeID = TRUSTED_USER_ID
|
||||
user.AccountTypeID = PACKAGE_MAINTAINER_ID
|
||||
assert not user.Suspended
|
||||
|
||||
cookies = {"AURSID": user.login(Request(), "testPassword")}
|
||||
|
@ -1223,7 +1223,7 @@ def test_post_account_edit_self_type_as_user(client: TestClient, user: User):
|
|||
data = {
|
||||
"U": user.Username,
|
||||
"E": user.Email,
|
||||
"T": TRUSTED_USER_ID,
|
||||
"T": PACKAGE_MAINTAINER_ID,
|
||||
"passwd": "testPassword",
|
||||
}
|
||||
with client as request:
|
||||
|
@ -1298,7 +1298,7 @@ def test_post_account_edit_other_user_type_as_tu(
|
|||
data = {
|
||||
"U": user2.Username,
|
||||
"E": user2.Email,
|
||||
"T": TRUSTED_USER_ID,
|
||||
"T": PACKAGE_MAINTAINER_ID,
|
||||
"passwd": "testPassword",
|
||||
}
|
||||
|
||||
|
@ -1308,13 +1308,13 @@ def test_post_account_edit_other_user_type_as_tu(
|
|||
assert resp.status_code == int(HTTPStatus.OK)
|
||||
|
||||
# Let's make sure the DB got updated properly.
|
||||
assert user2.AccountTypeID == TRUSTED_USER_ID
|
||||
assert user2.AccountTypeID == PACKAGE_MAINTAINER_ID
|
||||
|
||||
# and also that this got logged out at DEBUG level.
|
||||
expected = (
|
||||
f"Trusted User '{tu_user.Username}' has "
|
||||
f"Package Maintainer '{tu_user.Username}' has "
|
||||
f"modified '{user2.Username}' account's type to"
|
||||
f" {TRUSTED_USER}."
|
||||
f" {PACKAGE_MAINTAINER}."
|
||||
)
|
||||
assert expected in caplog.text
|
||||
|
||||
|
@ -1601,7 +1601,7 @@ def test_post_accounts_account_type(client: TestClient, user: User, tu_user: Use
|
|||
# Set our only user to a Trusted User.
|
||||
with db.begin():
|
||||
user.AccountType = (
|
||||
query(AccountType).filter(AccountType.ID == TRUSTED_USER_ID).first()
|
||||
query(AccountType).filter(AccountType.ID == PACKAGE_MAINTAINER_ID).first()
|
||||
)
|
||||
|
||||
with client as request:
|
||||
|
@ -1615,7 +1615,7 @@ def test_post_accounts_account_type(client: TestClient, user: User, tu_user: Use
|
|||
row = next(iter(rows))
|
||||
username, type, status, realname, irc, pgp_key, edit = row
|
||||
|
||||
assert type.text.strip() == "Trusted User"
|
||||
assert type.text.strip() == "Package Maintainer"
|
||||
|
||||
with db.begin():
|
||||
user.AccountType = (
|
||||
|
@ -1637,7 +1637,9 @@ def test_post_accounts_account_type(client: TestClient, user: User, tu_user: Use
|
|||
|
||||
with db.begin():
|
||||
user.AccountType = (
|
||||
query(AccountType).filter(AccountType.ID == TRUSTED_USER_AND_DEV_ID).first()
|
||||
query(AccountType)
|
||||
.filter(AccountType.ID == PACKAGE_MAINTAINER_AND_DEV_ID)
|
||||
.first()
|
||||
)
|
||||
|
||||
with client as request:
|
||||
|
@ -1651,7 +1653,7 @@ def test_post_accounts_account_type(client: TestClient, user: User, tu_user: Use
|
|||
row = next(iter(rows))
|
||||
username, type, status, realname, irc, pgp_key, edit = row
|
||||
|
||||
assert type.text.strip() == "Trusted User & Developer"
|
||||
assert type.text.strip() == "Package Maintainer & Developer"
|
||||
|
||||
|
||||
def test_post_accounts_status(client: TestClient, user: User, tu_user: User):
|
||||
|
@ -1783,7 +1785,9 @@ def test_post_accounts_sortby(client: TestClient, user: User, tu_user: User):
|
|||
|
||||
with db.begin():
|
||||
user.AccountType = (
|
||||
query(AccountType).filter(AccountType.ID == TRUSTED_USER_AND_DEV_ID).first()
|
||||
query(AccountType)
|
||||
.filter(AccountType.ID == PACKAGE_MAINTAINER_AND_DEV_ID)
|
||||
.first()
|
||||
)
|
||||
|
||||
# Fetch first_rows again with our new AccountType ordering.
|
||||
|
|
|
@ -48,12 +48,12 @@ def test_adduser_tu():
|
|||
"-p",
|
||||
"abcd1234",
|
||||
"-t",
|
||||
at.TRUSTED_USER,
|
||||
at.PACKAGE_MAINTAINER,
|
||||
]
|
||||
)
|
||||
test = db.query(User).filter(User.Username == "test").first()
|
||||
assert test is not None
|
||||
assert test.AccountTypeID == at.TRUSTED_USER_ID
|
||||
assert test.AccountTypeID == at.PACKAGE_MAINTAINER_ID
|
||||
|
||||
|
||||
def test_adduser_ssh_pk():
|
||||
|
|
|
@ -137,9 +137,9 @@ def test_account_type_required():
|
|||
account_type_required({"FAKE"})
|
||||
|
||||
|
||||
def test_is_trusted_user():
|
||||
def test_is_package_maintainer():
|
||||
user_ = AnonymousUser()
|
||||
assert not user_.is_trusted_user()
|
||||
assert not user_.is_package_maintainer()
|
||||
|
||||
|
||||
def test_is_developer():
|
||||
|
|
|
@ -62,7 +62,7 @@ def redis():
|
|||
"package_count",
|
||||
"orphan_count",
|
||||
"user_count",
|
||||
"trusted_user_count",
|
||||
"package_maintainer_count",
|
||||
"seven_days_old_added",
|
||||
"seven_days_old_updated",
|
||||
"year_old_updated",
|
||||
|
|
|
@ -12,7 +12,7 @@ from fastapi.testclient import TestClient
|
|||
|
||||
from aurweb import asgi, config, db
|
||||
from aurweb.models import PackageBase
|
||||
from aurweb.models.account_type import TRUSTED_USER_ID, USER_ID
|
||||
from aurweb.models.account_type import PACKAGE_MAINTAINER_ID, USER_ID
|
||||
from aurweb.models.user import User
|
||||
from aurweb.testing.html import get_errors, get_successes, parse_root
|
||||
from aurweb.testing.requests import Request
|
||||
|
@ -42,9 +42,9 @@ def user() -> User:
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def trusted_user(user: User) -> User:
|
||||
def package_maintainer(user: User) -> User:
|
||||
with db.begin():
|
||||
user.AccountTypeID = TRUSTED_USER_ID
|
||||
user.AccountTypeID = PACKAGE_MAINTAINER_ID
|
||||
yield user
|
||||
|
||||
|
||||
|
@ -81,7 +81,7 @@ def test_archdev_navbar_authenticated(client: TestClient, user: User):
|
|||
assert item.text.strip() == expected[i]
|
||||
|
||||
|
||||
def test_archdev_navbar_authenticated_tu(client: TestClient, trusted_user: User):
|
||||
def test_archdev_navbar_authenticated_tu(client: TestClient, package_maintainer: User):
|
||||
expected = [
|
||||
"Dashboard",
|
||||
"Packages",
|
||||
|
@ -91,7 +91,7 @@ def test_archdev_navbar_authenticated_tu(client: TestClient, trusted_user: User)
|
|||
"Trusted User",
|
||||
"Logout",
|
||||
]
|
||||
cookies = {"AURSID": trusted_user.login(Request(), "testPassword")}
|
||||
cookies = {"AURSID": package_maintainer.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
request.cookies = cookies
|
||||
resp = request.get("/")
|
||||
|
|
|
@ -5,7 +5,7 @@ import pytest
|
|||
|
||||
from aurweb import config, db, models, time
|
||||
from aurweb.models import Package, PackageBase, PackageRequest, User
|
||||
from aurweb.models.account_type import TRUSTED_USER_ID, USER_ID
|
||||
from aurweb.models.account_type import PACKAGE_MAINTAINER_ID, USER_ID
|
||||
from aurweb.models.request_type import ORPHAN_ID
|
||||
from aurweb.scripts import notify, rendercomment
|
||||
from aurweb.testing.email import Email
|
||||
|
@ -393,7 +393,7 @@ please go to [3] and click "Disable notifications".
|
|||
def set_tu(users: list[User]) -> User:
|
||||
with db.begin():
|
||||
for user in users:
|
||||
user.AccountTypeID = TRUSTED_USER_ID
|
||||
user.AccountTypeID = PACKAGE_MAINTAINER_ID
|
||||
|
||||
|
||||
def test_open_close_request(
|
||||
|
|
|
@ -114,7 +114,9 @@ def maintainer() -> User:
|
|||
|
||||
@pytest.fixture
|
||||
def tu_user():
|
||||
tu_type = db.query(AccountType, AccountType.AccountType == "Trusted User").first()
|
||||
tu_type = db.query(
|
||||
AccountType, AccountType.AccountType == "Package Maintainer"
|
||||
).first()
|
||||
with db.begin():
|
||||
tu_user = db.create(
|
||||
User,
|
||||
|
|
|
@ -117,7 +117,9 @@ def comaintainer() -> User:
|
|||
|
||||
@pytest.fixture
|
||||
def tu_user():
|
||||
tu_type = db.query(AccountType, AccountType.AccountType == "Trusted User").first()
|
||||
tu_type = db.query(
|
||||
AccountType, AccountType.AccountType == "Package Maintainer"
|
||||
).first()
|
||||
with db.begin():
|
||||
tu_user = db.create(
|
||||
User,
|
||||
|
|
|
@ -8,7 +8,7 @@ from fastapi.testclient import TestClient
|
|||
|
||||
from aurweb import asgi, config, db, defaults, time
|
||||
from aurweb.models import Package, PackageBase, PackageRequest, User
|
||||
from aurweb.models.account_type import TRUSTED_USER_ID, USER_ID
|
||||
from aurweb.models.account_type import PACKAGE_MAINTAINER_ID, USER_ID
|
||||
from aurweb.models.package_comaintainer import PackageComaintainer
|
||||
from aurweb.models.package_notification import PackageNotification
|
||||
from aurweb.models.package_request import ACCEPTED_ID, PENDING_ID, REJECTED_ID
|
||||
|
@ -161,7 +161,7 @@ def tu_user() -> User:
|
|||
"""Yield an authenticated Trusted User instance."""
|
||||
user = create_user("test_tu", "test_tu@example.org")
|
||||
with db.begin():
|
||||
user.AccountTypeID = TRUSTED_USER_ID
|
||||
user.AccountTypeID = PACKAGE_MAINTAINER_ID
|
||||
cookies = {"AURSID": user.login(Request(), "testPassword")}
|
||||
user.cookies = cookies
|
||||
yield user
|
||||
|
|
|
@ -3,7 +3,7 @@ from prometheus_client import REGISTRY, generate_latest
|
|||
|
||||
from aurweb import cache, db, time
|
||||
from aurweb.models import Package, PackageBase, PackageRequest
|
||||
from aurweb.models.account_type import TRUSTED_USER_ID, USER_ID
|
||||
from aurweb.models.account_type import PACKAGE_MAINTAINER_ID, USER_ID
|
||||
from aurweb.models.package_request import (
|
||||
ACCEPTED_ID,
|
||||
CLOSED_ID,
|
||||
|
@ -64,7 +64,7 @@ def test_data():
|
|||
|
||||
# Modify some data to get some variances for our counters
|
||||
if i == 1:
|
||||
user.AccountTypeID = TRUSTED_USER_ID
|
||||
user.AccountTypeID = PACKAGE_MAINTAINER_ID
|
||||
pkgbase.Maintainer = None
|
||||
pkgbase.SubmittedTS = now
|
||||
pkgreq.Status = PENDING_ID
|
||||
|
@ -99,7 +99,7 @@ def stats() -> Statistics:
|
|||
("year_old_updated", 9),
|
||||
("never_updated", 1),
|
||||
("user_count", 10),
|
||||
("trusted_user_count", 1),
|
||||
("package_maintainer_count", 1),
|
||||
("regular_user_count", 9),
|
||||
("updated_packages", 9),
|
||||
("total_requests", 10),
|
||||
|
@ -116,7 +116,7 @@ def test_get_count(stats: Statistics, test_data, counter: str, expected: int):
|
|||
|
||||
def test_get_count_change(stats: Statistics, test_data):
|
||||
pkgs_before = stats.get_count("package_count")
|
||||
tus_before = stats.get_count("trusted_user_count")
|
||||
tus_before = stats.get_count("package_maintainer_count")
|
||||
|
||||
assert pkgs_before == 10
|
||||
assert tus_before == 1
|
||||
|
@ -127,16 +127,16 @@ def test_get_count_change(stats: Statistics, test_data):
|
|||
db.delete(pkgbase)
|
||||
|
||||
user = db.query(User).filter(User.AccountTypeID == USER_ID).first()
|
||||
user.AccountTypeID = TRUSTED_USER_ID
|
||||
user.AccountTypeID = PACKAGE_MAINTAINER_ID
|
||||
|
||||
# Values should end up in (fake) redis cache so they should be the same
|
||||
assert stats.get_count("package_count") == pkgs_before
|
||||
assert stats.get_count("trusted_user_count") == tus_before
|
||||
assert stats.get_count("package_maintainer_count") == tus_before
|
||||
|
||||
# Let's clear the cache and check again
|
||||
cache._redis.flushall()
|
||||
assert stats.get_count("package_count") != pkgs_before
|
||||
assert stats.get_count("trusted_user_count") != tus_before
|
||||
assert stats.get_count("package_maintainer_count") != tus_before
|
||||
|
||||
|
||||
def test_update_prometheus_metrics(test_data):
|
||||
|
|
|
@ -8,7 +8,7 @@ import pytest
|
|||
from fastapi.testclient import TestClient
|
||||
|
||||
from aurweb import config, db, filters, time
|
||||
from aurweb.models.account_type import DEVELOPER_ID, TRUSTED_USER_ID, AccountType
|
||||
from aurweb.models.account_type import DEVELOPER_ID, PACKAGE_MAINTAINER_ID, AccountType
|
||||
from aurweb.models.tu_vote import TUVote
|
||||
from aurweb.models.tu_voteinfo import TUVoteInfo
|
||||
from aurweb.models.user import User
|
||||
|
@ -90,7 +90,9 @@ def client():
|
|||
|
||||
@pytest.fixture
|
||||
def tu_user():
|
||||
tu_type = db.query(AccountType, AccountType.AccountType == "Trusted User").first()
|
||||
tu_type = db.query(
|
||||
AccountType, AccountType.AccountType == "Package Maintainer"
|
||||
).first()
|
||||
with db.begin():
|
||||
tu_user = db.create(
|
||||
User,
|
||||
|
@ -112,7 +114,7 @@ def tu_user2():
|
|||
Email="test_tu2@example.org",
|
||||
RealName="Test TU 2",
|
||||
Passwd="testPassword",
|
||||
AccountTypeID=TRUSTED_USER_ID,
|
||||
AccountTypeID=PACKAGE_MAINTAINER_ID,
|
||||
)
|
||||
yield tu_user2
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import pytest
|
|||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
from aurweb import db, time
|
||||
from aurweb.models.account_type import TRUSTED_USER_ID
|
||||
from aurweb.models.account_type import PACKAGE_MAINTAINER_ID
|
||||
from aurweb.models.tu_vote import TUVote
|
||||
from aurweb.models.tu_voteinfo import TUVoteInfo
|
||||
from aurweb.models.user import User
|
||||
|
@ -22,7 +22,7 @@ def user() -> User:
|
|||
Email="test@example.org",
|
||||
RealName="Test User",
|
||||
Passwd="testPassword",
|
||||
AccountTypeID=TRUSTED_USER_ID,
|
||||
AccountTypeID=PACKAGE_MAINTAINER_ID,
|
||||
)
|
||||
yield user
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ from sqlalchemy.exc import IntegrityError
|
|||
|
||||
from aurweb import db, time
|
||||
from aurweb.db import create, rollback
|
||||
from aurweb.models.account_type import TRUSTED_USER_ID
|
||||
from aurweb.models.account_type import PACKAGE_MAINTAINER_ID
|
||||
from aurweb.models.tu_voteinfo import TUVoteInfo
|
||||
from aurweb.models.user import User
|
||||
|
||||
|
@ -22,7 +22,7 @@ def user() -> User:
|
|||
Email="test@example.org",
|
||||
RealName="Test User",
|
||||
Passwd="testPassword",
|
||||
AccountTypeID=TRUSTED_USER_ID,
|
||||
AccountTypeID=PACKAGE_MAINTAINER_ID,
|
||||
)
|
||||
yield user
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import pytest
|
|||
|
||||
from aurweb import config, db, time
|
||||
from aurweb.models import TUVote, TUVoteInfo, User
|
||||
from aurweb.models.account_type import TRUSTED_USER_ID
|
||||
from aurweb.models.account_type import PACKAGE_MAINTAINER_ID
|
||||
from aurweb.scripts import tuvotereminder as reminder
|
||||
from aurweb.testing.email import Email
|
||||
|
||||
|
@ -47,17 +47,17 @@ def email_pieces(voteinfo: TUVoteInfo) -> Tuple[str, str]:
|
|||
|
||||
@pytest.fixture
|
||||
def user(db_test) -> User:
|
||||
yield create_user("test", TRUSTED_USER_ID)
|
||||
yield create_user("test", PACKAGE_MAINTAINER_ID)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user2() -> User:
|
||||
yield create_user("test2", TRUSTED_USER_ID)
|
||||
yield create_user("test2", PACKAGE_MAINTAINER_ID)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user3() -> User:
|
||||
yield create_user("test3", TRUSTED_USER_ID)
|
||||
yield create_user("test3", PACKAGE_MAINTAINER_ID)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
|
@ -12,8 +12,8 @@ from aurweb import db
|
|||
from aurweb.auth import creds
|
||||
from aurweb.models.account_type import (
|
||||
DEVELOPER_ID,
|
||||
TRUSTED_USER_AND_DEV_ID,
|
||||
TRUSTED_USER_ID,
|
||||
PACKAGE_MAINTAINER_AND_DEV_ID,
|
||||
PACKAGE_MAINTAINER_ID,
|
||||
USER_ID,
|
||||
)
|
||||
from aurweb.models.ban import Ban
|
||||
|
@ -53,7 +53,7 @@ def user() -> User:
|
|||
|
||||
@pytest.fixture
|
||||
def tu_user() -> User:
|
||||
user = create_user("test_tu", TRUSTED_USER_ID)
|
||||
user = create_user("test_tu", PACKAGE_MAINTAINER_ID)
|
||||
yield user
|
||||
|
||||
|
||||
|
@ -65,7 +65,7 @@ def dev_user() -> User:
|
|||
|
||||
@pytest.fixture
|
||||
def tu_and_dev_user() -> User:
|
||||
user = create_user("test_tu_and_dev", TRUSTED_USER_AND_DEV_ID)
|
||||
user = create_user("test_tu_and_dev", PACKAGE_MAINTAINER_AND_DEV_ID)
|
||||
yield user
|
||||
|
||||
|
||||
|
@ -207,33 +207,33 @@ def test_user_ssh_pub_key(user: User):
|
|||
|
||||
|
||||
def test_user_credential_types(user: User):
|
||||
assert user.AccountTypeID in creds.user_developer_or_trusted_user
|
||||
assert user.AccountTypeID not in creds.trusted_user
|
||||
assert user.AccountTypeID in creds.user_developer_or_package_maintainer
|
||||
assert user.AccountTypeID not in creds.package_maintainer
|
||||
assert user.AccountTypeID not in creds.developer
|
||||
assert user.AccountTypeID not in creds.trusted_user_or_dev
|
||||
assert user.AccountTypeID not in creds.package_maintainer_or_dev
|
||||
|
||||
with db.begin():
|
||||
user.AccountTypeID = at.TRUSTED_USER_ID
|
||||
user.AccountTypeID = at.PACKAGE_MAINTAINER_ID
|
||||
|
||||
assert user.AccountTypeID in creds.trusted_user
|
||||
assert user.AccountTypeID in creds.trusted_user_or_dev
|
||||
assert user.AccountTypeID in creds.package_maintainer
|
||||
assert user.AccountTypeID in creds.package_maintainer_or_dev
|
||||
|
||||
with db.begin():
|
||||
user.AccountTypeID = at.DEVELOPER_ID
|
||||
|
||||
assert user.AccountTypeID in creds.developer
|
||||
assert user.AccountTypeID in creds.trusted_user_or_dev
|
||||
assert user.AccountTypeID in creds.package_maintainer_or_dev
|
||||
|
||||
with db.begin():
|
||||
user.AccountTypeID = at.TRUSTED_USER_AND_DEV_ID
|
||||
user.AccountTypeID = at.PACKAGE_MAINTAINER_AND_DEV_ID
|
||||
|
||||
assert user.AccountTypeID in creds.trusted_user
|
||||
assert user.AccountTypeID in creds.package_maintainer
|
||||
assert user.AccountTypeID in creds.developer
|
||||
assert user.AccountTypeID in creds.trusted_user_or_dev
|
||||
assert user.AccountTypeID in creds.package_maintainer_or_dev
|
||||
|
||||
# Some model authorization checks.
|
||||
assert user.is_elevated()
|
||||
assert user.is_trusted_user()
|
||||
assert user.is_package_maintainer()
|
||||
assert user.is_developer()
|
||||
|
||||
|
||||
|
@ -255,15 +255,15 @@ def test_user_as_dict(user: User):
|
|||
assert isinstance(data.get("RegistrationTS"), datetime)
|
||||
|
||||
|
||||
def test_user_is_trusted_user(user: User):
|
||||
def test_user_is_package_maintainer(user: User):
|
||||
with db.begin():
|
||||
user.AccountTypeID = at.TRUSTED_USER_ID
|
||||
assert user.is_trusted_user() is True
|
||||
user.AccountTypeID = at.PACKAGE_MAINTAINER_ID
|
||||
assert user.is_package_maintainer() is True
|
||||
|
||||
# Do it again with the combined role.
|
||||
with db.begin():
|
||||
user.AccountTypeID = at.TRUSTED_USER_AND_DEV_ID
|
||||
assert user.is_trusted_user() is True
|
||||
user.AccountTypeID = at.PACKAGE_MAINTAINER_AND_DEV_ID
|
||||
assert user.is_package_maintainer() is True
|
||||
|
||||
|
||||
def test_user_is_developer(user: User):
|
||||
|
@ -273,7 +273,7 @@ def test_user_is_developer(user: User):
|
|||
|
||||
# Do it again with the combined role.
|
||||
with db.begin():
|
||||
user.AccountTypeID = at.TRUSTED_USER_AND_DEV_ID
|
||||
user.AccountTypeID = at.PACKAGE_MAINTAINER_AND_DEV_ID
|
||||
assert user.is_developer() is True
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue