Пример #1
0
 def test_is_admin(self):
     """
     Verifies the check for a user having Administrator privileges.
     """
     self.assertTrue(auth.is_admin(self.admin))
     self.assertFalse(auth.is_admin(self.moderator))
     self.assertFalse(auth.is_admin(self.user))
Пример #2
0
 def test_is_admin(self):
     """
     Verifies the check for a user having Administrator privileges.
     """
     self.assertTrue(auth.is_admin(self.admin))
     self.assertFalse(auth.is_admin(self.moderator))
     self.assertFalse(auth.is_admin(self.user))
Пример #3
0
def add_forum(request, section_id):
    """
    Adds a Forum to a Section.
    """
    if not auth.is_admin(request.user):
        return permission_denied(request)
    section = get_object_or_404(Section, pk=section_id)
    forums = list(section.forums.all())
    if app_settings.USE_REDIS:
        redis.seen_user(request.user, "Adding a new forum")
    if request.method == "POST":
        form = forms.AddForumForm(forums, request.POST)
        if form.is_valid():
            if not form.cleaned_data["forum"]:
                # Add to the end
                order = len(forums) + 1
            else:
                # Insert before an existing Forum
                order = Forum.objects.get(pk=form.cleaned_data["forum"]).order
                Forum.objects.increment_orders(section.id, order)
            forum = Forum.objects.create(
                name=form.cleaned_data["name"],
                section=section,
                order=order,
                description=form.cleaned_data["description"],
            )
            return HttpResponseRedirect(forum.get_absolute_url())
    else:
        form = forms.AddForumForm(forums)
    return render(
        request, "forum/add_forum.html", {"form": form, "section": section, "title": "Add Forum to %s" % section.name}
    )
Пример #4
0
def add_forum(request, section_id):
    """
    Adds a Forum to a Section.
    """
    if not auth.is_admin(request.user):
        return permission_denied(request)
    section = get_object_or_404(Section, pk=section_id)
    forums = list(section.forums.all())
    if app_settings.USE_REDIS:
        redis.seen_user(request.user, 'Adding a new forum')
    if request.method == 'POST':
        form = forms.AddForumForm(forums, request.POST)
        if form.is_valid():
            if not form.cleaned_data['forum']:
                # Add to the end
                order = len(forums) + 1
            else:
                # Insert before an existing Forum
                order = Forum.objects.get(pk=form.cleaned_data['forum']).order
                Forum.objects.increment_orders(section.id, order)
            forum = Forum.objects.create(
                name=form.cleaned_data['name'],
                section=section,
                order=order,
                description=form.cleaned_data['description'])
            return HttpResponseRedirect(forum.get_absolute_url())
    else:
        form = forms.AddForumForm(forums)
    return render(
        request, 'forum/add_forum.html', {
            'form': form,
            'section': section,
            'title': 'Add Forum to %s' % section.name,
        })
Пример #5
0
def add_forum(request, section_id):
    """
    Adds a Forum to a Section.
    """
    if not auth.is_admin(request.user):
        return permission_denied(request)
    section = get_object_or_404(Section, pk=section_id)
    forums = list(section.forums.all())
    if app_settings.USE_REDIS:
        redis.seen_user(request.user, 'Adding a new forum')
    if request.method == 'POST':
        form = forms.AddForumForm(forums, request.POST)
        if form.is_valid():
            if not form.cleaned_data['forum']:
                # Add to the end
                order = len(forums) + 1
            else:
                # Insert before an existing Forum
                order = Forum.objects.get(pk=form.cleaned_data['forum']).order
                Forum.objects.increment_orders(section.id, order)
            forum = Forum.objects.create(name=form.cleaned_data['name'],
                section=section, order=order,
                description=form.cleaned_data['description'])
            return HttpResponseRedirect(forum.get_absolute_url())
    else:
        form = forms.AddForumForm(forums)
    return render(request, 'forum/add_forum.html', {
        'form': form,
        'section': section,
        'title': 'Add Forum to %s' % section.name,
    })
