mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-06 10:50:13 +00:00
* MM-68219 - Add redacted files placeholder and related functionality * add feature flag control and e2e tests * adjust placeholder design, polish code, fix permalink preview issue * polish code and add missing test * use import path with right path * gate post refetch behind the feature flag, refetch the open thread and avoid observeCount * restore filesInfo for the permalink files prop added upstream * fix stale redaction on background servers, consume the flag on every fetch path and share the viewport emitter * replace the in-memory redaction flag with a persisted per-post epoch so ABAC file decisions survive restarts and stale posts stay hidden * raise the redaction epoch on every resync, capture the epoch counter, only invalidate channels on role changes, and store the newer epoch when a re-verified post is otherwise unchanged * store superseded responses unverified instead of dropping them, keep the since-fetch when re-verifying, verify permalink embeds against the linked channel, and capture the websocket epoch on arrival * nvalidate file decisions when a user attribute field changes or all its values are cleared * batch channel invalidations, close file viewers only when affected, reset the epoch on unstamped redaction changes, and only re-verify the newest page's attachment posts * re-check older channel posts a page at a time instead of one request per post * skip the unstamped epoch lookup for posts with no files, redacted count or permalink * keep the attribute-view retry after later invalidations, retry linked posts unless refused for the current epoch, and stop older payloads from rolling back edits via the redaction check * MM-70905 - disable and grey out the attachment button when an ABAC pe… (#10195) * MM-70905 - disable and grey out the attachment button when an ABAC permission policy denies uploads in the channel * only back off render permission fetches when the server request fails, and log other errors without retrying * remove the disableServer helper and have removeServer do both steps * split defaultAllowed into allowWhenUnenforced and allowWhenNotEvaluated, and treat render permissions as unenforced on servers without the decisions API * MM-69627: Add playbook task requirements support on mobile (#10035) * MM-69627: Add playbook task requirements support on mobile Allow filling required task fields when checking off checklist items during a run, gated by the same Playbooks beta setting used on web. Co-authored-by: Cursor <cursoragent@cursor.com> * MM-69627: Address PR review feedback for task requirements Propagate settings write failures, harden fill-requirements save/title handling, and add missing unit coverage. Co-authored-by: Cursor <cursoragent@cursor.com> * MM-69627: Fix TypeScript errors in new unit tests Co-authored-by: Cursor <cursoragent@cursor.com> * MM-69627: Use defineMessages for fill requirements titles Keep i18n extraction able to find the header titles after moving them to the route. Co-authored-by: Cursor <cursoragent@cursor.com> * MM-69627: Address review feedback for task requirements Update checklist items locally when saving requirement values instead of refetching the run, add missing query/navigation tests, and apply small callback/reduce cleanups from review. Co-authored-by: Cursor <cursoragent@cursor.com> * MM-69627: Fix task requirements review follow-ups Propagate local checklist write failures, clear a stale task-requirements flag when playbooks is unsupported, and cap fill values at the desktop/ server max length. Co-authored-by: Cursor <cursoragent@cursor.com> * MM-69627: Move requirement field into its own component Keep one component per file on the fill-requirements screen. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com> * MM-69122: Add file element support to interactive dialogs (#9898) * Implement Interactive Dialog - file upload * update demo plugin version for e2etests * fix and add e2etests * review fixes * Fix version bump checkout when a tag shares the branch name (#10229) * Fix Android crashes caused by animated custom emoji (#10030) * Route GIF decoding through Glide - Keep APNG4Android for APNG, animated WebP, and animated AVIF support. - Prepend Glide's GIF decoders to avoid APNG4Android's native GIF overflow. * Clear Expo image resources with Glide targets - Detach drawables when Glide clears their custom target. - Prevent recycled GIF frame resources from remaining attached to Expo image views. * Preserve foreground image during GIF target recycling --------- Co-authored-by: Asaad Mahmood <asaadmahmood@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Scott Bishel <scott.bishel@mattermost.com> Co-authored-by: Nuno Simões <nuno.simoes@mattermost.com> Co-authored-by: MangelSpec <74370284+MangelSpec@users.noreply.github.com> * detox - fix clobbering of feature flags that cause failures in other suites. Also small fix of a incorrectly set test-id --------- Co-authored-by: Asaad Mahmood <asaadmahmood@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Scott Bishel <scott.bishel@mattermost.com> Co-authored-by: Nuno Simões <nuno.simoes@mattermost.com> Co-authored-by: MangelSpec <74370284+MangelSpec@users.noreply.github.com> Co-authored-by: Nate Schlossberg <nate.schlossberg@mattermost.com>
186 lines
7.6 KiB
TypeScript
186 lines
7.6 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {BehaviorSubject, type Observable} from 'rxjs';
|
|
import {distinctUntilChanged, map} from 'rxjs/operators';
|
|
|
|
export type RenderPermissionsEntry = {
|
|
|
|
// Redaction epoch counter captured when the request was dispatched. Once the channel's required
|
|
// epoch moves past it the entry is due for revalidation, so every ABAC invalidation reaches it.
|
|
epoch: number;
|
|
decisions: Record<string, RenderPermissionDecision>;
|
|
|
|
// Past its time to live, or taken on a network the device has since left. Still rendered until the
|
|
// revalidation lands, so a control does not flip to its default and back on every refresh.
|
|
expired?: boolean;
|
|
};
|
|
|
|
// Websocket delivery is not guaranteed, so no entry is trusted indefinitely. Revalidation is also
|
|
// triggered by any redaction epoch raise (see @actions/websocket/access_control), a network change
|
|
// (expireServer from WebsocketManager), the server refusing an upload the entry allowed, and the entry
|
|
// is dropped on logout or server removal.
|
|
export const RENDER_PERMISSIONS_TTL_MS = 5 * 60 * 1000;
|
|
|
|
// First delay after an outcome that says nothing about the policy: a failed request, or a fail-closed
|
|
// deny returned because evaluation itself failed. Doubles on each consecutive one, up to the TTL.
|
|
export const RENDER_PERMISSIONS_RETRY_MS = 15 * 1000;
|
|
|
|
// Identifies one request, so an answer can be matched to the claim it was sent under.
|
|
type FetchClaim = object;
|
|
|
|
class RenderPermissionsStoreSingleton {
|
|
private entries: {[serverUrl: string]: BehaviorSubject<Map<string, RenderPermissionsEntry>>} = {};
|
|
private expiries: {[serverUrl: string]: Map<string, ReturnType<typeof setTimeout>>} = {};
|
|
private claims: {[serverUrl: string]: Map<string, FetchClaim>} = {};
|
|
private transientFailures: {[serverUrl: string]: Map<string, number>} = {};
|
|
|
|
private getSubject = (serverUrl: string) => {
|
|
if (!this.entries[serverUrl]) {
|
|
this.entries[serverUrl] = new BehaviorSubject(new Map());
|
|
}
|
|
return this.entries[serverUrl];
|
|
};
|
|
|
|
private clearExpiry = (serverUrl: string, channelId: string) => {
|
|
const timeout = this.expiries[serverUrl]?.get(channelId);
|
|
if (timeout) {
|
|
clearTimeout(timeout);
|
|
this.expiries[serverUrl].delete(channelId);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Marks a channel's entry due for revalidation, keeping its decisions on screen until it lands.
|
|
* Used when the server refuses an action the entry allowed.
|
|
*/
|
|
expireEntry = (serverUrl: string, channelId: string) => {
|
|
this.clearExpiry(serverUrl, channelId);
|
|
|
|
const subject = this.entries[serverUrl];
|
|
const entry = subject?.value.get(channelId);
|
|
if (!entry || entry.expired) {
|
|
return;
|
|
}
|
|
const next = new Map(subject.value);
|
|
next.set(channelId, {...entry, expired: true});
|
|
subject.next(next);
|
|
};
|
|
|
|
observeEntry = (serverUrl: string, channelId: string): Observable<RenderPermissionsEntry | undefined> => {
|
|
return this.getSubject(serverUrl).pipe(
|
|
map((entries) => entries.get(channelId)),
|
|
distinctUntilChanged(),
|
|
);
|
|
};
|
|
|
|
getEntry = (serverUrl: string, channelId: string) => {
|
|
return this.entries[serverUrl]?.value.get(channelId);
|
|
};
|
|
|
|
setEntry = (serverUrl: string, channelId: string, entry: RenderPermissionsEntry, ttlMs: number) => {
|
|
this.clearExpiry(serverUrl, channelId);
|
|
|
|
const subject = this.getSubject(serverUrl);
|
|
const next = new Map(subject.value);
|
|
next.set(channelId, entry);
|
|
subject.next(next);
|
|
|
|
if (!this.expiries[serverUrl]) {
|
|
this.expiries[serverUrl] = new Map();
|
|
}
|
|
this.expiries[serverUrl].set(channelId, setTimeout(() => this.expireEntry(serverUrl, channelId), ttlMs));
|
|
};
|
|
|
|
/**
|
|
* Claims the request slot for a channel. Undefined when a request for it is already in flight, so
|
|
* concurrent composers (a channel and a thread of it) or quick remounts share one request.
|
|
*/
|
|
startFetch = (serverUrl: string, channelId: string): FetchClaim | undefined => {
|
|
if (!this.claims[serverUrl]) {
|
|
this.claims[serverUrl] = new Map();
|
|
}
|
|
if (this.claims[serverUrl].has(channelId)) {
|
|
return undefined;
|
|
}
|
|
const claim = {};
|
|
this.claims[serverUrl].set(channelId, claim);
|
|
return claim;
|
|
};
|
|
|
|
/**
|
|
* Releases the slot and stores the outcome, unless the claim was revoked while the request was in
|
|
* flight: by a network change (the answer was evaluated for the old network) or by the server being
|
|
* removed (it belongs to a session that no longer exists, even if the user logged straight back in).
|
|
* The slot is released before storing, so an answer that is already stale can be refetched at once.
|
|
*/
|
|
finishFetch = (serverUrl: string, channelId: string, claim: FetchClaim, entry?: RenderPermissionsEntry, ttlMs = RENDER_PERMISSIONS_TTL_MS) => {
|
|
if (this.claims[serverUrl]?.get(channelId) !== claim) {
|
|
return;
|
|
}
|
|
this.claims[serverUrl].delete(channelId);
|
|
if (entry) {
|
|
this.setEntry(serverUrl, channelId, entry, ttlMs);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Counts a consecutive outcome that said nothing about the policy and returns how long to wait
|
|
* before asking again.
|
|
*/
|
|
nextRetryDelay = (serverUrl: string, channelId: string) => {
|
|
if (!this.transientFailures[serverUrl]) {
|
|
this.transientFailures[serverUrl] = new Map();
|
|
}
|
|
const failures = (this.transientFailures[serverUrl].get(channelId) ?? 0) + 1;
|
|
this.transientFailures[serverUrl].set(channelId, failures);
|
|
return Math.min(RENDER_PERMISSIONS_RETRY_MS * (2 ** (failures - 1)), RENDER_PERMISSIONS_TTL_MS);
|
|
};
|
|
|
|
resetRetryDelay = (serverUrl: string, channelId: string) => {
|
|
this.transientFailures[serverUrl]?.delete(channelId);
|
|
};
|
|
|
|
/**
|
|
* Network session attributes (SSID, VPN, interface, IP) are part of the ABAC subject and follow the
|
|
* device's network, so a network change can flip any decision on a server that collects them.
|
|
* Requests in flight were evaluated for the previous network, so their claims are revoked too.
|
|
*/
|
|
expireServer = (serverUrl: string) => {
|
|
for (const timeout of this.expiries[serverUrl]?.values() ?? []) {
|
|
clearTimeout(timeout);
|
|
}
|
|
this.expiries[serverUrl]?.clear();
|
|
this.claims[serverUrl]?.clear();
|
|
|
|
const subject = this.entries[serverUrl];
|
|
if (!subject) {
|
|
return;
|
|
}
|
|
|
|
// One emission for the whole server rather than one per channel.
|
|
const next = new Map<string, RenderPermissionsEntry>();
|
|
for (const [channelId, entry] of subject.value) {
|
|
next.set(channelId, entry.expired ? entry : {...entry, expired: true});
|
|
}
|
|
subject.next(next);
|
|
};
|
|
|
|
removeServer = (serverUrl: string) => {
|
|
for (const timeout of this.expiries[serverUrl]?.values() ?? []) {
|
|
clearTimeout(timeout);
|
|
}
|
|
delete this.expiries[serverUrl];
|
|
delete this.claims[serverUrl];
|
|
delete this.transientFailures[serverUrl];
|
|
|
|
// Emptied before it is dropped, so a subscriber still attached stops trusting its entry.
|
|
const subject = this.entries[serverUrl];
|
|
delete this.entries[serverUrl];
|
|
subject?.next(new Map());
|
|
};
|
|
}
|
|
|
|
const RenderPermissionsStore = new RenderPermissionsStoreSingleton();
|
|
export default RenderPermissionsStore;
|