vj4
vj4 copied to clipboard
Fix dudoc_has_perm
I think we should use ROLE_DEFAULT if udoc has PRIV_USER_PROFILE.
From original comment it seems like the intention was to fix the caller. From code reference all 3 callers (problem.py:242, problem.py:613, problem.py:633) will not pass in null
dudoc
. In this case, we can remove the comment and null check. The modified code should look like this:def dudoc_has_perm(self, ...): if not udoc: role = builtin.ROLE_GUEST else: role = dudoc.get('role', builtin.ROLE_DEFAULT) ...
There are also a lot of uses of dudoc_has_perm
from templates, e.g., ui/templates/user_detail.html:69 and ui/templates/components/user.html:21 (the render_inline
macro, which is used everywhere). I'm not sure whether they will pass in null dudoc
. So I prefer to keep the comment and the null check.