| 217 | acreate_superuser.alters_data = True |
| 218 | |
| 219 | def with_perm( |
| 220 | self, perm, is_active=True, include_superusers=True, backend=None, obj=None |
| 221 | ): |
| 222 | if backend is None: |
| 223 | backends = auth.get_backends() |
| 224 | if len(backends) == 1: |
| 225 | backend = backends[0] |
| 226 | else: |
| 227 | raise ValueError( |
| 228 | "You have multiple authentication backends configured and " |
| 229 | "therefore must provide the `backend` argument." |
| 230 | ) |
| 231 | elif not isinstance(backend, str): |
| 232 | raise TypeError( |
| 233 | "backend must be a dotted import path string (got %r)." % backend |
| 234 | ) |
| 235 | else: |
| 236 | backend = auth.load_backend(backend) |
| 237 | if hasattr(backend, "with_perm"): |
| 238 | return backend.with_perm( |
| 239 | perm, |
| 240 | is_active=is_active, |
| 241 | include_superusers=include_superusers, |
| 242 | obj=obj, |
| 243 | ) |
| 244 | return self.none() |
| 245 | |
| 246 | |
| 247 | # A few helper functions for common logic between User and AnonymousUser. |