示例#1
0
    def test_create_comment_ok(self):
        uapi = UserApi(None)
        groups = [
            GroupApi(None).get_one(Group.TIM_USER),
            GroupApi(None).get_one(Group.TIM_MANAGER),
            GroupApi(None).get_one(Group.TIM_ADMIN)
        ]

        user = uapi.create_user(email='this.is@user',
                                groups=groups,
                                save_now=True)

        workspace = WorkspaceApi(user).create_workspace('test workspace',
                                                        save_now=True)

        api = ContentApi(user)
        p = api.create(ContentType.Page, workspace, None, 'this_is_a_page')
        c = api.create_comment(workspace, p, 'this is the comment', True)

        eq_(Content, c.__class__)
        eq_(p.content_id, c.parent_id)
        eq_(user, c.owner)
        eq_(workspace, c.workspace)
        eq_(ContentType.Comment, c.type)
        eq_('this is the comment', c.description)
        eq_('', c.label)
        eq_(ActionDescription.COMMENT, c.revision_type)
示例#2
0
    def put(self, item_id, file_data=None, comment=None, label=''):
        # TODO - SECURE THIS
        workspace = tmpl_context.workspace

        try:
            item_saved = False
            api = ContentApi(tmpl_context.current_user)
            item = api.get_one(int(item_id), self._item_type, workspace)

            # TODO - D.A. - 2015-03-19
            # refactor this method in order to make code easier to understand

            if comment and label:
                updated_item = api.update_content(
                    item, label if label else item.label,
                    comment if comment else ''
                )
                api.save(updated_item, ActionDescription.EDITION)

                # This case is the default "file title and description update"
                # In this case the file itself is not revisionned

            else:
                # So, now we may have a comment and/or a file revision
                if comment and ''==label:
                    comment_item = api.create_comment(workspace,
                                                      item, comment,
                                                      do_save=False)

                    if not isinstance(file_data, FieldStorage):
                        api.save(comment_item, ActionDescription.COMMENT)
                    else:
                        # The notification is only sent
                        # if the file is NOT updated
                        #
                        #  If the file is also updated,
                        #  then a 'file revision' notification will be sent.
                        api.save(comment_item,
                                 ActionDescription.COMMENT,
                                 do_notify=False)

                if isinstance(file_data, FieldStorage):
                    api.update_file_data(item, file_data.filename, file_data.type, file_data.file.read())
                    api.save(item, ActionDescription.REVISION)

            msg = _('{} updated').format(self._item_type_label)
            tg.flash(msg, CST.STATUS_OK)
            tg.redirect(self._std_url.format(tmpl_context.workspace_id, tmpl_context.folder_id, item.content_id))

        except ValueError as e:
            msg = _('{} not updated - error: {}').format(self._item_type_label, str(e))
            tg.flash(msg, CST.STATUS_ERROR)
            tg.redirect(self._err_url.format(tmpl_context.workspace_id, tmpl_context.folder_id, item_id))
示例#3
0
文件: content.py 项目: qyqx/tracim
    def post(self, content: str = ''):
        # TODO - SECURE THIS
        workspace = tmpl_context.workspace
        thread = tmpl_context.thread

        api = ContentApi(tmpl_context.current_user)

        comment = api.create_comment(workspace, thread, content, True)
        next_str = '/workspaces/{}/folders/{}/threads/{}'
        next_url = tg.url(next_str).format(tmpl_context.workspace_id,
                                           tmpl_context.folder_id,
                                           tmpl_context.thread_id)
        tg.flash(_('Comment added'), CST.STATUS_OK)
        tg.redirect(next_url)
示例#4
0
    def post(self, content=''):
        # TODO - SECURE THIS
        workspace = tmpl_context.workspace
        thread = tmpl_context.thread


        api = ContentApi(tmpl_context.current_user)

        comment = api.create_comment(workspace, thread, content, True)

        next_url = tg.url('/workspaces/{}/folders/{}/threads/{}').format(tmpl_context.workspace_id,
                                                                              tmpl_context.folder_id,
                                                                              tmpl_context.thread_id)
        tg.flash(_('Comment added'), CST.STATUS_OK)
        tg.redirect(next_url)
示例#5
0
    def test_create_comment_ok(self):
        uapi = UserApi(None)
        groups = [GroupApi(None).get_one(Group.TIM_USER),
                  GroupApi(None).get_one(Group.TIM_MANAGER),
                  GroupApi(None).get_one(Group.TIM_ADMIN)]

        user = uapi.create_user(email='this.is@user',
                                groups=groups, save_now=True)

        workspace = WorkspaceApi(user).create_workspace('test workspace',
                                                        save_now=True)

        api = ContentApi(user)
        p = api.create(ContentType.Page, workspace, None, 'this_is_a_page')
        c = api.create_comment(workspace, p, 'this is the comment', True)

        eq_(Content, c.__class__)
        eq_(p.content_id, c.parent_id)
        eq_(user, c.owner)
        eq_(workspace, c.workspace)
        eq_(ContentType.Comment, c.type)
        eq_('this is the comment', c.description)
        eq_('', c.label)
        eq_(ActionDescription.COMMENT, c.revision_type)
