(core) Mark column changing actions as indirect when adding data to empty column

Summary:
Fixing https://gristlabs.getgrist.com/doc/check-ins/p/12#a1.s19.r1045.c19 :

> Problem: user creates fresh new empty column. Users with access to write to that column, but not modify schema, will not in fact be able to write into it (since on first data entry column type needs to change). Experience is confusing.

Refactored `enter_indirection` and `leave_indirection` to a single context manager method for use with `with` instead of `try/finally`.

Used the new method in `_ensure_column_accepts_data` around column changing actions converting empty column to data column.

Test Plan:
Updated a Python test, reflecting that the correct actions are now marked as direct=False.

Tested manually that I can now add data to a blank column without schema access, while I wasn't able to before, and I still can't make other schema changes.

Reviewers: paulfitz

Reviewed By: paulfitz

Differential Revision: https://phab.getgrist.com/D3446
This commit is contained in:
Alex Hall
2022-05-23 19:36:21 +02:00
parent 3d3a5e334a
commit 8ee23f5344
3 changed files with 35 additions and 33 deletions

View File

@@ -324,12 +324,10 @@ class Table(object):
if summary_table._summary_simple:
@usertypes.formulaType(usertypes.Reference(summary_table.table_id))
def _updateSummary(rec, table): # pylint: disable=unused-argument
try:
# summary table output should be treated as we treat formula columns, for acl purposes
self._engine.user_actions.enter_indirection()
# summary table output should be treated as we treat formula columns, for acl purposes
with self._engine.user_actions.indirect_actions():
return summary_table.lookupOrAddDerived(**{c: getattr(rec, c) for c in groupby_cols})
finally:
self._engine.user_actions.leave_indirection()
else:
@usertypes.formulaType(usertypes.ReferenceList(summary_table.table_id))
def _updateSummary(rec, table): # pylint: disable=unused-argument
@@ -368,14 +366,11 @@ class Table(object):
new_row_ids.append(None)
if new_row_ids and not self._engine.is_triggered_by_table_action(summary_table.table_id):
try:
# summary table output should be treated as we treat formula columns, for acl purposes
self._engine.user_actions.enter_indirection()
# summary table output should be treated as we treat formula columns, for acl purposes
with self._engine.user_actions.indirect_actions():
result += self._engine.user_actions.BulkAddRecord(
summary_table.table_id, new_row_ids, values_to_add
)
finally:
self._engine.user_actions.leave_indirection()
return result