Skip to content

Commit 4dfbb86

Browse files
committed
Fix staff not linking to user, slightly added more to privacy (pending GDPR response), added dependabot.
1 parent 2276f28 commit 4dfbb86

3 files changed

Lines changed: 31 additions & 21 deletions

File tree

.github/workflows/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 2
2+
3+
updates:
4+
- package-ecosystem: "uv"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"
8+
groups:
9+
python-packages:
10+
patterns:
11+
- "*"

app/models/staff.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -224,37 +224,36 @@ def update_staff_link(sender, instance, created, **kwargs):
224224
:param kwargs:
225225
:return:
226226
"""
227-
if not hasattr(instance, 'staff') and not instance.is_superuser:
228-
# If this user isn't linked to a staff member
227+
if '@' in instance.username:
228+
# If this isn't the default Django superuser (who won't have an email-based account)
229229
account: str = instance.username.split('@')[0]
230230

231231
try:
232-
logger.info(f"Looking up a staff member for user {instance.username}")
232+
logger.info(f"Looking up a staff member for user '{instance.username}'")
233233
staff: Staff|None = Staff.objects.get(account=account)
234234

235235
except Staff.DoesNotExist:
236236
# There's no staff member with this account name, so let's try surname...
237237
try:
238-
logger.info(f"No account match for {account}, looking for last name {instance.last_name}")
238+
logger.info(f"No account match for {account}, looking for last name '{instance.last_name}'")
239239
staff = Staff.objects.get(name=instance.last_name)
240240

241241
except Staff.DoesNotExist:
242-
logger.info(f"No staff with last name {instance.last_name}")
242+
logger.info(f"No staff with last name '{instance.last_name}'")
243243
staff = None
244244

245-
if staff:
246-
# If we did find a staff member, then update that member with account number, name from AD, link them.
247-
staff.user = instance
248-
staff.account = account
249-
staff.name = f"{instance.first_name} {instance.last_name}"
250-
staff.save()
251-
logger.info(f"Updated Staff: {instance.username} - {staff}")
252-
245+
# Don't create a staff record for the manual Django superuser
246+
# Otherwise, either create a new Staff model from their ActiveDirectory account,
247+
# or just update their Staff model with their full name from the AD account.
248+
249+
staff, staff_created = Staff.objects.update_or_create(
250+
account=instance.username.split('@')[0],
251+
user=instance,
252+
defaults={
253+
'name': f"{instance.first_name} {instance.last_name}",
254+
}
255+
)
256+
if staff_created:
257+
logger.info(f"Created Staff: '{instance.username}' - {staff}")
253258
else:
254-
# If there's no staff member for this user, create one
255-
staff = Staff(
256-
account=account,
257-
user=instance,
258-
name=f"{instance.first_name} {instance.last_name}",
259-
)
260-
logger.info(f"Created Staff: {instance.username} - {staff}")
259+
logger.info(f"Updated Staff: '{instance.username}' - {staff}")

app/templates/app/basic/privacy.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ <h2>Where we get personal information from</h2>
7575

7676
<h2>How long we keep information</h2>
7777
<p>
78-
[Insert information about how long you store personal information here.]
78+
Your information is kept as long as you are an active member of staff.
7979
</p>
8080
<br>
8181

0 commit comments

Comments
 (0)