Esempio n. 1
0
    def dispatch(self, request, *args, **kwargs):
        if kwargs.get('subject_slug'):
            subject = get_object_or_404(Subject, slug=kwargs.get('subject_slug', ''))

            if not has_category_permissions(request.user, subject.category):
                return redirect(reverse_lazy('subjects:home'))

        if kwargs.get('slug'):
            category = get_object_or_404(Category, slug=kwargs.get('slug', ''))

            if not has_category_permissions(request.user, category):
                return redirect(reverse_lazy('subjects:home'))

        return super(SubjectCreateView, self).dispatch(request, *args, **kwargs)
Esempio n. 2
0
    def dispatch(self, request, *args, **kwargs):
        if kwargs.get('subject_slug'):
            subject = get_object_or_404(Subject,
                                        slug=kwargs.get('subject_slug', ''))

            if not has_category_permissions(request.user, subject.category):
                return redirect(reverse_lazy('subjects:home'))

        if kwargs.get('slug'):
            category = get_object_or_404(Category, slug=kwargs.get('slug', ''))

            if not has_category_permissions(request.user, category):
                return redirect(reverse_lazy('subjects:home'))

        return super(SubjectCreateView, self).dispatch(request, *args,
                                                       **kwargs)
Esempio n. 3
0
def my_categories(user):
    my_categories = []
    categories = Category.objects.filter()
    for category in categories:
        if has_category_permissions(user, category) or has:
            my_categories.append(category)

    return my_categories
Esempio n. 4
0
    def dispatch(self, request, *args, **kwargs):
        security = Security.objects.get(id=1)
        category = get_object_or_404(Category, slug=self.kwargs["slug"])

        if not request.user.is_staff:
            if security.deny_category_edition or not has_category_permissions(request.user, category):
                return redirect(reverse_lazy("subjects:index"))

        return super(UpdateCategory, self).dispatch(request, *args, **kwargs)
Esempio n. 5
0
    def dispatch(self, request, *args, **kwargs):
        slug = self.kwargs.get("slug", None)

        if slug is None:
            if not request.user.is_staff:
                return redirect(reverse_lazy('subjects:index'))
        else:
            category = get_object_or_404(Category, slug=slug)
            security = Security.objects.get(id=1)

            if not request.user.is_staff:
                if security.deny_category_edition or not has_category_permissions(request.user, category):
                    return redirect(reverse_lazy('subjects:index'))

        return super(CreateCategory, self).dispatch(request, *args, **kwargs)
Esempio n. 6
0
def category_permissions(user, category):
    return permissions.has_category_permissions(user, category)
def category_permissions(user, category):
	return permissions.has_category_permissions(user, category)