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:
moson 2023-09-01 13:25:21 +02:00
parent 7466e96449
commit 1702075875
No known key found for this signature in database
GPG key ID: 4A4760AB4EE15296
34 changed files with 265 additions and 203 deletions

View file

@ -71,7 +71,7 @@ class AnonymousUser:
return False return False
@staticmethod @staticmethod
def is_trusted_user(): def is_package_maintainer():
return False return False
@staticmethod @staticmethod
@ -205,7 +205,7 @@ def account_type_required(one_of: set):
@router.get('/some_route') @router.get('/some_route')
@auth_required(True) @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): async def some_route(request: fastapi.Request):
return Response() return Response()

View file

@ -1,7 +1,7 @@
from aurweb.models.account_type import ( from aurweb.models.account_type import (
DEVELOPER_ID, DEVELOPER_ID,
TRUSTED_USER_AND_DEV_ID, PACKAGE_MAINTAINER_AND_DEV_ID,
TRUSTED_USER_ID, PACKAGE_MAINTAINER_ID,
USER_ID, USER_ID,
) )
from aurweb.models.user import User from aurweb.models.user import User
@ -30,47 +30,49 @@ PKGBASE_VOTE = 16
PKGREQ_FILE = 23 PKGREQ_FILE = 23
PKGREQ_CLOSE = 17 PKGREQ_CLOSE = 17
PKGREQ_LIST = 18 PKGREQ_LIST = 18
TU_ADD_VOTE = 19 PM_ADD_VOTE = 19
TU_LIST_VOTES = 20 PM_LIST_VOTES = 20
TU_VOTE = 21 PM_VOTE = 21
PKGBASE_MERGE = 29 PKGBASE_MERGE = 29
user_developer_or_trusted_user = set( user_developer_or_package_maintainer = set(
[USER_ID, TRUSTED_USER_ID, DEVELOPER_ID, TRUSTED_USER_AND_DEV_ID] [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]) package_maintainer_or_dev = set(
developer = set([DEVELOPER_ID, TRUSTED_USER_AND_DEV_ID]) [PACKAGE_MAINTAINER_ID, DEVELOPER_ID, PACKAGE_MAINTAINER_AND_DEV_ID]
trusted_user = set([TRUSTED_USER_ID, TRUSTED_USER_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 = { cred_filters = {
PKGBASE_FLAG: user_developer_or_trusted_user, PKGBASE_FLAG: user_developer_or_package_maintainer,
PKGBASE_NOTIFY: user_developer_or_trusted_user, PKGBASE_NOTIFY: user_developer_or_package_maintainer,
PKGBASE_VOTE: user_developer_or_trusted_user, PKGBASE_VOTE: user_developer_or_package_maintainer,
PKGREQ_FILE: user_developer_or_trusted_user, PKGREQ_FILE: user_developer_or_package_maintainer,
ACCOUNT_CHANGE_TYPE: trusted_user_or_dev, ACCOUNT_CHANGE_TYPE: package_maintainer_or_dev,
ACCOUNT_EDIT: trusted_user_or_dev, ACCOUNT_EDIT: package_maintainer_or_dev,
ACCOUNT_LAST_LOGIN: trusted_user_or_dev, ACCOUNT_LAST_LOGIN: package_maintainer_or_dev,
ACCOUNT_LIST_COMMENTS: trusted_user_or_dev, ACCOUNT_LIST_COMMENTS: package_maintainer_or_dev,
ACCOUNT_SEARCH: trusted_user_or_dev, ACCOUNT_SEARCH: package_maintainer_or_dev,
COMMENT_DELETE: trusted_user_or_dev, COMMENT_DELETE: package_maintainer_or_dev,
COMMENT_UNDELETE: trusted_user_or_dev, COMMENT_UNDELETE: package_maintainer_or_dev,
COMMENT_VIEW_DELETED: trusted_user_or_dev, COMMENT_VIEW_DELETED: package_maintainer_or_dev,
COMMENT_EDIT: trusted_user_or_dev, COMMENT_EDIT: package_maintainer_or_dev,
COMMENT_PIN: trusted_user_or_dev, COMMENT_PIN: package_maintainer_or_dev,
PKGBASE_ADOPT: trusted_user_or_dev, PKGBASE_ADOPT: package_maintainer_or_dev,
PKGBASE_SET_KEYWORDS: trusted_user_or_dev, PKGBASE_SET_KEYWORDS: package_maintainer_or_dev,
PKGBASE_DELETE: trusted_user_or_dev, PKGBASE_DELETE: package_maintainer_or_dev,
PKGBASE_EDIT_COMAINTAINERS: trusted_user_or_dev, PKGBASE_EDIT_COMAINTAINERS: package_maintainer_or_dev,
PKGBASE_DISOWN: trusted_user_or_dev, PKGBASE_DISOWN: package_maintainer_or_dev,
PKGBASE_LIST_VOTERS: trusted_user_or_dev, PKGBASE_LIST_VOTERS: package_maintainer_or_dev,
PKGBASE_UNFLAG: trusted_user_or_dev, PKGBASE_UNFLAG: package_maintainer_or_dev,
PKGREQ_CLOSE: trusted_user_or_dev, PKGREQ_CLOSE: package_maintainer_or_dev,
PKGREQ_LIST: trusted_user_or_dev, PKGREQ_LIST: package_maintainer_or_dev,
TU_ADD_VOTE: trusted_user, PM_ADD_VOTE: package_maintainer,
TU_LIST_VOTES: trusted_user_or_dev, PM_LIST_VOTES: package_maintainer_or_dev,
TU_VOTE: trusted_user, PM_VOTE: package_maintainer,
ACCOUNT_EDIT_DEV: developer, ACCOUNT_EDIT_DEV: developer,
PKGBASE_MERGE: trusted_user_or_dev, PKGBASE_MERGE: package_maintainer_or_dev,
} }

View file

@ -13,9 +13,9 @@ def feed_initial_data(conn):
aurweb.schema.AccountTypes.insert(), aurweb.schema.AccountTypes.insert(),
[ [
{"ID": 1, "AccountType": "User"}, {"ID": 1, "AccountType": "User"},
{"ID": 2, "AccountType": "Trusted User"}, {"ID": 2, "AccountType": "Package Maintainer"},
{"ID": 3, "AccountType": "Developer"}, {"ID": 3, "AccountType": "Developer"},
{"ID": 4, "AccountType": "Trusted User & Developer"}, {"ID": 4, "AccountType": "Package Maintainer & Developer"},
], ],
) )
conn.execute( conn.execute(

View file

@ -2,21 +2,21 @@ from aurweb import schema
from aurweb.models.declarative import Base from aurweb.models.declarative import Base
USER = "User" USER = "User"
TRUSTED_USER = "Trusted User" PACKAGE_MAINTAINER = "Package Maintainer"
DEVELOPER = "Developer" DEVELOPER = "Developer"
TRUSTED_USER_AND_DEV = "Trusted User & Developer" PACKAGE_MAINTAINER_AND_DEV = "Package Maintainer & Developer"
USER_ID = 1 USER_ID = 1
TRUSTED_USER_ID = 2 PACKAGE_MAINTAINER_ID = 2
DEVELOPER_ID = 3 DEVELOPER_ID = 3
TRUSTED_USER_AND_DEV_ID = 4 PACKAGE_MAINTAINER_AND_DEV_ID = 4
# Map string constants to integer constants. # Map string constants to integer constants.
ACCOUNT_TYPE_ID = { ACCOUNT_TYPE_ID = {
USER: USER_ID, USER: USER_ID,
TRUSTED_USER: TRUSTED_USER_ID, PACKAGE_MAINTAINER: PACKAGE_MAINTAINER_ID,
DEVELOPER: DEVELOPER_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. # Reversed ACCOUNT_TYPE_ID mapping.

View file

@ -157,25 +157,25 @@ class User(Base):
with db.begin(): with db.begin():
db.delete(self.session) db.delete(self.session)
def is_trusted_user(self): def is_package_maintainer(self):
return self.AccountType.ID in { return self.AccountType.ID in {
aurweb.models.account_type.TRUSTED_USER_ID, aurweb.models.account_type.PACKAGE_MAINTAINER_ID,
aurweb.models.account_type.TRUSTED_USER_AND_DEV_ID, aurweb.models.account_type.PACKAGE_MAINTAINER_AND_DEV_ID,
} }
def is_developer(self): def is_developer(self):
return self.AccountType.ID in { return self.AccountType.ID in {
aurweb.models.account_type.DEVELOPER_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 is_elevated(self): def is_elevated(self):
"""A User is 'elevated' when they have either a """A User is 'elevated' when they have either a
Trusted User or Developer AccountType.""" Trusted User or Developer AccountType."""
return self.AccountType.ID in { 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.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: def can_edit_user(self, target: "User") -> bool:

View file

@ -187,7 +187,7 @@ def pkgbase_merge_instance(
# Log this out for accountability purposes. # Log this out for accountability purposes.
logger.info( logger.info(
f"Trusted User '{request.user.Username}' merged " f"Package Maintainer '{request.user.Username}' merged "
f"'{pkgbasename}' into '{target.Name}'." f"'{pkgbasename}' into '{target.Name}'."
) )

View file

@ -7,13 +7,13 @@ from . import (
accounts, accounts,
auth, auth,
html, html,
package_maintainer,
packages, packages,
pkgbase, pkgbase,
requests, requests,
rpc, rpc,
rss, rss,
sso, sso,
trusted_user,
) )
""" """
@ -28,7 +28,7 @@ APP_ROUTES = [
packages, packages,
pkgbase, pkgbase,
requests, requests,
trusted_user, package_maintainer,
rss, rss,
rpc, rpc,
sso, sso,

View file

@ -184,9 +184,9 @@ def make_account_form_context(
lambda e: request.user.AccountTypeID >= e[0], lambda e: request.user.AccountTypeID >= e[0],
[ [
(at.USER_ID, f"Normal {at.USER}"), (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.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") @router.get("/accounts")
@requires_auth @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): async def accounts(request: Request):
context = make_context(request, "Accounts") context = make_context(request, "Accounts")
return render_template(request, "account/search.html", context) return render_template(request, "account/search.html", context)
@ -529,7 +531,9 @@ async def accounts(request: Request):
@router.post("/accounts") @router.post("/accounts")
@handle_form_exceptions @handle_form_exceptions
@requires_auth @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( async def accounts_post(
request: Request, request: Request,
O: int = Form(default=0), # Offset O: int = Form(default=0), # Offset
@ -564,9 +568,9 @@ async def accounts_post(
# Convert parameter T to an AccountType ID. # Convert parameter T to an AccountType ID.
account_types = { account_types = {
"u": at.USER_ID, "u": at.USER_ID,
"t": at.TRUSTED_USER_ID, "t": at.PACKAGE_MAINTAINER_ID,
"d": at.DEVELOPER_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) account_type_id = account_types.get(T, None)

View file

@ -11,7 +11,10 @@ from aurweb import aur_logging, db, l10n, models, time
from aurweb.auth import creds, requires_auth from aurweb.auth import creds, requires_auth
from aurweb.exceptions import handle_form_exceptions from aurweb.exceptions import handle_form_exceptions
from aurweb.models import User 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 from aurweb.templates import make_context, make_variable_context, render_template
router = APIRouter() router = APIRouter()
@ -26,32 +29,32 @@ ADDVOTE_SPECIFICS = {
# When a proposal is added, duration is added to the current # When a proposal is added, duration is added to the current
# timestamp. # timestamp.
# "addvote_type": (duration, quorum) # "addvote_type": (duration, quorum)
"add_tu": (7 * 24 * 60 * 60, 0.66), "add_pm": (7 * 24 * 60 * 60, 0.66),
"remove_tu": (7 * 24 * 60 * 60, 0.75), "remove_pm": (7 * 24 * 60 * 60, 0.75),
"remove_inactive_tu": (5 * 24 * 60 * 60, 0.66), "remove_inactive_pm": (5 * 24 * 60 * 60, 0.66),
"bylaws": (7 * 24 * 60 * 60, 0.75), "bylaws": (7 * 24 * 60 * 60, 0.75),
} }
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( pm_query = db.query(User).filter(
or_( or_(
User.AccountTypeID == TRUSTED_USER_ID, User.AccountTypeID == PACKAGE_MAINTAINER_ID,
User.AccountTypeID == TRUSTED_USER_AND_DEV_ID, User.AccountTypeID == PACKAGE_MAINTAINER_AND_DEV_ID,
) )
) )
context["trusted_user_count"] = tu_query.count() context["package_maintainer_count"] = pm_query.count()
# In case any records have a None InactivityTS. # In case any records have a None InactivityTS.
active_tu_query = tu_query.filter( active_pm_query = pm_query.filter(
or_(User.InactivityTS.is_(None), User.InactivityTS == 0) or_(User.InactivityTS.is_(None), User.InactivityTS == 0)
) )
context["active_trusted_user_count"] = active_tu_query.count() context["active_package_maintainer_count"] = active_pm_query.count()
@router.get("/tu") @router.get("/tu")
@requires_auth @requires_auth
async def trusted_user( async def package_maintainer(
request: Request, request: Request,
coff: int = 0, # current offset coff: int = 0, # current offset
cby: str = "desc", # current by cby: str = "desc", # current by
@ -63,7 +66,7 @@ async def trusted_user(
if not request.user.has_credential(creds.TU_LIST_VOTES): if not request.user.has_credential(creds.TU_LIST_VOTES):
return RedirectResponse("/", status_code=HTTPStatus.SEE_OTHER) 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_by, past_by = cby, pby
current_off, past_off = coff, poff current_off, past_off = coff, poff
@ -108,7 +111,7 @@ async def trusted_user(
context["past_off"] = past_off context["past_off"] = past_off
last_vote = func.max(models.TUVote.VoteID).label("LastVote") last_vote = func.max(models.TUVote.VoteID).label("LastVote")
last_votes_by_tu = ( last_votes_by_pm = (
db.query(models.TUVote) db.query(models.TUVote)
.join(models.User) .join(models.User)
.join(models.TUVoteInfo, models.TUVoteInfo.ID == models.TUVote.VoteID) .join(models.TUVoteInfo, models.TUVoteInfo.ID == models.TUVote.VoteID)
@ -124,12 +127,12 @@ async def trusted_user(
.group_by(models.TUVote.UserID) .group_by(models.TUVote.UserID)
.order_by(last_vote.desc(), models.User.Username.asc()) .order_by(last_vote.desc(), models.User.Username.asc())
) )
context["last_votes_by_tu"] = last_votes_by_tu.all() context["last_votes_by_pm"] = last_votes_by_pm.all()
context["current_by_next"] = "asc" if current_by == "desc" else "desc" context["current_by_next"] = "asc" if current_by == "desc" else "desc"
context["past_by_next"] = "asc" if past_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"] = { context["q"] = {
"coff": current_off, "coff": current_off,
@ -178,11 +181,11 @@ def render_proposal(
@router.get("/tu/{proposal}") @router.get("/tu/{proposal}")
@requires_auth @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): if not request.user.has_credential(creds.TU_LIST_VOTES):
return RedirectResponse("/tu", status_code=HTTPStatus.SEE_OTHER) 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) proposal = int(proposal)
voteinfo = ( voteinfo = (
@ -221,13 +224,13 @@ async def trusted_user_proposal(request: Request, proposal: int):
@router.post("/tu/{proposal}") @router.post("/tu/{proposal}")
@handle_form_exceptions @handle_form_exceptions
@requires_auth @requires_auth
async def trusted_user_proposal_post( async def package_maintainer_proposal_post(
request: Request, proposal: int, decision: str = Form(...) request: Request, proposal: int, decision: str = Form(...)
): ):
if not request.user.has_credential(creds.TU_LIST_VOTES): if not request.user.has_credential(creds.TU_LIST_VOTES):
return RedirectResponse("/tu", status_code=HTTPStatus.SEE_OTHER) 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. proposal = int(proposal) # Make sure it's an int.
voteinfo = ( voteinfo = (
@ -285,8 +288,8 @@ async def trusted_user_proposal_post(
@router.get("/addvote") @router.get("/addvote")
@requires_auth @requires_auth
async def trusted_user_addvote( async def package_maintainer_addvote(
request: Request, user: str = str(), type: str = "add_tu", agenda: str = str() request: Request, user: str = str(), type: str = "add_pm", agenda: str = str()
): ):
if not request.user.has_credential(creds.TU_ADD_VOTE): if not request.user.has_credential(creds.TU_ADD_VOTE):
return RedirectResponse("/tu", status_code=HTTPStatus.SEE_OTHER) return RedirectResponse("/tu", status_code=HTTPStatus.SEE_OTHER)
@ -295,7 +298,7 @@ async def trusted_user_addvote(
if type not in ADDVOTE_SPECIFICS: if type not in ADDVOTE_SPECIFICS:
context["error"] = "Invalid type." context["error"] = "Invalid type."
type = "add_tu" # Default it. type = "add_pm" # Default it.
context["user"] = user context["user"] = user
context["type"] = type context["type"] = type
@ -308,7 +311,7 @@ async def trusted_user_addvote(
@router.post("/addvote") @router.post("/addvote")
@handle_form_exceptions @handle_form_exceptions
@requires_auth @requires_auth
async def trusted_user_addvote_post( async def package_maintainer_addvote_post(
request: Request, request: Request,
user: str = Form(default=str()), user: str = Form(default=str()),
type: str = Form(default=str()), type: str = Form(default=str()),
@ -352,7 +355,7 @@ async def trusted_user_addvote_post(
if type not in ADDVOTE_SPECIFICS: if type not in ADDVOTE_SPECIFICS:
context["error"] = "Invalid type." context["error"] = "Invalid type."
context["type"] = type = "add_tu" # Default for rendering. context["type"] = type = "add_pm" # Default for rendering.
return render_addvote(context, HTTPStatus.BAD_REQUEST) return render_addvote(context, HTTPStatus.BAD_REQUEST)
if not agenda: if not agenda:
@ -364,11 +367,11 @@ async def trusted_user_addvote_post(
timestamp = time.utcnow() timestamp = time.utcnow()
# Active TU types we filter for. # 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)! # Create a new TUVoteInfo (proposal)!
with db.begin(): with db.begin():
active_tus = ( active_pms = (
db.query(User) db.query(User)
.filter( .filter(
and_( and_(
@ -386,7 +389,7 @@ async def trusted_user_addvote_post(
Submitted=timestamp, Submitted=timestamp,
End=(timestamp + duration), End=(timestamp + duration),
Quorum=quorum, Quorum=quorum,
ActiveTUs=active_tus, ActiveTUs=active_pms,
Submitter=request.user, Submitter=request.user,
) )

View file

@ -3,7 +3,11 @@ from sqlalchemy import func
from aurweb import config, db, time from aurweb import config, db, time
from aurweb.cache import db_count_cache, db_query_cache from aurweb.cache import db_count_cache, db_query_cache
from aurweb.models import PackageBase, PackageRequest, RequestType, User 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 ( from aurweb.models.package_request import (
ACCEPTED_ID, ACCEPTED_ID,
CLOSED_ID, CLOSED_ID,
@ -22,7 +26,7 @@ HOMEPAGE_COUNTERS = [
"year_old_updated", "year_old_updated",
"never_updated", "never_updated",
"user_count", "user_count",
"trusted_user_count", "package_maintainer_count",
] ]
REQUEST_COUNTERS = [ REQUEST_COUNTERS = [
"total_requests", "total_requests",
@ -32,7 +36,7 @@ REQUEST_COUNTERS = [
"rejected_requests", "rejected_requests",
] ]
PROMETHEUS_USER_COUNTERS = [ PROMETHEUS_USER_COUNTERS = [
("trusted_user_count", "tu"), ("package_maintainer_count", "package_maintainer"),
("regular_user_count", "user"), ("regular_user_count", "user"),
] ]
PROMETHEUS_PACKAGE_COUNTERS = [ PROMETHEUS_PACKAGE_COUNTERS = [
@ -92,12 +96,12 @@ class Statistics:
# Users # Users
case "user_count": case "user_count":
query = self.user_query query = self.user_query
case "trusted_user_count": case "package_maintainer_count":
query = self.user_query.filter( query = self.user_query.filter(
User.AccountTypeID.in_( User.AccountTypeID.in_(
( (
TRUSTED_USER_ID, PACKAGE_MAINTAINER_ID,
TRUSTED_USER_AND_DEV_ID, PACKAGE_MAINTAINER_AND_DEV_ID,
) )
) )
) )

View file

@ -220,7 +220,7 @@ def invalid_account_type(
raise ValidationError([error]) raise ValidationError([error])
logger.debug( 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"modified '{user.Username}' account's type to"
f" {name}." f" {name}."
) )

View file

@ -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():
pm = db.query(AccountType).filter(AccountType.ID == 2).first()
pmdev = db.query(AccountType).filter(AccountType.ID == 4).first()
pm.AccountType = "Trusted User"
pmdev.AccountType = "Trusted User & Developer"

View file

@ -156,9 +156,9 @@ contents = None
# developer/tu IDs # developer/tu IDs
# #
developers = [] developers = []
trustedusers = [] packagemaintainers = []
has_devs = 0 has_devs = 0
has_tus = 0 has_pms = 0
# Just let python throw the errors if any happen # Just let python throw the errors if any happen
# #
@ -170,7 +170,7 @@ out.write("BEGIN;\n")
log.debug("Creating SQL statements for users.") log.debug("Creating SQL statements for users.")
for u in user_keys: for u in user_keys:
account_type = 1 # default to normal user account_type = 1 # default to normal user
if not has_devs or not has_tus: if not has_devs or not has_pms:
account_type = random.randrange(1, 4) account_type = random.randrange(1, 4)
if account_type == 3 and not has_devs: if account_type == 3 and not has_devs:
# this will be a dev account # this will be a dev account
@ -178,12 +178,12 @@ for u in user_keys:
developers.append(seen_users[u]) developers.append(seen_users[u])
if len(developers) >= MAX_DEVS * MAX_USERS: if len(developers) >= MAX_DEVS * MAX_USERS:
has_devs = 1 has_devs = 1
elif account_type == 2 and not has_tus: elif account_type == 2 and not has_pms:
# this will be a trusted user account # this will be a trusted user account
# #
trustedusers.append(seen_users[u]) packagemaintainers.append(seen_users[u])
if len(trustedusers) >= MAX_TUS * MAX_USERS: if len(packagemaintainers) >= MAX_TUS * MAX_USERS:
has_tus = 1 has_pms = 1
else: else:
# a normal user account # a normal user account
# #
@ -205,8 +205,10 @@ for u in user_keys:
out.write(s) out.write(s)
log.debug("Number of developers: %d" % len(developers)) log.debug("Number of developers: %d" % len(developers))
log.debug("Number of trusted users: %d" % len(trustedusers)) log.debug("Number of package maintainers: %d" % len(packagemaintainers))
log.debug("Number of users: %d" % (MAX_USERS - len(developers) - len(trustedusers))) log.debug(
"Number of users: %d" % (MAX_USERS - len(developers) - len(packagemaintainers))
)
log.debug("Number of packages: %d" % MAX_PKGS) log.debug("Number of packages: %d" % MAX_PKGS)
log.debug("Gathering text from fortune file...") log.debug("Gathering text from fortune file...")
@ -224,8 +226,8 @@ for p in list(seen_pkgs.keys()):
muid = developers[random.randrange(0, len(developers))] muid = developers[random.randrange(0, len(developers))]
puid = developers[random.randrange(0, len(developers))] puid = developers[random.randrange(0, len(developers))]
else: else:
muid = trustedusers[random.randrange(0, len(trustedusers))] muid = packagemaintainers[random.randrange(0, len(packagemaintainers))]
puid = trustedusers[random.randrange(0, len(trustedusers))] puid = packagemaintainers[random.randrange(0, len(packagemaintainers))]
if count % 20 == 0: # every so often, there are orphans... if count % 20 == 0: # every so often, there are orphans...
muid = "NULL" muid = "NULL"
@ -339,7 +341,7 @@ for p in seen_pkgs_keys:
# Create trusted user proposals # Create trusted user proposals
# #
log.debug("Creating SQL statements for trusted user proposals.") log.debug("Creating SQL statements for package maintainer proposals.")
count = 0 count = 0
for t in range(0, OPEN_PROPOSALS + CLOSE_PROPOSALS): for t in range(0, OPEN_PROPOSALS + CLOSE_PROPOSALS):
now = int(time.time()) now = int(time.time())
@ -353,7 +355,7 @@ for t in range(0, OPEN_PROPOSALS + CLOSE_PROPOSALS):
user = "" user = ""
else: else:
user = user_keys[random.randrange(0, len(user_keys))] user = user_keys[random.randrange(0, len(user_keys))]
suid = trustedusers[random.randrange(0, len(trustedusers))] suid = packagemaintainers[random.randrange(0, len(packagemaintainers))]
s = ( s = (
"INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End," "INSERT INTO TU_VoteInfo (Agenda, User, Submitted, End,"
" Quorum, SubmitterID) VALUES ('%s', '%s', %d, %d, 0.0, %d);\n" " Quorum, SubmitterID) VALUES ('%s', '%s', %d, %d, 0.0, %d);\n"

View file

@ -19,22 +19,22 @@
<p class="vote-type"> <p class="vote-type">
<label for="id_type">{{ "Type" | tr }}</label> <label for="id_type">{{ "Type" | tr }}</label>
<select name="type" id="id_type"> <select name="type" id="id_type">
<option value="add_tu" <option value="add_pm"
{% if "add_tu" == type %} {% if "add_pm" == type %}
selected selected
{% endif %} {% endif %}
> >
{{ "Addition of a TU" | tr }} {{ "Addition of a TU" | tr }}
</option> </option>
<option value="remove_tu" <option value="remove_pm"
{% if "remove_tu" == type %} {% if "remove_pm" == type %}
selected selected
{% endif %} {% endif %}
> >
{{ "Removal of a TU" | tr }} {{ "Removal of a TU" | tr }}
</option> </option>
<option value="remove_inactive_tu" <option value="remove_inactive_pm"
{% if "remove_inactive_tu" == type %} {% if "remove_inactive_pm" == type %}
selected selected
{% endif %} {% endif %}
> >

View file

@ -37,7 +37,7 @@
</li> </li>
{# Only CRED_TU_LIST_VOTES privileged users see Trusted User #} {# Only CRED_TU_LIST_VOTES privileged users see Trusted User #}
{% if request.user.has_credential(creds.TU_LIST_VOTES) %} {% if request.user.has_credential(creds.PM_LIST_VOTES) %}
<li> <li>
<a href="/tu">{% trans %}Trusted User{% endtrans %}</a> <a href="/tu">{% trans %}Trusted User{% endtrans %}</a>
</li> </li>

View file

@ -4,7 +4,7 @@
<option value="unflag">{{ "Unflag Out-of-date" | tr }}</option> <option value="unflag">{{ "Unflag Out-of-date" | tr }}</option>
<option value="adopt">{{ "Adopt Packages" | tr }}</option> <option value="adopt">{{ "Adopt Packages" | tr }}</option>
<option value="disown">{{ "Disown 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> <option value="delete">{{ "Delete Packages" | tr }}</option>
{% endif %} {% endif %}
<option value="notify">{{ "Notify" | tr }}</option> <option value="notify">{{ "Notify" | tr }}</option>

View file

@ -44,7 +44,7 @@
<td class="stat-desc"> <td class="stat-desc">
{{ "Trusted Users" | tr }} {{ "Trusted Users" | tr }}
</td> </td>
<td>{{ trusted_user_count }}</td> <td>{{ package_maintainer_count }}</td>
</tr> </tr>
</table> </table>
</div> </div>

View file

@ -1,7 +1,7 @@
<div class="box"> <div class="box">
<h2>{% trans %}{{ title }}{% endtrans %}</h2> <h2>{% trans %}{{ title }}{% endtrans %}</h2>
{% if title == "Current Votes" and request.user.has_credential(creds.TU_ADD_VOTE) %} {% if title == "Current Votes" and request.user.has_credential(creds.PM_ADD_VOTE) %}
<ul class="admin-actions"> <ul class="admin-actions">
<li> <li>
<a href="/addvote"> <a href="/addvote">

View file

@ -7,11 +7,11 @@
<tbody> <tbody>
<tr> <tr>
<td>{{ "Total" | tr }} {{ "Trusted Users" | tr }}:</td> <td>{{ "Total" | tr }} {{ "Trusted Users" | tr }}:</td>
<td>{{ trusted_user_count }}</td> <td>{{ package_maintainer_count }}</td>
</tr> </tr>
<tr> <tr>
<td>{{ "Active" | tr }} {{ "Trusted Users" | tr }}:</td> <td>{{ "Active" | tr }} {{ "Trusted Users" | tr }}:</td>
<td>{{ active_trusted_user_count }}</td> <td>{{ active_package_maintainer_count }}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -45,7 +45,7 @@
{% include "partials/tu/proposals.html" %} {% include "partials/tu/proposals.html" %}
{% endwith %} {% endwith %}
{% with title = "Last Votes by TU", votes = last_votes_by_tu %} {% with title = "Last Votes by TU", votes = last_votes_by_pm %}
{% include "partials/tu/last_votes.html" %} {% include "partials/tu/last_votes.html" %}
{% endwith %} {% endwith %}
{% endblock %} {% endblock %}

View file

@ -17,9 +17,9 @@ from aurweb.db import create, query
from aurweb.models.accepted_term import AcceptedTerm from aurweb.models.accepted_term import AcceptedTerm
from aurweb.models.account_type import ( from aurweb.models.account_type import (
DEVELOPER_ID, DEVELOPER_ID,
TRUSTED_USER, PACKAGE_MAINTAINER,
TRUSTED_USER_AND_DEV_ID, PACKAGE_MAINTAINER_AND_DEV_ID,
TRUSTED_USER_ID, PACKAGE_MAINTAINER_ID,
USER_ID, USER_ID,
AccountType, AccountType,
) )
@ -98,7 +98,7 @@ def user() -> User:
@pytest.fixture @pytest.fixture
def tu_user(user: User): def tu_user(user: User):
with db.begin(): with db.begin():
user.AccountTypeID = TRUSTED_USER_AND_DEV_ID user.AccountTypeID = PACKAGE_MAINTAINER_AND_DEV_ID
yield user 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.""" """Test edit get route of another TU as a TU."""
with db.begin(): with db.begin():
user2 = create_user("test2") user2 = create_user("test2")
user2.AccountTypeID = at.TRUSTED_USER_ID user2.AccountTypeID = at.PACKAGE_MAINTAINER_ID
cookies = {"AURSID": tu_user.login(Request(), "testPassword")} cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
endpoint = f"/account/{user2.Username}/edit" 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) assert response.status_code == int(HTTPStatus.OK)
# Verify that we have an account type selection and that the # 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) root = parse_root(response.text)
atype = root.xpath('//select[@id="id_type"]/option[@selected="selected"]') atype = root.xpath('//select[@id="id_type"]/option[@selected="selected"]')
expected = at.TRUSTED_USER expected = at.PACKAGE_MAINTAINER
assert atype[0].text.strip() == expected assert atype[0].text.strip() == expected
username = root.xpath('//input[@id="id_username"]')[0] 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): def test_post_account_edit_invalid_type_as_tu(client: TestClient, tu_user: User):
with db.begin(): with db.begin():
user2 = create_user("test_tu") 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")} cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
endpoint = f"/account/{user2.Username}/edit" 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): def test_post_account_edit_dev(client: TestClient, tu_user: User):
# Modify our user to be a "Trusted User & Developer" # Modify our user to be a "Package Maintainer & Developer"
name = "Trusted User & Developer" name = "Package Maintainer & Developer"
tu_or_dev = query(AccountType, AccountType.AccountType == name).first() tu_or_dev = query(AccountType, AccountType.AccountType == name).first()
with db.begin(): with db.begin():
user.AccountType = tu_or_dev 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): def test_post_account_edit_inactivity(client: TestClient, user: User):
with db.begin(): with db.begin():
user.AccountTypeID = TRUSTED_USER_ID user.AccountTypeID = PACKAGE_MAINTAINER_ID
assert not user.Suspended assert not user.Suspended
cookies = {"AURSID": user.login(Request(), "testPassword")} 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): def test_post_account_edit_suspended(client: TestClient, user: User):
with db.begin(): with db.begin():
user.AccountTypeID = TRUSTED_USER_ID user.AccountTypeID = PACKAGE_MAINTAINER_ID
assert not user.Suspended assert not user.Suspended
cookies = {"AURSID": user.login(Request(), "testPassword")} cookies = {"AURSID": user.login(Request(), "testPassword")}
@ -1223,7 +1223,7 @@ def test_post_account_edit_self_type_as_user(client: TestClient, user: User):
data = { data = {
"U": user.Username, "U": user.Username,
"E": user.Email, "E": user.Email,
"T": TRUSTED_USER_ID, "T": PACKAGE_MAINTAINER_ID,
"passwd": "testPassword", "passwd": "testPassword",
} }
with client as request: with client as request:
@ -1298,7 +1298,7 @@ def test_post_account_edit_other_user_type_as_tu(
data = { data = {
"U": user2.Username, "U": user2.Username,
"E": user2.Email, "E": user2.Email,
"T": TRUSTED_USER_ID, "T": PACKAGE_MAINTAINER_ID,
"passwd": "testPassword", "passwd": "testPassword",
} }
@ -1308,13 +1308,13 @@ def test_post_account_edit_other_user_type_as_tu(
assert resp.status_code == int(HTTPStatus.OK) assert resp.status_code == int(HTTPStatus.OK)
# Let's make sure the DB got updated properly. # 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. # and also that this got logged out at DEBUG level.
expected = ( expected = (
f"Trusted User '{tu_user.Username}' has " f"Package Maintainer '{tu_user.Username}' has "
f"modified '{user2.Username}' account's type to" f"modified '{user2.Username}' account's type to"
f" {TRUSTED_USER}." f" {PACKAGE_MAINTAINER}."
) )
assert expected in caplog.text 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. # Set our only user to a Trusted User.
with db.begin(): with db.begin():
user.AccountType = ( user.AccountType = (
query(AccountType).filter(AccountType.ID == TRUSTED_USER_ID).first() query(AccountType).filter(AccountType.ID == PACKAGE_MAINTAINER_ID).first()
) )
with client as request: 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)) row = next(iter(rows))
username, type, status, realname, irc, pgp_key, edit = row username, type, status, realname, irc, pgp_key, edit = row
assert type.text.strip() == "Trusted User" assert type.text.strip() == "Package Maintainer"
with db.begin(): with db.begin():
user.AccountType = ( user.AccountType = (
@ -1637,7 +1637,9 @@ def test_post_accounts_account_type(client: TestClient, user: User, tu_user: Use
with db.begin(): with db.begin():
user.AccountType = ( 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: 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)) row = next(iter(rows))
username, type, status, realname, irc, pgp_key, edit = row 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): 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(): with db.begin():
user.AccountType = ( 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. # Fetch first_rows again with our new AccountType ordering.

View file

@ -48,12 +48,12 @@ def test_adduser_tu():
"-p", "-p",
"abcd1234", "abcd1234",
"-t", "-t",
at.TRUSTED_USER, at.PACKAGE_MAINTAINER,
] ]
) )
test = db.query(User).filter(User.Username == "test").first() test = db.query(User).filter(User.Username == "test").first()
assert test is not None assert test is not None
assert test.AccountTypeID == at.TRUSTED_USER_ID assert test.AccountTypeID == at.PACKAGE_MAINTAINER_ID
def test_adduser_ssh_pk(): def test_adduser_ssh_pk():

View file

@ -137,9 +137,9 @@ def test_account_type_required():
account_type_required({"FAKE"}) account_type_required({"FAKE"})
def test_is_trusted_user(): def test_is_package_maintainer():
user_ = AnonymousUser() user_ = AnonymousUser()
assert not user_.is_trusted_user() assert not user_.is_package_maintainer()
def test_is_developer(): def test_is_developer():

View file

@ -62,7 +62,7 @@ def redis():
"package_count", "package_count",
"orphan_count", "orphan_count",
"user_count", "user_count",
"trusted_user_count", "package_maintainer_count",
"seven_days_old_added", "seven_days_old_added",
"seven_days_old_updated", "seven_days_old_updated",
"year_old_updated", "year_old_updated",

View file

@ -12,7 +12,7 @@ from fastapi.testclient import TestClient
from aurweb import asgi, config, db from aurweb import asgi, config, db
from aurweb.models import PackageBase 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.models.user import User
from aurweb.testing.html import get_errors, get_successes, parse_root from aurweb.testing.html import get_errors, get_successes, parse_root
from aurweb.testing.requests import Request from aurweb.testing.requests import Request
@ -42,9 +42,9 @@ def user() -> User:
@pytest.fixture @pytest.fixture
def trusted_user(user: User) -> User: def package_maintainer(user: User) -> User:
with db.begin(): with db.begin():
user.AccountTypeID = TRUSTED_USER_ID user.AccountTypeID = PACKAGE_MAINTAINER_ID
yield user yield user
@ -81,7 +81,7 @@ def test_archdev_navbar_authenticated(client: TestClient, user: User):
assert item.text.strip() == expected[i] 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 = [ expected = [
"Dashboard", "Dashboard",
"Packages", "Packages",
@ -91,7 +91,7 @@ def test_archdev_navbar_authenticated_tu(client: TestClient, trusted_user: User)
"Trusted User", "Trusted User",
"Logout", "Logout",
] ]
cookies = {"AURSID": trusted_user.login(Request(), "testPassword")} cookies = {"AURSID": package_maintainer.login(Request(), "testPassword")}
with client as request: with client as request:
request.cookies = cookies request.cookies = cookies
resp = request.get("/") resp = request.get("/")

View file

@ -5,7 +5,7 @@ import pytest
from aurweb import config, db, models, time from aurweb import config, db, models, time
from aurweb.models import Package, PackageBase, PackageRequest, User 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.models.request_type import ORPHAN_ID
from aurweb.scripts import notify, rendercomment from aurweb.scripts import notify, rendercomment
from aurweb.testing.email import Email 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: def set_tu(users: list[User]) -> User:
with db.begin(): with db.begin():
for user in users: for user in users:
user.AccountTypeID = TRUSTED_USER_ID user.AccountTypeID = PACKAGE_MAINTAINER_ID
def test_open_close_request( def test_open_close_request(

View file

@ -114,7 +114,9 @@ def maintainer() -> User:
@pytest.fixture @pytest.fixture
def tu_user(): 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(): with db.begin():
tu_user = db.create( tu_user = db.create(
User, User,

View file

@ -117,7 +117,9 @@ def comaintainer() -> User:
@pytest.fixture @pytest.fixture
def tu_user(): 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(): with db.begin():
tu_user = db.create( tu_user = db.create(
User, User,

View file

@ -8,7 +8,7 @@ from fastapi.testclient import TestClient
from aurweb import asgi, config, db, defaults, time from aurweb import asgi, config, db, defaults, time
from aurweb.models import Package, PackageBase, PackageRequest, User 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_comaintainer import PackageComaintainer
from aurweb.models.package_notification import PackageNotification from aurweb.models.package_notification import PackageNotification
from aurweb.models.package_request import ACCEPTED_ID, PENDING_ID, REJECTED_ID 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.""" """Yield an authenticated Trusted User instance."""
user = create_user("test_tu", "test_tu@example.org") user = create_user("test_tu", "test_tu@example.org")
with db.begin(): with db.begin():
user.AccountTypeID = TRUSTED_USER_ID user.AccountTypeID = PACKAGE_MAINTAINER_ID
cookies = {"AURSID": user.login(Request(), "testPassword")} cookies = {"AURSID": user.login(Request(), "testPassword")}
user.cookies = cookies user.cookies = cookies
yield user yield user

View file

@ -3,7 +3,7 @@ from prometheus_client import REGISTRY, generate_latest
from aurweb import cache, db, prometheus, time from aurweb import cache, db, prometheus, time
from aurweb.models import Package, PackageBase, PackageRequest 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 ( from aurweb.models.package_request import (
ACCEPTED_ID, ACCEPTED_ID,
CLOSED_ID, CLOSED_ID,
@ -64,7 +64,7 @@ def test_data():
# Modify some data to get some variances for our counters # Modify some data to get some variances for our counters
if i == 1: if i == 1:
user.AccountTypeID = TRUSTED_USER_ID user.AccountTypeID = PACKAGE_MAINTAINER_ID
pkgbase.Maintainer = None pkgbase.Maintainer = None
pkgbase.SubmittedTS = now pkgbase.SubmittedTS = now
pkgreq.Status = PENDING_ID pkgreq.Status = PENDING_ID
@ -99,7 +99,7 @@ def stats() -> Statistics:
("year_old_updated", 9), ("year_old_updated", 9),
("never_updated", 1), ("never_updated", 1),
("user_count", 10), ("user_count", 10),
("trusted_user_count", 1), ("package_maintainer_count", 1),
("regular_user_count", 9), ("regular_user_count", 9),
("updated_packages", 9), ("updated_packages", 9),
("total_requests", 10), ("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): def test_get_count_change(stats: Statistics, test_data):
pkgs_before = stats.get_count("package_count") 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 pkgs_before == 10
assert tus_before == 1 assert tus_before == 1
@ -127,16 +127,16 @@ def test_get_count_change(stats: Statistics, test_data):
db.delete(pkgbase) db.delete(pkgbase)
user = db.query(User).filter(User.AccountTypeID == USER_ID).first() 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 # 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("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 # Let's clear the cache and check again
cache._redis.flushall() cache._redis.flushall()
assert stats.get_count("package_count") != pkgs_before 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): def test_update_prometheus_metrics(test_data):

View file

@ -8,7 +8,7 @@ import pytest
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from aurweb import config, db, filters, time 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_vote import TUVote
from aurweb.models.tu_voteinfo import TUVoteInfo from aurweb.models.tu_voteinfo import TUVoteInfo
from aurweb.models.user import User from aurweb.models.user import User
@ -90,7 +90,9 @@ def client():
@pytest.fixture @pytest.fixture
def tu_user(): 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(): with db.begin():
tu_user = db.create( tu_user = db.create(
User, User,
@ -112,7 +114,7 @@ def tu_user2():
Email="test_tu2@example.org", Email="test_tu2@example.org",
RealName="Test TU 2", RealName="Test TU 2",
Passwd="testPassword", Passwd="testPassword",
AccountTypeID=TRUSTED_USER_ID, AccountTypeID=PACKAGE_MAINTAINER_ID,
) )
yield tu_user2 yield tu_user2
@ -918,7 +920,7 @@ def test_tu_addvote_invalid_type(client: TestClient, tu_user: User):
def test_tu_addvote_post(client: TestClient, tu_user: User, user: User): def test_tu_addvote_post(client: TestClient, tu_user: User, user: User):
cookies = {"AURSID": tu_user.login(Request(), "testPassword")} cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
data = {"user": user.Username, "type": "add_tu", "agenda": "Blah"} data = {"user": user.Username, "type": "add_pm", "agenda": "Blah"}
with client as request: with client as request:
request.cookies = cookies request.cookies = cookies
@ -934,7 +936,7 @@ def test_tu_addvote_post_cant_duplicate_username(
): ):
cookies = {"AURSID": tu_user.login(Request(), "testPassword")} cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
data = {"user": user.Username, "type": "add_tu", "agenda": "Blah"} data = {"user": user.Username, "type": "add_pm", "agenda": "Blah"}
with client as request: with client as request:
request.cookies = cookies request.cookies = cookies
@ -970,7 +972,7 @@ def test_tu_addvote_post_invalid_type(client: TestClient, tu_user: User, user: U
def test_tu_addvote_post_invalid_agenda(client: TestClient, tu_user: User, user: User): def test_tu_addvote_post_invalid_agenda(client: TestClient, tu_user: User, user: User):
cookies = {"AURSID": tu_user.login(Request(), "testPassword")} cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
data = {"user": user.Username, "type": "add_tu"} data = {"user": user.Username, "type": "add_pm"}
with client as request: with client as request:
request.cookies = cookies request.cookies = cookies
response = request.post("/addvote", data=data) response = request.post("/addvote", data=data)

View file

@ -2,7 +2,7 @@ import pytest
from sqlalchemy.exc import IntegrityError from sqlalchemy.exc import IntegrityError
from aurweb import db, time 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_vote import TUVote
from aurweb.models.tu_voteinfo import TUVoteInfo from aurweb.models.tu_voteinfo import TUVoteInfo
from aurweb.models.user import User from aurweb.models.user import User
@ -22,7 +22,7 @@ def user() -> User:
Email="test@example.org", Email="test@example.org",
RealName="Test User", RealName="Test User",
Passwd="testPassword", Passwd="testPassword",
AccountTypeID=TRUSTED_USER_ID, AccountTypeID=PACKAGE_MAINTAINER_ID,
) )
yield user yield user

View file

@ -3,7 +3,7 @@ from sqlalchemy.exc import IntegrityError
from aurweb import db, time from aurweb import db, time
from aurweb.db import create, rollback 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.tu_voteinfo import TUVoteInfo
from aurweb.models.user import User from aurweb.models.user import User
@ -22,7 +22,7 @@ def user() -> User:
Email="test@example.org", Email="test@example.org",
RealName="Test User", RealName="Test User",
Passwd="testPassword", Passwd="testPassword",
AccountTypeID=TRUSTED_USER_ID, AccountTypeID=PACKAGE_MAINTAINER_ID,
) )
yield user yield user

View file

@ -4,7 +4,7 @@ import pytest
from aurweb import config, db, time from aurweb import config, db, time
from aurweb.models import TUVote, TUVoteInfo, User 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.scripts import tuvotereminder as reminder
from aurweb.testing.email import Email from aurweb.testing.email import Email
@ -47,17 +47,17 @@ def email_pieces(voteinfo: TUVoteInfo) -> Tuple[str, str]:
@pytest.fixture @pytest.fixture
def user(db_test) -> User: def user(db_test) -> User:
yield create_user("test", TRUSTED_USER_ID) yield create_user("test", PACKAGE_MAINTAINER_ID)
@pytest.fixture @pytest.fixture
def user2() -> User: def user2() -> User:
yield create_user("test2", TRUSTED_USER_ID) yield create_user("test2", PACKAGE_MAINTAINER_ID)
@pytest.fixture @pytest.fixture
def user3() -> User: def user3() -> User:
yield create_user("test3", TRUSTED_USER_ID) yield create_user("test3", PACKAGE_MAINTAINER_ID)
@pytest.fixture @pytest.fixture

View file

@ -12,8 +12,8 @@ from aurweb import db
from aurweb.auth import creds from aurweb.auth import creds
from aurweb.models.account_type import ( from aurweb.models.account_type import (
DEVELOPER_ID, DEVELOPER_ID,
TRUSTED_USER_AND_DEV_ID, PACKAGE_MAINTAINER_AND_DEV_ID,
TRUSTED_USER_ID, PACKAGE_MAINTAINER_ID,
USER_ID, USER_ID,
) )
from aurweb.models.ban import Ban from aurweb.models.ban import Ban
@ -53,7 +53,7 @@ def user() -> User:
@pytest.fixture @pytest.fixture
def tu_user() -> User: def tu_user() -> User:
user = create_user("test_tu", TRUSTED_USER_ID) user = create_user("test_tu", PACKAGE_MAINTAINER_ID)
yield user yield user
@ -65,7 +65,7 @@ def dev_user() -> User:
@pytest.fixture @pytest.fixture
def tu_and_dev_user() -> User: 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 yield user
@ -207,33 +207,33 @@ def test_user_ssh_pub_key(user: User):
def test_user_credential_types(user: User): def test_user_credential_types(user: User):
assert user.AccountTypeID in creds.user_developer_or_trusted_user assert user.AccountTypeID in creds.user_developer_or_package_maintainer
assert user.AccountTypeID not in creds.trusted_user assert user.AccountTypeID not in creds.package_maintainer
assert user.AccountTypeID not in creds.developer 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(): 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.package_maintainer
assert user.AccountTypeID in creds.trusted_user_or_dev assert user.AccountTypeID in creds.package_maintainer_or_dev
with db.begin(): with db.begin():
user.AccountTypeID = at.DEVELOPER_ID user.AccountTypeID = at.DEVELOPER_ID
assert user.AccountTypeID in creds.developer 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(): 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.developer
assert user.AccountTypeID in creds.trusted_user_or_dev assert user.AccountTypeID in creds.package_maintainer_or_dev
# Some model authorization checks. # Some model authorization checks.
assert user.is_elevated() assert user.is_elevated()
assert user.is_trusted_user() assert user.is_package_maintainer()
assert user.is_developer() assert user.is_developer()
@ -255,15 +255,15 @@ def test_user_as_dict(user: User):
assert isinstance(data.get("RegistrationTS"), datetime) 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(): with db.begin():
user.AccountTypeID = at.TRUSTED_USER_ID user.AccountTypeID = at.PACKAGE_MAINTAINER_ID
assert user.is_trusted_user() is True assert user.is_package_maintainer() is True
# Do it again with the combined role. # Do it again with the combined role.
with db.begin(): with db.begin():
user.AccountTypeID = at.TRUSTED_USER_AND_DEV_ID user.AccountTypeID = at.PACKAGE_MAINTAINER_AND_DEV_ID
assert user.is_trusted_user() is True assert user.is_package_maintainer() is True
def test_user_is_developer(user: User): 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. # Do it again with the combined role.
with db.begin(): 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 assert user.is_developer() is True