diff --git a/mural/views.py b/mural/views.py index bfe443f..6ed9007 100644 --- a/mural/views.py +++ b/mural/views.py @@ -559,25 +559,25 @@ class CategoryDelete(LoginRequiredMixin, LogMixin, generic.DeleteView): @log_decorator_ajax('mural', 'view', 'category') def mural_category_log(request, category): - action = request.GET.get('action') + action = request.GET.get('action') - if action == 'open': - category = get_object_or_404(Category, id = category) + if action == 'open': + category = get_object_or_404(Category, id = category) - log_context = {} - log_context['category_id'] = category.id - log_context['category_name'] = category.name - log_context['category_slug'] = category.slug - log_context['timestamp_start'] = str(int(time.time())) - log_context['timestamp_end'] = '-1' + log_context = {} + log_context['category_id'] = category.id + log_context['category_name'] = category.name + log_context['category_slug'] = category.slug + log_context['timestamp_start'] = str(int(time.time())) + log_context['timestamp_end'] = '-1' - request.log_context = log_context + request.log_context = log_context - log_id = Log.objects.latest('id').id + log_id = Log.objects.latest('id').id - return JsonResponse({'message': 'ok', 'log_id': log_id}) + return JsonResponse({'message': 'ok', 'log_id': log_id}) - return JsonResponse({'message': 'ok'}) + return JsonResponse({'message': 'ok'}) """ Section for SubjectPost classes @@ -928,7 +928,7 @@ class SubjectView(LoginRequiredMixin, LogMixin, generic.ListView): slug = self.kwargs.get('slug') subject = get_object_or_404(Subject, slug = slug) - posts = getSubjectPosts(subject, user, favorites, mines) + posts = getSubjectPosts(subject.id, user, favorites, mines) if showing: #Exclude ajax creation posts results showing = showing.split(',') @@ -978,25 +978,25 @@ class SubjectView(LoginRequiredMixin, LogMixin, generic.ListView): @log_decorator_ajax('mural', 'view', 'subject') def mural_subject_log(request, subject): - action = request.GET.get('action') + action = request.GET.get('action') - if action == 'open': - subject = get_object_or_404(Subject, id = subject) + if action == 'open': + subject = get_object_or_404(Subject, id = subject) - log_context = {} - log_context['subject_id'] = subject.id - log_context['subject_name'] = subject.name - log_context['subject_slug'] = subject.slug - log_context['timestamp_start'] = str(int(time.time())) - log_context['timestamp_end'] = '-1' + log_context = {} + log_context['subject_id'] = subject.id + log_context['subject_name'] = subject.name + log_context['subject_slug'] = subject.slug + log_context['timestamp_start'] = str(int(time.time())) + log_context['timestamp_end'] = '-1' - request.log_context = log_context + request.log_context = log_context - log_id = Log.objects.latest('id').id + log_id = Log.objects.latest('id').id - return JsonResponse({'message': 'ok', 'log_id': log_id}) + return JsonResponse({'message': 'ok', 'log_id': log_id}) - return JsonResponse({'message': 'ok'}) + return JsonResponse({'message': 'ok'}) """ Section for specific resource post classes @@ -1034,14 +1034,46 @@ class ResourceView(LoginRequiredMixin, LogMixin, generic.ListView): if not favorites: if mines: - 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, resource = resource) + if not user.is_staff: + 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( + Q(resource = resource) & Q(mural_ptr__user = user) & ( + Q(space__category__coordinators = user) | + Q(space__professor = user) | + Q(resource__isnull = True) | + (Q(resource__isnull = False) & (Q(resource__all_students = True) | Q(resource__students = user) | Q(resource__groups__participants = user))))).distinct() + else: + 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(resource = resource, mural_ptr__user = user) else: - 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(resource = resource) + if not user.is_staff: + 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( + Q(resource = resource) & ( + Q(space__category__coordinators = user) | + Q(space__professor = user) | + Q(resource__isnull = True) | + (Q(resource__isnull = False) & (Q(resource__all_students = True) | Q(resource__students = user) | Q(resource__groups__participants = user))))).distinct() + else: + 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(resource = resource) else: if mines: - 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, resource = resource) + if not user.is_staff: + 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( + Q(resource = resource) & Q(favorites_post__isnull = False) & Q(favorites_post__user = user) & Q(mural_ptr__user = user) & ( + Q(space__category__coordinators = user) | + Q(space__professor = user) | + Q(resource__isnull = True) | + (Q(resource__isnull = False) & (Q(resource__all_students = True) | Q(resource__students = user) | Q(resource__groups__participants = user))))).distinct() + else: + 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(resource = resource, favorites_post__isnull = False, favorites_post__user = user, mural_ptr__user = user) else: - 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, resource = resource) + if not user.is_staff: + 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( + Q(resource = resource) & Q(favorites_post__isnull = False) & Q(favorites_post__user = user) & ( + Q(space__category__coordinators = user) | + Q(space__professor = user) | + Q(resource__isnull = True) | + (Q(resource__isnull = False) & (Q(resource__all_students = True) | Q(resource__students = user) | Q(resource__groups__participants = user))))).distinct() + else: + 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(resource = resource, favorites_post__isnull = False, favorites_post__user = user) if showing: #Exclude ajax creation posts results showing = showing.split(',') -- libgit2 0.21.2