0001-WIP-user-actions-and-modifications-journals-20695.patch
src/authentic2/manager/tables.py | ||
---|---|---|
8 | 8 |
from django_rbac.utils import get_role_model, get_permission_model, \ |
9 | 9 |
get_ou_model |
10 | 10 | |
11 |
from authentic2.models import Service |
|
11 |
from authentic2.models import Service, Journal
|
|
12 | 12 |
from authentic2.compat import get_user_model |
13 | 13 |
from authentic2.middleware import StoreRequestMiddleware |
14 | 14 | |
... | ... | |
163 | 163 |
attrs = {'class': 'main', 'id': 'service-role-table'} |
164 | 164 |
fields = ('name',) |
165 | 165 |
empty_text = _('No access restriction. All users are allowed to connect to this service.') |
166 | ||
167 | ||
168 |
class UserActionsTable(tables.Table): |
|
169 |
class Meta: |
|
170 |
attrs = {'class': 'main'} |
|
171 |
model = Journal |
|
172 |
exclude = ['id', 'actor'] |
|
173 |
empty_text = _('None') |
|
174 | ||
175 | ||
176 |
class UserModificationsTable(tables.Table): |
|
177 |
class Meta: |
|
178 |
attrs = {'class': 'main'} |
|
179 |
model = Journal |
|
180 |
exclude = ['id', 'subject'] |
|
181 |
empty_text = _('None') |
src/authentic2/manager/templates/authentic2/manager/user_actions_journal.html | ||
---|---|---|
1 |
{% extends "authentic2/manager/base.html" %} |
|
2 |
{% load i18n staticfiles django_tables2 %} |
|
3 | ||
4 |
{% block breadcrumb %} |
|
5 |
{{ block.super }} |
|
6 |
<a href="{% url 'a2-manager-users' %}{% if object.ou %}?search-ou={{ object.ou.pk }}{% endif %}">{% trans 'Users' %}{% if object.ou %} : {{ object.ou }}{% endif %}</a> |
|
7 |
<a href="{% url 'a2-manager-user-detail' pk=object.pk %}">{{ object.get_full_name }}</a> |
|
8 |
<a href="#">Journal des actions</a> |
|
9 | ||
10 |
{% endblock %} |
|
11 | ||
12 |
{% block page_title %} |
|
13 |
Journal des actions |
|
14 |
{% endblock %} |
|
15 | ||
16 |
{% block content %} |
|
17 |
{% render_table table "authentic2/manager/table.html" %} |
|
18 |
{% endblock %} |
src/authentic2/manager/templates/authentic2/manager/user_modifications_journal.html | ||
---|---|---|
1 |
{% extends "authentic2/manager/base.html" %} |
|
2 |
{% load i18n staticfiles django_tables2 %} |
|
3 | ||
4 |
{% block breadcrumb %} |
|
5 |
{{ block.super }} |
|
6 |
<a href="{% url 'a2-manager-users' %}{% if object.ou %}?search-ou={{ object.ou.pk }}{% endif %}">{% trans 'Users' %}{% if object.ou %} : {{ object.ou }}{% endif %}</a> |
|
7 |
<a href="{% url 'a2-manager-user-detail' pk=object.pk %}">{{ object.get_full_name }}</a> |
|
8 |
<a href="#">Journal des modifications</a> |
|
9 | ||
10 |
{% endblock %} |
|
11 | ||
12 |
{% block page_title %} |
|
13 |
Journal des modifications |
|
14 |
{% endblock %} |
|
15 | ||
16 |
{% block content %} |
|
17 |
{% render_table table "authentic2/manager/table.html" %} |
|
18 |
{% endblock %} |
src/authentic2/manager/urls.py | ||
---|---|---|
38 | 38 |
url(r'^users/(?P<pk>\d+)/change-email/$', |
39 | 39 |
user_views.user_change_email, |
40 | 40 |
name='a2-manager-user-change-email'), |
41 |
url('^users/(?P<pk>\d+)/actions-journal/$', |
|
42 |
user_views.user_actions_journal, |
|
43 |
name='a2-manager-user-actions-journal'), |
|
44 |
url('^users/(?P<pk>\d+)/modifications-journal/$', |
|
45 |
user_views.user_modifications_journal, |
|
46 |
name='a2-manager-user-modifications-journal'), |
|
41 | 47 |
# by uuid |
42 | 48 |
url(r'^users/uuid:(?P<slug>[a-z0-9]+)/$', user_views.user_detail, |
43 | 49 |
name='a2-manager-user-by-uuid-detail'), |
src/authentic2/manager/user_views.py | ||
---|---|---|
18 | 18 |
from import_export.fields import Field |
19 | 19 | |
20 | 20 |
from authentic2.constants import SWITCH_USER_SESSION_KEY |
21 |
from authentic2.models import Attribute, PasswordReset |
|
21 |
from authentic2.models import Attribute, PasswordReset, Journal
|
|
22 | 22 |
from authentic2.utils import switch_user, send_password_reset_mail, redirect, send_email_change_email |
23 | 23 |
from authentic2.a2_rbac.utils import get_default_ou |
24 | 24 |
from authentic2 import hooks |
... | ... | |
27 | 27 | |
28 | 28 |
from .views import BaseTableView, BaseAddView, \ |
29 | 29 |
BaseEditView, ActionMixin, OtherActionsMixin, Action, ExportMixin, \ |
30 |
BaseSubTableView, HideOUColumnMixin, BaseDeleteView, BaseDetailView |
|
31 |
from .tables import UserTable, UserRolesTable, OuUserRolesTable |
|
30 |
BaseSubTableView, HideOUColumnMixin, BaseDeleteView, BaseDetailView, \ |
|
31 |
SimpleSubTableView |
|
32 |
from .tables import UserTable, UserRolesTable, OuUserRolesTable, \ |
|
33 |
UserActionsTable, UserModificationsTable |
|
32 | 34 |
from .forms import (UserSearchForm, UserAddForm, UserEditForm, |
33 | 35 |
UserChangePasswordForm, ChooseUserRoleForm, UserRoleSearchForm, UserChangeEmailForm) |
34 | 36 |
from .resources import UserResource |
... | ... | |
510 | 512 | |
511 | 513 | |
512 | 514 |
user_delete = UserDeleteView.as_view() |
515 | ||
516 | ||
517 |
class UserActionsJournal(SimpleSubTableView): |
|
518 |
model = get_user_model() |
|
519 |
table_class = UserActionsTable |
|
520 |
template_name = 'authentic2/manager/user_actions_journal.html' |
|
521 |
permissions = ['custom_user.view_user'] |
|
522 |
filter_table_by_perm = False |
|
523 | ||
524 |
def get_table_queryset(self): |
|
525 |
return self.object.actor_journal.all() |
|
526 | ||
527 | ||
528 |
user_actions_journal = UserActionsJournal.as_view() |
|
529 | ||
530 | ||
531 |
class UserModificationsJournal(SimpleSubTableView): |
|
532 |
model = get_user_model() |
|
533 |
table_class = UserModificationsTable |
|
534 |
template_name = 'authentic2/manager/user_modifications_journal.html' |
|
535 |
permissions = ['custom_user.view_user'] |
|
536 |
filter_table_by_perm = False |
|
537 | ||
538 |
def get_table_queryset(self): |
|
539 |
return self.object.subject_journal.all() |
|
540 | ||
541 | ||
542 |
user_modifications_journal = UserModificationsJournal.as_view() |
src/authentic2/models.py | ||
---|---|---|
416 | 416 |
class AuthorizedRole(models.Model): |
417 | 417 |
service = models.ForeignKey(Service, on_delete=models.CASCADE) |
418 | 418 |
role = models.ForeignKey(get_role_model_name(), on_delete=models.CASCADE) |
419 | ||
420 | ||
421 |
class Journal(models.Model): |
|
422 |
timestamp = models.DateTimeField( |
|
423 |
verbose_name=u'Horodatage', |
|
424 |
db_index=True, |
|
425 |
auto_now_add=True) |
|
426 |
actor = models.ForeignKey( |
|
427 |
settings.AUTH_USER_MODEL, |
|
428 |
verbose_name=u'Auteur', |
|
429 |
null=True, |
|
430 |
related_name='actor_journal') |
|
431 |
subject = models.ForeignKey( |
|
432 |
settings.AUTH_USER_MODEL, |
|
433 |
verbose_name='Sujet', |
|
434 |
null=True, |
|
435 |
related_name='subject_journal') |
|
436 |
message = models.TextField( |
|
437 |
verbose_name='Message', |
|
438 |
null=True) |
|
419 |
- |