(core) Showing censored values as a grey cell

Test Plan: Block read access to column A based on the condition rec.B == 1. Then setting B = 1 in a row makes the cell under A grey.

Reviewers: dsagal

Reviewed By: dsagal

Subscribers: paulfitz, dsagal

Differential Revision: https://phab.getgrist.com/D2828
This commit is contained in:
Alex Hall
2021-06-03 17:01:31 +02:00
parent 2feef7f780
commit 2f3a0e0c7f
5 changed files with 67 additions and 3 deletions

View File

@@ -109,6 +109,19 @@ export class SkipValue {
}
}
/**
* A placeholder for a value hidden by access control rules.
* Depending on the types of the columns involved, copying
* a censored value and pasting elsewhere will either use
* CensoredValue.__repr__ (python) or CensoredValue.toString (typescript)
* so they should match
*/
export class CensoredValue {
public toString() {
return 'CENSORED';
}
}
/**
* Produces a Grist-encoded version of the value, e.g. turning a Date into ['d', timestamp].
* Returns ['U', repr(value)] if it fails to encode otherwise.
@@ -135,6 +148,8 @@ export function encodeObject(value: unknown): CellValue {
// TODO Depending on how it's used, may want to return ['d', timestamp] for UTC midnight.
return ['D', timestamp, 'UTC'];
}
} else if (value instanceof CensoredValue) {
return ['C'];
} else if (value instanceof RaisedException) {
return ['E', value.name, value.message, value.details];
} else if (Array.isArray(value)) {
@@ -172,6 +187,7 @@ export function decodeObject(value: CellValue): unknown {
case 'P': return new PendingValue();
case 'R': return new Reference(String(args[0]), args[1]);
case 'S': return new SkipValue();
case 'C': return new CensoredValue();
case 'U': return new UnknownValue(args[0]);
}
} catch (e) {