mattermost-mobile-upstream/app/components/post_draft/quick_actions/index.ts
Nate Schlossberg 16c5849eb6
Some checks failed
ci / lint-typecheck (push) Has been cancelled
ci / detox-lint-typecheck (push) Has been cancelled
ci / test (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
MM-70693: Hide burn-on-read quick action when ABAC policy denies it (#10239)
* Remove BoR quick action on ABAC permission denial

* Update Render Permission to support handling for ABAC servers that do not yet support a particular permision action - they will be treated as "unenforced"

* detox - allow skipping of tests on permission policy actions that are not supported by the test server yet
2026-10-16 15:13:04 -07:00

66 lines
2.9 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {withDatabase, withObservables} from '@nozbe/watermelondb/react';
import React from 'react';
import {combineLatest} from 'rxjs';
import {distinctUntilChanged, map} from 'rxjs/operators';
import {observeIsAgentsEnabled} from '@agents/queries/agents';
import {Preferences} from '@constants';
import {RenderPermissionAction} from '@constants/access_control';
import {withServerUrl} from '@context/server';
import {observeIsBoREnabled, observeIsPostPriorityEnabled} from '@queries/servers/post';
import {queryPreferencesByCategoryAndName} from '@queries/servers/preference';
import {observeRenderPermission} from '@queries/servers/render_permissions';
import {observeCanUploadFiles} from '@queries/servers/security';
import {observeConfigBooleanValue, observeMaxFileCount} from '@queries/servers/system';
import QuickActions from './quick_actions';
import type {WithDatabaseArgs} from '@typings/database/database';
type EnhancedProps = WithDatabaseArgs & {
channelId: string;
serverUrl: string;
}
const enhanced = withObservables(['channelId'], ({database, channelId, serverUrl}: EnhancedProps) => {
// Denied by policy looks the same as disabled by config: dimmed and inert.
const canUploadFiles = combineLatest([
observeCanUploadFiles(database),
observeRenderPermission(database, serverUrl, channelId, RenderPermissionAction.UploadFileAttachment, true),
]).pipe(
map(([allowedByConfig, allowedByPolicy]) => allowedByConfig && allowedByPolicy),
distinctUntilChanged(),
);
// Denied by policy hides the control rather than dimming it. Unlike upload, it is withheld until
// the server answers: showing it first would flicker.
const isBoREnabled = combineLatest([
observeIsBoREnabled(database),
observeRenderPermission(database, serverUrl, channelId, RenderPermissionAction.CreateBurnOnReadPost, true, false),
]).pipe(
map(([allowedByConfig, allowedByPolicy]) => allowedByConfig && allowedByPolicy),
distinctUntilChanged(),
);
const maxFileCount = observeMaxFileCount(database);
const allowDownloadLogs = observeConfigBooleanValue(database, 'AllowDownloadLogs', true);
const attachLogsEnabled = queryPreferencesByCategoryAndName(database, Preferences.CATEGORIES.ADVANCED_SETTINGS, Preferences.ATTACH_APP_LOGS).
observeWithColumns(['value']).
pipe(map((prefs) => prefs[0]?.value === 'true'));
return {
canUploadFiles,
isAgentsEnabled: observeIsAgentsEnabled(serverUrl),
isPostPriorityEnabled: observeIsPostPriorityEnabled(database),
isBoREnabled,
maxFileCount,
showAttachLogs: combineLatest([allowDownloadLogs, attachLogsEnabled]).pipe(
map(([allowed, enabled]) => allowed && enabled),
),
};
});
export default React.memo(withDatabase(withServerUrl(enhanced(QuickActions))));