123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- # -*- coding: utf-8 -*-
- from depot.io.utils import FileIntent
- import transaction
-
- from tracim_backend import models
- from tracim_backend.fixtures import Fixture
- from tracim_backend.fixtures.users_and_groups import Test
- from tracim_backend.lib.core.content import ContentApi
- from tracim_backend.lib.core.userworkspace import RoleApi
- from tracim_backend.lib.core.workspace import WorkspaceApi
- from tracim_backend.models.data import ContentType
- from tracim_backend.models.data import UserRoleInWorkspace
- from tracim_backend.models.revision_protection import new_revision
-
-
- class Content(Fixture):
- require = [Test]
-
- def insert(self):
- admin = self._session.query(models.User) \
- .filter(models.User.email == 'admin@admin.admin') \
- .one()
- bob = self._session.query(models.User) \
- .filter(models.User.email == 'bob@fsf.local') \
- .one()
- john_the_reader = self._session.query(models.User) \
- .filter(models.User.email == 'john-the-reader@reader.local') \
- .one()
-
- admin_workspace_api = WorkspaceApi(
- current_user=admin,
- session=self._session,
- config=self._config,
- )
- bob_workspace_api = WorkspaceApi(
- current_user=bob,
- session=self._session,
- config=self._config
- )
- content_api = ContentApi(
- current_user=admin,
- session=self._session,
- config=self._config
- )
- bob_content_api = ContentApi(
- current_user=bob,
- session=self._session,
- config=self._config
- )
- reader_content_api = ContentApi(
- current_user=john_the_reader,
- session=self._session,
- config=self._config
- )
- role_api = RoleApi(
- current_user=admin,
- session=self._session,
- config=self._config,
- )
-
- # Workspaces
- business_workspace = admin_workspace_api.create_workspace(
- 'Business',
- description='All importants documents',
- save_now=True,
- )
- recipe_workspace = admin_workspace_api.create_workspace(
- 'Recipes',
- description='Our best recipes',
- save_now=True,
- )
- other_workspace = bob_workspace_api.create_workspace(
- 'Others',
- description='Other Workspace',
- save_now=True,
- )
-
- # Workspaces roles
- role_api.create_one(
- user=bob,
- workspace=recipe_workspace,
- role_level=UserRoleInWorkspace.CONTENT_MANAGER,
- with_notif=False,
- )
- role_api.create_one(
- user=john_the_reader,
- workspace=recipe_workspace,
- role_level=UserRoleInWorkspace.READER,
- with_notif=False,
- )
- # Folders
-
- tool_workspace = content_api.create(
- content_type=ContentType.Folder,
- workspace=business_workspace,
- label='Tools',
- do_save=True,
- do_notify=False,
- )
- menu_workspace = content_api.create(
- content_type=ContentType.Folder,
- workspace=business_workspace,
- label='Menus',
- do_save=True,
- do_notify=False,
- )
-
- dessert_folder = content_api.create(
- content_type=ContentType.Folder,
- workspace=recipe_workspace,
- label='Desserts',
- do_save=True,
- do_notify=False,
- )
- salads_folder = content_api.create(
- content_type=ContentType.Folder,
- workspace=recipe_workspace,
- label='Salads',
- do_save=True,
- do_notify=False,
- )
- other_folder = content_api.create(
- content_type=ContentType.Folder,
- workspace=other_workspace,
- label='Infos',
- do_save=True,
- do_notify=False,
- )
-
- # Pages, threads, ..
- tiramisu_page = content_api.create(
- content_type=ContentType.Page,
- workspace=recipe_workspace,
- parent=dessert_folder,
- label='Tiramisu Recipes!!!',
- do_save=True,
- do_notify=False,
- )
- with new_revision(
- session=self._session,
- tm=transaction.manager,
- content=tiramisu_page,
- ):
- content_api.update_content(
- item=tiramisu_page,
- new_content='<p>To cook a greet Tiramisu, you need many ingredients.</p>', # nopep8
- new_label='Tiramisu Recipes!!!',
- )
- content_api.save(tiramisu_page)
-
- best_cake_thread = content_api.create(
- content_type=ContentType.Thread,
- workspace=recipe_workspace,
- parent=dessert_folder,
- label='Best Cake',
- do_save=False,
- do_notify=False,
- )
- best_cake_thread.description = 'Which is the best cake?'
- self._session.add(best_cake_thread)
- apple_pie_recipe = content_api.create(
- content_type=ContentType.File,
- workspace=recipe_workspace,
- parent=dessert_folder,
- label='Apple_Pie',
- do_save=False,
- do_notify=False,
- )
- apple_pie_recipe.file_extension = '.txt'
- apple_pie_recipe.depot_file = FileIntent(
- b'Apple pie Recipe',
- 'apple_Pie.txt',
- 'text/plain',
- )
- self._session.add(apple_pie_recipe)
- Brownie_recipe = content_api.create(
- content_type=ContentType.File,
- workspace=recipe_workspace,
- parent=dessert_folder,
- label='Brownie Recipe',
- do_save=False,
- do_notify=False,
- )
- Brownie_recipe.file_extension = '.html'
- Brownie_recipe.depot_file = FileIntent(
- b'<p>Brownie Recipe</p>',
- 'brownie_recipe.html',
- 'text/html',
- )
- self._session.add(Brownie_recipe)
- fruits_desserts_folder = content_api.create(
- content_type=ContentType.Folder,
- workspace=recipe_workspace,
- label='Fruits Desserts',
- parent=dessert_folder,
- do_save=True,
- )
-
- menu_page = content_api.create(
- content_type=ContentType.Page,
- workspace=business_workspace,
- parent=menu_workspace,
- label='Current Menu',
- do_save=True,
- )
-
- new_fruit_salad = content_api.create(
- content_type=ContentType.Page,
- workspace=recipe_workspace,
- parent=fruits_desserts_folder,
- label='New Fruit Salad',
- do_save=True,
- )
- old_fruit_salad = content_api.create(
- content_type=ContentType.Page,
- workspace=recipe_workspace,
- parent=fruits_desserts_folder,
- label='Fruit Salad',
- do_save=True,
- do_notify=False,
- )
- with new_revision(
- session=self._session,
- tm=transaction.manager,
- content=old_fruit_salad,
- ):
- content_api.archive(old_fruit_salad)
- content_api.save(old_fruit_salad)
-
- bad_fruit_salad = content_api.create(
- content_type=ContentType.Page,
- workspace=recipe_workspace,
- parent=fruits_desserts_folder,
- label='Bad Fruit Salad',
- do_save=True,
- do_notify=False,
- )
- with new_revision(
- session=self._session,
- tm=transaction.manager,
- content=bad_fruit_salad,
- ):
- content_api.delete(bad_fruit_salad)
- content_api.save(bad_fruit_salad)
-
- # File at the root for test
- new_fruit_salad = content_api.create(
- content_type=ContentType.Page,
- workspace=other_workspace,
- label='New Fruit Salad',
- do_save=True,
- )
- old_fruit_salad = content_api.create(
- content_type=ContentType.Page,
- workspace=other_workspace,
- label='Fruit Salad',
- do_save=True,
- )
- with new_revision(
- session=self._session,
- tm=transaction.manager,
- content=old_fruit_salad,
- ):
- content_api.archive(old_fruit_salad)
- content_api.save(old_fruit_salad)
-
- bad_fruit_salad = content_api.create(
- content_type=ContentType.Page,
- workspace=other_workspace,
- label='Bad Fruit Salad',
- do_save=True,
- )
- with new_revision(
- session=self._session,
- tm=transaction.manager,
- content=bad_fruit_salad,
- ):
- content_api.delete(bad_fruit_salad)
- content_api.save(bad_fruit_salad)
-
- content_api.create_comment(
- parent=best_cake_thread,
- content='<p>What is for you the best cake ever? </br> I personnally vote for Chocolate cupcake!</p>', # nopep8
- do_save=True,
- )
- bob_content_api.create_comment(
- parent=best_cake_thread,
- content='<p>What about Apple Pie? There are Awesome!</p>',
- do_save=True,
- )
- reader_content_api.create_comment(
- parent=best_cake_thread,
- content='<p>You are right, but Kouign-amann are clearly better.</p>',
- do_save=True,
- )
- with new_revision(
- session=self._session,
- tm=transaction.manager,
- content=best_cake_thread,
- ):
- bob_content_api.update_content(
- item=best_cake_thread,
- new_content='What is the best cake?',
- new_label='Best Cakes?',
- )
- bob_content_api.save(best_cake_thread)
-
- with new_revision(
- session=self._session,
- tm=transaction.manager,
- content=tiramisu_page,
- ):
- bob_content_api.update_content(
- item=tiramisu_page,
- new_content='<p>To cook a great Tiramisu, you need many ingredients.</p>', # nopep8
- new_label='Tiramisu Recipe',
- )
- bob_content_api.save(tiramisu_page)
- self._session.flush()
|