Commit 44c1868c10bdb7695ee0a8533c0fde4210592962
1 parent
4fcd4533
Exists in
master
and in
3 other branches
Adding mural logs
Showing
4 changed files
with
330 additions
and
16 deletions
Show diff stats
mural/templates/mural/list_category.html
| ... | ... | @@ -66,6 +66,9 @@ |
| 66 | 66 | </div> |
| 67 | 67 | </div> |
| 68 | 68 | <div id="{{category.slug}}" class="panel-collapse panel-body collapse mural-ungeneral"> |
| 69 | + <input type="hidden" class="log_url" value="{% url 'mural:view_log_cat' category.id %}" /> | |
| 70 | + <input type="hidden" class="log_id" value="" /> | |
| 71 | + | |
| 69 | 72 | <div class="col-md-12 cards-content mural" data-url="{% url 'mural:load_category' category.id %}"> |
| 70 | 73 | <div class="col-sm-12 col-xs-12 visible-xs visible-sm" style="padding-left: 0px"> |
| 71 | 74 | <div class="post-filter post-filter-small"> | ... | ... |
mural/templates/mural/list_subject.html
| ... | ... | @@ -65,6 +65,9 @@ |
| 65 | 65 | </div> |
| 66 | 66 | </div> |
| 67 | 67 | <div id="{{subject.slug}}" class="panel-collapse panel-body collapse mural-ungeneral"> |
| 68 | + <input type="hidden" class="log_url" value="{% url 'mural:view_log_sub' subject.id %}" /> | |
| 69 | + <input type="hidden" class="log_id" value="" /> | |
| 70 | + | |
| 68 | 71 | <div class="col-md-12 cards-content mural" data-url="{% url 'mural:load_subject' subject.id %}"> |
| 69 | 72 | <div class="col-sm-12 col-xs-12 visible-xs visible-sm" style="padding-left: 0px"> |
| 70 | 73 | <div class="post-filter post-filter-small"> | ... | ... |
mural/urls.py
| ... | ... | @@ -19,6 +19,8 @@ urlpatterns = [ |
| 19 | 19 | url(r'^resource/(?P<slug>[\w_-]+)/$', views.ResourceView.as_view(), name='resource_view'), |
| 20 | 20 | url(r'^load_category/([\w_-]+)/$', views.load_category_posts, name='load_category'), |
| 21 | 21 | url(r'^load_subject/([\w_-]+)/$', views.load_subject_posts, name='load_subject'), |
| 22 | + url(r'^view_log_cat/(?P<category>[\w_-]+)/$', views.mural_category_log, name = 'view_log_cat'), | |
| 23 | + url(r'^view_log_sub/(?P<subject>[\w_-]+)/$', views.mural_subject_log, name = 'view_log_sub'), | |
| 22 | 24 | url(r'^favorite/([\w_-]+)/$', views.favorite, name='favorite'), |
| 23 | 25 | url(r'^deleted/$', views.deleted_post, name='deleted_post'), |
| 24 | 26 | url(r'^comment/(?P<post>[\w_-]+)/$', views.CommentCreate.as_view(), name='create_comment'), | ... | ... |
mural/views.py
| ... | ... | @@ -19,6 +19,11 @@ from subjects.models import Subject |
| 19 | 19 | from topics.models import Resource |
| 20 | 20 | from users.models import User |
| 21 | 21 | |
| 22 | +from log.models import Log | |
| 23 | +from log.mixins import LogMixin | |
| 24 | +from log.decorators import log_decorator, log_decorator_ajax | |
| 25 | +import time | |
| 26 | + | |
| 22 | 27 | from .models import Mural, GeneralPost, CategoryPost, SubjectPost, MuralVisualizations, MuralFavorites, Comment |
| 23 | 28 | from .forms import GeneralPostForm, CategoryPostForm, SubjectPostForm, ResourcePostForm, CommentForm |
| 24 | 29 | from .utils import getSpaceUsers |
| ... | ... | @@ -28,7 +33,12 @@ from amadeus.permissions import has_subject_view_permissions, has_resource_permi |
| 28 | 33 | """ |
| 29 | 34 | Section for GeneralPost classes |
| 30 | 35 | """ |
| 31 | -class GeneralIndex(LoginRequiredMixin, generic.ListView): | |
| 36 | +class GeneralIndex(LoginRequiredMixin, LogMixin, generic.ListView): | |
| 37 | + log_component = "mural" | |
| 38 | + log_action = "view" | |
| 39 | + log_resource = "general" | |
| 40 | + log_context = {} | |
| 41 | + | |
| 32 | 42 | login_url = reverse_lazy("users:login") |
| 33 | 43 | redirect_field_name = 'next' |
| 34 | 44 | |
| ... | ... | @@ -80,6 +90,12 @@ class GeneralIndex(LoginRequiredMixin, generic.ListView): |
| 80 | 90 | |
| 81 | 91 | if page: |
| 82 | 92 | self.template_name = "mural/_list_view.html" |
| 93 | + else: | |
| 94 | + self.log_context['timestamp_start'] = str(int(time.time())) | |
| 95 | + | |
| 96 | + super(GeneralIndex, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 97 | + | |
| 98 | + self.request.session['log_id'] = Log.objects.latest('id').id | |
| 83 | 99 | |
| 84 | 100 | context['title'] = _('Mural') |
| 85 | 101 | context['totals'] = self.totals |
| ... | ... | @@ -99,7 +115,12 @@ class GeneralIndex(LoginRequiredMixin, generic.ListView): |
| 99 | 115 | |
| 100 | 116 | return context |
| 101 | 117 | |
| 102 | -class GeneralCreate(LoginRequiredMixin, generic.edit.CreateView): | |
| 118 | +class GeneralCreate(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | |
| 119 | + log_component = "mural" | |
| 120 | + log_action = "create_post" | |
| 121 | + log_resource = "general" | |
| 122 | + log_context = {} | |
| 123 | + | |
| 103 | 124 | login_url = reverse_lazy("users:login") |
| 104 | 125 | redirect_field_name = 'next' |
| 105 | 126 | |
| ... | ... | @@ -144,6 +165,8 @@ class GeneralCreate(LoginRequiredMixin, generic.edit.CreateView): |
| 144 | 165 | |
| 145 | 166 | MuralVisualizations.objects.bulk_create(entries) |
| 146 | 167 | |
| 168 | + super(GeneralCreate, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 169 | + | |
| 147 | 170 | return super(GeneralCreate, self).form_valid(form) |
| 148 | 171 | |
| 149 | 172 | def get_context_data(self, *args, **kwargs): |
| ... | ... | @@ -156,7 +179,12 @@ class GeneralCreate(LoginRequiredMixin, generic.edit.CreateView): |
| 156 | 179 | def get_success_url(self): |
| 157 | 180 | return reverse_lazy('mural:render_post', args = (self.object.id, 'create', 'gen', )) |
| 158 | 181 | |
| 159 | -class GeneralUpdate(LoginRequiredMixin, generic.UpdateView): | |
| 182 | +class GeneralUpdate(LoginRequiredMixin, LogMixin, generic.UpdateView): | |
| 183 | + log_component = "mural" | |
| 184 | + log_action = "edit_post" | |
| 185 | + log_resource = "general" | |
| 186 | + log_context = {} | |
| 187 | + | |
| 160 | 188 | login_url = reverse_lazy("users:login") |
| 161 | 189 | redirect_field_name = 'next' |
| 162 | 190 | |
| ... | ... | @@ -193,6 +221,10 @@ class GeneralUpdate(LoginRequiredMixin, generic.UpdateView): |
| 193 | 221 | |
| 194 | 222 | for user in users: |
| 195 | 223 | Group("user-%s" % user.id).send({'text': notification}) |
| 224 | + | |
| 225 | + self.log_context['post_id'] = str(self.object.id) | |
| 226 | + | |
| 227 | + super(GeneralUpdate, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 196 | 228 | |
| 197 | 229 | return super(GeneralUpdate, self).form_valid(form) |
| 198 | 230 | |
| ... | ... | @@ -206,7 +238,12 @@ class GeneralUpdate(LoginRequiredMixin, generic.UpdateView): |
| 206 | 238 | def get_success_url(self): |
| 207 | 239 | return reverse_lazy('mural:render_post', args = (self.object.id, 'update', 'gen', )) |
| 208 | 240 | |
| 209 | -class GeneralDelete(LoginRequiredMixin, generic.DeleteView): | |
| 241 | +class GeneralDelete(LoginRequiredMixin, LogMixin, generic.DeleteView): | |
| 242 | + log_component = "mural" | |
| 243 | + log_action = "delete_post" | |
| 244 | + log_resource = "general" | |
| 245 | + log_context = {} | |
| 246 | + | |
| 210 | 247 | login_url = reverse_lazy("users:login") |
| 211 | 248 | redirect_field_name = 'next' |
| 212 | 249 | |
| ... | ... | @@ -238,6 +275,10 @@ class GeneralDelete(LoginRequiredMixin, generic.DeleteView): |
| 238 | 275 | for user in users: |
| 239 | 276 | Group("user-%s" % user.id).send({'text': notification}) |
| 240 | 277 | |
| 278 | + self.log_context['post_id'] = str(self.object.id) | |
| 279 | + | |
| 280 | + super(GeneralDelete, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 281 | + | |
| 241 | 282 | return reverse_lazy('mural:deleted_post') |
| 242 | 283 | |
| 243 | 284 | """ |
| ... | ... | @@ -327,7 +368,12 @@ class CategoryIndex(LoginRequiredMixin, generic.ListView): |
| 327 | 368 | |
| 328 | 369 | return context |
| 329 | 370 | |
| 330 | -class CategoryCreate(LoginRequiredMixin, generic.edit.CreateView): | |
| 371 | +class CategoryCreate(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | |
| 372 | + log_component = "mural" | |
| 373 | + log_action = "create_post" | |
| 374 | + log_resource = "category" | |
| 375 | + log_context = {} | |
| 376 | + | |
| 331 | 377 | login_url = reverse_lazy("users:login") |
| 332 | 378 | redirect_field_name = 'next' |
| 333 | 379 | |
| ... | ... | @@ -376,6 +422,12 @@ class CategoryCreate(LoginRequiredMixin, generic.edit.CreateView): |
| 376 | 422 | |
| 377 | 423 | MuralVisualizations.objects.bulk_create(entries) |
| 378 | 424 | |
| 425 | + self.log_context['category_id'] = self.object.space.id | |
| 426 | + self.log_context['category_name'] = self.object.space.name | |
| 427 | + self.log_context['category_slug'] = self.object.space.slug | |
| 428 | + | |
| 429 | + super(CategoryCreate, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 430 | + | |
| 379 | 431 | return super(CategoryCreate, self).form_valid(form) |
| 380 | 432 | |
| 381 | 433 | def get_context_data(self, *args, **kwargs): |
| ... | ... | @@ -388,7 +440,12 @@ class CategoryCreate(LoginRequiredMixin, generic.edit.CreateView): |
| 388 | 440 | def get_success_url(self): |
| 389 | 441 | return reverse_lazy('mural:render_post', args = (self.object.id, 'create', 'cat', )) |
| 390 | 442 | |
| 391 | -class CategoryUpdate(LoginRequiredMixin, generic.UpdateView): | |
| 443 | +class CategoryUpdate(LoginRequiredMixin, LogMixin, generic.UpdateView): | |
| 444 | + log_component = "mural" | |
| 445 | + log_action = "edit_post" | |
| 446 | + log_resource = "category" | |
| 447 | + log_context = {} | |
| 448 | + | |
| 392 | 449 | login_url = reverse_lazy("users:login") |
| 393 | 450 | redirect_field_name = 'next' |
| 394 | 451 | |
| ... | ... | @@ -426,6 +483,13 @@ class CategoryUpdate(LoginRequiredMixin, generic.UpdateView): |
| 426 | 483 | for user in users: |
| 427 | 484 | Group("user-%s" % user.id).send({'text': notification}) |
| 428 | 485 | |
| 486 | + self.log_context['post_id'] = self.object.id | |
| 487 | + self.log_context['category_id'] = self.object.space.id | |
| 488 | + self.log_context['category_name'] = self.object.space.name | |
| 489 | + self.log_context['category_slug'] = self.object.space.slug | |
| 490 | + | |
| 491 | + super(CategoryUpdate, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 492 | + | |
| 429 | 493 | return super(CategoryUpdate, self).form_valid(form) |
| 430 | 494 | |
| 431 | 495 | def get_context_data(self, *args, **kwargs): |
| ... | ... | @@ -438,7 +502,12 @@ class CategoryUpdate(LoginRequiredMixin, generic.UpdateView): |
| 438 | 502 | def get_success_url(self): |
| 439 | 503 | return reverse_lazy('mural:render_post', args = (self.object.id, 'update', 'cat', )) |
| 440 | 504 | |
| 441 | -class CategoryDelete(LoginRequiredMixin, generic.DeleteView): | |
| 505 | +class CategoryDelete(LoginRequiredMixin, LogMixin, generic.DeleteView): | |
| 506 | + log_component = "mural" | |
| 507 | + log_action = "delete_post" | |
| 508 | + log_resource = "category" | |
| 509 | + log_context = {} | |
| 510 | + | |
| 442 | 511 | login_url = reverse_lazy("users:login") |
| 443 | 512 | redirect_field_name = 'next' |
| 444 | 513 | |
| ... | ... | @@ -470,8 +539,37 @@ class CategoryDelete(LoginRequiredMixin, generic.DeleteView): |
| 470 | 539 | for user in users: |
| 471 | 540 | Group("user-%s" % user.id).send({'text': notification}) |
| 472 | 541 | |
| 542 | + self.log_context['post_id'] = self.object.id | |
| 543 | + self.log_context['category_id'] = self.object.space.id | |
| 544 | + self.log_context['category_name'] = self.object.space.name | |
| 545 | + self.log_context['category_slug'] = self.object.space.slug | |
| 546 | + | |
| 547 | + super(CategoryDelete, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 548 | + | |
| 473 | 549 | return reverse_lazy('mural:deleted_post') |
| 474 | 550 | |
| 551 | +@log_decorator_ajax('mural', 'view', 'category') | |
| 552 | +def mural_category_log(request, category): | |
| 553 | + action = request.GET.get('action') | |
| 554 | + | |
| 555 | + if action == 'open': | |
| 556 | + category = get_object_or_404(Category, id = category) | |
| 557 | + | |
| 558 | + log_context = {} | |
| 559 | + log_context['category_id'] = category.id | |
| 560 | + log_context['category_name'] = category.name | |
| 561 | + log_context['category_slug'] = category.slug | |
| 562 | + log_context['timestamp_start'] = str(int(time.time())) | |
| 563 | + log_context['timestamp_end'] = '-1' | |
| 564 | + | |
| 565 | + request.log_context = log_context | |
| 566 | + | |
| 567 | + log_id = Log.objects.latest('id').id | |
| 568 | + | |
| 569 | + return JsonResponse({'message': 'ok', 'log_id': log_id}) | |
| 570 | + | |
| 571 | + return JsonResponse({'message': 'ok'}) | |
| 572 | + | |
| 475 | 573 | """ |
| 476 | 574 | Section for SubjectPost classes |
| 477 | 575 | """ |
| ... | ... | @@ -559,7 +657,12 @@ class SubjectIndex(LoginRequiredMixin, generic.ListView): |
| 559 | 657 | |
| 560 | 658 | return context |
| 561 | 659 | |
| 562 | -class SubjectCreate(LoginRequiredMixin, generic.edit.CreateView): | |
| 660 | +class SubjectCreate(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | |
| 661 | + log_component = "mural" | |
| 662 | + log_action = "create_post" | |
| 663 | + log_resource = "subject" | |
| 664 | + log_context = {} | |
| 665 | + | |
| 563 | 666 | login_url = reverse_lazy("users:login") |
| 564 | 667 | redirect_field_name = 'next' |
| 565 | 668 | |
| ... | ... | @@ -625,6 +728,17 @@ class SubjectCreate(LoginRequiredMixin, generic.edit.CreateView): |
| 625 | 728 | |
| 626 | 729 | MuralVisualizations.objects.bulk_create(entries) |
| 627 | 730 | |
| 731 | + self.log_context['subject_id'] = self.object.space.id | |
| 732 | + self.log_context['subject_name'] = self.object.space.name | |
| 733 | + self.log_context['subject_slug'] = self.object.space.slug | |
| 734 | + | |
| 735 | + if self.object.resource: | |
| 736 | + self.log_context['resource_id'] = self.object.resource.id | |
| 737 | + self.log_context['resource_name'] = self.object.resource.name | |
| 738 | + self.log_context['resource_slug'] = self.object.resource.slug | |
| 739 | + | |
| 740 | + super(SubjectCreate, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 741 | + | |
| 628 | 742 | return super(SubjectCreate, self).form_valid(form) |
| 629 | 743 | |
| 630 | 744 | def get_context_data(self, *args, **kwargs): |
| ... | ... | @@ -637,7 +751,12 @@ class SubjectCreate(LoginRequiredMixin, generic.edit.CreateView): |
| 637 | 751 | def get_success_url(self): |
| 638 | 752 | return reverse_lazy('mural:render_post', args = (self.object.id, 'create', 'sub', )) |
| 639 | 753 | |
| 640 | -class SubjectUpdate(LoginRequiredMixin, generic.UpdateView): | |
| 754 | +class SubjectUpdate(LoginRequiredMixin, LogMixin, generic.UpdateView): | |
| 755 | + log_component = "mural" | |
| 756 | + log_action = "edit_post" | |
| 757 | + log_resource = "subject" | |
| 758 | + log_context = {} | |
| 759 | + | |
| 641 | 760 | login_url = reverse_lazy("users:login") |
| 642 | 761 | redirect_field_name = 'next' |
| 643 | 762 | |
| ... | ... | @@ -694,6 +813,18 @@ class SubjectUpdate(LoginRequiredMixin, generic.UpdateView): |
| 694 | 813 | |
| 695 | 814 | for user in users: |
| 696 | 815 | Group("user-%s" % user.id).send({'text': notification}) |
| 816 | + | |
| 817 | + self.log_context['post_id'] = self.object.id | |
| 818 | + self.log_context['subject_id'] = self.object.space.id | |
| 819 | + self.log_context['subject_name'] = self.object.space.name | |
| 820 | + self.log_context['subject_slug'] = self.object.space.slug | |
| 821 | + | |
| 822 | + if self.object.resource: | |
| 823 | + self.log_context['resource_id'] = self.object.resource.id | |
| 824 | + self.log_context['resource_name'] = self.object.resource.name | |
| 825 | + self.log_context['resource_slug'] = self.object.resource.slug | |
| 826 | + | |
| 827 | + super(SubjectUpdate, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 697 | 828 | |
| 698 | 829 | return super(SubjectUpdate, self).form_valid(form) |
| 699 | 830 | |
| ... | ... | @@ -707,7 +838,12 @@ class SubjectUpdate(LoginRequiredMixin, generic.UpdateView): |
| 707 | 838 | def get_success_url(self): |
| 708 | 839 | return reverse_lazy('mural:render_post', args = (self.object.id, 'update', 'sub', )) |
| 709 | 840 | |
| 710 | -class SubjectDelete(LoginRequiredMixin, generic.DeleteView): | |
| 841 | +class SubjectDelete(LoginRequiredMixin, LogMixin, generic.DeleteView): | |
| 842 | + log_component = "mural" | |
| 843 | + log_action = "delete_post" | |
| 844 | + log_resource = "subject" | |
| 845 | + log_context = {} | |
| 846 | + | |
| 711 | 847 | login_url = reverse_lazy("users:login") |
| 712 | 848 | redirect_field_name = 'next' |
| 713 | 849 | |
| ... | ... | @@ -745,9 +881,26 @@ class SubjectDelete(LoginRequiredMixin, generic.DeleteView): |
| 745 | 881 | for user in users: |
| 746 | 882 | Group("user-%s" % user.id).send({'text': notification}) |
| 747 | 883 | |
| 884 | + self.log_context['post_id'] = self.object.id | |
| 885 | + self.log_context['subject_id'] = self.object.space.id | |
| 886 | + self.log_context['subject_name'] = self.object.space.name | |
| 887 | + self.log_context['subject_slug'] = self.object.space.slug | |
| 888 | + | |
| 889 | + if self.object.resource: | |
| 890 | + self.log_context['resource_id'] = self.object.resource.id | |
| 891 | + self.log_context['resource_name'] = self.object.resource.name | |
| 892 | + self.log_context['resource_slug'] = self.object.resource.slug | |
| 893 | + | |
| 894 | + super(SubjectDelete, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 895 | + | |
| 748 | 896 | return reverse_lazy('mural:deleted_post') |
| 749 | 897 | |
| 750 | -class SubjectView(LoginRequiredMixin, generic.ListView): | |
| 898 | +class SubjectView(LoginRequiredMixin, LogMixin, generic.ListView): | |
| 899 | + log_component = "mural" | |
| 900 | + log_action = "view" | |
| 901 | + log_resource = "subject" | |
| 902 | + log_context = {} | |
| 903 | + | |
| 751 | 904 | login_url = reverse_lazy("users:login") |
| 752 | 905 | redirect_field_name = 'next' |
| 753 | 906 | |
| ... | ... | @@ -802,6 +955,15 @@ class SubjectView(LoginRequiredMixin, generic.ListView): |
| 802 | 955 | |
| 803 | 956 | if page: |
| 804 | 957 | self.template_name = "mural/_list_view.html" |
| 958 | + else: | |
| 959 | + self.log_context['subject_id'] = subject.id | |
| 960 | + self.log_context['subject_name'] = subject.name | |
| 961 | + self.log_context['subject_slug'] = subject.slug | |
| 962 | + self.log_context['timestamp_start'] = str(int(time.time())) | |
| 963 | + | |
| 964 | + super(SubjectView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 965 | + | |
| 966 | + self.request.session['log_id'] = Log.objects.latest('id').id | |
| 805 | 967 | |
| 806 | 968 | context['title'] = _('%s - Mural')%(str(subject)) |
| 807 | 969 | context['subject'] = subject |
| ... | ... | @@ -820,10 +982,37 @@ class SubjectView(LoginRequiredMixin, generic.ListView): |
| 820 | 982 | |
| 821 | 983 | return context |
| 822 | 984 | |
| 985 | +@log_decorator_ajax('mural', 'view', 'subject') | |
| 986 | +def mural_subject_log(request, subject): | |
| 987 | + action = request.GET.get('action') | |
| 988 | + | |
| 989 | + if action == 'open': | |
| 990 | + subject = get_object_or_404(Subject, id = subject) | |
| 991 | + | |
| 992 | + log_context = {} | |
| 993 | + log_context['subject_id'] = subject.id | |
| 994 | + log_context['subject_name'] = subject.name | |
| 995 | + log_context['subject_slug'] = subject.slug | |
| 996 | + log_context['timestamp_start'] = str(int(time.time())) | |
| 997 | + log_context['timestamp_end'] = '-1' | |
| 998 | + | |
| 999 | + request.log_context = log_context | |
| 1000 | + | |
| 1001 | + log_id = Log.objects.latest('id').id | |
| 1002 | + | |
| 1003 | + return JsonResponse({'message': 'ok', 'log_id': log_id}) | |
| 1004 | + | |
| 1005 | + return JsonResponse({'message': 'ok'}) | |
| 1006 | + | |
| 823 | 1007 | """ |
| 824 | 1008 | Section for specific resource post classes |
| 825 | 1009 | """ |
| 826 | -class ResourceView(LoginRequiredMixin, generic.ListView): | |
| 1010 | +class ResourceView(LoginRequiredMixin, LogMixin, generic.ListView): | |
| 1011 | + log_component = "mural" | |
| 1012 | + log_action = "view" | |
| 1013 | + log_resource = "subject" | |
| 1014 | + log_context = {} | |
| 1015 | + | |
| 827 | 1016 | login_url = reverse_lazy("users:login") |
| 828 | 1017 | redirect_field_name = 'next' |
| 829 | 1018 | |
| ... | ... | @@ -879,6 +1068,18 @@ class ResourceView(LoginRequiredMixin, generic.ListView): |
| 879 | 1068 | |
| 880 | 1069 | if page: |
| 881 | 1070 | self.template_name = "mural/_list_view.html" |
| 1071 | + else: | |
| 1072 | + self.log_context['subject_id'] = resource.topic.subject.id | |
| 1073 | + self.log_context['subject_name'] = resource.topic.subject.name | |
| 1074 | + self.log_context['subject_slug'] = resource.topic.subject.slug | |
| 1075 | + self.log_context['resource_id'] = resource.id | |
| 1076 | + self.log_context['resource_name'] = resource.name | |
| 1077 | + self.log_context['resource_slug'] = resource.slug | |
| 1078 | + self.log_context['timestamp_start'] = str(int(time.time())) | |
| 1079 | + | |
| 1080 | + super(ResourceView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 1081 | + | |
| 1082 | + self.request.session['log_id'] = Log.objects.latest('id').id | |
| 882 | 1083 | |
| 883 | 1084 | context['title'] = _('%s - Mural')%(str(resource)) |
| 884 | 1085 | context['subject'] = resource.topic.subject |
| ... | ... | @@ -898,7 +1099,12 @@ class ResourceView(LoginRequiredMixin, generic.ListView): |
| 898 | 1099 | |
| 899 | 1100 | return context |
| 900 | 1101 | |
| 901 | -class ResourceCreate(LoginRequiredMixin, generic.edit.CreateView): | |
| 1102 | +class ResourceCreate(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | |
| 1103 | + log_component = "mural" | |
| 1104 | + log_action = "create_post" | |
| 1105 | + log_resource = "subject" | |
| 1106 | + log_context = {} | |
| 1107 | + | |
| 902 | 1108 | login_url = reverse_lazy("users:login") |
| 903 | 1109 | redirect_field_name = 'next' |
| 904 | 1110 | |
| ... | ... | @@ -957,6 +1163,17 @@ class ResourceCreate(LoginRequiredMixin, generic.edit.CreateView): |
| 957 | 1163 | |
| 958 | 1164 | MuralVisualizations.objects.bulk_create(entries) |
| 959 | 1165 | |
| 1166 | + self.log_context['subject_id'] = self.object.space.id | |
| 1167 | + self.log_context['subject_name'] = self.object.space.name | |
| 1168 | + self.log_context['subject_slug'] = self.object.space.slug | |
| 1169 | + | |
| 1170 | + if self.object.resource: | |
| 1171 | + self.log_context['resource_id'] = self.object.resource.id | |
| 1172 | + self.log_context['resource_name'] = self.object.resource.name | |
| 1173 | + self.log_context['resource_slug'] = self.object.resource.slug | |
| 1174 | + | |
| 1175 | + super(ResourceCreate, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 1176 | + | |
| 960 | 1177 | return super(ResourceCreate, self).form_valid(form) |
| 961 | 1178 | |
| 962 | 1179 | def get_context_data(self, *args, **kwargs): |
| ... | ... | @@ -1014,7 +1231,12 @@ def favorite(request, post): |
| 1014 | 1231 | """ |
| 1015 | 1232 | Section for comment functions |
| 1016 | 1233 | """ |
| 1017 | -class CommentCreate(LoginRequiredMixin, generic.edit.CreateView): | |
| 1234 | +class CommentCreate(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | |
| 1235 | + log_component = "mural" | |
| 1236 | + log_action = "create_comment" | |
| 1237 | + log_resource = "general" | |
| 1238 | + log_context = {} | |
| 1239 | + | |
| 1018 | 1240 | login_url = reverse_lazy("users:login") |
| 1019 | 1241 | redirect_field_name = 'next' |
| 1020 | 1242 | |
| ... | ... | @@ -1073,6 +1295,30 @@ class CommentCreate(LoginRequiredMixin, generic.edit.CreateView): |
| 1073 | 1295 | |
| 1074 | 1296 | MuralVisualizations.objects.bulk_create(entries) |
| 1075 | 1297 | |
| 1298 | + self.log_context = {} | |
| 1299 | + self.log_context['post_id'] = str(post.id) | |
| 1300 | + | |
| 1301 | + if post._my_subclass == "categorypost": | |
| 1302 | + self.log_resource = "category" | |
| 1303 | + | |
| 1304 | + self.log_context['category_id'] = post.categorypost.space.id | |
| 1305 | + self.log_context['category_name'] = post.categorypost.space.name | |
| 1306 | + self.log_context['category_slug'] = post.categorypost.space.slug | |
| 1307 | + | |
| 1308 | + elif post._my_subclass == "subjectpost": | |
| 1309 | + self.log_resource = "subject" | |
| 1310 | + | |
| 1311 | + self.log_context['subject_id'] = post.subjectpost.space.id | |
| 1312 | + self.log_context['subject_name'] = post.subjectpost.space.name | |
| 1313 | + self.log_context['subject_slug'] = post.subjectpost.space.slug | |
| 1314 | + | |
| 1315 | + if post.subjectpost.resource: | |
| 1316 | + self.log_context['resource_id'] = post.subjectpost.resource.id | |
| 1317 | + self.log_context['resource_name'] = post.subjectpost.resource.name | |
| 1318 | + self.log_context['resource_slug'] = post.subjectpost.resource.slug | |
| 1319 | + | |
| 1320 | + super(CommentCreate, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 1321 | + | |
| 1076 | 1322 | return super(CommentCreate, self).form_valid(form) |
| 1077 | 1323 | |
| 1078 | 1324 | def get_context_data(self, *args, **kwargs): |
| ... | ... | @@ -1087,7 +1333,12 @@ class CommentCreate(LoginRequiredMixin, generic.edit.CreateView): |
| 1087 | 1333 | def get_success_url(self): |
| 1088 | 1334 | return reverse_lazy('mural:render_comment', args = (self.object.id, 'create', )) |
| 1089 | 1335 | |
| 1090 | -class CommentUpdate(LoginRequiredMixin, generic.UpdateView): | |
| 1336 | +class CommentUpdate(LoginRequiredMixin, LogMixin, generic.UpdateView): | |
| 1337 | + log_component = "mural" | |
| 1338 | + log_action = "edit_comment" | |
| 1339 | + log_resource = "general" | |
| 1340 | + log_context = {} | |
| 1341 | + | |
| 1091 | 1342 | login_url = reverse_lazy("users:login") |
| 1092 | 1343 | redirect_field_name = 'next' |
| 1093 | 1344 | |
| ... | ... | @@ -1134,6 +1385,31 @@ class CommentUpdate(LoginRequiredMixin, generic.UpdateView): |
| 1134 | 1385 | |
| 1135 | 1386 | for user in users: |
| 1136 | 1387 | Group("user-%s" % user.id).send({'text': notification}) |
| 1388 | + | |
| 1389 | + self.log_context = {} | |
| 1390 | + self.log_context['post_id'] = str(self.object.post.id) | |
| 1391 | + self.log_context['comment_id'] = str(self.object.id) | |
| 1392 | + | |
| 1393 | + if self.object.post._my_subclass == "categorypost": | |
| 1394 | + self.log_resource = "category" | |
| 1395 | + | |
| 1396 | + self.log_context['category_id'] = self.object.post.categorypost.space.id | |
| 1397 | + self.log_context['category_name'] = self.object.post.categorypost.space.name | |
| 1398 | + self.log_context['category_slug'] = self.object.post.categorypost.space.slug | |
| 1399 | + | |
| 1400 | + elif self.object.post._my_subclass == "subjectpost": | |
| 1401 | + self.log_resource = "subject" | |
| 1402 | + | |
| 1403 | + self.log_context['subject_id'] = self.object.post.subjectpost.space.id | |
| 1404 | + self.log_context['subject_name'] = self.object.post.subjectpost.space.name | |
| 1405 | + self.log_context['subject_slug'] = self.object.post.subjectpost.space.slug | |
| 1406 | + | |
| 1407 | + if self.object.post.subjectpost.resource: | |
| 1408 | + self.log_context['resource_id'] = self.object.post.subjectpost.resource.id | |
| 1409 | + self.log_context['resource_name'] = self.object.post.subjectpost.resource.name | |
| 1410 | + self.log_context['resource_slug'] = self.object.post.subjectpost.resource.slug | |
| 1411 | + | |
| 1412 | + super(CommentUpdate, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 1137 | 1413 | |
| 1138 | 1414 | return super(CommentUpdate, self).form_valid(form) |
| 1139 | 1415 | |
| ... | ... | @@ -1147,7 +1423,12 @@ class CommentUpdate(LoginRequiredMixin, generic.UpdateView): |
| 1147 | 1423 | def get_success_url(self): |
| 1148 | 1424 | return reverse_lazy('mural:render_comment', args = (self.object.id, 'update', )) |
| 1149 | 1425 | |
| 1150 | -class CommentDelete(LoginRequiredMixin, generic.DeleteView): | |
| 1426 | +class CommentDelete(LoginRequiredMixin, LogMixin, generic.DeleteView): | |
| 1427 | + log_component = "mural" | |
| 1428 | + log_action = "delete_comment" | |
| 1429 | + log_resource = "general" | |
| 1430 | + log_context = {} | |
| 1431 | + | |
| 1151 | 1432 | login_url = reverse_lazy("users:login") |
| 1152 | 1433 | redirect_field_name = 'next' |
| 1153 | 1434 | |
| ... | ... | @@ -1189,6 +1470,31 @@ class CommentDelete(LoginRequiredMixin, generic.DeleteView): |
| 1189 | 1470 | for user in users: |
| 1190 | 1471 | Group("user-%s" % user.id).send({'text': notification}) |
| 1191 | 1472 | |
| 1473 | + self.log_context = {} | |
| 1474 | + self.log_context['post_id'] = str(self.object.post.id) | |
| 1475 | + self.log_context['comment_id'] = str(self.object.id) | |
| 1476 | + | |
| 1477 | + if self.object.post._my_subclass == "categorypost": | |
| 1478 | + self.log_resource = "category" | |
| 1479 | + | |
| 1480 | + self.log_context['category_id'] = self.object.post.categorypost.space.id | |
| 1481 | + self.log_context['category_name'] = self.object.post.categorypost.space.name | |
| 1482 | + self.log_context['category_slug'] = self.object.post.categorypost.space.slug | |
| 1483 | + | |
| 1484 | + elif self.object.post._my_subclass == "subjectpost": | |
| 1485 | + self.log_resource = "subject" | |
| 1486 | + | |
| 1487 | + self.log_context['subject_id'] = self.object.post.subjectpost.space.id | |
| 1488 | + self.log_context['subject_name'] = self.object.post.subjectpost.space.name | |
| 1489 | + self.log_context['subject_slug'] = self.object.post.subjectpost.space.slug | |
| 1490 | + | |
| 1491 | + if self.object.post.subjectpost.resource: | |
| 1492 | + self.log_context['resource_id'] = self.object.post.subjectpost.resource.id | |
| 1493 | + self.log_context['resource_name'] = self.object.post.subjectpost.resource.name | |
| 1494 | + self.log_context['resource_slug'] = self.object.post.subjectpost.resource.slug | |
| 1495 | + | |
| 1496 | + super(CommentDelete, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 1497 | + | |
| 1192 | 1498 | return reverse_lazy('mural:deleted_comment') |
| 1193 | 1499 | |
| 1194 | 1500 | def render_comment(request, comment, msg): | ... | ... |