Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: add permission checks for issue subscribe section (#13082)

boojack81bb06f26aa7
diff --git a/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentList.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentList.vue
index 562fbd01ce..d425672fcf 100644
--- a/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentList.vue
+++ b/frontend/src/components/IssueV1/components/IssueCommentSection/IssueCommentList.vue
@@ -124,7 +124,7 @@ import { isValidProjectName } from "@/types";
import type { ComposedIssue } from "@/types";
import { ListIssueCommentsRequest } from "@/types/proto/v1/issue_service";
import { extractUserResourceName, hasProjectPermissionV2 } from "@/utils";
-import { doSubscribeIssue, useIssueContext } from "../../logic";
+import { useIssueContext } from "../../logic";
import {
IssueCommentView,
isSimilarIssueComment,
@@ -222,13 +222,6 @@ const doCreateComment = async (comment: string) => {
});
state.newComment = "";
await prepareIssueComments();
- // Because the user just added a comment and we assume she is interested in this
- // issue, and we add her to the subscriber list if she is not there
- try {
- await doSubscribeIssue(issue.value, currentUser.value);
- } catch {
- // Nothing
- }
};
const allowEditIssueComment = (comment: ComposedIssueComment) => {
diff --git a/frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/SubscriberList.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/SubscriberList.vue
index 3c29e274bf..651b40bdc4 100644
--- a/frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/SubscriberList.vue
+++ b/frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/SubscriberList.vue
@@ -7,16 +7,11 @@
:scrollable="true"
trigger="click"
placement="left"
+ :disabled="readonly"
@update:show="onUpdateShow"
@update:value="onUpdateSubscribers"
>
- <NButton
- quaternary
- :style="{
- '--n-padding':
- subscriberList.length === 0 ? '0 8px 0 8px' : '0 8px 0 12px',
- }"
- >
+ <NButton quaternary>
<div class="flex items-center gap-x-1">
<UserAvatar
v-for="user in subscriberList"
@@ -25,7 +20,7 @@
size="SMALL"
class="ml-[-18px] first:ml-0"
/>
- <heroicons:ellipsis-horizontal class="w-5 h-5" />
+ <heroicons:ellipsis-horizontal v-if="!readonly" class="w-5 h-5" />
</div>
</NButton>
@@ -53,6 +48,10 @@ import { State } from "@/types/proto/v1/common";
import { extractUserResourceName } from "@/utils";
import SubscriberListItem from "./SubscriberListItem.vue";
+defineProps<{
+ readonly?: boolean;
+}>();
+
type UserSelectOption = SelectOption & {
user: ComposedUser;
value: string;
diff --git a/frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/Subscribers.vue b/frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/Subscribers.vue
index 9e51b7acb9..a45fc7a631 100644
--- a/frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/Subscribers.vue
+++ b/frontend/src/components/IssueV1/components/IssueCommentSection/Subscribers/Subscribers.vue
@@ -1,11 +1,39 @@
<template>
<div class="flex items-center gap-x-2">
- <SubscribeButton />
- <SubscriberList />
+ <SubscribeButton v-if="allowSubscribe" />
+ <SubscriberList :readonly="!allowSubscribe" />
</div>
</template>
<script setup lang="ts">
+import { computed } from "vue";
+import { useIssueContext } from "@/components/IssueV1/logic";
+import { useCurrentUserV1 } from "@/store";
+import { extractUserResourceName, hasProjectPermissionV2 } from "@/utils";
import SubscribeButton from "./SubscribeButton.vue";
import SubscriberList from "./SubscriberList.vue";
+
+const { issue } = useIssueContext();
+const currentUser = useCurrentUserV1();
+
+const allowSubscribe = computed(() => {
+ if (
+ extractUserResourceName(issue.value.creator) === currentUser.value.email
+ ) {
+ // Allowed if current user is the creator.
+ return true;
+ }
+
+ if (
+ hasProjectPermissionV2(
+ issue.value.projectEntity,
+ currentUser.value,
+ "bb.issues.update"
+ )
+ ) {
+ return true;
+ }
+
+ return false;
+});
</script>
diff --git a/frontend/src/components/IssueV1/logic/subscriber.ts b/frontend/src/components/IssueV1/logic/subscriber.ts
index 8c02313d0b..d93ca000d3 100644
--- a/frontend/src/components/IssueV1/logic/subscriber.ts
+++ b/frontend/src/components/IssueV1/logic/subscriber.ts
@@ -42,14 +42,3 @@ export const toggleSubscribeIssue = async (
}
return await updateIssueSubscribers(issue, subscribers);
};
-
-export const doSubscribeIssue = async (issue: Issue, user: ComposedUser) => {
- const subscribers = [...issue.subscribers];
- const userTag = `users/${user.email}`;
- const isSubscribed = subscribers.includes(userTag);
- if (isSubscribed) {
- return;
- }
- subscribers.push(userTag);
- return await updateIssueSubscribers(issue, subscribers, true);
-};