示例#6
0
文件: content.py 项目: qyqx/tracim
    def put(self, item_id, file_data=None, comment=None, label=None):
        # TODO - SECURE THIS
        workspace = tmpl_context.workspace

        try:
            api = ContentApi(tmpl_context.current_user)
            item = api.get_one(int(item_id), self._item_type, workspace)
            label_changed = False
            if label is not None and label != item.label:
                label_changed = True

            if label is None:
                label = ''

            # TODO - D.A. - 2015-03-19
            # refactor this method in order to make code easier to understand

            with new_revision(item):

                if (comment and label) or (not comment and label_changed):
                    updated_item = api.update_content(
                        item, label if label else item.label,
                        comment if comment else '')

                    # Display error page to user if chosen label is in conflict
                    if not self._path_validation.validate_new_content(
                            updated_item, ):
                        return render_invalid_integrity_chosen_path(
                            updated_item.get_label_as_file(), )

                    api.save(updated_item, ActionDescription.EDITION)

                    # This case is the default "file title and description
                    # update" In this case the file itself is not revisionned

                else:
                    # So, now we may have a comment and/or a file revision
                    if comment and '' == label:
                        comment_item = api.create_comment(workspace,
                                                          item,
                                                          comment,
                                                          do_save=False)

                        if not isinstance(file_data, FieldStorage):
                            api.save(comment_item, ActionDescription.COMMENT)
                        else:
                            # The notification is only sent
                            # if the file is NOT updated
                            #
                            # If the file is also updated,
                            # then a 'file revision' notification will be sent.
                            api.save(comment_item,
                                     ActionDescription.COMMENT,
                                     do_notify=False)

                    if isinstance(file_data, FieldStorage):
                        api.update_file_data(item, file_data.filename,
                                             file_data.type,
                                             file_data.file.read())

                        # Display error page to user if chosen label is in
                        # conflict
                        if not self._path_validation.validate_new_content(
                                item, ):
                            return render_invalid_integrity_chosen_path(
                                item.get_label_as_file(), )

                        api.save(item, ActionDescription.REVISION)

            msg = _('{} updated').format(self._item_type_label)
            tg.flash(msg, CST.STATUS_OK)
            tg.redirect(
                self._std_url.format(tmpl_context.workspace_id,
                                     tmpl_context.folder_id, item.content_id))

        except ValueError as e:
            error = '{} not updated - error: {}'
            msg = _(error).format(self._item_type_label, str(e))
            tg.flash(msg, CST.STATUS_ERROR)
            tg.redirect(
                self._err_url.format(tmpl_context.workspace_id,
                                     tmpl_context.folder_id, item_id))
示例#7
0
文件: events.py 项目: norsig/tracim
    def post(self) -> Response:
        cfg = CFG.get_instance()

        try:
            json = request.json_body
        except ValueError:
            return Response(
                status=400,
                json_body={'msg': 'Bad json'},
            )

        if json.get('token', None) != cfg.EMAIL_REPLY_TOKEN:
            # TODO - G.M - 2017-11-23 - Switch to status 403 ?
            # 403 is a better status code in this case.
            # 403 status response can't now return clean json, because they are
            # handled somewhere else to return html.
            return Response(
                status=400,
                json_body={'msg': 'Invalid token'}
            )

        if 'user_mail' not in json:
            return Response(
                status=400,
                json_body={'msg': 'Bad json: user_mail is required'}
            )

        if 'content_id' not in json:
            return Response(
                status=400,
                json_body={'msg': 'Bad json: content_id is required'}
            )

        if 'payload' not in json:
            return Response(
                status=400,
                json_body={'msg': 'Bad json: payload is required'}
            )

        uapi = UserApi(None)
        try:
            user = uapi.get_one_by_email(json['user_mail'])
        except NoResultFound:
            return Response(
                status=400,
                json_body={'msg': 'Unknown user email'},
            )
        api = ContentApi(user)

        try:
            thread = api.get_one(json['content_id'],
                                 content_type=ContentType.Any)
        except NoResultFound:
            return Response(
                status=400,
                json_body={'msg': 'Unknown content_id'},
            )

        # INFO - G.M - 2017-11-17
        # When content_id is a sub-elem of a main content like Comment,
        # Attach the thread to the main content.
        if thread.type == ContentType.Comment:
            thread = thread.parent
        if thread.type == ContentType.Folder:
            return Response(
                status=400,
                json_body={'msg': 'comment for folder not allowed'},
            )
        if 'content' in json['payload']:
            api.create_comment(
                workspace=thread.workspace,
                parent=thread,
                content=json['payload']['content'],
                do_save=True,
            )
            return Response(
                status=204,
            )
        else:
            return Response(
                status=400,
                json_body={'msg': 'No content to add new comment'},
            )