Mercurial > kallithea
diff kallithea/controllers/changeset.py @ 7092:aa25ef34ebab
auth: refactor to introduce @LoginRequired(allow_default_user=True) and deprecate @NotAnonymous()
It was error prone that @LoginRequired defaulted to allow anonymous users (if
'default' user is enabled). See also 245b4e3abf39.
Refactor code to make it more explicit and safe by default: Deprecate
@NotAnonymous by making it the default of @LoginRequired. That will make it
safe by default.
To preserve same functionality, set allow_default_user=True in all the cases
where @LoginRequired was *not* followed by @NotAnonymous or other permission
checks - that was done with some script hacks:
sed -i 's/@LoginRequired(\(..*\))/@LoginRequired(\1, allow_default_user=True)/g' `hg mani`
sed -i 's/@LoginRequired()/@LoginRequired(allow_default_user=True)/g' `hg mani`
perl -0pi -e 's/\@LoginRequired\(allow_default_user=True\)\n\s*\@NotAnonymous\(\)/\@LoginRequired()/g' `hg mani`
perl -0pi -e 's/\@LoginRequired\(allow_default_user=True\)(\n\s*\@Has(Repo)?Permission)/\@LoginRequired()\1/g' `hg mani`
It has been reviewed that all uses of allow_default_user=True are in places
where the there indeed wasn't any checking for default user before. These may
or may not be correct, but now they are explicit and can be spotted and fixed.
The few remaining uses of @NotAnonymous should probably be removed somehow.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Sun, 21 Jan 2018 02:49:15 +0100 |
parents | 205daed7185b |
children | 9f976d75b04c |
line wrap: on
line diff
--- a/kallithea/controllers/changeset.py Sat Dec 16 22:10:45 2017 +0100 +++ b/kallithea/controllers/changeset.py Sun Jan 21 02:49:15 2018 +0100 @@ -37,8 +37,7 @@ ChangesetDoesNotExistError, EmptyRepositoryError import kallithea.lib.helpers as h -from kallithea.lib.auth import LoginRequired, HasRepoPermissionLevelDecorator, \ - NotAnonymous +from kallithea.lib.auth import LoginRequired, HasRepoPermissionLevelDecorator from kallithea.lib.base import BaseRepoController, render, jsonify from kallithea.lib.utils import action_logger from kallithea.lib.compat import OrderedDict @@ -348,7 +347,6 @@ return self._index(revision, method='download') @LoginRequired() - @NotAnonymous() @HasRepoPermissionLevelDecorator('read') @jsonify def comment(self, repo_name, revision): @@ -399,7 +397,6 @@ return data @LoginRequired() - @NotAnonymous() @HasRepoPermissionLevelDecorator('read') @jsonify def delete_comment(self, repo_name, comment_id):