Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WCM-462: toggle single columns on and off #890

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/docs/changelog/WCM-462.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WCM-462: toggle single columns on and off
18 changes: 14 additions & 4 deletions core/src/zeit/connector/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class PublishInfo:
Boolean,
server_default='false',
nullable=False,
info={'namespace': 'workflow', 'name': 'published'},
info={'namespace': 'workflow', 'name': 'published', 'toggled': True},
)


Expand Down Expand Up @@ -188,8 +188,18 @@ def column_by_name(cls, name, namespace):
return column

@classmethod
def _columns_with_name(cls):
return [x for x in sqlalchemy.orm.class_mapper(cls).columns if x.info.get('namespace')]
def is_column_enabled(cls, column, mode):
namespace = column.info.get('namespace')
name = column.info.get('name')
if column.info.get('toggled'):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oder wir machen es gleich per Default für alle Felder :D

return FEATURE_TOGGLES.find(f'{namespace}_{name}_{mode}')
return namespace is not None

@classmethod
def _columns_with_name(cls, mode='read'):
return [
c for c in sqlalchemy.orm.class_mapper(cls).columns if cls.is_column_enabled(c, mode)
]

@property
def binary_body(self):
Expand Down Expand Up @@ -253,7 +263,7 @@ def from_webdav(self, props):
if FEATURE_TOGGLES.find('write_metadata_columns') or FEATURE_TOGGLES.find(
'write_metadata_columns_strict'
):
for column in self._columns_with_name():
for column in self._columns_with_name(mode='write'):
namespace, name = column.info['namespace'], column.info['name']
value = props.get((name, self.NS + namespace), self)

Expand Down
6 changes: 3 additions & 3 deletions core/src/zeit/connector/tests/test_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ class MockTypeConversionTest(zeit.connector.testing.MockTest):
def test_converts_sql_properties_on_read(self):
params = [
[
('workflow', 'published'),
True,
'yes',
('document', 'year'),
2024,
'2024',
],
[
('document', 'date_created'),
Expand Down
23 changes: 23 additions & 0 deletions core/src/zeit/connector/tests/test_postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,26 @@ def test_search_looks_in_columns_or_unsorted_depending_on_toggle(self):
result = self.connector.search([var], var == 'Wissen')
unique_id, uuid = next(result)
self.assertEqual(res.id, unique_id)

def test_single_properties_can_be_toggled(self):
FEATURE_TOGGLES.set('write_metadata_columns')
FEATURE_TOGGLES.set('read_metadata_columns')
res = self.add_resource('foo', properties={('published', f'{NS}workflow'): 'yes'})
content = self.connector._get_content(res.id)
self.assertEqual({'workflow': {'published': 'yes'}}, content.unsorted)
# we have not written into the column yet
self.assertFalse(content.published)
# now you are allowed to write
FEATURE_TOGGLES.set('workflow_published_write')
content = self.connector._get_content(res.id)
self.connector[res.id] = res
self.assertTrue(content.published)
# check if we can read our value back
content.published = False
props = content.to_webdav()
# now still read from unsorted
self.assertEqual(props[('published', f'{NS}workflow')], 'yes')
# and now read from column
FEATURE_TOGGLES.set('workflow_published_read')
props = content.to_webdav()
self.assertEqual(props[('published', f'{NS}workflow')], False)