Пример #6
0
def add_section(request):
    """
    Adds a Section.
    """
    if not auth.is_admin(request.user):
        return permission_denied(request)
    sections = list(Section.objects.all())
    if app_settings.USE_REDIS:
        redis.seen_user(request.user, 'Adding a new section')
    if request.method == 'POST':
        form = forms.AddSectionForm(sections, request.POST)
        if form.is_valid():
            if not form.cleaned_data['section']:
                # Add to the end
                order = len(sections) + 1
            else:
                # Insert before an existing Section
                order = Section.objects.get(pk=form.cleaned_data['section']).order
                Section.objects.increment_orders(order)
            section = Section.objects.create(name=form.cleaned_data['name'],
                                             order=order)
            return HttpResponseRedirect(section.get_absolute_url())
    else:
        form = forms.AddSectionForm(sections)
    return render(request, 'forum/add_section.html', {
        'form': form,
        'title': 'Add Section',
    })
Пример #7
0
def add_section(request):
    """
    Adds a Section.
    """
    if not auth.is_admin(request.user):
        return permission_denied(request)
    sections = list(Section.objects.all())
    if app_settings.USE_REDIS:
        redis.seen_user(request.user, 'Adding a new section')
    if request.method == 'POST':
        form = forms.AddSectionForm(sections, request.POST)
        if form.is_valid():
            if not form.cleaned_data['section']:
                # Add to the end
                order = len(sections) + 1
            else:
                # Insert before an existing Section
                order = Section.objects.get(
                    pk=form.cleaned_data['section']).order
                Section.objects.increment_orders(order)
            section = Section.objects.create(name=form.cleaned_data['name'],
                                             order=order)
            return HttpResponseRedirect(section.get_absolute_url())
    else:
        form = forms.AddSectionForm(sections)
    return render(request, 'forum/add_section.html', {
        'form': form,
        'title': 'Add Section',
    })
Пример #8
0
def is_admin(user):
    """
    Returns ``True`` if the given user has admin permissions,
    ``False`` otherwise.
    """
    return user.is_authenticated() and \
           auth.is_admin(user)
Пример #9
0
def is_admin(user):
    """
    Returns ``True`` if the given user has admin permissions,
    ``False`` otherwise.
    """
    return user.is_authenticated() and \
           auth.is_admin(user)
Пример #10
0
def edit_section(request, section_id):
    """
    Edits a Section.
    """
    if not auth.is_admin(request.user):
        return permission_denied(request)
    section = get_object_or_404(Section, pk=section_id)
    if app_settings.USE_REDIS:
        redis.seen_user(request.user, "Editing a section")
    if request.method == "POST":
        form = forms.EditSectionForm(request.POST, instance=section)
        if form.is_valid():
            form.save(commit=True)
            return HttpResponseRedirect(section.get_absolute_url())
    else:
        form = forms.EditSectionForm(instance=section)
    return render(request, "forum/edit_section.html", {"form": form, "section": section, "title": "Edit Section"})
Пример #11
0
def delete_section(request, section_id):
    """
    Deletes a Section after confirmation is made via POST.
    """
    if not auth.is_admin(request.user):
        return permission_denied(request)
    section = get_object_or_404(Section, pk=section_id)
    if app_settings.USE_REDIS:
        redis.seen_user(request.user, 'Deleting a section')
    if request.method == 'POST':
        section.delete()
        return HttpResponseRedirect(reverse('forum_index'))
    else:
        return render(request, 'forum/delete_section.html', {
            'section': section,
            'forum_list': section.forums.all(),
            'title': 'Delete Section',
        })
Пример #12
0
def delete_section(request, section_id):
    """
    Deletes a Section after confirmation is made via POST.
    """
    if not auth.is_admin(request.user):
        return permission_denied(request)
    section = get_object_or_404(Section, pk=section_id)
    if app_settings.USE_REDIS:
        redis.seen_user(request.user, "Deleting a section")
    if request.method == "POST":
        section.delete()
        return HttpResponseRedirect(reverse("forum_index"))
    else:
        return render(
            request,
            "forum/delete_section.html",
            {"section": section, "forum_list": section.forums.all(), "title": "Delete Section"},
        )
Пример #13
0
def delete_section(request, section_id):
    """
    Deletes a Section after confirmation is made via POST.
    """
    if not auth.is_admin(request.user):
        return permission_denied(request)
    section = get_object_or_404(Section, pk=section_id)
    if app_settings.USE_REDIS:
        redis.seen_user(request.user, 'Deleting a section')
    if request.method == 'POST':
        section.delete()
        return HttpResponseRedirect(reverse('forum_index'))
    else:
        return render(
            request, 'forum/delete_section.html', {
                'section': section,
                'forum_list': section.forums.all(),
                'title': 'Delete Section',
            })
