Projet

Général

Profil

0001-WIP-add-journal-application-20695.patch

Paul Marillonnet, 16 novembre 2018 19:10

Télécharger (10,1 ko)

Voir les différences:

Subject: [PATCH] WIP add journal application (#20695)

 MANIFEST.in                                   |  2 ++
 setup.py                                      |  1 +
 src/authentic2/settings.py                    |  1 +
 src/authentic2_journal/__init__.py            |  9 ++++++
 src/authentic2_journal/admin.py               |  0
 src/authentic2_journal/apps.py                |  8 ++++++
 src/authentic2_journal/event_logger.py        | 17 +++++++++++
 src/authentic2_journal/kinds.py               | 20 +++++++++++++
 src/authentic2_journal/migrations/__init__.py |  0
 src/authentic2_journal/models.py              | 28 +++++++++++++++++++
 src/authentic2_journal/tables.py              | 12 ++++++++
 .../authentic2_journal/user_events.html       | 10 +++++++
 src/authentic2_journal/urls.py                | 10 +++++++
 src/authentic2_journal/utils.py               | 20 +++++++++++++
 src/authentic2_journal/views.py               | 21 ++++++++++++++
 15 files changed, 159 insertions(+)
 create mode 100644 src/authentic2_journal/__init__.py
 create mode 100644 src/authentic2_journal/admin.py
 create mode 100644 src/authentic2_journal/apps.py
 create mode 100644 src/authentic2_journal/event_logger.py
 create mode 100644 src/authentic2_journal/kinds.py
 create mode 100644 src/authentic2_journal/migrations/__init__.py
 create mode 100644 src/authentic2_journal/models.py
 create mode 100644 src/authentic2_journal/tables.py
 create mode 100644 src/authentic2_journal/templates/authentic2_journal/user_events.html
 create mode 100644 src/authentic2_journal/urls.py
 create mode 100644 src/authentic2_journal/utils.py
 create mode 100644 src/authentic2_journal/views.py
MANIFEST.in
22 22
recursive-include src/authentic2_auth_saml/templates/authentic2_auth_saml *.html
23 23
recursive-include src/authentic2_auth_oidc/templates/authentic2_auth_oidc *.html
24 24
recursive-include src/authentic2_idp_oidc/templates/authentic2_idp_oidc *.html
25
recursive-include src/authentic2_journal/templates/authentic2_journal *.html
25 26

  
26 27
recursive-include src/authentic2/vendor/totp_js/js *.js
27 28
recursive-include src/authentic2/saml/fixtures *.json
......
41 42
recursive-include src/authentic2_auth_saml/locale *.po *.mo
42 43
recursive-include src/authentic2_auth_oidc/locale *.po *.mo
43 44
recursive-include src/authentic2_idp_oidc/locale *.po *.mo
45
recursive-include src/authentic2_journal/locale *.po *.mo
44 46

  
45 47
recursive-include src/authentic2 README  xrds.xml *.txt yadis.xrdf
46 48
recursive-include src/authentic2_provisionning_ldap/tests *.ldif
setup.py
165 165
              'authentic2-idp-cas = authentic2_idp_cas:Plugin',
166 166
              'authentic2-idp-oidc = authentic2_idp_oidc:Plugin',
167 167
              'authentic2-provisionning-ldap = authentic2_provisionning_ldap:Plugin',
168
              'authentic2-journal = authentic2_journal:Plugin',
168 169
          ],
169 170
      })
src/authentic2/settings.py
126 126
    'authentic2.disco_service',
127 127
    'authentic2.manager',
128 128
    'authentic2_provisionning_ldap',
129
    'authentic2_journal',
129 130
    'authentic2',
130 131
    'django_rbac',
131 132
    'authentic2.a2_rbac',
src/authentic2_journal/__init__.py
1
# -*- coding: utf-8 -*-
2
class Plugin(object):
3
    def get_after_urls(self):
4
        from django.conf.urls import include, url
5

  
6
        return [url(r'^manage/journal/', include(__name__ + '.urls'))]
7

  
8
    def get_apps(self):
9
        return [__name__]
src/authentic2_journal/apps.py
1
# -*- coding: utf-8 -*-
2
from __future__ import unicode_literals
3

  
4
from django.apps import AppConfig
5

  
6

  
7
class Authentic2JournalConfig(AppConfig):
8
    name = 'authentic2_journal'
src/authentic2_journal/event_logger.py
1
# -*- coding: utf-8 -*-
2
from authentic2_journal.models import Line
3
from authentic2_journal import kinds
4
from authentic2_journal.utils import (new_line, new_action_reference,
5
        new_modification_reference)
