vj4 icon indicating copy to clipboard operation
vj4 copied to clipboard

Fix dudoc_has_perm

Open moesoha opened this issue 3 years ago • 2 comments

moesoha avatar Jan 01 '22 09:01 moesoha

I think we should use ROLE_DEFAULT if udoc has PRIV_USER_PROFILE.

undefined-moe avatar Jan 13 '22 04:01 undefined-moe

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.

twd2 avatar Jan 16 '22 08:01 twd2