Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to track organizer issues #939

Merged
merged 7 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
from core.admin.event_page_content import EventPageContentAdmin
from core.admin.event_page_menu import EventPageMenuAdmin
from core.admin.flat_page import MyFlatPageAdmin
from core.admin.organizerissue import OrganizerIssueAdmin
from core.admin.user import UserAdmin
from core.models import Event, EventPageContent, EventPageMenu, User
from core.models.organizerissue import OrganizerIssue

admin.site.unregister(FlatPage)
admin.site.register(FlatPage, MyFlatPageAdmin)
admin.site.register(Event, EventAdmin)
admin.site.register(EventPageContent, EventPageContentAdmin)
admin.site.register(EventPageMenu, EventPageMenuAdmin)
admin.site.register(User, UserAdmin)
admin.site.register(OrganizerIssue, OrganizerIssueAdmin)
25 changes: 25 additions & 0 deletions core/admin/forms/organizerissue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django import forms

from core.models.event import Event
from core.models.organizerissue import OrganizerIssue
from core.models.user import User


class OrganizerIssueForm(forms.ModelForm):
organizer = forms.ModelChoiceField(queryset=User.objects.all())
event = forms.ModelChoiceField(queryset=Event.objects.all())
issue_handled_by = forms.ModelChoiceField(queryset=User.objects.filter(is_staff=True))

class Meta:
model = OrganizerIssue
fields = (
"organizer",
"event",
"date_reported",
"reported_by",
"issue",
"issue_handled",
"issue_handled_by",
"findings",
"comments",
)
68 changes: 68 additions & 0 deletions core/admin/organizerissue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from django.contrib import admin, messages
from django.shortcuts import get_object_or_404, redirect
from django.urls import path
from django.utils.translation import gettext_lazy as _

from core.models.organizerissue import OrganizerIssue

from .forms.organizerissue import OrganizerIssueForm


class OrganizerIssueAdmin(admin.ModelAdmin):
form = OrganizerIssueForm
list_display = (
"organizer",
"event",
"date_reported",
"reported_by",
"issue_handled",
"issue_handled_by",
"last_updated",
)
list_filter = (
"organizer",
"event",
"reported_by",
)
search_fields = (
"organizer",
"event",
"reported_by",
)

def get_urls(self):
urls = super().get_urls()

my_urls = [
path(
"<int:organizerissue_id>/triage/blacklist/",
self.admin_site.admin_view(self.blacklist),
name="core_organizerissue_blacklist",
),
path(
"<int:organizerissue_id>/triage/reverse_blacklist/",
self.admin_site.admin_view(self.reverse_blacklist),
name="core_organizerissue_reverse_blacklist",
),
]
return my_urls + urls

def blacklist(self, request, organizerissue_id):
organizer = get_object_or_404(OrganizerIssue, id=organizerissue_id)
organizer.blacklist_organizer()
messages.success(
request,
_("Organizer %(organizer)s, of %(event)s has been blacklisted.")
% {"organizer": f"{organizer.organizer.get_full_name()}", "event": organizer.event},
)
return redirect("admin:core_organizerissue_changelist")

def reverse_blacklist(self, request, organizerissue_id):
organizer = get_object_or_404(OrganizerIssue, id=organizerissue_id)
organizer.reverse_blacklist_organizer()
messages.success(
request,
_("Blacklisting for organizer %(organizer)s, of %(event)s has been reversed.")
% {"organizer": f"{organizer.organizer.get_full_name()}", "event": organizer.event},
)
return redirect("admin:core_organizerissue_changelist")
2 changes: 1 addition & 1 deletion core/admin/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class UserAdmin(auth_admin.UserAdmin):
fieldsets = (
(None, {"fields": ("email", "password")}),
(_("Personal info"), {"fields": ("first_name", "last_name")}),
(_("Personal info"), {"fields": ("first_name", "last_name", "is_blacklisted")}),
(_("Permissions"), {"fields": ("is_active", "is_staff", "is_superuser", "groups", "user_permissions")}),
("Important dates", {"fields": ("last_login", "date_joined")}),
)
Expand Down
69 changes: 69 additions & 0 deletions core/migrations/0006_auto_20240130_1644.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Generated by Django 3.2.20 on 2024-01-30 16:44

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.db.models.manager


