Skip to content

Commit

Permalink
Merge branch 'master' into index-sort-field
Browse files Browse the repository at this point in the history
  • Loading branch information
nilbacardit26 committed Jan 23, 2024
2 parents 179efd0 + c270e12 commit 38d40d8
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 8 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ CHANGELOG

7.0.1 (unreleased)
------------------

- Calling context.register() and notify ObjectModifiedEvent after
calling @sort/{field}, @delete/{field} and
@delete/{field}/{file_key} to index changes
[nilbacardit26]

- Feat: Add metadata info to workflows
- Fix: Update workflow vocabulary name
- Feat: Update workflow vocabulary title attribute to use metadata
[rboixaderg]

7.0.0 (2023-12-06)
------------------
Expand Down
6 changes: 5 additions & 1 deletion guillotina/contrib/workflows/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ async def __call__(self):
return workflow
async for action_name, action in workflow_obj.available_actions(self.request):
workflow["transitions"].append(
{"@id": obj_url + "/@workflow/" + action_name, "title": action["title"]}
{
"@id": obj_url + "/@workflow/" + action_name,
"title": action["title"],
"metadata": action.get("metadata", {}),
}
)

workflow_obj = query_adapter(self.context, IWorkflowBehavior)
Expand Down
4 changes: 4 additions & 0 deletions guillotina/contrib/workflows/base/guillotina_basic.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
initial_state: private
states:
private:
metadata:
title: Private
actions:
publish:
title: Publish
Expand All @@ -18,6 +20,8 @@ states:
role: guillotina.Anonymous
permission: guillotina.SearchContent
public:
metadata:
title: Public
actions:
retire:
title: Retire
Expand Down
4 changes: 1 addition & 3 deletions guillotina/contrib/workflows/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class IWorkflowUtility(IAsyncUtility):


class IWorkflow(Interface):

initial_state = Attribute("Initial state of the workflow")


Expand All @@ -54,14 +53,13 @@ def __call__(self, context: IResource) -> Optional[str]:


class IWorkflowBehavior(Interface):

index_field("review_state", store=True, type="keyword")
review_state = schema.Choice(
readonly=True,
title="Workflow review state",
required=False,
defaultFactory=DefaultReviewState(),
source="worklow_states",
source="workflow_states",
)

history = schema.List(
Expand Down
5 changes: 4 additions & 1 deletion guillotina/contrib/workflows/vocabularies.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from guillotina.interfaces import IResource


@configure.vocabulary(name="worklow_states")
@configure.vocabulary(name="workflow_states")
class WorkflowVocabulary:
def __init__(self, context):
self.context = context
Expand Down Expand Up @@ -35,6 +35,9 @@ def __len__(self):

def getTerm(self, value):
if value in self.states:
metadata = self.states[value].get("metadata", None)
if metadata:
return metadata
return value
else:
raise KeyError("No valid state")
1 change: 1 addition & 0 deletions guillotina/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime
from datetime import time
from guillotina import configure
from guillotina import schema
from guillotina.addons import Addon
Expand Down
118 changes: 117 additions & 1 deletion guillotina/tests/workflows/test_workflow_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,110 @@

pytestmark = pytest.mark.asyncio

guillotina_basic_with_translations = {
"initial_state": "private",
"states": {
"private": {
"metadata": {
"title": "Private",
"translated_title": {
"en": "Private",
"ca": "Privat",
"es": "Privado",
},
},
"actions": {
"publish": {
"title": "Publish",
"metadata": {
"translated_title": {
"en": "Publish",
"ca": "Publicar",
"es": "Publicar",
},
},
"to": "public",
"check_permission": "guillotina.ReviewContent",
}
},
"set_permission": {
"roleperm": [
{
"setting": "Deny",
"role": "guillotina.Anonymous",
"permission": "guillotina.ViewContent",
},
{
"setting": "Deny",
"role": "guillotina.Anonymous",
"permission": "guillotina.AccessContent",
},
{
"setting": "Deny",
"role": "guillotina.Anonymous",
"permission": "guillotina.SearchContent",
},
]
},
},
"public": {
"metadata": {
"title": "Public",
"translated_title": {
"en": "Public",
"ca": "Públic",
"es": "Público",
},
},
"actions": {
"retire": {
"title": "Retire",
"to": "private",
"check_permission": "guillotina.ReviewContent",
},
},
"set_permission": {
"roleperm": [
{
"setting": "AllowSingle",
"role": "guillotina.Anonymous",
"permission": "guillotina.ViewContent",
},
{
"setting": "AllowSingle",
"role": "guillotina.Anonymous",
"permission": "guillotina.AccessContent",
},
{
"setting": "AllowSingle",
"role": "guillotina.Anonymous",
"permission": "guillotina.SearchContent",
},
]
},
},
},
}


@pytest.mark.app_settings(
{
"applications": ["guillotina", "guillotina.contrib.workflows"],
"workflows_content": {"guillotina.interfaces.IContainer": "guillotina_basic"},
"workflows_content": {"guillotina.interfaces.IContainer": "guillotina_basic_with_translations"},
"workflows": {"guillotina_basic_with_translations": guillotina_basic_with_translations},
}
)
async def test_workflow_basic(container_requester):
async with container_requester as requester:
response, _ = await requester("GET", "/db/guillotina/@workflow")
assert response["transitions"][0]["title"] == "Publish"
assert response["transitions"][0]["metadata"] == {
"translated_title": {
"en": "Publish",
"ca": "Publicar",
"es": "Publicar",
}
}

response, _ = await requester("GET", "/db/guillotina")
assert response["review_state"] == "private"
Expand All @@ -38,3 +131,26 @@ async def test_workflow_basic(container_requester):

response, status = await requester("GET", "/db/guillotina", token=None)
assert status == 200

response, status = await requester("GET", "/db/guillotina/@vocabularies/workflow_states")
assert status == 200
assert response == {
"@id": "http://localhost/db/guillotina/@vocabularies/workflow_states",
"items": [
{
"title": {
"title": "Private",
"translated_title": {"en": "Private", "ca": "Privat", "es": "Privado"},
},
"token": "private",
},
{
"title": {
"title": "Public",
"translated_title": {"en": "Public", "ca": "Públic", "es": "Público"},
},
"token": "public",
},
],
"items_total": 2,
}

0 comments on commit 38d40d8

Please sign in to comment.