# HG changeset patch # User Sandrine Ribeau <sandrine.ribeau@logilab.fr> # Date 1256051756 25200 # Tue Oct 20 08:15:56 2009 -0700 # Node ID c31eb0c07ac6abf71a34f5b592ce99dfda8d6ab8 # Parent 38eda314be3929a9f6bed4cd5ff0a36b9e3ee634 [schema] add workflow on BlogEntry so that anonymous could only see published blog entries diff --git a/migration/1.7.0_Any.py b/migration/1.7.0_Any.py new file mode 100644 --- /dev/null +++ b/migration/1.7.0_Any.py @@ -0,0 +1,22 @@ +add_relation_definition('BlogEntry', 'in_state', 'State') +add_relation_definition('TrInfo', 'wf_info_for', 'BlogEntry') +add_relation_definition('BlogEntry', 'custom_workflow', 'Workflow') + + +# add BlogEntry workflow +bwf = add_workflow(_('default BlogEntry workflow'), 'BlogEntry') + +draft = bwf.add_state(_('draft'), initial=True) +published = bwf.add_state(_('published')) + +publish = bwf.add_transition(_('publish'), draft, published, + ('managers',)) +checkpoint() + +# set state to published for already existing blog entries +blogentries = rql('Any B WHERE B is BlogEntry') + +for blogentry in blogentries: + session.unsafe_execute('SET B in_state S WHERE S name "published", B eid %(b)s', {'b': blogentry[0]}) + +checkpoint() diff --git a/migration/postcreate.py b/migration/postcreate.py --- a/migration/postcreate.py +++ b/migration/postcreate.py @@ -1,2 +1,11 @@ # postcreate script. You could setup a workflow here for example +# BlogEntry workflow +bwf = add_workflow(_('default BlogEntry workflow'), 'BlogEntry') + +draft = bwf.add_state(_('draft'), initial=True) +published = bwf.add_state(_('published')) + +publish = bwf.add_transition(_('publish'), draft, published, + ('managers',)) + diff --git a/schema.py b/schema.py --- a/schema.py +++ b/schema.py @@ -1,4 +1,5 @@ from yams.buildobjs import EntityType, String, SubjectRelation +from cubicweb.schema import WorkflowableEntityType try: from yams.buildobjs import RichString except ImportError: @@ -11,7 +12,13 @@ rss_url = String(maxsize=128, description=_('blog\'s rss url (useful for when using external site such as feedburner)')) -class BlogEntry(EntityType): +class BlogEntry(WorkflowableEntityType): + permissions = { + 'read': ('managers', 'users', ERQLExpression('X in_state S, S name "published"'),), + 'add': ('managers', 'users'), + 'update': ('managers', 'owners'), + 'delete': ('managers', 'owners') + } title = String(required=True, fulltextindexed=True, maxsize=256) content = RichString(required=True, fulltextindexed=True) entry_of = SubjectRelation('Blog', cardinality='**')