class Migration(migrations.Migration):
dependencies = [
("core", "0005_auto_20220422_1321"),
]

operations = [
migrations.AlterModelManagers(
name="event",
managers=[
("all_objects", django.db.models.manager.Manager()),
],
),
migrations.AddField(
model_name="user",
name="is_blacklisted",
field=models.BooleanField(default=False),
),
migrations.CreateModel(
name="OrganizerIssue",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("created_at", models.DateTimeField(auto_now_add=True)),
("date_reported", models.DateField()),
("reported_by", models.CharField(max_length=100)),
("reporter_email", models.EmailField(max_length=100)),
("issue", models.TextField()),
("issue_handled", models.BooleanField()),
("findings", models.TextField(blank=True, null=True)),
("comments", models.TextField(blank=True, null=True)),
("last_updated", models.DateTimeField(auto_now=True)),
(
"event",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="event",
to="core.event",
),
),
(
"issue_handled_by",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="staff_responsible",
to=settings.AUTH_USER_MODEL,
),
),
(
"organizer",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="organizer",
to=settings.AUTH_USER_MODEL,
),
),
],
),
]
34 changes: 34 additions & 0 deletions core/models/organizerissue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from django.db import models

from core.models.event import Event
from core.models.user import User


class OrganizerIssue(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
organizer = models.ForeignKey(User, related_name="organizer", on_delete=models.deletion.CASCADE)
event = models.ForeignKey(to=Event, null=True, blank=True, related_name="event", on_delete=models.deletion.SET_NULL)
date_reported = models.DateField()
reported_by = models.CharField(max_length=100)
reporter_email = models.EmailField(max_length=100)
issue = models.TextField()
issue_handled = models.BooleanField()
issue_handled_by = models.ForeignKey(
to=User, null=True, blank=True, related_name="staff_responsible", on_delete=models.deletion.SET_NULL
)
findings = models.TextField(blank=True, null=True)
comments = models.TextField(blank=True, null=True)
last_updated = models.DateTimeField(auto_now=True)

def __str__(self):
return f"{self.organizer.get_full_name()} - {self.event}"

def blacklist_organizer(self):
user = User.objects.get(id=self.organizer.id)
user.is_blacklisted = True
user.save(update_fields=["is_blacklisted"])

def reverse_blacklist_organizer(self):
user = User.objects.get(id=self.organizer.id)
user.is_blacklisted = False
user.save(update_fields=["is_blacklisted"])
7 changes: 5 additions & 2 deletions core/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class User(auth_models.AbstractBaseUser, auth_models.PermissionsMixin):
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
date_joined = models.DateTimeField(auto_now_add=True)
is_blacklisted = models.BooleanField(default=False)

objects = UserManager()

Expand Down Expand Up @@ -41,9 +42,11 @@ def add_to_organizers_group(self):
self.groups.add(group)

def __str__(self):
status = "- (Organizer is Blacklisted)" if self.is_blacklisted else ""

if not self.first_name and not self.last_name:
return f"{self.email}"
return f"{self.get_full_name()} ({self.email})"
return f"{self.email} {status}"
return f"{self.get_full_name()} ({self.email}) {status}"

def get_short_name(self):
return self.first_name
Expand Down
8 changes: 7 additions & 1 deletion organize/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class EventApplicationAdmin(admin.ModelAdmin):
"status",
"created_at",
"status_changed_at",
"organizer_blacklisted",
"about_you",
"why",
"involvement",
Expand Down Expand Up @@ -126,7 +127,12 @@ class EventApplicationAdmin(admin.ModelAdmin):
(
_("Main organizer"),
{
"fields": ["main_organizer_email", "main_organizer_first_name", "main_organizer_last_name"],
"fields": [
"main_organizer_email",
"main_organizer_first_name",
"main_organizer_last_name",
"organizer_blacklisted",
],
"classes": (
"suit-tab",
"suit-tab-organizers",
Expand Down
Loading
Loading