Skip to content
This repository has been archived by the owner on Oct 24, 2018. It is now read-only.

Commit

Permalink
Merge 0acf666 into 60e88c5
Browse files Browse the repository at this point in the history
  • Loading branch information
inkhey committed Jul 18, 2018
2 parents 60e88c5 + 0acf666 commit e8356f2
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
3 changes: 3 additions & 0 deletions tracim/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,6 @@ class EmptyLabelNotAllowed(EmptyValueNotAllowed):

class EmptyCommentContentNotAllowed(EmptyValueNotAllowed):
pass

class ParentNotFound(NotFound):
pass
2 changes: 2 additions & 0 deletions tracim/models/context_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ def __init__(
self,
label: str,
content_type: str,
parent_id: typing.Optional[int] = None,
) -> None:
self.label = label
self.content_type = content_type
self.parent_id = parent_id


class CommentCreation(object):
Expand Down
43 changes: 43 additions & 0 deletions tracim/tests/functional/test_workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,49 @@ def test_api__post_content_create_generic_content__ok_200__nominal_case(self) ->
active_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_active, status=200).json_body # nopep8
assert res.json_body in active_contents

def test_api__post_content_create_generic_content__ok_200__in_folder(self) -> None: # nopep8
"""
Create generic content in folder
"""
self.testapp.authorization = (
'Basic',
(
'admin@admin.admin',
'admin@admin.admin'
)
)
params = {
'label': 'GenericCreatedContent',
'content_type': 'markdownpage',
'parent_id': 10,
}
res = self.testapp.post_json(
'/api/v2/workspaces/1/contents',
params=params,
status=200
)
assert res
assert res.json_body
assert res.json_body['status'] == 'open'
assert res.json_body['content_id']
assert res.json_body['content_type'] == 'markdownpage'
assert res.json_body['is_archived'] is False
assert res.json_body['is_deleted'] is False
assert res.json_body['workspace_id'] == 1
assert res.json_body['slug'] == 'genericcreatedcontent'
assert res.json_body['parent_id'] == 10
assert res.json_body['show_in_ui'] is True
assert res.json_body['sub_content_types']
params_active = {
'parent_id': 10,
'show_archived': 0,
'show_deleted': 0,
'show_active': 1,
}
# INFO - G.M - 2018-06-165 - Verify if new content is correctly created
active_contents = self.testapp.get('/api/v2/workspaces/1/contents', params=params_active, status=200).json_body # nopep8
assert res.json_body in active_contents

def test_api__post_content_create_generic_content__err_400__empty_label(self) -> None: # nopep8
"""
Create generic content
Expand Down
5 changes: 5 additions & 0 deletions tracim/views/core_api/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ class ContentCreationSchema(marshmallow.Schema):
example='html-documents',
validate=OneOf(ContentType.allowed_types_for_folding()), # nopep8
)
parent_id = marshmallow.fields.Integer(
example=35,
description='content_id of parent content, if content should be placed in a folder, this should be folder content_id.'
)


@post_load
def make_content_filter(self, data):
Expand Down
13 changes: 12 additions & 1 deletion tracim/views/core_api/workspace_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
from tracim.models.context_models import UserRoleWorkspaceInContext
from tracim.models.context_models import ContentInContext
from tracim.exceptions import EmptyLabelNotAllowed
from tracim.exceptions import ContentNotFound
from tracim.exceptions import WorkspacesDoNotMatch
from tracim.exceptions import ParentNotFound
from tracim.views.controllers import Controller
from tracim.views.core_api.schemas import FilterContentQuerySchema
from tracim.views.core_api.schemas import ContentMoveSchema
Expand Down Expand Up @@ -133,12 +135,21 @@ def create_generic_empty_content(
api = ContentApi(
current_user=request.current_user,
session=request.dbsession,
config=app_config,
config=app_config
)
parent = None
if creation_data.parent_id:
try:
parent = api.get_one(content_id=creation_data.parent_id, content_type=ContentType.Any) # nopep8
except ContentNotFound as exc:
raise ParentNotFound(
'Parent with content_id {} not found'.format(creation_data.parent_id)
) from exc
content = api.create(
label=creation_data.label,
content_type=creation_data.content_type,
workspace=request.current_workspace,
parent=parent,
)
api.save(content, ActionDescription.CREATION)
content = api.get_content_in_context(content)
Expand Down

0 comments on commit e8356f2

Please sign in to comment.