Skip to content

Commit

Permalink
Merge 718af68 into 6366873
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Forsythe-Cheasley committed Jun 24, 2014
2 parents 6366873 + 718af68 commit 5971c13
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/ploneintranet/simplesharing/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from plone.directives import form
from z3c.form import button
from z3c.form import field
from z3c.form.interfaces import NOT_CHANGED
from zope.interface import alsoProvides
from zope.interface import provider
from zope import schema
Expand All @@ -24,7 +25,7 @@ class ISimpleSharing(form.Schema):
title=u"Visibility",
description=u"Who should see this document?",
source=WorkflowStatesSource(),
required=False
required=True,
)

share_with = schema.List(
Expand Down Expand Up @@ -80,7 +81,7 @@ def visibility(self):

@visibility.setter
def visibility(self, value):
if not value:
if value == NOT_CHANGED:
return
api.content.transition(obj=self.context, transition=value)

Expand Down
9 changes: 2 additions & 7 deletions src/ploneintranet/simplesharing/tests/test_simplesharing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from z3c.form.interfaces import IFormLayer
from z3c.form.interfaces import NOT_CHANGED
from zope.annotation import IAttributeAnnotatable
from zope.component import provideAdapter
from zope.interface import alsoProvides, Interface
Expand Down Expand Up @@ -45,7 +46,7 @@ def make_request(self, visibility, share_with):
alsoProvides(request, IAttributeAnnotatable)
return request

def simple_share(self, users, visibility='private', obj=None):
def simple_share(self, users, visibility=str(NOT_CHANGED), obj=None):
if obj is None:
obj = self.doc
request = self.make_request(
Expand All @@ -64,12 +65,6 @@ def simple_share(self, users, visibility='private', obj=None):
def test_visibility(self):
self.login_as_portal_owner()

# Test empty form
shareform = self.simple_share([], '')
self.assertFalse(shareform.status)
self.assertEqual(api.content.get_state(self.doc), 'private')
self.assertEqual(self.doc.users_with_local_role('Reader'), [])

# Test validation error
shareform = self.simple_share(['foobar'], 'published')
self.assertTrue(shareform.status)
Expand Down
9 changes: 7 additions & 2 deletions src/ploneintranet/simplesharing/tests/test_vocabularies.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ def test_class(self):
vocab = cls.__call__(doc)

self.assertIsInstance(vocab, SimpleVocabulary)
self.assertEqual(len(vocab), 2)
self.assertEqual(
len(vocab),
3,
'Incorrect number of transitions shown',
)
self.assertIsInstance(list(vocab)[0], SimpleTerm)
self.assertIn('Visible to everyone', list(vocab)[0].title)
self.assertIn('edited by the owner', list(vocab)[0].title)
self.assertIn('Visible to everyone', list(vocab)[1].title)
13 changes: 11 additions & 2 deletions src/ploneintranet/simplesharing/vocabularies.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from z3c.form.interfaces import NOT_CHANGED
from zope.interface import classProvides, implements
from zope.schema.interfaces import IContextSourceBinder
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
Expand Down Expand Up @@ -31,8 +32,16 @@ def __call__(self, context):
workflows = workflow.getWorkflowsFor(context)
states = workflows[0].states.objectValues()
state_mapping = {x.id: x for x in states}

vocab = []
current_state = api.content.get_state(obj=context)

# add the current state
vocab = [
SimpleTerm(
value=NOT_CHANGED,
token=NOT_CHANGED,
title=state_mapping[current_state].description,
)
]
final_states = []
for transition in transitions:
new_state = transition['transition'].new_state_id
Expand Down

0 comments on commit 5971c13

Please sign in to comment.