Skip to content

Commit

Permalink
inline get_collection_groups in get_collections
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickhilber committed Mar 28, 2023
1 parent cc2c081 commit 66ed801
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions bitwarden_access_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,18 +374,6 @@ def get_groups(self) -> Iterable[Group]:
access_all=group["accessAll"],
)

def get_collection_groups(self, groups: Any) -> Iterable[GroupCollectionAccess]:
for group in groups:
access = self.map_access(readonly=group["readOnly"])

group_id = group["id"]
yield GroupCollectionAccess(
group_name=json.load(self._http_get(f"/public/groups/{group_id}"))[
"name"
],
access=access,
)

def get_collections(
self,
org_members: Dict[str, Member],
Expand All @@ -402,8 +390,22 @@ def get_collections(
self._http_get(f"/public/collections/{collection_id}")
)

group_collection_accesses: List[GroupCollectionAccess] = []

for group in collection_data["groups"]:
access = self.map_access(readonly=group["readOnly"])
group_id = group["id"]
group_collection_accesses.append(
GroupCollectionAccess(
group_name=json.load(
self._http_get(f"/public/groups/{group_id}")
)["name"],
access=access,
)
)

group_accesses_data = tuple(
sorted(self.get_collection_groups(collection_data["groups"]))
sorted(group_collection_accesses)
)

if len(group_accesses_data) > 0:
Expand Down Expand Up @@ -446,7 +448,9 @@ def get_members(
members = json.load(data)

members_result: List[Member] = []
collection_access: Dict[str, List[MemberCollectionAccess]] = defaultdict(lambda: [])
collection_access: Dict[str, List[MemberCollectionAccess]] = defaultdict(
lambda: []
)
groups: Tuple[str, ...] = tuple()

for member in members["data"]:
Expand All @@ -471,7 +475,9 @@ def get_members(
access = self.map_access(readonly=collection["readOnly"])

collection_access[collection["id"]].append(
MemberCollectionAccess(member_name=member["name"], access=access)
MemberCollectionAccess(
member_name=member["name"], access=access
)
)

return members_result, collection_access
Expand Down

0 comments on commit 66ed801

Please sign in to comment.