Skip to content

Commit

Permalink
Default to JSON datasets in RoleAccessProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Dec 12, 2023
1 parent c835f25 commit cbdd82e
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/coaster/sqlalchemy/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,10 +795,11 @@ def __class__(self, value: t.Any) -> t.NoReturn: # noqa: F811
def __init__(
self,
obj: RoleMixinType,
*,
roles: t.Union[LazyRoleSet, t.Set[str]],
actor: t.Optional[t.Any],
anchors: t.Sequence[t.Any],
datasets: t.Optional[t.Sequence[str]],
actor: t.Optional[t.Any] = None,
anchors: t.Sequence[t.Any] = (),
datasets: t.Optional[t.Sequence[str]] = None,
) -> None:
object.__setattr__(self, '_obj', obj)
object.__setattr__(self, 'current_roles', InspectableSet(roles))
Expand Down Expand Up @@ -975,6 +976,18 @@ def __iter__(self) -> t.Iterator[str]:
yield from self._all_read

def __json__(self) -> t.Dict[str, t.Any]:
if self._datasets is None and self._obj.__json_datasets__:
# This proxy was created without specifying datasets, so we create a new
# proxy using the object's default JSON datasets, then convert it to a dict
return dict(
RoleAccessProxy(
obj=self._obj,
roles=self._roles,
actor=self._actor,
anchors=self._anchors,
datasets=self._obj.__json_datasets__,
)
)
return dict(self)

def __eq__(self, other: t.Any) -> bool:
Expand Down

0 comments on commit cbdd82e

Please sign in to comment.