Skip to content

Commit

Permalink
fix(hub-discussions): user can read channel if group is non-discussab…
Browse files Browse the repository at this point in the history
…le (#1201)
  • Loading branch information
brittneyjb authored Sep 7, 2023
1 parent 1961c7c commit 28d61f3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
10 changes: 8 additions & 2 deletions packages/discussions/src/utils/channel-permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,14 @@ export class ChannelPermission {
return groupAccessControls.some((permission) => {
const group = userGroupsById[permission.key];

if (!group || !isGroupDiscussable(group)) {
return false;
if (action === ChannelAction.READ_POSTS) {
if (!group) {
return false;
}
} else {
if (!group || !isGroupDiscussable(group)) {
return false;
}
}

return (
Expand Down
27 changes: 25 additions & 2 deletions packages/discussions/test/utils/channel-permission.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,29 @@ describe("ChannelPermission class", () => {

expect(channelPermission.canReadChannel(user)).toBe(false);
});

it("returns true if user logged in and in non-discussable group", async () => {
const user = buildUser({
groups: [buildGroup("groupND", "member", [CANNOT_DISCUSS])],
});
const channelAcl = [
{
category: AclCategory.GROUP,
subCategory: AclSubCategory.MEMBER,
key: "groupND",
role: Role.READ, // members write
},
{
category: AclCategory.GROUP,
subCategory: AclSubCategory.ADMIN,
key: "groupND",
role: Role.READ, // members write
},
] as IChannelAclPermission[];
const channelPermission = new ChannelPermission(channelAcl, "foo");

expect(channelPermission.canReadChannel(user)).toBe(true);
});
});

describe("Anonymous User Permissions", () => {
Expand Down Expand Up @@ -1766,7 +1789,7 @@ describe("ChannelPermission class", () => {
expect(channelPermission.canReadChannel(user)).toBe(true);
});

it("returns false if user is group member in permissions list but the group is not discussable", async () => {
it("returns true if user is group member in permissions list but the group is not discussable", async () => {
const user = buildUser({
orgId: orgId1,
groups: [
Expand All @@ -1790,7 +1813,7 @@ describe("ChannelPermission class", () => {

const channelPermission = new ChannelPermission(channelAcl, "foo");

expect(channelPermission.canReadChannel(user)).toBe(false);
expect(channelPermission.canReadChannel(user)).toBe(true);
});

it("returns false if user is group admin but group is not in permissions list", async () => {
Expand Down

0 comments on commit 28d61f3

Please sign in to comment.