Skip to content
This repository has been archived by the owner on Apr 12, 2021. It is now read-only.

Commit

Permalink
http://luc.lino-framework.org/blog/2019/1127.html
Browse files Browse the repository at this point in the history
  • Loading branch information
lsaffre committed Nov 27, 2019
1 parent 33e450d commit 48a3a4e
Show file tree
Hide file tree
Showing 15 changed files with 234 additions and 173 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Expand Up @@ -24,6 +24,9 @@ before_install:
- sudo apt-get install -y tidy libreoffice python3-uno
- sudo apt install libgconf-2-4 # Required for cypress with Ubuntu 16.04
- libreoffice --accept="socket,host=localhost,port=8100;urp;" &
# Trying to understand func=xmlSecCheckVersionExt:file=xmlsec.c:line=188:obj=unknown:subj=unknown:error=19:invalid version:mode=abi compatible;expected minor version=2;real minor version=2;expected subminor version=25;real subminor version=26
# https://bugs.documentfoundation.org/show_bug.cgi?id=118373
- libreoffice --version

install:
- pip install -U setuptools
Expand Down
2 changes: 1 addition & 1 deletion docs/dev/action_parameters.rst
Expand Up @@ -109,4 +109,4 @@ to make it possible).
True
>>> msg = ar.response['message']
>>> print(tostring(msg))
<div class="htmlText"><p>Are you sure you want to merge #1 (⛶ Föö fails to bar when baz) into #2 (☎ Bar is not always baz)?</p><ul><li>1 Dependencies, 3 Sessions, 1 Comments <b>will get reassigned.</b></li><li>#1 (⛶ Föö fails to bar when baz) will be deleted</li></ul></div>
<div class="htmlText"><p>Are you sure you want to merge #1 (⛶ Föö fails to bar when baz) into #2 (☎ Bar is not always baz)?</p><ul><li>1 Dependencies, 3 Sessions, 8 Comments <b>will get reassigned.</b></li><li>#1 (⛶ Föö fails to bar when baz) will be deleted</li></ul></div>
67 changes: 44 additions & 23 deletions docs/specs/comments.rst
Expand Up @@ -25,16 +25,24 @@ Overview

Comment

A **comment** is a written text that one user wants to share with "whoever
is interested". A comment has no "recipient" but is always "about"
something, a topic. When you submit a comment, Lino notifies all users who
registered their interest in the topic. All comments about the same topic
form a discussion thread. Comments are stored in the :class:`Comment`
database model.
A written text that one user wants to share with others.

Comments have no workflow management nor rating mechanism etc. As in the
real world it is the user's responsibility to think before they say
something.
A comment is always "about" something, called the :term:`discussion topic`.

A comment has no "recipient". When you submit a comment, Lino notifies all
users who registered their interest in the :term:`discussion topic`.

A comment can be a *reply* to another comments. All comments replying directly
or indirectly to a given comment are called a *discussion thread*.

Comments are stored in the :class:`Comment` database model.

Comments have no workflow management nor rating mechanism etc. It is the
author's responsibility to think before they write something.

Discussion topic

The database object that is the "topic" of a comment.

Commentable topic

Expand All @@ -52,8 +60,7 @@ Comments

.. class:: Comment

A **comment** is a short text which some user writes about some database
object. It has no recipient.
Django model to represent a :term:`comment`.

.. attribute:: body

Expand All @@ -69,15 +76,13 @@ Comments

.. attribute:: owner

The *topic* this comment is about. This field is a Generic Foreign Key, i.e. users can
basically comment on any database object. It is however the application
developer who decides where comments can be created and how they are being
displayed.

The *topic* this comment is about. This field is a Generic Foreign Key,
i.e. users can basically comment on any database object. It is however
the :term:`application developer` who decides where comments can be
created and how they are being displayed.


A generic foreign key to the commentable database object to
which this comment relates.
The :attr:`owner` of a comment is always an instance of a subclass of
:class:`Commentable`.

.. attribute:: published

Expand Down Expand Up @@ -200,11 +205,27 @@ Commentable
If not None, the object must have a field :attr:`ref` which will be
shown in the summary of :class:`RecentComments`.

.. method:: add_comments_filter(cls, qs, user):
.. method:: get_comments_filter(cls, user):

Return the filter to be added when a given user requests comments about
commentables of this type.

Return `None` to not add any filter. Otherwise the return value should
be a :class:`django.db.models.Q` object.

Default behaviour is that public comments are visible even to anonymous
while private comments are visible only to their author and to
:class:`PrivateCommentsReader`.

