Skip to content

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
owlester12 committed Dec 17, 2024
2 parents 4daa2d4 + 56b9394 commit 2256206
Show file tree
Hide file tree
Showing 76 changed files with 2,080 additions and 827 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/build-and-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ jobs:
black: false
ruff: true

frontend-check:
name: "Frontend Check"
uses: pennlabs/shared-actions/.github/workflows/[email protected]
with:
path: frontend
nodeVersion: 20.11.1

build-backend:
name: Build backend
runs-on: ubuntu-latest
Expand Down Expand Up @@ -79,7 +72,6 @@ jobs:
with:
name: build-frontend
path: /tmp/image.tar
needs: frontend-check

publish:
name: Publish Images
Expand Down
8 changes: 7 additions & 1 deletion backend/clubs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Cart,
Club,
ClubApplication,
ClubApprovalResponseTemplate,
ClubFair,
ClubFairBooth,
ClubFairRegistration,
Expand Down Expand Up @@ -324,7 +325,7 @@ def club(self, obj):

class AdvisorAdmin(admin.ModelAdmin):
search_fields = ("name", "title", "email", "phone", "club__name")
list_display = ("name", "title", "email", "phone", "club", "public")
list_display = ("name", "title", "email", "phone", "club", "visibility")

def club(self, obj):
return obj.club.name
Expand Down Expand Up @@ -415,6 +416,10 @@ class ApplicationSubmissionAdmin(admin.ModelAdmin):
list_display = ("user", "id", "created_at", "status")


class ClubApprovalResponseTemplateAdmin(admin.ModelAdmin):
search_fields = ("title", "content")


admin.site.register(Asset)
admin.site.register(ApplicationCommittee)
admin.site.register(ApplicationExtension)
Expand Down Expand Up @@ -460,3 +465,4 @@ class ApplicationSubmissionAdmin(admin.ModelAdmin):
admin.site.register(TicketTransferRecord)
admin.site.register(Cart)
admin.site.register(ApplicationCycle)
admin.site.register(ClubApprovalResponseTemplate, ClubApprovalResponseTemplateAdmin)
3 changes: 2 additions & 1 deletion backend/clubs/management/commands/deactivate.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def handle(self, *args, **kwargs):
num_ghosted += 1

club.save()
cache.delete(f"clubs:{club.id}") # clear cache
cache.delete(f"clubs:{club.id}-authed") # clear cache
cache.delete(f"clubs:{club.id}-anon")

self.stdout.write(
f"{clubs.count()} clubs deactivated! {num_ghosted} clubs ghosted!"
Expand Down
1 change: 0 additions & 1 deletion backend/clubs/management/commands/graduate_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class Command(BaseCommand):
"Mark all memberships where the student has graduated as inactive. "
"This script should be run at the beginning of each year."
)
web_execute = True

def handle(self, *args, **kwargs):
now = timezone.now()
Expand Down
36 changes: 36 additions & 0 deletions backend/clubs/management/commands/osa_perms_updates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group, Permission
from django.contrib.contenttypes.models import ContentType
from django.core.management.base import BaseCommand

from clubs.models import Club


class Command(BaseCommand):
help = "Give superuser to hard-coded user accounts affiliated with OSA."
web_execute = True

def handle(self, *args, **kwargs):
User = get_user_model()
content_type = ContentType.objects.get_for_model(Club)
approve_perm = Permission.objects.get(
codename="approve_club", content_type=content_type
)
pending_perm = Permission.objects.get(
codename="see_pending_clubs", content_type=content_type
)
if not settings.OSA_KEYS:
raise ValueError("OSA_KEYS not set in settings")
if not (approvers := Group.objects.filter(name="Approvers").first()):
raise ValueError("Approvers group not found")
for key in settings.OSA_KEYS:
if not key or not (user := User.objects.get(username=key)):
continue
user.is_superuser = True
user.is_staff = True
user.user_permissions.add(approve_perm)
user.user_permissions.add(pending_perm)
approvers.user_set.add(user)
user.save()
approvers.save()
2 changes: 1 addition & 1 deletion backend/clubs/management/commands/populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def get_image(url):
department="Accounting Department",
email="[email protected]",
phone="+12158985000",
defaults={"public": True},
defaults={"visibility": Advisor.ADVISOR_VISIBILITY_STUDENTS},
)

