Skip to content

Commit

Permalink
fix(core): user ownership on resources within a team (#808)
Browse files Browse the repository at this point in the history
* fix(core): user ownership on resources within a team

* Create lazy-sheep-sparkle.md

---------

Co-authored-by: David Boyne <[email protected]>
  • Loading branch information
boyney123 and David Boyne authored Sep 16, 2024
1 parent 7f6bec4 commit 7e63592
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-sheep-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@eventcatalog/core": patch
---

fix(core): user ownership on resources within a team
26 changes: 14 additions & 12 deletions src/utils/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,27 @@ export const getUsers = async (): Promise<User[]> => {
});

return users.map((user) => {
const associatedTeams = teams.filter((team) => {
return team.data.members?.some((member) => member.slug === user.data.id);
});

const ownedDomains = domains.filter((domain) => {
return domain.data.owners?.find((owner) => owner.slug === user.data.id);
});

const ownedServices = services.filter((service) => {
return service.data.owners?.find((owner) => owner.slug === user.data.id);
});
const isOwnedByUserOrAssociatedTeam = () => {
const associatedTeamsSlug: string[] = associatedTeams.map((team) => team.slug);

const ownedEvents = events.filter((event) => {
return event.data.owners?.find((owner) => owner.slug === user.data.id);
});
return ({ data }: { data: { owners?: Array<{ slug: string }> } }) => {
return data.owners?.some((owner) => owner.slug === user.data.id || associatedTeamsSlug.includes(owner.slug));
};
};

const ownedCommands = commands.filter((command) => {
return command.data.owners?.find((owner) => owner.slug === user.data.id);
});
const ownedServices = services.filter(isOwnedByUserOrAssociatedTeam());

const associatedTeams = teams.filter((team) => {
return team.data.members?.find((member) => member.slug === user.data.id);
});
const ownedEvents = events.filter(isOwnedByUserOrAssociatedTeam());

const ownedCommands = commands.filter(isOwnedByUserOrAssociatedTeam());

return {
...user,
Expand Down

0 comments on commit 7e63592

Please sign in to comment.