Пример #14
0
def delete_forum(request, forum_id):
    """
    Deletes a Forum after confirmation is made via POST.
    """
    if not auth.is_admin(request.user):
        return permission_denied(request)
    forum = get_object_or_404(Forum.objects.select_related(), pk=forum_id)
    section = forum.section
    if app_settings.USE_REDIS:
        redis.seen_user(request.user, "Deleting a forum")
    if request.method == "POST":
        forum.delete()
        return HttpResponseRedirect(section.get_absolute_url())
    else:
        return render(
            request,
            "forum/delete_forum.html",
            {"section": section, "forum": forum, "topic_count": forum.topics.count(), "title": "Delete Forum"},
        )
Пример #15
0
def edit_forum(request, forum_id):
    """
    Edits a Forum.
    """
    if not auth.is_admin(request.user):
        return permission_denied(request)
    forum = get_object_or_404(Forum.objects.select_related(), pk=forum_id)
    if app_settings.USE_REDIS:
        redis.seen_user(request.user, "Editing a forum")
    if request.method == "POST":
        form = forms.EditForumForm(request.POST, instance=forum)
        if form.is_valid():
            form.save(commit=True)
            return HttpResponseRedirect(forum.get_absolute_url())
    else:
        form = forms.EditForumForm(instance=forum)
    return render(
        request,
        "forum/edit_forum.html",
        {"form": form, "forum": forum, "section": forum.section, "title": "Edit Forum"},
    )
Пример #16
0
def delete_forum(request, forum_id):
    """
    Deletes a Forum after confirmation is made via POST.
    """
    if not auth.is_admin(request.user):
        return permission_denied(request)
    forum = get_object_or_404(Forum.objects.select_related(), pk=forum_id)
    section = forum.section
    if app_settings.USE_REDIS:
        redis.seen_user(request.user, 'Deleting a forum')
    if request.method == 'POST':
        forum.delete()
        return HttpResponseRedirect(section.get_absolute_url())
    else:
        return render(
            request, 'forum/delete_forum.html', {
                'section': section,
                'forum': forum,
                'topic_count': forum.topics.count(),
                'title': 'Delete Forum',
            })
Пример #17
0
def edit_section(request, section_id):
    """
    Edits a Section.
    """
    if not auth.is_admin(request.user):
        return permission_denied(request)
    section = get_object_or_404(Section, pk=section_id)
    if app_settings.USE_REDIS:
        redis.seen_user(request.user, 'Editing a section')
    if request.method == 'POST':
        form = forms.EditSectionForm(request.POST, instance=section)
        if form.is_valid():
            form.save(commit=True)
            return HttpResponseRedirect(section.get_absolute_url())
    else:
        form = forms.EditSectionForm(instance=section)
    return render(request, 'forum/edit_section.html', {
        'form': form,
        'section': section,
        'title': 'Edit Section',
    })
Пример #18
0
def delete_forum(request, forum_id):
    """
    Deletes a Forum after confirmation is made via POST.
    """
    if not auth.is_admin(request.user):
        return permission_denied(request)
    forum = get_object_or_404(Forum.objects.select_related(), pk=forum_id)
    section = forum.section
    if section.is_managed():
        if not section.is_corp_authed(request.user):
            raise Http404
    if app_settings.USE_REDIS:
        redis.seen_user(request.user, 'Deleting a forum')
    if request.method == 'POST':
        forum.delete()
        return HttpResponseRedirect(section.get_absolute_url())
    else:
        return render(request, 'forum/delete_forum.html', {
            'section': section,
            'forum': forum,
            'topic_count': forum.topics.count(),
            'title': 'Delete Forum',
        })
Пример #19
0
def edit_forum(request, forum_id):
    """
    Edits a Forum.
    """
    if not auth.is_admin(request.user):
        return permission_denied(request)
    forum = get_object_or_404(Forum.objects.select_related(), pk=forum_id)
    if app_settings.USE_REDIS:
        redis.seen_user(request.user, 'Editing a forum')
    if request.method == 'POST':
        form = forms.EditForumForm(request.POST, instance=forum)
        if form.is_valid():
            form.save(commit=True)
            return HttpResponseRedirect(forum.get_absolute_url())
    else:
        form = forms.EditForumForm(instance=forum)
    return render(
        request, 'forum/edit_forum.html', {
            'form': form,
            'forum': forum,
            'section': forum.section,
            'title': 'Edit Forum',
        })