You can override this class method to define your own privacy settings.

Usage example in
:class:`lino_xl.lib.groups.Group` and
:class:`lino_xl.lib.tickets.Ticket`.

Override this class method to define your own privacy settings.
Default behaviour is that comments are visible only to real users (not to anonymous).
Usage example in :class:`lino_noi.lib.tickets.Ticket`
If you override this method, you probably want to define a
:class:`django.contrib.contenttypes.fields.GenericRelation` on your Commentable
in order to write filter conditions based on the owner of the comment.



Expand Down
106 changes: 106 additions & 0 deletions docs/specs/noi/comments.rst
@@ -0,0 +1,106 @@
.. doctest docs/specs/noi/comments.rst
.. _noi.specs.comments:

==============================
``comments`` (comments in Noi)
==============================

.. currentmodule:: lino.modlib.comments

Noi does not extend :mod:`lino.modlib.comments`


.. contents::
:local:

.. include:: /../docs/shared/include/tested.rst

>>> from lino import startup
>>> startup('lino_book.projects.team.settings.demo')
>>> from lino.api.doctest import *

Comments
========

Comments in :ref:`noi` are visible even to anonymous users. At least non-private
comments. Whether a comment is private or not depends on its :attr:`owner` (a
:class:`lino.modlib.comments.Commentable`).

There are two :class:`Commentable` things in :ref:`noi` tickets and teams.

Comments are private by default:

>>> dd.plugins.comments.private_default
True

>>> list(rt.models_by_base(comments.Commentable))
[<class 'lino_noi.lib.groups.models.Group'>, <class 'lino_noi.lib.tickets.models.Ticket'>]

Comments on a ticket are public when neither the ticket nor its site are marked
private.

Comments on a team are public when the team is not private.

>>> rt.models.comments.Comment.objects.all().count()
168
>>> rt.models.comments.Comment.objects.filter(private=True).count()
134

>>> rt.login("robin").show(comments.Comments,
... column_names="id ticket__site user owner short_preview",
... offset=82, limit=6)
... #doctest: +ELLIPSIS +NORMALIZE_WHITESPACE +REPORT_UDIFF
+----+--------+-------------+-----------------------------------------------+--------------------------------------------------------------------------------+
| ID | Site | Author | Topic | Preview |
+====+========+=============+===============================================+================================================================================+
| 83 | | Rolf Rompen | `Developers <Detail>`__ | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc cursus felis |
| | | | | nisi, eu pellentesque lorem lobortis non. Aenean non sodales neque, vitae |
| | | | | venenatis lectus. In eros dui, gravida et dolor at, pellentesque hendrerit |
| | | | | magna. Quisque vel lectus dictum, rhoncus massa feugiat, condimentum sem. |
| | | | | Donec elit nisl, placerat vitae imperdiet eget, hendrerit nec quam. Ut |
| | | | | elementum ligula vitae odio efficitur rhoncus. Duis in blandit neque. Sed |
| | | | | dictum mollis volutpat. Morbi at est et nisi euismod viverra. Nulla quis lacus |
| | | | | vitae ante sollicitudin tincidunt. Donec nec enim in leo vulputate ultrices. |
| | | | | Suspendisse potenti. Ut elit nibh, porta ut enim ac, convallis molestie risus. |
| | | | | Praesent consectetur lacus lacus, in faucibus justo fringilla vel. (...) |
+----+--------+-------------+-----------------------------------------------+--------------------------------------------------------------------------------+
| 84 | | Robin Rood | `Managers <Detail>`__ | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec interdum dictum |
| | | | | erat. Fusce condimentum erat a pulvinar ultricies. (...) |
+----+--------+-------------+-----------------------------------------------+--------------------------------------------------------------------------------+
| 85 | welket | Jean | `#1 (⛶ Föö fails to bar when baz) <Detail>`__ | breaking (...) |
+----+--------+-------------+-----------------------------------------------+--------------------------------------------------------------------------------+
| 86 | welket | Luc | `#1 (⛶ Föö fails to bar when baz) <Detail>`__ | (...) |
+----+--------+-------------+-----------------------------------------------+--------------------------------------------------------------------------------+
| 87 | welket | Marc | `#1 (⛶ Föö fails to bar when baz) <Detail>`__ | Some plain text. |
+----+--------+-------------+-----------------------------------------------+--------------------------------------------------------------------------------+
| 88 | welket | Mathieu | `#1 (⛶ Föö fails to bar when baz) <Detail>`__ | Two paragraphs of plain text. (...) |
+----+--------+-------------+-----------------------------------------------+--------------------------------------------------------------------------------+
<BLANKLINE>



