mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Rework user hack for "login-free" sessions #394
This commit is contained in:
		| @@ -10,6 +10,12 @@ Changelog | ||||
|   been updated on the Docker Hub, so you just need to pull the latest one from | ||||
|   there if you're a Docker user. | ||||
|  | ||||
| * "Login free" instances of Paperless were breaking whenever you tried to edit | ||||
|   objects in the admin: adding/deleting tags or correspondents, or even fixing | ||||
|   spelling.  This was due to the "user hack" we were applying to sessions that | ||||
|   weren't using a login, as that hack user didn't have a valid id.  The fix was | ||||
|   to attribute the first user id in the system to this hack user.  `#394`_ | ||||
|  | ||||
| * A problem in how we handle slug values on Tags and Correspondents required a | ||||
|   few changes to how we handle this field `#393`_: | ||||
|  | ||||
| @@ -648,6 +654,7 @@ bulk of the work on this big change. | ||||
| .. _#392: https://github.com/danielquinn/paperless/issues/392 | ||||
| .. _#393: https://github.com/danielquinn/paperless/issues/393 | ||||
| .. _#395: https://github.com/danielquinn/paperless/pull/395 | ||||
| .. _#394: https://github.com/danielquinn/paperless/issues/394 | ||||
| .. _#396: https://github.com/danielquinn/paperless/pull/396 | ||||
| .. _#399: https://github.com/danielquinn/paperless/pull/399 | ||||
| .. _#400: https://github.com/danielquinn/paperless/pull/400 | ||||
|   | ||||
| @@ -1,15 +1,20 @@ | ||||
| from django.contrib.auth.models import User as DjangoUser | ||||
|  | ||||
|  | ||||
| class User: | ||||
|     """ | ||||
|       This is a dummy django User used with our middleware to disable | ||||
|       login authentication if that is configured in paperless.conf | ||||
|     This is a dummy django User used with our middleware to disable | ||||
|     login authentication if that is configured in paperless.conf | ||||
|     """ | ||||
|  | ||||
|     is_superuser = True | ||||
|     is_active = True | ||||
|     is_staff = True | ||||
|     is_authenticated = True | ||||
|  | ||||
|     # Must be -1 to avoid colliding with real user ID's (which start at 1) | ||||
|     id = -1 | ||||
|     @property | ||||
|     def id(self): | ||||
|         return DjangoUser.objects.order_by("pk").first().pk | ||||
|  | ||||
|     @property | ||||
|     def pk(self): | ||||
| @@ -17,9 +22,9 @@ class User: | ||||
|  | ||||
|  | ||||
| """ | ||||
|   NOTE: These are here as a hack instead of being in the User definition | ||||
|   above due to the way pycodestyle handles lamdbdas. | ||||
|   See https://github.com/PyCQA/pycodestyle/issues/379 for more. | ||||
| NOTE: These are here as a hack instead of being in the User definition | ||||
| NOTE: above due to the way pycodestyle handles lamdbdas. | ||||
| NOTE: See https://github.com/PyCQA/pycodestyle/issues/379 for more. | ||||
| """ | ||||
|  | ||||
| User.has_module_perms = lambda *_: True | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Daniel Quinn
					Daniel Quinn