Skip to content
Snippets Groups Projects
Commit c31eb0c07ac6 authored by Sandrine Ribeau's avatar Sandrine Ribeau
Browse files

[schema] add workflow on BlogEntry so that anonymous could only see published blog entries

parent 38eda314be39
No related branches found
No related tags found
No related merge requests found
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()
# 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',))
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='**')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment