Skip to content

Commit 7594ebd

Browse files
committed
Merge branch 'main' of github.com:Southampton-RSG/physics-workload
2 parents 184bb87 + 527224b commit 7594ebd

3 files changed

Lines changed: 27 additions & 21 deletions

File tree

.github/dependabot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
3+
updates:
4+
- package-ecosystem: "uv"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"

app/models/staff.py

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

236236
try:
237-
logger.info(f"Looking up a staff member for user {instance.username}")
237+
logger.info(f"Looking up a staff member for user '{instance.username}'")
238238
staff: Staff|None = Staff.objects.get(account=account)
239239

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

246246
except Staff.DoesNotExist:
247-
logger.info(f"No staff with last name {instance.last_name}")
247+
logger.info(f"No staff with last name '{instance.last_name}'")
248248
staff = None
249249

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