Commit 69144042dc03637b2b98e0e22407db0ff8716b10
1 parent
7b215765
Exists in
master
and in
2 other branches
Adjusting subject mural post with resource visualization permissions
Showing
2 changed files
with
52 additions
and
22 deletions
Show diff stats
mural/utils.py
1 | from django.db.models import Q | 1 | from django.db.models import Q |
2 | 2 | ||
3 | +from .models import SubjectPost | ||
4 | + | ||
3 | from users.models import User | 5 | from users.models import User |
4 | 6 | ||
5 | def getSpaceUsers(user, post): | 7 | def getSpaceUsers(user, post): |
@@ -19,4 +21,50 @@ def getSpaceUsers(user, post): | @@ -19,4 +21,50 @@ def getSpaceUsers(user, post): | ||
19 | else: | 21 | else: |
20 | return User.objects.filter(Q(is_staff = True) | Q(professors__id = space) | Q(coordinators__subject_category__id = space) | Q(subject_student__id = space)).exclude(id = user).distinct() | 22 | return User.objects.filter(Q(is_staff = True) | Q(professors__id = space) | Q(coordinators__subject_category__id = space) | Q(subject_student__id = space)).exclude(id = user).distinct() |
21 | 23 | ||
22 | - return None | ||
23 | \ No newline at end of file | 24 | \ No newline at end of file |
25 | + return None | ||
26 | + | ||
27 | +def getSubjectPosts(subject, user, favorites, mines): | ||
28 | + if not favorites: | ||
29 | + if mines: | ||
30 | + if not user.is_staff: | ||
31 | + posts = SubjectPost.objects.extra(select = {"most_recent": "greatest(mural_mural.last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_subjectpost.mural_ptr_id))"}).filter( | ||
32 | + Q(space__id = subject) & Q(mural_ptr__user = user) & ( | ||
33 | + Q(space__category__coordinators = user) | | ||
34 | + Q(space__professor = user) | | ||
35 | + Q(resource__isnull = True) | | ||
36 | + (Q(resource__isnull = False) & (Q(resource__all_students = True) | Q(resource__students = user) | Q(resource__groups__participants = user))))).distinct() | ||
37 | + else: | ||
38 | + posts = SubjectPost.objects.extra(select = {"most_recent": "greatest(mural_mural.last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_subjectpost.mural_ptr_id))"}).filter(space__id = subject, mural_ptr__user = user) | ||
39 | + else: | ||
40 | + if not user.is_staff: | ||
41 | + posts = SubjectPost.objects.extra(select = {"most_recent": "greatest(mural_mural.last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_subjectpost.mural_ptr_id))"}).filter( | ||
42 | + Q(space__id = subject) & ( | ||
43 | + Q(space__category__coordinators = user) | | ||
44 | + Q(space__professor = user) | | ||
45 | + Q(resource__isnull = True) | | ||
46 | + (Q(resource__isnull = False) & (Q(resource__all_students = True) | Q(resource__students = user) | Q(resource__groups__participants = user))))).distinct() | ||
47 | + else: | ||
48 | + posts = SubjectPost.objects.extra(select = {"most_recent": "greatest(mural_mural.last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_subjectpost.mural_ptr_id))"}).filter(space__id = subject) | ||
49 | + else: | ||
50 | + if mines: | ||
51 | + if not user.is_staff: | ||
52 | + posts = SubjectPost.objects.extra(select = {"most_recent": "greatest(mural_mural.last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_subjectpost.mural_ptr_id))"}).filter( | ||
53 | + Q(space__id = subject) & Q(favorites_post__isnull = False) & Q(favorites_post__user = user) & Q(mural_ptr__user = user) & ( | ||
54 | + Q(space__category__coordinators = user) | | ||
55 | + Q(space__professor = user) | | ||
56 | + Q(resource__isnull = True) | | ||
57 | + (Q(resource__isnull = False) & (Q(resource__all_students = True) | Q(resource__students = user) | Q(resource__groups__participants = user))))).distinct() | ||
58 | + else: | ||
59 | + posts = SubjectPost.objects.extra(select = {"most_recent": "greatest(mural_mural.last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_subjectpost.mural_ptr_id))"}).filter(space__id = subject, favorites_post__isnull = False, favorites_post__user = user, mural_ptr__user = user) | ||
60 | + else: | ||
61 | + if not user.is_staff: | ||
62 | + posts = SubjectPost.objects.extra(select = {"most_recent": "greatest(mural_mural.last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_subjectpost.mural_ptr_id))"}).filter( | ||
63 | + Q(space__id = subject) & Q(favorites_post__isnull = False) & Q(favorites_post__user = user) & ( | ||
64 | + Q(space__category__coordinators = user) | | ||
65 | + Q(space__professor = user) | | ||
66 | + Q(resource__isnull = True) | | ||
67 | + (Q(resource__isnull = False) & (Q(resource__all_students = True) | Q(resource__students = user) | Q(resource__groups__participants = user))))).distinct() | ||
68 | + else: | ||
69 | + posts = SubjectPost.objects.extra(select = {"most_recent": "greatest(mural_mural.last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_subjectpost.mural_ptr_id))"}).filter(space__id = subject, favorites_post__isnull = False, favorites_post__user = user) | ||
70 | + | ||
71 | + return posts | ||
24 | \ No newline at end of file | 72 | \ No newline at end of file |
mural/views.py
@@ -29,7 +29,7 @@ from api.utils import sendMuralPushNotification | @@ -29,7 +29,7 @@ from api.utils import sendMuralPushNotification | ||
29 | 29 | ||
30 | from .models import Mural, GeneralPost, CategoryPost, SubjectPost, MuralVisualizations, MuralFavorites, Comment | 30 | from .models import Mural, GeneralPost, CategoryPost, SubjectPost, MuralVisualizations, MuralFavorites, Comment |
31 | from .forms import GeneralPostForm, CategoryPostForm, SubjectPostForm, ResourcePostForm, CommentForm | 31 | from .forms import GeneralPostForm, CategoryPostForm, SubjectPostForm, ResourcePostForm, CommentForm |
32 | -from .utils import getSpaceUsers | 32 | +from .utils import getSpaceUsers, getSubjectPosts |
33 | 33 | ||
34 | from amadeus.permissions import has_subject_view_permissions, has_resource_permissions | 34 | from amadeus.permissions import has_subject_view_permissions, has_resource_permissions |
35 | 35 | ||
@@ -593,16 +593,7 @@ def load_subject_posts(request, subject): | @@ -593,16 +593,7 @@ def load_subject_posts(request, subject): | ||
593 | showing = request.GET.get('showing', '') | 593 | showing = request.GET.get('showing', '') |
594 | n_views = 0 | 594 | n_views = 0 |
595 | 595 | ||
596 | - if not favorites: | ||
597 | - if mines: | ||
598 | - posts = SubjectPost.objects.extra(select = {"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_subjectpost.mural_ptr_id))"}).filter(space__id = subject, mural_ptr__user = user) | ||
599 | - else: | ||
600 | - posts = SubjectPost.objects.extra(select = {"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_subjectpost.mural_ptr_id))"}).filter(space__id = subject) | ||
601 | - else: | ||
602 | - if mines: | ||
603 | - posts = SubjectPost.objects.extra(select = {"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_subjectpost.mural_ptr_id))"}).filter(space__id = subject, favorites_post__isnull = False, favorites_post__user = user, mural_ptr__user = user) | ||
604 | - else: | ||
605 | - posts = SubjectPost.objects.extra(select = {"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_subjectpost.mural_ptr_id))"}).filter(space__id = subject, favorites_post__isnull = False, favorites_post__user = user) | 596 | + posts = getSubjectPosts(subject, user, favorites, mines) |
606 | 597 | ||
607 | if showing: #Exclude ajax creation posts results | 598 | if showing: #Exclude ajax creation posts results |
608 | showing = showing.split(',') | 599 | showing = showing.split(',') |
@@ -937,16 +928,7 @@ class SubjectView(LoginRequiredMixin, LogMixin, generic.ListView): | @@ -937,16 +928,7 @@ class SubjectView(LoginRequiredMixin, LogMixin, generic.ListView): | ||
937 | slug = self.kwargs.get('slug') | 928 | slug = self.kwargs.get('slug') |
938 | subject = get_object_or_404(Subject, slug = slug) | 929 | subject = get_object_or_404(Subject, slug = slug) |
939 | 930 | ||
940 | - if not favorites: | ||
941 | - if mines: | ||
942 | - posts = SubjectPost.objects.extra(select = {"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_subjectpost.mural_ptr_id))"}).filter(mural_ptr__user = user, space = subject) | ||
943 | - else: | ||
944 | - posts = SubjectPost.objects.extra(select = {"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_subjectpost.mural_ptr_id))"}).filter(space = subject) | ||
945 | - else: | ||
946 | - if mines: | ||
947 | - posts = SubjectPost.objects.extra(select = {"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_subjectpost.mural_ptr_id))"}).filter(favorites_post__isnull = False, favorites_post__user = user, mural_ptr__user = user, space = subject) | ||
948 | - else: | ||
949 | - posts = SubjectPost.objects.extra(select = {"most_recent": "greatest(last_update, (select max(mural_comment.last_update) from mural_comment where mural_comment.post_id = mural_subjectpost.mural_ptr_id))"}).filter(favorites_post__isnull = False, favorites_post__user = user, space = subject) | 931 | + posts = getSubjectPosts(subject, user, favorites, mines) |
950 | 932 | ||
951 | if showing: #Exclude ajax creation posts results | 933 | if showing: #Exclude ajax creation posts results |
952 | showing = showing.split(',') | 934 | showing = showing.split(',') |