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

point of contact (onboarding/demo) + case insensitive username and duplicate email check during provisioning (issue #500) #572

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions hknweb/events/forms/event/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Meta:
model = Event
fields = (
"name",
"point_of_contact",
"location",
"description",
"event_type",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 4.2.5 on 2024-03-14 22:03

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("events", "0012_icalview"),
]

operations = [
migrations.AlterModelOptions(
name="icalview",
options={"verbose_name": "iCal view"},
),
migrations.AddField(
model_name="event",
name="point_of_contact",
field=models.CharField(default="N/A", max_length=255),
),
]
1 change: 1 addition & 0 deletions hknweb/events/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

class Event(models.Model):
name = models.CharField(max_length=255)
point_of_contact = models.CharField(max_length=255, default="N/A")
start_time = models.DateTimeField()
end_time = models.DateTimeField()
location = models.CharField(max_length=255)
Expand Down
1 change: 1 addition & 0 deletions hknweb/events/views/event_transactions/show_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def show_details_helper(request, id, back_link: str, can_edit: bool):

context = {
"event": event,
"event_point_of_contact": markdownify(event.point_of_contact),
"event_description": markdownify(event.description),
"event_location": format_url(event.location),
"user_access_level": ACCESSLEVEL_TO_DESCRIPTION[get_access_level(request.user)],
Expand Down
17 changes: 13 additions & 4 deletions hknweb/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def add_messages(self, request) -> None:
if invalid_emails:
messages.error(
request,
f"All accounts created successfully except the following with invalid emails: {invalid_emails}. As a reminder, all emails must end in '@berkeley.edu'.",
f"All accounts created successfully except the following with invalid or existing emails: {invalid_emails}. As a reminder, all emails must end in '@berkeley.edu'.",
)
else:
messages.info(request, "All accounts successfully created!")
Expand Down Expand Up @@ -206,22 +206,30 @@ def email_to_username(email: str) -> str:

# Get existing usernames
usernames = []
emails = []
invalid_emails = []
for row in rows:
email = row["Berkeley email"]
username = email_to_username(email)

if username:
usernames.append(username)
emails.append(email)
else:
invalid_emails.append(email)

row["username"] = username

existing_usernames = set(
existing_usernames = {u.lower() for u in
User.objects.filter(username__in=usernames).values_list(
"username", flat=True
)
}

existing_emails = set(
User.objects.filter(email__in=emails).values_list(
"email", flat=True
)
)

# Setup account provisioning utils
Expand All @@ -238,8 +246,9 @@ def generate_password() -> str:

email_information = []
for row in rows:
# If username is None or already exists, skip provisioning
if (row["username"] is None) or (row["username"] in existing_usernames):
# If username is None or already exists or email already exists, skip provisioning
if (row["username"] is None) or (row["username"].lower() in existing_usernames) or (row["Berkeley email"] in existing_emails):
invalid_emails.append(row["Berkeley email"])
continue

# Generate a password
Expand Down
1 change: 1 addition & 0 deletions hknweb/templates/events/show_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ <h1 id="event-detail-title"> {{ event.name }} </h1>
<div id="left-details">

<p>{{ event_description | safe }}</p>
<p><b>Point of Contact</b>: {{ event.point_of_contact}}</p>
<p><b>Event Type</b>: {{ event.event_type }}</p>
<p><b>Location</b>: {{ event_location }}</p>
<p><b>Date(s) and Time(s)</b>: {{ event | process_event_time }}</p>
Expand Down
4 changes: 2 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.