{"action":"created","comment":{"url":"https://api.github.com/repos/liqd/adhocracy3/pulls/comments/55355168","id":55355168,"diff_hunk":"@@ -36,28 +38,103 @@ def get_next_states(self, context, request: IRequest) -> list:\n         return list(set(states))\n \n \n-def add_workflow(registry: Registry, cstruct: dict, name: str):\n+def add_workflow(registry: Registry, workflow_asset: str, name: str):\n     \"\"\"Create and add workflow to registry.\n \n     :param registry: registry to register the workflow and store meta data.\n-    :param cstruct: meta data :term:`cstruct` to create the workflow. The data\n-        schema is :class:`adhocracy_core.workflows.schemas.Workflow`.\n+    :param workfow_asset: yaml asset file to import the workflow metadata.\n+        The data schema is :class:`adhocracy_core.workflows.schemas.Workflow`.\n     :param name: identifier for the workflow\n     :raises adhocracy_core.exceptions.ConfigurationError: if the validation\n-        for :term:`cstruct` and the sanity checks in\n-        class:`substanced.workflow.Workflow` fails.\n+        for :term:`cstruct` or the sanity checks in\n+        class:`substanced.workflow.Workflow` fail.\n     \"\"\"\n-    error_msg = 'Cannot create workflow {0}: {1}'\n+    cstruct = _get_meta(workflow_asset, registry)\n+    appstruct = _deserialize_meta(cstruct, name)\n+    appstruct = _add_defaults(appstruct, registry)\n+    registry.content.workflows_meta[name] = appstruct\n+    workflow = _create_workflow(appstruct, name)\n+    registry.content.workflows[name] = workflow\n+\n+\n+def _get_meta(workflow_asset: str, registry: Registry) -> dict:\n+    dummy_request = Request.blank('/')  # pass the local registry in tests\n+    dummy_request.registry = registry\n+    cstruct = render(workflow_asset, {}, request=dummy_request)\n+    return cstruct\n+\n+\n+def _deserialize_meta(cstruct: dict, name: str) -> PMap:\n+    schema = create_workflow_meta_schema(cstruct)\n+    try:\n+        appstruct = schema.deserialize(cstruct)\n+    except Invalid as err:\n+        msg = 'Error add workflow with name {0}: {1}'\n+        raise ConfigurationError(msg.format(name, str(err.asdict())))\n+    return freeze(appstruct)\n+\n+\n+def _add_defaults(appstruct: PMap, registry: Registry) -> PMap:\n+    \"\"\"Add values form default workflow to `appstruct`.\"\"\"\n+    default_name = appstruct.get('defaults', '')\n+    if not default_name:\n+        return appstruct\n+    updated = registry.content.workflows_meta[default_name]\n+    for key, value in appstruct.items():\n+        if key in ['initial_state', 'defaults']:\n+            updated = updated.transform([key], value)\n+        elif key == 'transitions':\n+            for transition_name, transition in value.items():\n+                updated = updated.transform(['transitions', transition_name],\n+                                            transition)\n+        elif key == 'states':\n+            for state_name, state in value.items():\n+                for permission in state.get('acm', {}).get('permissions', []):\n+                    name = permission[0]\n+                    permissions = \\\n+                        updated['states'][state_name]['acm']['permissions']\n+                    editing = name in [p[0] for p in permissions]\n+                    if editing:","path":"src/adhocracy_core/adhocracy_core/workflows/__init__.py","position":82,"original_position":82,"commit_id":"6a4dc401dab183ecb61a71a041b21e01fa008720","original_commit_id":"6a4dc401dab183ecb61a71a041b21e01fa008720","user":{"login":"pallix","id":676838,"avatar_url":"https://avatars.githubusercontent.com/u/676838?v=3","gravatar_id":"","url":"https://api.github.com/users/pallix","html_url":"https://github.com/pallix","followers_url":"https://api.github.com/users/pallix/followers","following_url":"https://api.github.com/users/pallix/following{/other_user}","gists_url":"https://api.github.com/users/pallix/gists{/gist_id}","starred_url":"https://api.github.com/users/pallix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pallix/subscriptions","organizations_url":"https://api.github.com/users/pallix/orgs","repos_url":"https://api.github.com/users/pallix/repos","events_url":"https://api.github.com/users/pallix/events{/privacy}","received_events_url":"https://api.github.com/users/pallix/received_events","type":"User","site_admin":false},"body":"would it make more sense to name it `overwriting` ?","created_at":"2016-03-08T13:00:11Z","updated_at":"2016-03-08T13:00:11Z","html_url":"https://github.com/liqd/adhocracy3/pull/2132#discussion_r55355168","pull_request_url":"https://api.github.com/repos/liqd/adhocracy3/pulls/2132","_links":{"self":{"href":"https://api.github.com/repos/liqd/adhocracy3/pulls/comments/55355168"},"html":{"href":"https://github.com/liqd/adhocracy3/pull/2132#discussion_r55355168"},"pull_request":{"href":"https://api.github.com/repos/liqd/adhocracy3/pulls/2132"}}},"pull_request":{"url":"https://api.github.com/repos/liqd/adhocracy3/pulls/2132","id":61830521,"html_url":"https://github.com/liqd/adhocracy3/pull/2132","diff_url":"https://github.com/liqd/adhocracy3/pull/2132.diff","patch_url":"https://github.com/liqd/adhocracy3/pull/2132.patch","issue_url":"https://api.github.com/repos/liqd/adhocracy3/issues/2132","number":2132,"state":"open","locked":false,"title":"use yaml files to define workflows and root permissions","user":{"login":"joka","id":353982,"avatar_url":"https://avatars.githubusercontent.com/u/353982?v=3","gravatar_id":"","url":"https://api.github.com/users/joka","html_url":"https://github.com/joka","followers_url":"https://api.github.com/users/joka/followers","following_url":"https://api.github.com/users/joka/following{/other_user}","gists_url":"https://api.github.com/users/joka/gists{/gist_id}","starred_url":"https://api.github.com/users/joka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joka/subscriptions","organizations_url":"https://api.github.com/users/joka/orgs","repos_url":"https://api.github.com/users/joka/repos","events_url":"https://api.github.com/users/joka/events{/privacy}","received_events_url":"https://api.github.com/users/joka/received_events","type":"User","site_admin":false},"body":"Refector  workflow and permissions definitions:\r\n\r\n- use IRootACMExtension adapter to override the permissions for the root\r\n  object. See example in adhocracy_core.authorization.\r\n  This way we can set the subscriber to update the root permission in adhocray_core and we have\r\n  less boilerplate in extension packages.\r\n\r\n- move root acm definition to adhocray_core.authorization (better SRP)\r\n\r\n- refactor set_acm_for_app_root: use safe way to get the root object\r\n\r\n- add yaml to python renderer (activated by default when rendering `.yaml` files)\r\n\r\n- allow shortcuts in ACM permission tables: ` 'A' = Allow   'D' = Deny  '~' = None (yaml syntax)`\r\n  This way we are less busy fixing the table layout. (Feel free to suggest better shortcuts)\r\n\r\n- import root acm from yaml file (asset: `adhocracy_core.authorization:root_permissions.yaml`)\r\n\r\n- import workflow metadata from yaml file\r\n\r\n- add config directive 'add_workflow' to register workflow, example: \r\n     `config.add_workflow('adhocracy_core.workflows:debate.yaml', 'debate')`\r\n\r\n","created_at":"2016-03-06T01:28:03Z","updated_at":"2016-03-08T13:00:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d9a69dbe8f0e9ab0318ab8f011c5096dc813ae71","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/liqd/adhocracy3/pulls/2132/commits","review_comments_url":"https://api.github.com/repos/liqd/adhocracy3/pulls/2132/comments","review_comment_url":"https://api.github.com/repos/liqd/adhocracy3/pulls/comments{/number}","comments_url":"https://api.github.com/repos/liqd/adhocracy3/issues/2132/comments","statuses_url":"https://api.github.com/repos/liqd/adhocracy3/statuses/6a4dc401dab183ecb61a71a041b21e01fa008720","head":{"label":"liqd:2016-03-jk-refactor-root-permissions","ref":"2016-03-jk-refactor-root-permissions","sha":"6a4dc401dab183ecb61a71a041b21e01fa008720","user":{"login":"liqd","id":2312088,"avatar_url":"https://avatars.githubusercontent.com/u/2312088?v=3","gravatar_id":"","url":"https://api.github.com/users/liqd","html_url":"https://github.com/liqd","followers_url":"https://api.github.com/users/liqd/followers","following_url":"https://api.github.com/users/liqd/following{/other_user}","gists_url":"https://api.github.com/users/liqd/gists{/gist_id}","starred_url":"https://api.github.com/users/liqd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liqd/subscriptions","organizations_url":"https://api.github.com/users/liqd/orgs","repos_url":"https://api.github.com/users/liqd/repos","events_url":"https://api.github.com/users/liqd/events{/privacy}","received_events_url":"https://api.github.com/users/liqd/received_events","type":"Organization","site_admin":false},"repo":{"id":22982974,"name":"adhocracy3","full_name":"liqd/adhocracy3","owner":{"login":"liqd","id":2312088,"avatar_url":"https://avatars.githubusercontent.com/u/2312088?v=3","gravatar_id":"","url":"https://api.github.com/users/liqd","html_url":"https://github.com/liqd","followers_url":"https://api.github.com/users/liqd/followers","following_url":"https://api.github.com/users/liqd/following{/other_user}","gists_url":"https://api.github.com/users/liqd/gists{/gist_id}","starred_url":"https://api.github.com/users/liqd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liqd/subscriptions","organizations_url":"https://api.github.com/users/liqd/orgs","repos_url":"https://api.github.com/users/liqd/repos","events_url":"https://api.github.com/users/liqd/events{/privacy}","received_events_url":"https://api.github.com/users/liqd/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/liqd/adhocracy3","description":"Adhocracy 3 with customizations for various projects","fork":false,"url":"https://api.github.com/repos/liqd/adhocracy3","forks_url":"https://api.github.com/repos/liqd/adhocracy3/forks","keys_url":"https://api.github.com/repos/liqd/adhocracy3/keys{/key_id}","collaborators_url":"https://api.github.com/repos/liqd/adhocracy3/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/liqd/adhocracy3/teams","hooks_url":"https://api.github.com/repos/liqd/adhocracy3/hooks","issue_events_url":"https://api.github.com/repos/liqd/adhocracy3/issues/events{/number}","events_url":"https://api.github.com/repos/liqd/adhocracy3/events","assignees_url":"https://api.github.com/repos/liqd/adhocracy3/assignees{/user}","branches_url":"https://api.github.com/repos/liqd/adhocracy3/branches{/branch}","tags_url":"https://api.github.com/repos/liqd/adhocracy3/tags","blobs_url":"https://api.github.com/repos/liqd/adhocracy3/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/liqd/adhocracy3/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/liqd/adhocracy3/git/refs{/sha}","trees_url":"https://api.github.com/repos/liqd/adhocracy3/git/trees{/sha}","statuses_url":"https://api.github.com/repos/liqd/adhocracy3/statuses/{sha}","languages_url":"https://api.github.com/repos/liqd/adhocracy3/languages","stargazers_url":"https://api.github.com/repos/liqd/adhocracy3/stargazers","contributors_url":"https://api.github.com/repos/liqd/adhocracy3/contributors","subscribers_url":"https://api.github.com/repos/liqd/adhocracy3/subscribers","subscription_url":"https://api.github.com/repos/liqd/adhocracy3/subscription","commits_url":"https://api.github.com/repos/liqd/adhocracy3/commits{/sha}","git_commits_url":"https://api.github.com/repos/liqd/adhocracy3/git/commits{/sha}","comments_url":"https://api.github.com/repos/liqd/adhocracy3/comments{/number}","issue_comment_url":"https://api.github.com/repos/liqd/adhocracy3/issues/comments{/number}","contents_url":"https://api.github.com/repos/liqd/adhocracy3/contents/{+path}","compare_url":"https://api.github.com/repos/liqd/adhocracy3/compare/{base}...{head}","merges_url":"https://api.github.com/repos/liqd/adhocracy3/merges","archive_url":"https://api.github.com/repos/liqd/adhocracy3/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/liqd/adhocracy3/downloads","issues_url":"https://api.github.com/repos/liqd/adhocracy3/issues{/number}","pulls_url":"https://api.github.com/repos/liqd/adhocracy3/pulls{/number}","milestones_url":"https://api.github.com/repos/liqd/adhocracy3/milestones{/number}","notifications_url":"https://api.github.com/repos/liqd/adhocracy3/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/liqd/adhocracy3/labels{/name}","releases_url":"https://api.github.com/repos/liqd/adhocracy3/releases{/id}","deployments_url":"https://api.github.com/repos/liqd/adhocracy3/deployments","created_at":"2014-08-15T08:07:57Z","updated_at":"2016-03-05T13:02:17Z","pushed_at":"2016-03-08T10:15:35Z","git_url":"git://github.com/liqd/adhocracy3.git","ssh_url":"git@github.com:liqd/adhocracy3.git","clone_url":"https://github.com/liqd/adhocracy3.git","svn_url":"https://github.com/liqd/adhocracy3","homepage":"","size":22649,"stargazers_count":38,"watchers_count":38,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":13,"mirror_url":null,"open_issues_count":88,"forks":13,"open_issues":88,"watchers":38,"default_branch":"master"}},"base":{"label":"liqd:master","ref":"master","sha":"35c5d1a538f1b537b6bc9963295ac3b287b00ea6","user":{"login":"liqd","id":2312088,"avatar_url":"https://avatars.githubusercontent.com/u/2312088?v=3","gravatar_id":"","url":"https://api.github.com/users/liqd","html_url":"https://github.com/liqd","followers_url":"https://api.github.com/users/liqd/followers","following_url":"https://api.github.com/users/liqd/following{/other_user}","gists_url":"https://api.github.com/users/liqd/gists{/gist_id}","starred_url":"https://api.github.com/users/liqd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liqd/subscriptions","organizations_url":"https://api.github.com/users/liqd/orgs","repos_url":"https://api.github.com/users/liqd/repos","events_url":"https://api.github.com/users/liqd/events{/privacy}","received_events_url":"https://api.github.com/users/liqd/received_events","type":"Organization","site_admin":false},"repo":{"id":22982974,"name":"adhocracy3","full_name":"liqd/adhocracy3","owner":{"login":"liqd","id":2312088,"avatar_url":"https://avatars.githubusercontent.com/u/2312088?v=3","gravatar_id":"","url":"https://api.github.com/users/liqd","html_url":"https://github.com/liqd","followers_url":"https://api.github.com/users/liqd/followers","following_url":"https://api.github.com/users/liqd/following{/other_user}","gists_url":"https://api.github.com/users/liqd/gists{/gist_id}","starred_url":"https://api.github.com/users/liqd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liqd/subscriptions","organizations_url":"https://api.github.com/users/liqd/orgs","repos_url":"https://api.github.com/users/liqd/repos","events_url":"https://api.github.com/users/liqd/events{/privacy}","received_events_url":"https://api.github.com/users/liqd/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/liqd/adhocracy3","description":"Adhocracy 3 with customizations for various projects","fork":false,"url":"https://api.github.com/repos/liqd/adhocracy3","forks_url":"https://api.github.com/repos/liqd/adhocracy3/forks","keys_url":"https://api.github.com/repos/liqd/adhocracy3/keys{/key_id}","collaborators_url":"https://api.github.com/repos/liqd/adhocracy3/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/liqd/adhocracy3/teams","hooks_url":"https://api.github.com/repos/liqd/adhocracy3/hooks","issue_events_url":"https://api.github.com/repos/liqd/adhocracy3/issues/events{/number}","events_url":"https://api.github.com/repos/liqd/adhocracy3/events","assignees_url":"https://api.github.com/repos/liqd/adhocracy3/assignees{/user}","branches_url":"https://api.github.com/repos/liqd/adhocracy3/branches{/branch}","tags_url":"https://api.github.com/repos/liqd/adhocracy3/tags","blobs_url":"https://api.github.com/repos/liqd/adhocracy3/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/liqd/adhocracy3/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/liqd/adhocracy3/git/refs{/sha}","trees_url":"https://api.github.com/repos/liqd/adhocracy3/git/trees{/sha}","statuses_url":"https://api.github.com/repos/liqd/adhocracy3/statuses/{sha}","languages_url":"https://api.github.com/repos/liqd/adhocracy3/languages","stargazers_url":"https://api.github.com/repos/liqd/adhocracy3/stargazers","contributors_url":"https://api.github.com/repos/liqd/adhocracy3/contributors","subscribers_url":"https://api.github.com/repos/liqd/adhocracy3/subscribers","subscription_url":"https://api.github.com/repos/liqd/adhocracy3/subscription","commits_url":"https://api.github.com/repos/liqd/adhocracy3/commits{/sha}","git_commits_url":"https://api.github.com/repos/liqd/adhocracy3/git/commits{/sha}","comments_url":"https://api.github.com/repos/liqd/adhocracy3/comments{/number}","issue_comment_url":"https://api.github.com/repos/liqd/adhocracy3/issues/comments{/number}","contents_url":"https://api.github.com/repos/liqd/adhocracy3/contents/{+path}","compare_url":"https://api.github.com/repos/liqd/adhocracy3/compare/{base}...{head}","merges_url":"https://api.github.com/repos/liqd/adhocracy3/merges","archive_url":"https://api.github.com/repos/liqd/adhocracy3/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/liqd/adhocracy3/downloads","issues_url":"https://api.github.com/repos/liqd/adhocracy3/issues{/number}","pulls_url":"https://api.github.com/repos/liqd/adhocracy3/pulls{/number}","milestones_url":"https://api.github.com/repos/liqd/adhocracy3/milestones{/number}","notifications_url":"https://api.github.com/repos/liqd/adhocracy3/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/liqd/adhocracy3/labels{/name}","releases_url":"https://api.github.com/repos/liqd/adhocracy3/releases{/id}","deployments_url":"https://api.github.com/repos/liqd/adhocracy3/deployments","created_at":"2014-08-15T08:07:57Z","updated_at":"2016-03-05T13:02:17Z","pushed_at":"2016-03-08T10:15:35Z","git_url":"git://github.com/liqd/adhocracy3.git","ssh_url":"git@github.com:liqd/adhocracy3.git","clone_url":"https://github.com/liqd/adhocracy3.git","svn_url":"https://github.com/liqd/adhocracy3","homepage":"","size":22649,"stargazers_count":38,"watchers_count":38,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":13,"mirror_url":null,"open_issues_count":88,"forks":13,"open_issues":88,"watchers":38,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/liqd/adhocracy3/pulls/2132"},"html":{"href":"https://github.com/liqd/adhocracy3/pull/2132"},"issue":{"href":"https://api.github.com/repos/liqd/adhocracy3/issues/2132"},"comments":{"href":"https://api.github.com/repos/liqd/adhocracy3/issues/2132/comments"},"review_comments":{"href":"https://api.github.com/repos/liqd/adhocracy3/pulls/2132/comments"},"review_comment":{"href":"https://api.github.com/repos/liqd/adhocracy3/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/liqd/adhocracy3/pulls/2132/commits"},"statuses":{"href":"https://api.github.com/repos/liqd/adhocracy3/statuses/6a4dc401dab183ecb61a71a041b21e01fa008720"}}}}