The demo database contains 168 comments, 84 about a team and 84 about a ticket.
34 comments are public.

>>> comments.Comment.objects.all().count()
168
>>> comments.Comment.objects.filter(ticket__isnull=False).count()
84
>>> comments.Comment.objects.filter(ticket=None).count()
84
>>> comments.Comment.objects.filter(group=None).count()
84
>>> comments.Comment.objects.filter(private=False).count()
34


>>> rt.show(comments.RecentComments,
... column_names="id ticket__site user owner short_preview",
... limit=6)
... #doctest: +ELLIPSIS +NORMALIZE_WHITESPACE +REPORT_UDIFF


>>> obj = tickets.Ticket.objects.get(pk=2)
>>> rt.login('luc').show(comments.CommentsByRFC, obj)
... #doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
<p><b>Write comment</b></p><ul><li><a ...>...</a> by <a href="Detail">Luc</a> [<b> Reply </b>] <a ...>⁜</a><div id="comment-86"><p>Very confidential comment</p></div></li></ul>
8 changes: 4 additions & 4 deletions docs/specs/noi/db.rst
Expand Up @@ -26,7 +26,7 @@ Complexity factors
... #doctest: +ELLIPSIS +NORMALIZE_WHITESPACE +REPORT_UDIFF
- 44 plugins
- 65 models
- 19 user roles
- 20 user roles
- 5 user types
- 241 views
- 16 dialog actions
Expand Down Expand Up @@ -59,7 +59,7 @@ The database models
cal.Task cal.Tasks 18 0
changes.Change changes.Changes 10 0
checkdata.Problem checkdata.Problems 6 0
comments.Comment comments.Comments 11 168
comments.Comment comments.Comments 12 168
comments.CommentType comments.CommentTypes 4 0
comments.Mention comments.Mentions 7 0
contacts.Company contacts.Companies 22 14
Expand All @@ -80,8 +80,8 @@ The database models
gfks.HelpText gfks.HelpTexts 4 3
github.Commit github.Commits 14 0
github.Repository github.Repositories 4 0
groups.Group groups.Groups 8 3
groups.Membership groups.Memberships 4 2
groups.Group groups.Groups 7 3
groups.Membership groups.Memberships 4 7
lists.List lists.Lists 7 8
lists.ListType lists.ListTypes 4 3
lists.Member lists.Members 5 0
Expand Down
1 change: 1 addition & 0 deletions docs/specs/noi/index.rst
Expand Up @@ -14,6 +14,7 @@ This section contains specs for :ref:`noi`.
general
tickets
working
comments
smtpd
hosts
as_pdf
Expand Down
2 changes: 1 addition & 1 deletion docs/specs/noi/public.rst
Expand Up @@ -32,7 +32,7 @@ The home page:
>>> soup = BeautifulSoup(res.content, 'lxml')
>>> links = soup.find_all('a')
>>> len(links)
51
55
>>> print(links[0].get('href'))
/?ul=de
>>> print(links[1].get('href'))
Expand Down
4 changes: 2 additions & 2 deletions docs/specs/noi/sql.rst
Expand Up @@ -73,11 +73,11 @@ SELECT tickets_ticket.id,
tickets_ticket.ref,
tickets_ticket.user_id,
tickets_ticket.assigned_to_id,
tickets_ticket.private,
tickets_ticket.priority,
tickets_ticket.closed,
tickets_ticket.planned_time,
tickets_ticket.site_id,
tickets_ticket.private,
tickets_ticket.summary,
tickets_ticket.description,
tickets_ticket.upgrade_notes,
Expand Down Expand Up @@ -195,11 +195,11 @@ SELECT tickets_ticket.id,
T9.ref,
T9.user_id,
T9.assigned_to_id,
T9.private,
T9.priority,
T9.closed,
T9.planned_time,
T9.site_id,
T9.private,
T9.summary,
T9.description,
T9.upgrade_notes,
Expand Down
4 changes: 2 additions & 2 deletions docs/specs/noi/tickets.rst
Expand Up @@ -21,8 +21,8 @@ our work. Lino Noi uses this information when generating a service report.

.. include:: /../docs/shared/include/tested.rst

>>> import lino
>>> lino.startup('lino_book.projects.team.settings.demo')
>>> from lino import startup
>>> startup('lino_book.projects.team.settings.demo')
>>> from lino.api.doctest import *


Expand Down

0 comments on commit 48a3a4e

Please sign in to comment.