Admin reset email problem

Hi. I found what I think must be a fairly recent bug in seahub, found with a brand new install of seafile 12 via docker compose following the instructions from the website.

The problem occurs when an admin resets a password for a user. In some cases this succeeds, but in others it gives the following error in the seahub log:

[WARNING] seahub.api2.endpoints.admin.users:1537 put cannot access local variable 'get_site_name' where it is not associated with a value

I didn’t see anything on this forum about this error so I took a look at the line it mentions in the warning (in /opt/seafile/seafile-server-12.0.11/seahub/seahub/api2/endpoints/admin/users.py). Sure enough, it does not have access to get_site_name() from that scope. Other branches import the variable but this one does not. I fixed it by changing the file adding:

                from seahub.utils import get_site_name
                from django.utils.http import int_to_base36
                from seahub.auth.tokens import default_token_generator

just above the point where the error occurred, after these pre-existing lines:

        if IS_EMAIL_CONFIGURED:
            if SEND_EMAIL_ON_RESETTING_USER_PASSWD:

Now it works great. There may be other places where similar issues occur; I didn’t check. I assume that until recently this variable was not scoped and this branch (and perhaps others) were missed during the update.

I had thought this was fixed upstream but it turned out it has not yet been, so I submitted a pull request on the github as well. This post is more so people can understand the issue until that pull request is merged.