mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Comments
Summary: First iteration for comments system for Grist. - Comments are stored in a generic metatable `_grist_Cells` - Each comment is connected to a particular cell (hence the generic name of the table) - Access level works naturally for records stored in this table -- User can add/read comments for cells he can see -- User can't update/remove comments that he doesn't own, but he can delete them by removing cells (rows/columns) -- Anonymous users can't see comments at all. - Each comment can have replies (but replies can't have more replies) Comments are hidden by default, they can be enabled by COMMENTS=true env variable. Some things for follow-up - Avatars, currently the user's profile image is not shown or retrieved from the server - Virtual rendering for comments list in creator panel. Currently, there is a limit of 200 comments. Test Plan: New and existing tests Reviewers: georgegevoian, paulfitz Reviewed By: georgegevoian Subscribers: paulfitz Differential Revision: https://phab.getgrist.com/D3509
This commit is contained in:
@@ -147,6 +147,21 @@ class MetaTableExtras(object):
|
||||
table.docmodel.setAutoRemove(rec, not rec.colRef)
|
||||
|
||||
|
||||
class _grist_Cells(object):
|
||||
def setAutoRemove(rec, table):
|
||||
if rec.type == 1: # Cell info of type 1 == Comments
|
||||
# Remove if discussion is removed.
|
||||
noParent = not rec.root and not rec.parentId
|
||||
if rec.tableRef and rec.rowId:
|
||||
tableRef = table.docmodel.get_table(rec.tableRef.tableId)
|
||||
row = tableRef.lookupOne(id=rec.rowId)
|
||||
else:
|
||||
row = False
|
||||
# Remove if row is removed, column is removed, table is removed or all comments are removed.
|
||||
no_cell = not rec.colRef or not rec.tableRef or not row
|
||||
table.docmodel.setAutoRemove(rec, noParent or no_cell)
|
||||
|
||||
|
||||
def enhance_model(model_class):
|
||||
"""
|
||||
Given a metadata model class, add all members (formula methods) to it from the same-named inner
|
||||
@@ -198,6 +213,7 @@ class DocModel(object):
|
||||
self.aclResources = self._prep_table("_grist_ACLResources")
|
||||
self.aclRules = self._prep_table("_grist_ACLRules")
|
||||
self.filters = self._prep_table("_grist_Filters")
|
||||
self.cells = self._prep_table("_grist_Cells")
|
||||
|
||||
def _prep_table(self, name):
|
||||
"""
|
||||
|
||||
@@ -32,7 +32,7 @@ log = logger.Logger(__name__, logger.INFO)
|
||||
# After each migration you probably should run these commands:
|
||||
# ./test/upgradeDocument public_samples/*.grist
|
||||
# UPDATE_REGRESSION_DATA=1 GREP_TESTS=DocRegressionTests ./test/testrun.sh server
|
||||
# ./test/upgradeDocument test/fixtures/docs/Hello.grist
|
||||
# ./test/upgradeDocument core/test/fixtures/docs/Hello.grist
|
||||
|
||||
all_migrations = {}
|
||||
|
||||
@@ -1092,3 +1092,23 @@ def migration32(tdset):
|
||||
return tdset.apply_doc_actions([
|
||||
add_column('_grist_Views_section', 'rules', 'RefList:_grist_Tables_column'),
|
||||
])
|
||||
|
||||
@migration(schema_version=33)
|
||||
def migration33(tdset):
|
||||
"""
|
||||
Add _grist_Cells table
|
||||
"""
|
||||
doc_actions = [
|
||||
actions.AddTable('_grist_Cells', [
|
||||
schema.make_column("tableRef", "Ref:_grist_Tables"),
|
||||
schema.make_column("colRef", "Ref:_grist_Tables_column"),
|
||||
schema.make_column("rowId", "Int"),
|
||||
schema.make_column("root", "Bool"),
|
||||
schema.make_column("parentId", "Ref:_grist_Cells"),
|
||||
schema.make_column("type", "Int"),
|
||||
schema.make_column("content", "Text"),
|
||||
schema.make_column("userRef", "Text"),
|
||||
]),
|
||||
]
|
||||
|
||||
return tdset.apply_doc_actions(doc_actions)
|
||||
|
||||
@@ -15,7 +15,7 @@ import six
|
||||
|
||||
import actions
|
||||
|
||||
SCHEMA_VERSION = 32
|
||||
SCHEMA_VERSION = 33
|
||||
|
||||
def make_column(col_id, col_type, formula='', isFormula=False):
|
||||
return {
|
||||
@@ -317,6 +317,21 @@ def schema_create_actions():
|
||||
# Ex2: { excluded: ['apple', 'orange'] }
|
||||
make_column("filter", "Text")
|
||||
]),
|
||||
|
||||
# Additional metadata for cells
|
||||
actions.AddTable('_grist_Cells', [
|
||||
make_column("tableRef", "Ref:_grist_Tables"),
|
||||
make_column("colRef", "Ref:_grist_Tables_column"),
|
||||
make_column("rowId", "Int"),
|
||||
# Cell metadata is stored as in hierarchical structure.
|
||||
make_column("root", "Bool"),
|
||||
make_column("parentId", "Ref:_grist_Cells"),
|
||||
# Type of information, currently we have only one type Comments (with value 1).
|
||||
make_column("type", "Int"),
|
||||
# JSON representation of the metadata.
|
||||
make_column("content", "Text"),
|
||||
make_column("userRef", "Text"),
|
||||
]),
|
||||
]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user