|
7 | 7 |
|
8 | 8 | """Models for the VCS integration.""" |
9 | 9 |
|
| 10 | +from __future__ import annotations |
| 11 | + |
10 | 12 | import uuid |
11 | 13 | from datetime import datetime, timezone |
12 | 14 | from enum import Enum |
|
15 | 17 | from invenio_db import db |
16 | 18 | from invenio_i18n import lazy_gettext as _ |
17 | 19 | from invenio_webhooks.models import Event |
18 | | -from sqlalchemy import UniqueConstraint, delete, insert |
| 20 | +from sqlalchemy import UniqueConstraint, delete, insert, select |
19 | 21 | from sqlalchemy.dialects import postgresql |
20 | 22 | from sqlalchemy.ext.mutable import MutableDict |
21 | 23 | from sqlalchemy_utils.models import Timestamp |
@@ -174,15 +176,19 @@ def remove_user(self, user_id: int): |
174 | 176 | ) |
175 | 177 | db.session.execute(stmt) |
176 | 178 |
|
| 179 | + def list_users(self): |
| 180 | + """Return a list of users with access to the repository.""" |
| 181 | + return db.session.execute( |
| 182 | + select(repository_user_association).filter_by(repository_id=self.id) |
| 183 | + ) |
| 184 | + |
177 | 185 | @classmethod |
178 | | - def get(cls, provider: str, provider_id: str): |
| 186 | + def get(cls, provider: str, provider_id: str) -> Repository | None: |
179 | 187 | """Return a repository given its provider ID. |
180 | 188 |
|
181 | 189 | :param str provider: Registered ID of the VCS provider. |
182 | 190 | :param str provider_id: VCS provider repository identifier. |
183 | | - :returns: The repository object. |
184 | | - :raises: :py:exc:`~sqlalchemy.orm.exc.NoResultFound`: if the repository |
185 | | - doesn't exist. |
| 191 | + :returns: The repository object or None if one with the given ID and provider doesn't exist. |
186 | 192 | """ |
187 | 193 | return cls.query.filter( |
188 | 194 | Repository.provider_id == provider_id, Repository.provider == provider |
|
0 commit comments