6

  
7

  
8
def register(user, ou, content=None):
9
    line = new_line(user=user, obj=ou, kind=kinds.ActionRegister, content=content)
10
    new_reference(line, user)
11
    new_reference(line, ou)
12

  
13

  
14
def create(user, obj, content=None):
15
    line = new_line(user, ou, kinds.ModificationCreate, content)
16
    new_reference(line, user)
17
    new_reference(line, obj)
src/authentic2_journal/kinds.py
1
# -*- coding: utf-8 -*-
2

  
3
class BaseEvent(object):
4
    pass
5

  
6

  
7
class BaseAction(BaseEvent):
8
    pass
9

  
10

  
11
class BaseModification(BaseEvent):
12
    pass
13

  
14

  
15
class ActionRegister(BaseAction):
16
    pass
17

  
18

  
19
class ModificationCreate(BaseModification):
20
    pass
src/authentic2_journal/models.py
1
# -*- coding: utf-8 -*-
2
from __future__ import unicode_literals
3

  
4
from django.db import models
5
try:
6
    from django.contrib.contenttypes.fields import GenericForeignKey
7
except ImportError:
8
    from django.contrib.contenttypes.generic import GenericForeignKey
9
from django.contrib.contenttypes.models import ContentType
10
from django.utils.translation import ugettext_lazy as _
11
from jsonfield import JSONField
12

  
13
from authentic2_journal import kinds
14

  
15

  
16
class Line(models.Model):
17
    timestamp = models.DateTimeField(auto_now=True, verbose_name=_('timestamp'))
18
    kind = models.ForeignKey(kinds.BaseEvent)
19
    content = JSONField(blank=True,null=True, verbose_name=_('content'))
20

  
21

  
22
class Reference(models.Model):
23
    timestamp = models.DateTimeField(auto_now=True, verbose_name=_('timestamp'))
24
    line = models.ForeignKey(Line)
25
    representation = models.TextField(max_length=64)
26
    target_ct = models.ForeignKey(ContentType)
27
    target_id = models.IntegerField(default=0)
28
    target = GenericForeignKey('target_ct', 'target_id')
src/authentic2_journal/tables.py
1
# -*- coding: utf-8 -*-
2
import django_tables2 as tables
3

  
4
from .models import Reference
5

  
6

  
7
class UserEventsTable(tables.Table):
8
    class Meta:
9
        attrs = {'class': 'main'}
10
        model = Reference
11
        exclude = ['line', 'target_id', 'target_ct']
12
        empty_text = _('None')
src/authentic2_journal/templates/authentic2_journal/user_events.html
1
{% extends "authentic2/manager/base.html" %}
2
{% load i18n staticfiles django_tables2 %}
3

  
4
{% block page_title %}
5
{% trans "User events journal" %}
6
{% endblock %}
7

  
8
{% block content %}
9
  {% render_table table "authentic2/manager/table.html" %}
10
{% endblock %}
src/authentic2_journal/urls.py
1
from django.conf.urls import url
2

  
3
from . import views
4

  
5

  
6
urlpatterns = [
7
    url('^users/(?P<pk>\d+)/$',
8
        views.user_journal,
9
        name='a2-journal-user'),
10
]
src/authentic2_journal/utils.py
1
# -*- coding: utf-8 -*-
2

  
3
from . import kinds
4
from .models import Line, Reference
5
from django.contrib.contenttypes.models import ContentType
6

  
7

  
8
def new_line(user, obj, kind=kinds.BaseEvent, content={}):
9
    line = Line.objects.create(
10
            kind=kind,
11
            content=content)
12
    return line
13

  
14

  
15
def new_reference(line, obj):
16
    reference = Reference.objects.create(
17
            line=line,
18
            target_ct=ContentType.objects.get_for_model(obj.__class),
19
            target_id=obj.pk)
20
    return reference
src/authentic2_journal/views.py
1
# -*- coding: utf-8 -*-
2
from django.contrib.auth import get_user_model
3

  
4
from authentic2.views import SimpleSubTableView
5
from .tables import UserEventsTable
6
from .models import Reference
7
from .utils import get_actions_kinds, get_modification_kinds
8

  
9

  
10
class UserJournal(SimpleSubTableView):
11
    model = get_user_model()
12
    table_class = UserEventsTable
13
    template_name = 'authentic2/manager/user_events.html'
14
    permissions = ['custom_user.view_user']
15
    filter_table_by_perm = False
16

  
17
    def get_table_queryset(self):
18
        return Reference.objects.filter(target=self.object)
19

  
20

  
21
user_journal = UserJournal.as_view()
0
-