Skip to content

Commit 455a2c0

Browse files
committed
WIP: models: add list_users method to Repository
1 parent 7ba04da commit 455a2c0

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

invenio_vcs/models.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
"""Models for the VCS integration."""
99

10+
from __future__ import annotations
11+
1012
import uuid
1113
from datetime import datetime, timezone
1214
from enum import Enum
@@ -15,7 +17,7 @@
1517
from invenio_db import db
1618
from invenio_i18n import lazy_gettext as _
1719
from invenio_webhooks.models import Event
18-
from sqlalchemy import UniqueConstraint, delete, insert
20+
from sqlalchemy import UniqueConstraint, delete, insert, select
1921
from sqlalchemy.dialects import postgresql
2022
from sqlalchemy.ext.mutable import MutableDict
2123
from sqlalchemy_utils.models import Timestamp
@@ -174,15 +176,19 @@ def remove_user(self, user_id: int):
174176
)
175177
db.session.execute(stmt)
176178

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+
177185
@classmethod
178-
def get(cls, provider: str, provider_id: str):
186+
def get(cls, provider: str, provider_id: str) -> Repository | None:
179187
"""Return a repository given its provider ID.
180188
181189
:param str provider: Registered ID of the VCS provider.
182190
: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.
186192
"""
187193
return cls.query.filter(
188194
Repository.provider_id == provider_id, Repository.provider == provider

0 commit comments

Comments
 (0)