Fix mention sanitize when `g.v` not present.

This bug was discovered when lottery.check_if_end_lottery_task was
failing due to a stack trace thru end_lottery session < badge_grant
< send_repeatable_notifications < sanitize L208. In particular, when
`flask cron` (helpers/cron.py) executes, it does not set g.v, whereas
this code previously assumed that g.v : (None + User) and did not
check for its presence.
remotes/1693045480750635534/spooky-22
Snakes 2022-06-18 21:22:04 -04:00
parent 214d863ff3
commit e5193cbd46
1 changed files with 2 additions and 1 deletions

View File

@ -201,11 +201,12 @@ def sanitize(sanitized, alert=False, edit=False):
names = set( m.group(2) for m in matches )
users = get_users(names,graceful=True)
v = getattr(g, 'v', None)
for u in users:
if not u: continue
m = [ m for m in matches if u.username.lower() == m.group(2).lower() or u.original_username.lower() == m.group(2).lower() ]
for i in m:
if not (g.v and g.v.any_block_exists(u)) or g.v.admin_level > 1:
if not (v and v.any_block_exists(u)) or (v and v.admin_level >= 2):
sanitized = sanitized.replace(i.group(0), f'''{i.group(1)}<a href="/id/{u.id}"><img loading="lazy" src="/pp/{u.id}">@{u.username}</a>''', 1)