club.tags.add(tag_undergrad)
Expand Down
9 changes: 6 additions & 3 deletions backend/clubs/management/commands/rank.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import datetime
import random
from math import floor

import bleach
import numpy as np
from django.core.management.base import BaseCommand
from django.utils import timezone

Expand Down Expand Up @@ -220,8 +220,11 @@ def rank(self):
if num_testimonials >= 3:
ranking += 5

# rng
ranking += random.random() * 10
# random number, mostly shuffles similar clubs with average of 25 points
# but with long right tail to periodically feature less popular clubs
# given ~700 active clubs, multiplier c, expected # clubs with rand > cd
# is 257, 95, 35, 13, 5, 2, 1 for c = 1, 2, 3, 4, 5, 6, 7
ranking += np.random.standard_exponential() * 25

club.rank = floor(ranking)
club.skip_history_when_saving = True
Expand Down
35 changes: 35 additions & 0 deletions backend/clubs/migrations/0114_alter_advisor_public.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 5.0.4 on 2024-09-29 17:00

from django.db import migrations, models


def migrate_public_to_enum(apps, schema_editor):
Advisor = apps.get_model("clubs", "Advisor")
# Update 'public' field, assume public=True means only students by default
Advisor.objects.filter(public=False).update(visibility=1)
Advisor.objects.filter(public=True).update(visibility=2)

def reverse_migrate_public_to_enum(apps, schema_editor):
Advisor = apps.get_model("clubs", "Advisor")
Advisor.objects.filter(visibility=1).update(public=False)
Advisor.objects.filter(visibility__in=[2, 3]).update(public=True)

class Migration(migrations.Migration):
dependencies = [
("clubs", "0113_badge_message"),
]
operations = [
migrations.AddField(
model_name="advisor",
name="visibility",
field=models.IntegerField(
choices=[(1, "Admin Only"), (2, "Signed-in Students"), (3, "Public")],
default=2,
),
),
migrations.RunPython(migrate_public_to_enum, reverse_migrate_public_to_enum),
migrations.RemoveField(
model_name="advisor",
name="public",
),
]
23 changes: 23 additions & 0 deletions backend/clubs/migrations/0115_club_beta_historicalclub_beta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.0.4 on 2024-10-05 02:24

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("clubs", "0114_alter_advisor_public"),
]

operations = [
migrations.AddField(
model_name="club",
name="beta",
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name="historicalclub",
name="beta",
field=models.BooleanField(default=False),
),
]
23 changes: 23 additions & 0 deletions backend/clubs/migrations/0116_alter_club_approved_on_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.0.4 on 2024-10-07 14:56

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("clubs", "0115_club_beta_historicalclub_beta"),
]

operations = [
migrations.AlterField(
model_name="club",
name="approved_on",
field=models.DateTimeField(blank=True, db_index=True, null=True),
),
migrations.AlterField(
model_name="historicalclub",
name="approved_on",
field=models.DateTimeField(blank=True, db_index=True, null=True),
),
]
42 changes: 42 additions & 0 deletions backend/clubs/migrations/0117_clubapprovalresponsetemplate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Generated by Django 5.0.4 on 2024-10-16 02:18

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


class Migration(migrations.Migration):
dependencies = [
("clubs", "0116_alter_club_approved_on_and_more"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name="ClubApprovalResponseTemplate",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("title", models.CharField(max_length=255, unique=True)),
("content", models.TextField()),
("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"author",
models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="templates",
to=settings.AUTH_USER_MODEL,
),
),
],
),
]
Loading

0 comments on commit 2256206

Please sign in to comment.