django-usermgmt 1.0.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- django_usermgmt-1.0.6/.gitignore +41 -0
- django_usermgmt-1.0.6/CHANGELOG.md +17 -0
- django_usermgmt-1.0.6/LICENSE +21 -0
- django_usermgmt-1.0.6/PKG-INFO +229 -0
- django_usermgmt-1.0.6/README.md +186 -0
- django_usermgmt-1.0.6/docs/ARCHITECTURE.md +333 -0
- django_usermgmt-1.0.6/docs/COMMAND_REFERENCE.md +346 -0
- django_usermgmt-1.0.6/docs/DEVELOPER_GUIDE.md +206 -0
- django_usermgmt-1.0.6/docs/SECURITY.md +167 -0
- django_usermgmt-1.0.6/docs/TROUBLESHOOTING.md +120 -0
- django_usermgmt-1.0.6/docs/USER_GUIDE.md +393 -0
- django_usermgmt-1.0.6/examples/settings_snippet.py +36 -0
- django_usermgmt-1.0.6/examples/users.csv +3 -0
- django_usermgmt-1.0.6/examples/users.json +5 -0
- django_usermgmt-1.0.6/pyproject.toml +100 -0
- django_usermgmt-1.0.6/usermgmt/__init__.py +6 -0
- django_usermgmt-1.0.6/usermgmt/apps.py +13 -0
- django_usermgmt-1.0.6/usermgmt/management/__init__.py +6 -0
- django_usermgmt-1.0.6/usermgmt/management/commands/__init__.py +6 -0
- django_usermgmt-1.0.6/usermgmt/management/commands/usermgr.py +530 -0
- django_usermgmt-1.0.6/usermgmt/services.py +785 -0
- django_usermgmt-1.0.6/usermgmt/tests/__init__.py +6 -0
- django_usermgmt-1.0.6/usermgmt/tests/test_usermgr.py +119 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
*.pyc
|
|
2
|
+
*.bak
|
|
3
|
+
*.zip
|
|
4
|
+
*.rar
|
|
5
|
+
*.7z
|
|
6
|
+
*.mp3
|
|
7
|
+
*.wav
|
|
8
|
+
*.sublime-workspace
|
|
9
|
+
.hg/
|
|
10
|
+
build/
|
|
11
|
+
*.hgignore
|
|
12
|
+
*.hgtags
|
|
13
|
+
*dist/
|
|
14
|
+
*.egg-info/
|
|
15
|
+
traceback.log
|
|
16
|
+
__pycache__/
|
|
17
|
+
*.log
|
|
18
|
+
downloads/
|
|
19
|
+
download/
|
|
20
|
+
.pt/
|
|
21
|
+
gitignore_backup/
|
|
22
|
+
gitignore_backups/
|
|
23
|
+
src/tmp*
|
|
24
|
+
tmp*
|
|
25
|
+
PLAN.md
|
|
26
|
+
CLAUDE.md
|
|
27
|
+
ERROR*
|
|
28
|
+
ANSWER*
|
|
29
|
+
*egg-info*/
|
|
30
|
+
|
|
31
|
+
# Added entries (4 items)
|
|
32
|
+
*sublime*
|
|
33
|
+
*.patch
|
|
34
|
+
PLAN*.md
|
|
35
|
+
QUESTION*.md
|
|
36
|
+
|
|
37
|
+
# Added entries (1 items)
|
|
38
|
+
README.id.md
|
|
39
|
+
|
|
40
|
+
# Added entries (1 items)
|
|
41
|
+
README.orig.md
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
5
|
+
|
|
6
|
+
## [1.0.0] - 2026-11-16
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
- `usermgr` management command with 26 actions covering users, permissions, groups and bulk operations.
|
|
10
|
+
- Service layer (`usermgmt.services`) reusable from scripts, Celery tasks and tests.
|
|
11
|
+
- Support for custom user models via `USERNAME_FIELD` and `--field KEY=VALUE`.
|
|
12
|
+
- Safe password input (interactive prompt, stdin, environment variable) with `AUTH_PASSWORD_VALIDATORS` enforcement.
|
|
13
|
+
- Last-active-superuser guard on delete, deactivate and demote.
|
|
14
|
+
- Bulk import (CSV/JSON) with per-row savepoints and `--dry-run`; export to CSV/JSON.
|
|
15
|
+
- Audit logging through the `usermgmt.audit` logger.
|
|
16
|
+
- `table`, `json` and `csv` output formats.
|
|
17
|
+
- Documentation: README, user guide, command reference, architecture, security and troubleshooting guides.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hadi Cahyadi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: django-usermgmt
|
|
3
|
+
Version: 1.0.6
|
|
4
|
+
Summary: A production-oriented command line toolkit for managing users, groups and permissions in any Django project.
|
|
5
|
+
Project-URL: Homepage, https://github.com/cumulus13/django-usermgmt
|
|
6
|
+
Project-URL: Documentation, https://github.com/cumulus13/django-usermgmt/tree/main/docs
|
|
7
|
+
Project-URL: Repository, https://github.com/cumulus13/django-usermgmt.git
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/cumulus13/django-usermgmt/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/cumulus13/django-usermgmt/blob/main/CHANGELOG.md
|
|
10
|
+
Author-email: Hadi Cahyadi <cumulus13@gmail.com>
|
|
11
|
+
Maintainer-email: Hadi Cahyadi <cumulus13@gmail.com>
|
|
12
|
+
License-Expression: MIT
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Keywords: audit-log,bulk-import,cli,django,groups,management-command,permissions,user-management,usermgr
|
|
15
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
16
|
+
Classifier: Environment :: Console
|
|
17
|
+
Classifier: Environment :: Web Environment
|
|
18
|
+
Classifier: Framework :: Django
|
|
19
|
+
Classifier: Framework :: Django :: 4.2
|
|
20
|
+
Classifier: Framework :: Django :: 5.0
|
|
21
|
+
Classifier: Framework :: Django :: 5.1
|
|
22
|
+
Classifier: Framework :: Django :: 5.2
|
|
23
|
+
Classifier: Intended Audience :: Developers
|
|
24
|
+
Classifier: Intended Audience :: System Administrators
|
|
25
|
+
Classifier: Operating System :: OS Independent
|
|
26
|
+
Classifier: Programming Language :: Python :: 3
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
28
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
29
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
30
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
31
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
32
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
33
|
+
Classifier: Topic :: System :: Systems Administration :: Authentication/Directory
|
|
34
|
+
Requires-Python: >=3.9
|
|
35
|
+
Requires-Dist: django>=4.2
|
|
36
|
+
Provides-Extra: dev
|
|
37
|
+
Requires-Dist: build; extra == 'dev'
|
|
38
|
+
Requires-Dist: pytest-django>=4.8; extra == 'dev'
|
|
39
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
40
|
+
Requires-Dist: ruff>=0.6.0; extra == 'dev'
|
|
41
|
+
Requires-Dist: twine; extra == 'dev'
|
|
42
|
+
Description-Content-Type: text/markdown
|
|
43
|
+
|
|
44
|
+
# django-usermgmt
|
|
45
|
+
|
|
46
|
+
<p align="center">
|
|
47
|
+
<img src="https://raw.githubusercontent.com/licface15/images/refs/heads/main/django-usermgmt/logo.png" width="40%" alt="logo">
|
|
48
|
+
</p>
|
|
49
|
+
|
|
50
|
+
<p align="center">
|
|
51
|
+
<img src="https://raw.githubusercontent.com/licface15/images/refs/heads/main/django-usermgmt/screenshot.png" width="98%" alt="logo">
|
|
52
|
+
</p>
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
A production-oriented command line toolkit for managing **users, groups and permissions** in any Django project.
|
|
56
|
+
|
|
57
|
+
Stock `manage.py` only ships `createsuperuser` and `changepassword`. There is no built-in way to create a regular
|
|
58
|
+
user, list users, inspect permissions, manage groups or import accounts in bulk. `django-usermgmt` adds a single
|
|
59
|
+
management command, `usermgr`, that covers all of that, with safety guards, audit logging and scriptable output.
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
python manage.py usermgr create-user john --email john@example.com --group editors --create-missing-groups
|
|
63
|
+
python manage.py usermgr list-users --active --format json
|
|
64
|
+
python manage.py usermgr who-can blog.add_post
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Highlights
|
|
68
|
+
|
|
69
|
+
- **26 actions** across users, permissions, groups and bulk import/export.
|
|
70
|
+
- **Custom user model support**: the login field is read from `USERNAME_FIELD`; extra fields via `--field KEY=VALUE`.
|
|
71
|
+
- **Safe password handling**: interactive prompt, stdin or environment variable; validated against
|
|
72
|
+
`AUTH_PASSWORD_VALIDATORS`; never logged.
|
|
73
|
+
- **Safety guards**: the last active superuser cannot be deleted, deactivated or demoted without `--force`;
|
|
74
|
+
destructive actions ask for confirmation.
|
|
75
|
+
- **Atomic and auditable**: every mutation runs in a transaction and writes a line to the `usermgmt.audit` logger.
|
|
76
|
+
- **Automation friendly**: `table`, `json` and `csv` output, stable exit codes, no prompts when stdin is not a TTY.
|
|
77
|
+
- **Layered design**: all logic lives in `usermgmt.services`; the command is a thin CLI wrapper you can bypass.
|
|
78
|
+
|
|
79
|
+
## Requirements
|
|
80
|
+
|
|
81
|
+
| Component | Version |
|
|
82
|
+
|---|---|
|
|
83
|
+
| Python | 3.9 or newer |
|
|
84
|
+
| Django | 4.2 or newer |
|
|
85
|
+
|
|
86
|
+
No third-party dependencies.
|
|
87
|
+
|
|
88
|
+
## Installation
|
|
89
|
+
|
|
90
|
+
1. Copy the `usermgmt/` directory into your project, next to `manage.py`.
|
|
91
|
+
2. Add it to `INSTALLED_APPS`:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
INSTALLED_APPS = [
|
|
95
|
+
# ...
|
|
96
|
+
"django.contrib.auth",
|
|
97
|
+
"django.contrib.contenttypes",
|
|
98
|
+
"usermgmt",
|
|
99
|
+
]
|
|
100
|
+
```
|
|
101
|
+
3. Verify:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
python manage.py usermgr -h
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
See [`examples/settings_snippet.py`](examples/settings_snippet.py) for an audit-log configuration.
|
|
108
|
+
|
|
109
|
+
## Quick tour
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
# Create users
|
|
113
|
+
python manage.py usermgr create-user john --email john@example.com # prompts for a password
|
|
114
|
+
echo "$PW" | python manage.py usermgr create-user sari --password-stdin
|
|
115
|
+
python manage.py usermgr create-user svc-sso --no-password # unusable password (SSO / API only)
|
|
116
|
+
python manage.py usermgr create-user ops --staff --group operators --create-missing-groups
|
|
117
|
+
|
|
118
|
+
# Inspect
|
|
119
|
+
python manage.py usermgr list-users --active --stale-days 90 --format csv
|
|
120
|
+
python manage.py usermgr show-user john --all-perms
|
|
121
|
+
python manage.py usermgr check-user john --perm auth.view_user
|
|
122
|
+
|
|
123
|
+
# Permissions and groups
|
|
124
|
+
python manage.py usermgr create-group editors --perm blog.add_post --perm blog.change_post
|
|
125
|
+
python manage.py usermgr add-to-group john editors
|
|
126
|
+
python manage.py usermgr grant-perm john "reports.*"
|
|
127
|
+
python manage.py usermgr who-can blog.add_post
|
|
128
|
+
|
|
129
|
+
# Lifecycle
|
|
130
|
+
python manage.py usermgr set-password john --revoke-sessions
|
|
131
|
+
python manage.py usermgr deactivate john --revoke-sessions
|
|
132
|
+
|
|
133
|
+
# Bulk
|
|
134
|
+
python manage.py usermgr import-users examples/users.csv --dry-run
|
|
135
|
+
python manage.py usermgr export-users --format csv --output users.csv
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Action overview
|
|
139
|
+
|
|
140
|
+
```mermaid
|
|
141
|
+
mindmap
|
|
142
|
+
root((usermgr))
|
|
143
|
+
Users
|
|
144
|
+
create-user
|
|
145
|
+
list-users
|
|
146
|
+
show-user
|
|
147
|
+
check-user
|
|
148
|
+
update-user
|
|
149
|
+
set-password
|
|
150
|
+
set-flags
|
|
151
|
+
activate
|
|
152
|
+
deactivate
|
|
153
|
+
delete-user
|
|
154
|
+
revoke-sessions
|
|
155
|
+
Permissions
|
|
156
|
+
grant-perm
|
|
157
|
+
revoke-perm
|
|
158
|
+
list-perms
|
|
159
|
+
who-can
|
|
160
|
+
Groups
|
|
161
|
+
create-group
|
|
162
|
+
delete-group
|
|
163
|
+
rename-group
|
|
164
|
+
list-groups
|
|
165
|
+
show-group
|
|
166
|
+
group-grant
|
|
167
|
+
group-revoke
|
|
168
|
+
add-to-group
|
|
169
|
+
remove-from-group
|
|
170
|
+
Bulk
|
|
171
|
+
import-users
|
|
172
|
+
export-users
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
[](https://raw.githubusercontent.com/licface15/images/refs/heads/main/django-usermgmt/architecture1.jpg)
|
|
176
|
+
|
|
177
|
+
## How it fits together
|
|
178
|
+
|
|
179
|
+
```mermaid
|
|
180
|
+
flowchart LR
|
|
181
|
+
Admin["Operator / script / CI"] -->|"manage.py usermgr ..."| CLI["usermgr command<br/>(argparse, output, prompts)"]
|
|
182
|
+
CLI --> SVC["usermgmt.services<br/>(business logic)"]
|
|
183
|
+
Py["Your Python code<br/>(Celery, shell, tests)"] --> SVC
|
|
184
|
+
SVC --> ORM["Django ORM<br/>auth.User / Group / Permission"]
|
|
185
|
+
SVC --> LOG["usermgmt.audit logger"]
|
|
186
|
+
ORM --> DB[("Database")]
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
[](https://raw.githubusercontent.com/licface15/images/refs/heads/main/django-usermgmt/architecture2.jpg)
|
|
190
|
+
|
|
191
|
+
## Documentation
|
|
192
|
+
|
|
193
|
+
| Document | Purpose |
|
|
194
|
+
|---|---|
|
|
195
|
+
| [User guide](docs/USER_GUIDE.md) | Task-oriented walkthroughs and recipes |
|
|
196
|
+
| [Command reference](docs/COMMAND_REFERENCE.md) | Every action, argument, output and exit code |
|
|
197
|
+
| [Architecture](docs/ARCHITECTURE.md) | Design, data model and flow diagrams |
|
|
198
|
+
| [Security guide](docs/SECURITY.md) | Threat model, password handling, audit logging, hardening checklist |
|
|
199
|
+
| [Developer guide](docs/DEVELOPER_GUIDE.md) | Using the service layer, extending the command, running tests |
|
|
200
|
+
| [Troubleshooting](docs/TROUBLESHOOTING.md) | Common errors and fixes |
|
|
201
|
+
| [Changelog](CHANGELOG.md) | Release history |
|
|
202
|
+
|
|
203
|
+
## Running the tests
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
python manage.py test usermgmt
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Known limitations
|
|
210
|
+
|
|
211
|
+
- Operates on the default database connection only (no `--database` option yet).
|
|
212
|
+
- `revoke-sessions` supports database-backed sessions (`django.contrib.sessions`) only.
|
|
213
|
+
- `who-can` evaluates permissions the way Django's `ModelBackend` does (superuser, direct, via group).
|
|
214
|
+
Custom authentication backends with their own permission logic are not consulted.
|
|
215
|
+
- Passwords in import files are plain text; protect and delete those files (see the [security guide](docs/SECURITY.md)).
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
**for cli's color, install `pip install rchf`**
|
|
219
|
+
|
|
220
|
+
## 👤 Author
|
|
221
|
+
|
|
222
|
+
[Hadi Cahyadi](mailto:cumulus13@gmail.com)
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
[](https://www.buymeacoffee.com/cumulus13)
|
|
226
|
+
|
|
227
|
+
[](https://ko-fi.com/cumulus13)
|
|
228
|
+
|
|
229
|
+
[Support me on Patreon](https://www.patreon.com/cumulus13)
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# django-usermgmt
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/licface15/images/refs/heads/main/django-usermgmt/logo.png" width="40%" alt="logo">
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<img src="https://raw.githubusercontent.com/licface15/images/refs/heads/main/django-usermgmt/screenshot.png" width="98%" alt="logo">
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
A production-oriented command line toolkit for managing **users, groups and permissions** in any Django project.
|
|
13
|
+
|
|
14
|
+
Stock `manage.py` only ships `createsuperuser` and `changepassword`. There is no built-in way to create a regular
|
|
15
|
+
user, list users, inspect permissions, manage groups or import accounts in bulk. `django-usermgmt` adds a single
|
|
16
|
+
management command, `usermgr`, that covers all of that, with safety guards, audit logging and scriptable output.
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
python manage.py usermgr create-user john --email john@example.com --group editors --create-missing-groups
|
|
20
|
+
python manage.py usermgr list-users --active --format json
|
|
21
|
+
python manage.py usermgr who-can blog.add_post
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Highlights
|
|
25
|
+
|
|
26
|
+
- **26 actions** across users, permissions, groups and bulk import/export.
|
|
27
|
+
- **Custom user model support**: the login field is read from `USERNAME_FIELD`; extra fields via `--field KEY=VALUE`.
|
|
28
|
+
- **Safe password handling**: interactive prompt, stdin or environment variable; validated against
|
|
29
|
+
`AUTH_PASSWORD_VALIDATORS`; never logged.
|
|
30
|
+
- **Safety guards**: the last active superuser cannot be deleted, deactivated or demoted without `--force`;
|
|
31
|
+
destructive actions ask for confirmation.
|
|
32
|
+
- **Atomic and auditable**: every mutation runs in a transaction and writes a line to the `usermgmt.audit` logger.
|
|
33
|
+
- **Automation friendly**: `table`, `json` and `csv` output, stable exit codes, no prompts when stdin is not a TTY.
|
|
34
|
+
- **Layered design**: all logic lives in `usermgmt.services`; the command is a thin CLI wrapper you can bypass.
|
|
35
|
+
|
|
36
|
+
## Requirements
|
|
37
|
+
|
|
38
|
+
| Component | Version |
|
|
39
|
+
|---|---|
|
|
40
|
+
| Python | 3.9 or newer |
|
|
41
|
+
| Django | 4.2 or newer |
|
|
42
|
+
|
|
43
|
+
No third-party dependencies.
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
1. Copy the `usermgmt/` directory into your project, next to `manage.py`.
|
|
48
|
+
2. Add it to `INSTALLED_APPS`:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
INSTALLED_APPS = [
|
|
52
|
+
# ...
|
|
53
|
+
"django.contrib.auth",
|
|
54
|
+
"django.contrib.contenttypes",
|
|
55
|
+
"usermgmt",
|
|
56
|
+
]
|
|
57
|
+
```
|
|
58
|
+
3. Verify:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
python manage.py usermgr -h
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
See [`examples/settings_snippet.py`](examples/settings_snippet.py) for an audit-log configuration.
|
|
65
|
+
|
|
66
|
+
## Quick tour
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# Create users
|
|
70
|
+
python manage.py usermgr create-user john --email john@example.com # prompts for a password
|
|
71
|
+
echo "$PW" | python manage.py usermgr create-user sari --password-stdin
|
|
72
|
+
python manage.py usermgr create-user svc-sso --no-password # unusable password (SSO / API only)
|
|
73
|
+
python manage.py usermgr create-user ops --staff --group operators --create-missing-groups
|
|
74
|
+
|
|
75
|
+
# Inspect
|
|
76
|
+
python manage.py usermgr list-users --active --stale-days 90 --format csv
|
|
77
|
+
python manage.py usermgr show-user john --all-perms
|
|
78
|
+
python manage.py usermgr check-user john --perm auth.view_user
|
|
79
|
+
|
|
80
|
+
# Permissions and groups
|
|
81
|
+
python manage.py usermgr create-group editors --perm blog.add_post --perm blog.change_post
|
|
82
|
+
python manage.py usermgr add-to-group john editors
|
|
83
|
+
python manage.py usermgr grant-perm john "reports.*"
|
|
84
|
+
python manage.py usermgr who-can blog.add_post
|
|
85
|
+
|
|
86
|
+
# Lifecycle
|
|
87
|
+
python manage.py usermgr set-password john --revoke-sessions
|
|
88
|
+
python manage.py usermgr deactivate john --revoke-sessions
|
|
89
|
+
|
|
90
|
+
# Bulk
|
|
91
|
+
python manage.py usermgr import-users examples/users.csv --dry-run
|
|
92
|
+
python manage.py usermgr export-users --format csv --output users.csv
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Action overview
|
|
96
|
+
|
|
97
|
+
```mermaid
|
|
98
|
+
mindmap
|
|
99
|
+
root((usermgr))
|
|
100
|
+
Users
|
|
101
|
+
create-user
|
|
102
|
+
list-users
|
|
103
|
+
show-user
|
|
104
|
+
check-user
|
|
105
|
+
update-user
|
|
106
|
+
set-password
|
|
107
|
+
set-flags
|
|
108
|
+
activate
|
|
109
|
+
deactivate
|
|
110
|
+
delete-user
|
|
111
|
+
revoke-sessions
|
|
112
|
+
Permissions
|
|
113
|
+
grant-perm
|
|
114
|
+
revoke-perm
|
|
115
|
+
list-perms
|
|
116
|
+
who-can
|
|
117
|
+
Groups
|
|
118
|
+
create-group
|
|
119
|
+
delete-group
|
|
120
|
+
rename-group
|
|
121
|
+
list-groups
|
|
122
|
+
show-group
|
|
123
|
+
group-grant
|
|
124
|
+
group-revoke
|
|
125
|
+
add-to-group
|
|
126
|
+
remove-from-group
|
|
127
|
+
Bulk
|
|
128
|
+
import-users
|
|
129
|
+
export-users
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
[](https://raw.githubusercontent.com/licface15/images/refs/heads/main/django-usermgmt/architecture1.jpg)
|
|
133
|
+
|
|
134
|
+
## How it fits together
|
|
135
|
+
|
|
136
|
+
```mermaid
|
|
137
|
+
flowchart LR
|
|
138
|
+
Admin["Operator / script / CI"] -->|"manage.py usermgr ..."| CLI["usermgr command<br/>(argparse, output, prompts)"]
|
|
139
|
+
CLI --> SVC["usermgmt.services<br/>(business logic)"]
|
|
140
|
+
Py["Your Python code<br/>(Celery, shell, tests)"] --> SVC
|
|
141
|
+
SVC --> ORM["Django ORM<br/>auth.User / Group / Permission"]
|
|
142
|
+
SVC --> LOG["usermgmt.audit logger"]
|
|
143
|
+
ORM --> DB[("Database")]
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
[](https://raw.githubusercontent.com/licface15/images/refs/heads/main/django-usermgmt/architecture2.jpg)
|
|
147
|
+
|
|
148
|
+
## Documentation
|
|
149
|
+
|
|
150
|
+
| Document | Purpose |
|
|
151
|
+
|---|---|
|
|
152
|
+
| [User guide](docs/USER_GUIDE.md) | Task-oriented walkthroughs and recipes |
|
|
153
|
+
| [Command reference](docs/COMMAND_REFERENCE.md) | Every action, argument, output and exit code |
|
|
154
|
+
| [Architecture](docs/ARCHITECTURE.md) | Design, data model and flow diagrams |
|
|
155
|
+
| [Security guide](docs/SECURITY.md) | Threat model, password handling, audit logging, hardening checklist |
|
|
156
|
+
| [Developer guide](docs/DEVELOPER_GUIDE.md) | Using the service layer, extending the command, running tests |
|
|
157
|
+
| [Troubleshooting](docs/TROUBLESHOOTING.md) | Common errors and fixes |
|
|
158
|
+
| [Changelog](CHANGELOG.md) | Release history |
|
|
159
|
+
|
|
160
|
+
## Running the tests
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
python manage.py test usermgmt
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Known limitations
|
|
167
|
+
|
|
168
|
+
- Operates on the default database connection only (no `--database` option yet).
|
|
169
|
+
- `revoke-sessions` supports database-backed sessions (`django.contrib.sessions`) only.
|
|
170
|
+
- `who-can` evaluates permissions the way Django's `ModelBackend` does (superuser, direct, via group).
|
|
171
|
+
Custom authentication backends with their own permission logic are not consulted.
|
|
172
|
+
- Passwords in import files are plain text; protect and delete those files (see the [security guide](docs/SECURITY.md)).
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
**for cli's color, install `pip install rchf`**
|
|
176
|
+
|
|
177
|
+
## 👤 Author
|
|
178
|
+
|
|
179
|
+
[Hadi Cahyadi](mailto:cumulus13@gmail.com)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
[](https://www.buymeacoffee.com/cumulus13)
|
|
183
|
+
|
|
184
|
+
[](https://ko-fi.com/cumulus13)
|
|
185
|
+
|
|
186
|
+
[Support me on Patreon](https://www.patreon.com/cumulus13)
|