Skip to content

Commit

Permalink
chore: rename isOwner to isGroupOwner and add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
juliannemarik committed Aug 29, 2023
1 parent 1667a23 commit 157939c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async function searchGroupMembers(
// over the includes and requestOptions
const fn = (member: IGroupMember) => {
return memberToSearchResult(
{ ...member, isOwner: resp.owner.username === member.username },
{ ...member, isGroupOwner: resp.owner.username === member.username },
searchOptions.include,
searchOptions.requestOptions
);
Expand Down Expand Up @@ -179,7 +179,7 @@ interface IGroupMember {
* @returns
*/
async function memberToSearchResult(
member: IGroupMember & { isOwner: boolean },
member: IGroupMember & { isGroupOwner: boolean },
include: string[] = [],
requestOptions?: IHubRequestOptions
): Promise<IHubSearchResult> {
Expand All @@ -199,7 +199,7 @@ async function memberToSearchResult(
thumbnail: null,
created: null,
modified: null,
isOwner: member.isOwner,
isGroupOwner: member.isGroupOwner,
};

const fsGetUser = failSafe(getUser, user);
Expand Down
11 changes: 9 additions & 2 deletions packages/common/src/users/HubUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ export async function enrichUserSearchResult(
access: user.access as AccessLevel,
id: user.username,
type: "User",
/**
* We need to return a valid IHubSearchResult, so we store
* IUser information where it makes the most sense - e.g.
* we store the user's full name under the "name" property,
* and since users don't have an owner, we fill that property
* with the user's username
*/
name: user.fullName,
owner: user.username,
// A private user will not have a description prop at all
Expand All @@ -42,10 +49,10 @@ export async function enrichUserSearchResult(
thumbnail: null,
},
};
// Group Memberships need these properties
// Group Memberships need these additional properties
if (user.memberType) {
result.memberType = user.memberType;
result.isOwner = user.isOwner;
result.isGroupOwner = user.isGroupOwner;
}

// Informal Enrichments - basically adding type-specific props
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/users/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const getSharedUserCardModel = (user: IHubSearchResult): IHubCardViewModel => {
* card
*/
if (memberType) {
if (user.isOwner) {
if (user.isGroupOwner) {
badges.push({
icon: "user-key",
color: "gray",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/test/users/view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe("user view module:", () => {
describe("membership badges", () => {
it("adds an owner badge if the user is the group owner", () => {
const GROUP_MEMBER_RESULT = cloneObject(USER_HUB_SEARCH_RESULT);
GROUP_MEMBER_RESULT.isOwner = true;
GROUP_MEMBER_RESULT.isGroupOwner = true;
GROUP_MEMBER_RESULT.memberType = "admin";

const result = userResultToCardModel(GROUP_MEMBER_RESULT);
Expand Down

0 comments on commit 157939c

Please sign in to comment.