Skip notifications update for readonly role

Signed-off-by: Anton Alexeyev <alexeyev.anton@gmail.com>
This commit is contained in:
Anton Alexeyev 2025-05-22 14:57:18 +07:00
parent 57122b2f75
commit 6a910f26a6
2 changed files with 17 additions and 5 deletions

View File

@ -15,14 +15,15 @@
import activity from '@hcengineering/activity'
import {
type Account,
type Client,
SortingOrder,
getCurrentAccount,
toIdMap,
AccountRole,
type Class,
type Client,
type Doc,
getCurrentAccount,
type IdMap,
type Ref,
SortingOrder,
toIdMap,
type TxOperations,
type WithLookup
} from '@hcengineering/core'
@ -84,6 +85,7 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
}
)
private readOnlyAccount: boolean = false
private readonly contextsQuery = createQuery(true)
private readonly otherInboxNotificationsQuery = createQuery(true)
private readonly activityInboxNotificationsQuery = createQuery(true)
@ -95,6 +97,7 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
}
private async init (client: Client, account: Account): Promise<void> {
this.readOnlyAccount = account.role === AccountRole.ReadOnlyGuest
this.contextsQuery.query(
notification.class.DocNotifyContext,
{
@ -152,6 +155,8 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
}
async readDoc (_id: Ref<Doc>): Promise<void> {
if (this.readOnlyAccount) return
const docNotifyContext = this._contextByDoc.get(_id)
if (docNotifyContext === undefined) {
@ -174,6 +179,7 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
}
async forceReadDoc (_id: Ref<Doc>, _class: Ref<Class<Doc>>): Promise<void> {
if (this.readOnlyAccount) return
const context = this._contextByDoc.get(_id)
if (context !== undefined) {
@ -217,6 +223,7 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
}
async readNotifications (client: TxOperations, ids: Array<Ref<InboxNotification>>): Promise<void> {
if (this.readOnlyAccount) return
const notificationsToRead = (get(this.inboxNotifications) ?? []).filter(
({ _id, isViewed }) => ids.includes(_id) && !isViewed
)
@ -227,6 +234,7 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
}
async unreadNotifications (client: TxOperations, ids: Array<Ref<InboxNotification>>): Promise<void> {
if (this.readOnlyAccount) return
const notificationsToUnread = (get(this.inboxNotifications) ?? []).filter(({ _id }) => ids.includes(_id))
for (const notification of notificationsToUnread) {
@ -235,6 +243,7 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
}
async archiveNotifications (client: TxOperations, ids: Array<Ref<InboxNotification>>): Promise<void> {
if (this.readOnlyAccount) return
const inboxNotifications = (get(this.inboxNotifications) ?? []).filter(({ _id }) => ids.includes(_id))
for (const notification of inboxNotifications) {
await client.update(notification, { archived: true, isViewed: true })
@ -242,6 +251,7 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
}
async archiveAllNotifications (): Promise<void> {
if (this.readOnlyAccount) return
const ops = getClient().apply(undefined, 'archiveAllNotifications', true)
try {
@ -270,6 +280,7 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
}
async readAllNotifications (): Promise<void> {
if (this.readOnlyAccount) return
const ops = getClient().apply(undefined, 'readAllNotifications', true)
try {
@ -295,6 +306,7 @@ export class InboxNotificationsClientImpl implements InboxNotificationsClient {
}
async unreadAllNotifications (): Promise<void> {
if (this.readOnlyAccount) return
const ops = getClient().apply(undefined, 'unreadAllNotifications', true)
try {

View File

@ -600,7 +600,7 @@ export async function selectWorkspace (
role: AccountRole.DocGuest
}
}
if (accountUuid === systemAccountUuid || extra?.admin === 'true') {
return {
account: accountUuid,