micro-users 1.5.0__tar.gz → 1.6.2__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.
Potentially problematic release.
This version of micro-users might be problematic. Click here for more details.
- {micro_users-1.5.0 → micro_users-1.6.2}/PKG-INFO +54 -134
- {micro_users-1.5.0 → micro_users-1.6.2}/README.md +54 -134
- {micro_users-1.5.0 → micro_users-1.6.2}/micro_users.egg-info/PKG-INFO +54 -134
- {micro_users-1.5.0 → micro_users-1.6.2}/micro_users.egg-info/SOURCES.txt +10 -5
- {micro_users-1.5.0 → micro_users-1.6.2}/pyproject.toml +1 -1
- {micro_users-1.5.0 → micro_users-1.6.2}/setup.py +1 -1
- micro_users-1.6.2/users/admin.py +37 -0
- {micro_users-1.5.0 → micro_users-1.6.2}/users/apps.py +2 -1
- {micro_users-1.5.0 → micro_users-1.6.2}/users/filters.py +5 -4
- {micro_users-1.5.0 → micro_users-1.6.2}/users/forms.py +13 -13
- micro_users-1.6.2/users/middleware.py +32 -0
- micro_users-1.5.0/users/migrations/0003_department_alter_useractivitylog_options_and_more.py → micro_users-1.6.2/users/migrations/0003_scope_alter_customuser_options_and_more.py +16 -7
- {micro_users-1.5.0 → micro_users-1.6.2}/users/models.py +10 -5
- micro_users-1.6.2/users/signals.py +139 -0
- micro_users-1.6.2/users/static/img/login_logo.webp +0 -0
- {micro_users-1.5.0/users/static → micro_users-1.6.2/users/static/users}/css/login.css +50 -43
- micro_users-1.6.2/users/static/users/css/style.css +201 -0
- micro_users-1.6.2/users/static/users/js/anime.min.js +8 -0
- micro_users-1.6.2/users/static/users/js/login.js +60 -0
- {micro_users-1.5.0 → micro_users-1.6.2}/users/tables.py +19 -14
- micro_users-1.6.2/users/templates/registration/login.html +75 -0
- {micro_users-1.5.0 → micro_users-1.6.2}/users/templates/users/manage_users.html +20 -18
- micro_users-1.5.0/users/templates/users/partials/department_actions.html → micro_users-1.6.2/users/templates/users/partials/scope_actions.html +1 -1
- micro_users-1.5.0/users/templates/users/partials/department_form.html → micro_users-1.6.2/users/templates/users/partials/scope_form.html +3 -3
- micro_users-1.5.0/users/templates/users/partials/department_manager.html → micro_users-1.6.2/users/templates/users/partials/scope_manager.html +3 -3
- {micro_users-1.5.0 → micro_users-1.6.2}/users/templates/users/user_activity_log.html +2 -0
- {micro_users-1.5.0 → micro_users-1.6.2}/users/templates/users/widgets/grouped_permissions.html +1 -1
- {micro_users-1.5.0 → micro_users-1.6.2}/users/urls.py +8 -8
- {micro_users-1.5.0 → micro_users-1.6.2}/users/views.py +72 -50
- micro_users-1.5.0/users/admin.py +0 -18
- micro_users-1.5.0/users/signals.py +0 -41
- micro_users-1.5.0/users/templates/registration/login.html +0 -115
- {micro_users-1.5.0 → micro_users-1.6.2}/LICENSE +0 -0
- {micro_users-1.5.0 → micro_users-1.6.2}/MANIFEST.in +0 -0
- {micro_users-1.5.0 → micro_users-1.6.2}/micro_users.egg-info/dependency_links.txt +0 -0
- {micro_users-1.5.0 → micro_users-1.6.2}/micro_users.egg-info/requires.txt +0 -0
- {micro_users-1.5.0 → micro_users-1.6.2}/micro_users.egg-info/top_level.txt +0 -0
- {micro_users-1.5.0 → micro_users-1.6.2}/setup.cfg +0 -0
- {micro_users-1.5.0 → micro_users-1.6.2}/users/__init__.py +0 -0
- {micro_users-1.5.0 → micro_users-1.6.2}/users/migrations/0001_initial.py +0 -0
- {micro_users-1.5.0 → micro_users-1.6.2}/users/migrations/0002_alter_useractivitylog_action.py +0 -0
- {micro_users-1.5.0 → micro_users-1.6.2}/users/migrations/__init__.py +0 -0
- {micro_users-1.5.0 → micro_users-1.6.2}/users/static/img/default_profile.webp +0 -0
- {micro_users-1.5.0 → micro_users-1.6.2}/users/templates/users/partials/user_actions.html +0 -0
- {micro_users-1.5.0 → micro_users-1.6.2}/users/templates/users/profile/profile.html +0 -0
- {micro_users-1.5.0 → micro_users-1.6.2}/users/templates/users/profile/profile_edit.html +0 -0
- {micro_users-1.5.0 → micro_users-1.6.2}/users/templates/users/user_detail.html +0 -0
- {micro_users-1.5.0 → micro_users-1.6.2}/users/templates/users/user_form.html +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: micro_users
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.6.2
|
|
4
4
|
Summary: Arabic Django user management app with abstract user, permissions, and activity logging
|
|
5
5
|
Home-page: https://github.com/debeski/micro-users
|
|
6
6
|
Author: DeBeski
|
|
@@ -34,6 +34,10 @@ Requires-Dist: babel>=2.1
|
|
|
34
34
|
|
|
35
35
|
[](https://pypi.org/project/micro-users/)
|
|
36
36
|
|
|
37
|
+
<p align="center">
|
|
38
|
+
<img src="https://raw.githubusercontent.com/debeski/micro-users/main/users/static/img/login_logo.webp" alt="Micro Users Login Logo" width="450"/>
|
|
39
|
+
</p>
|
|
40
|
+
|
|
37
41
|
**Arabic** lightweight, reusable Django app providing user management with abstract user, permissions, localization, and activity logging.
|
|
38
42
|
|
|
39
43
|
## Requirements
|
|
@@ -48,10 +52,9 @@ Requires-Dist: babel>=2.1
|
|
|
48
52
|
|
|
49
53
|
## Features
|
|
50
54
|
- Custom AbstractUser model
|
|
51
|
-
-
|
|
52
|
-
- Custom Grouped User permissions system
|
|
53
|
-
-
|
|
54
|
-
- Activity logging (login/logout, CRUD tracking)
|
|
55
|
+
- Scope Management System (Optional)
|
|
56
|
+
- Custom Grouped User permissions system
|
|
57
|
+
- Automatic Activity logging (login/logout, CRUD for all models)
|
|
55
58
|
- Specific User detail and log view
|
|
56
59
|
- Localization support
|
|
57
60
|
- Admin interface integration
|
|
@@ -79,12 +82,22 @@ INSTALLED_APPS = [
|
|
|
79
82
|
]
|
|
80
83
|
```
|
|
81
84
|
|
|
82
|
-
2.
|
|
85
|
+
2. Add Middleware in `settings.py` (Required for logging):
|
|
86
|
+
```python
|
|
87
|
+
MIDDLEWARE = [
|
|
88
|
+
# ...
|
|
89
|
+
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
|
90
|
+
# ...
|
|
91
|
+
'users.middleware.ActivityLogMiddleware', # Add this line
|
|
92
|
+
]
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
3. Set custom user model in `settings.py`:
|
|
83
96
|
```python
|
|
84
97
|
AUTH_USER_MODEL = 'users.CustomUser'
|
|
85
98
|
```
|
|
86
99
|
|
|
87
|
-
|
|
100
|
+
4. Include URLs in your main project folder `urls.py`:
|
|
88
101
|
```python
|
|
89
102
|
urlpatterns = [
|
|
90
103
|
...
|
|
@@ -92,7 +105,7 @@ urlpatterns = [
|
|
|
92
105
|
]
|
|
93
106
|
```
|
|
94
107
|
|
|
95
|
-
|
|
108
|
+
5. Run migrations:
|
|
96
109
|
```bash
|
|
97
110
|
python manage.py migrate users
|
|
98
111
|
```
|
|
@@ -103,136 +116,18 @@ Once configured, the app automatically handles user management and activity logg
|
|
|
103
116
|
|
|
104
117
|
### Activity Logging
|
|
105
118
|
|
|
106
|
-
The app
|
|
107
|
-
|
|
108
|
-
#### Available Helper Functions
|
|
109
|
-
|
|
110
|
-
1. **Get Client IP** - Extract the user's IP address from request:
|
|
111
|
-
```python
|
|
112
|
-
from users.signals import get_client_ip
|
|
113
|
-
|
|
114
|
-
# Usage in views
|
|
115
|
-
ip_address = get_client_ip(request)
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
2. **Log User Action** - Create a reusable logging function:
|
|
119
|
-
```python
|
|
120
|
-
from django.utils import timezone
|
|
121
|
-
from users.models import UserActivityLog
|
|
122
|
-
from users.signals import get_client_ip
|
|
123
|
-
|
|
124
|
-
def log_user_action(request, instance, action, model_name):
|
|
125
|
-
"""
|
|
126
|
-
Logs a user action to the activity log.
|
|
127
|
-
|
|
128
|
-
Args:
|
|
129
|
-
request: HttpRequest object
|
|
130
|
-
instance: The model instance being acted upon
|
|
131
|
-
action: Action type (see ACTION_TYPES below)
|
|
132
|
-
model_name: Name of the model/entity (in Arabic or English)
|
|
133
|
-
"""
|
|
134
|
-
UserActivityLog.objects.create(
|
|
135
|
-
user=request.user,
|
|
136
|
-
action=action,
|
|
137
|
-
model_name=model_name,
|
|
138
|
-
object_id=instance.pk,
|
|
139
|
-
number=instance.number if hasattr(instance, 'number') else '',
|
|
140
|
-
timestamp=timezone.now(),
|
|
141
|
-
ip_address=get_client_ip(request),
|
|
142
|
-
user_agent=request.META.get("HTTP_USER_AGENT", ""),
|
|
143
|
-
)
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
#### Action Types Available
|
|
147
|
-
Use these constants when logging actions:
|
|
148
|
-
|
|
149
|
-
| Action Constant | Arabic Display | Description |
|
|
150
|
-
|-----------------|----------------|-------------|
|
|
151
|
-
| `'LOGIN'` | تسجيل دخـول | User login (auto-logged) |
|
|
152
|
-
| `'LOGOUT'` | تسجيل خـروج | User logout (auto-logged) |
|
|
153
|
-
| `'CREATE'` | انشـاء | Object creation |
|
|
154
|
-
| `'UPDATE'` | تعديـل | Object modification |
|
|
155
|
-
| `'DELETE'` | حــذف | Object deletion |
|
|
156
|
-
| `'VIEW'` | عـرض | Object viewing |
|
|
157
|
-
| `'DOWNLOAD'` | تحميل | File download |
|
|
158
|
-
| `'CONFIRM'` | تأكيـد | Action confirmation |
|
|
159
|
-
| `'REJECT'` | رفــض | Action rejection |
|
|
160
|
-
| `'RESET'` | اعادة ضبط | Password/Data reset |
|
|
119
|
+
The app provides a fully **automated** activity logging system. No manual configuration is required in your views.
|
|
161
120
|
|
|
162
|
-
|
|
121
|
+
- **Login/Logout**: Automatically tracked.
|
|
122
|
+
- **Create/Update/Delete**: Any change to any model in your app (including `Scope` and `User`) is automatically logged via Django Signals.
|
|
123
|
+
- **Log content**: Tracks the user, action type, model name, object ID, and timestamp.
|
|
124
|
+
- *Note*: `last_login` field updates are automatically filtered out to prevent redundant "Update" logs on login.
|
|
163
125
|
|
|
164
|
-
|
|
165
|
-
```python
|
|
166
|
-
def create_document(request):
|
|
167
|
-
# ... create logic ...
|
|
168
|
-
document = Document.objects.create(...)
|
|
169
|
-
|
|
170
|
-
# Log the action
|
|
171
|
-
from users.models import UserActivityLog
|
|
172
|
-
from users.signals import get_client_ip
|
|
173
|
-
|
|
174
|
-
UserActivityLog.objects.create(
|
|
175
|
-
user=request.user,
|
|
176
|
-
action='CREATE',
|
|
177
|
-
model_name='وثيقة',
|
|
178
|
-
object_id=document.pk,
|
|
179
|
-
number=document.number,
|
|
180
|
-
ip_address=get_client_ip(request),
|
|
181
|
-
user_agent=request.META.get("HTTP_USER_AGENT", ""),
|
|
182
|
-
)
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
2. **Using the helper function**:
|
|
186
|
-
```python
|
|
187
|
-
# Create a helper function in your app
|
|
188
|
-
def log_action(request, instance, action, model_name):
|
|
189
|
-
from users.models import UserActivityLog
|
|
190
|
-
from users.signals import get_client_ip
|
|
191
|
-
from django.utils import timezone
|
|
192
|
-
|
|
193
|
-
UserActivityLog.objects.create(
|
|
194
|
-
user=request.user,
|
|
195
|
-
action=action,
|
|
196
|
-
model_name=model_name,
|
|
197
|
-
object_id=instance.pk,
|
|
198
|
-
number=getattr(instance, 'number', ''),
|
|
199
|
-
timestamp=timezone.now(),
|
|
200
|
-
ip_address=get_client_ip(request),
|
|
201
|
-
user_agent=request.META.get("HTTP_USER_AGENT", ""),
|
|
202
|
-
)
|
|
203
|
-
|
|
204
|
-
# Usage in views
|
|
205
|
-
def update_order(request, order_id):
|
|
206
|
-
order = get_object_or_404(Order, pk=order_id)
|
|
207
|
-
# ... update logic ...
|
|
208
|
-
log_action(request, order, 'UPDATE', 'طلب')
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
3. **Logging without an instance** (for general actions):
|
|
212
|
-
```python
|
|
213
|
-
def log_general_action(request, action, model_name, description=''):
|
|
214
|
-
from users.models import UserActivityLog
|
|
215
|
-
from users.signals import get_client_ip
|
|
216
|
-
from django.utils import timezone
|
|
217
|
-
|
|
218
|
-
UserActivityLog.objects.create(
|
|
219
|
-
user=request.user,
|
|
220
|
-
action=action,
|
|
221
|
-
model_name=model_name,
|
|
222
|
-
object_id=None,
|
|
223
|
-
number=description,
|
|
224
|
-
timestamp=timezone.now(),
|
|
225
|
-
ip_address=get_client_ip(request),
|
|
226
|
-
user_agent=request.META.get("HTTP_USER_AGENT", ""),
|
|
227
|
-
)
|
|
228
|
-
|
|
229
|
-
# Usage
|
|
230
|
-
log_general_action(request, 'CONFIRM', 'نظام', 'تم تأكيد الإعدادات')
|
|
231
|
-
```
|
|
126
|
+
To view logs, navigate to `manage/logs/` or use the Django Admin interface ("حركات السجل").
|
|
232
127
|
|
|
233
128
|
## Available URLs
|
|
234
129
|
|
|
235
|
-
All user management URLs are prefixed with `manage/` as configured. Below is the complete list:
|
|
130
|
+
All user management URLs are prefixed with `manage/` as configured above. Below is the complete list:
|
|
236
131
|
|
|
237
132
|
| URL Pattern | View/Function | Description |
|
|
238
133
|
|-------------|---------------|-------------|
|
|
@@ -247,7 +142,7 @@ All user management URLs are prefixed with `manage/` as configured. Below is the
|
|
|
247
142
|
| `manage/profile/edit/` | `views.edit_profile` | Edit current profile |
|
|
248
143
|
| `manage/logs/` | `views.UserActivityLogView.as_view()` | View activity logs |
|
|
249
144
|
| `manage/reset_password/<int:pk>/` | `views.reset_password` | Reset user password |
|
|
250
|
-
| `manage/
|
|
145
|
+
| `manage/scopes/manage/` | `views.manage_scopes` | Scope Manager (Modal) |
|
|
251
146
|
|
|
252
147
|
## Structure
|
|
253
148
|
```
|
|
@@ -256,6 +151,7 @@ users/
|
|
|
256
151
|
├── urls.py # URL routing
|
|
257
152
|
├── tables.py # User and Activity Log tables
|
|
258
153
|
├── signals.py # Logging signals
|
|
154
|
+
├── middleware.py # Request capture for signals
|
|
259
155
|
├── models.py # User model, permissions, activity logs
|
|
260
156
|
├── forms.py # Creation, edit,. etc.
|
|
261
157
|
├── filter.py # Search filters
|
|
@@ -267,6 +163,27 @@ users/
|
|
|
267
163
|
└── migrations/ # Database migrations
|
|
268
164
|
```
|
|
269
165
|
|
|
166
|
+
## Customization
|
|
167
|
+
|
|
168
|
+
### Replacing Login Logo
|
|
169
|
+
To replace the default login logo, simply place your own `login_logo.webp` image in your project's static directory at `static/img/login_logo.webp`.
|
|
170
|
+
|
|
171
|
+
### Theme Configuration
|
|
172
|
+
You can configure the login page colors by defining `MICRO_USERS_THEME` in your project's `settings.py`. This dictionary overrides the default CSS variables.
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
MICRO_USERS_THEME = {
|
|
176
|
+
'right_bg': '#474745',
|
|
177
|
+
'left_bg': 'white',
|
|
178
|
+
'selection_bg': '#dbdbdb',
|
|
179
|
+
'gradient_start': '#a2a2a7',
|
|
180
|
+
'gradient_end': '#474745',
|
|
181
|
+
# Additional keys supported:
|
|
182
|
+
# 'selection_moz_bg', 'left_shadow', 'right_shadow', 'right_text',
|
|
183
|
+
# 'label_color', 'input_text', 'submit_color', 'submit_focus', 'submit_active'
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
270
187
|
## Version History
|
|
271
188
|
|
|
272
189
|
| Version | Changes |
|
|
@@ -288,3 +205,6 @@ users/
|
|
|
288
205
|
| v1.4.0 | • Redesigned Permissions UI (Grouped by App/Action) <br> • Added Global Bulk Permission Selectors <br> • Improved Arabic Localization for Permissions <br> • Optimized printing (hidden forms/buttons) <br> • Fixed various bugs and crashes |
|
|
289
206
|
| v1.4.1 | • Changed "Administrative User" translation to "Responsible User" (مستخدم مسؤول) <br> • Enforced custom sorting order for Permissions (View -> Add -> Change -> Other) |
|
|
290
207
|
| v1.5.0 | • Department Management (Modal-based CRUD)<br> • Department field implementation<br> • Template refactoring (partials/, profile/, users/ for logs)<br> • Verbose names for models |
|
|
208
|
+
| v1.6.0 | • **Automated Activity Logging**: dynamic logging for all CREATE/UPDATE/DELETE actions via Middleware & Signals<br> • **Refactor**: Renamed `Department` model to `Scope` (Scope Management)<br> • Removed manual logging requirement<br> • **Architecture**: Decoupled models, forms, and tables using dynamic imports and `apps.get_model` <br> • **Soft Delete**: Users are now marked as inactive with a timestamp instead of being permanently deleted<br> • **Activity Log**: Deleted users appear with a strikethrough<br> • **CSS Refactor**: Extracted and cleaned up styling with CSS variables<br> • **Login**: Refactored login page with separated JS/CSS and a new modern default logo |
|
|
209
|
+
| v1.6.1 | • **Theme Configuration**: Added `MICRO_USERS_THEME` setting for easy color customization <br> • **Bug Fixes**: Explicitly excluded unwanted columns (id, ip_address, user_agent) from Activity Log table <br> • **UI**: Improved Scope Manager button visibility |
|
|
210
|
+
| v1.6.2 | • **UI**: Improved some tooltips for buttons and descriptions |
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://pypi.org/project/micro-users/)
|
|
4
4
|
|
|
5
|
+
<p align="center">
|
|
6
|
+
<img src="https://raw.githubusercontent.com/debeski/micro-users/main/users/static/img/login_logo.webp" alt="Micro Users Login Logo" width="450"/>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
5
9
|
**Arabic** lightweight, reusable Django app providing user management with abstract user, permissions, localization, and activity logging.
|
|
6
10
|
|
|
7
11
|
## Requirements
|
|
@@ -16,10 +20,9 @@
|
|
|
16
20
|
|
|
17
21
|
## Features
|
|
18
22
|
- Custom AbstractUser model
|
|
19
|
-
-
|
|
20
|
-
- Custom Grouped User permissions system
|
|
21
|
-
-
|
|
22
|
-
- Activity logging (login/logout, CRUD tracking)
|
|
23
|
+
- Scope Management System (Optional)
|
|
24
|
+
- Custom Grouped User permissions system
|
|
25
|
+
- Automatic Activity logging (login/logout, CRUD for all models)
|
|
23
26
|
- Specific User detail and log view
|
|
24
27
|
- Localization support
|
|
25
28
|
- Admin interface integration
|
|
@@ -47,12 +50,22 @@ INSTALLED_APPS = [
|
|
|
47
50
|
]
|
|
48
51
|
```
|
|
49
52
|
|
|
50
|
-
2.
|
|
53
|
+
2. Add Middleware in `settings.py` (Required for logging):
|
|
54
|
+
```python
|
|
55
|
+
MIDDLEWARE = [
|
|
56
|
+
# ...
|
|
57
|
+
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
|
58
|
+
# ...
|
|
59
|
+
'users.middleware.ActivityLogMiddleware', # Add this line
|
|
60
|
+
]
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
3. Set custom user model in `settings.py`:
|
|
51
64
|
```python
|
|
52
65
|
AUTH_USER_MODEL = 'users.CustomUser'
|
|
53
66
|
```
|
|
54
67
|
|
|
55
|
-
|
|
68
|
+
4. Include URLs in your main project folder `urls.py`:
|
|
56
69
|
```python
|
|
57
70
|
urlpatterns = [
|
|
58
71
|
...
|
|
@@ -60,7 +73,7 @@ urlpatterns = [
|
|
|
60
73
|
]
|
|
61
74
|
```
|
|
62
75
|
|
|
63
|
-
|
|
76
|
+
5. Run migrations:
|
|
64
77
|
```bash
|
|
65
78
|
python manage.py migrate users
|
|
66
79
|
```
|
|
@@ -71,136 +84,18 @@ Once configured, the app automatically handles user management and activity logg
|
|
|
71
84
|
|
|
72
85
|
### Activity Logging
|
|
73
86
|
|
|
74
|
-
The app
|
|
75
|
-
|
|
76
|
-
#### Available Helper Functions
|
|
77
|
-
|
|
78
|
-
1. **Get Client IP** - Extract the user's IP address from request:
|
|
79
|
-
```python
|
|
80
|
-
from users.signals import get_client_ip
|
|
81
|
-
|
|
82
|
-
# Usage in views
|
|
83
|
-
ip_address = get_client_ip(request)
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
2. **Log User Action** - Create a reusable logging function:
|
|
87
|
-
```python
|
|
88
|
-
from django.utils import timezone
|
|
89
|
-
from users.models import UserActivityLog
|
|
90
|
-
from users.signals import get_client_ip
|
|
91
|
-
|
|
92
|
-
def log_user_action(request, instance, action, model_name):
|
|
93
|
-
"""
|
|
94
|
-
Logs a user action to the activity log.
|
|
95
|
-
|
|
96
|
-
Args:
|
|
97
|
-
request: HttpRequest object
|
|
98
|
-
instance: The model instance being acted upon
|
|
99
|
-
action: Action type (see ACTION_TYPES below)
|
|
100
|
-
model_name: Name of the model/entity (in Arabic or English)
|
|
101
|
-
"""
|
|
102
|
-
UserActivityLog.objects.create(
|
|
103
|
-
user=request.user,
|
|
104
|
-
action=action,
|
|
105
|
-
model_name=model_name,
|
|
106
|
-
object_id=instance.pk,
|
|
107
|
-
number=instance.number if hasattr(instance, 'number') else '',
|
|
108
|
-
timestamp=timezone.now(),
|
|
109
|
-
ip_address=get_client_ip(request),
|
|
110
|
-
user_agent=request.META.get("HTTP_USER_AGENT", ""),
|
|
111
|
-
)
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
#### Action Types Available
|
|
115
|
-
Use these constants when logging actions:
|
|
116
|
-
|
|
117
|
-
| Action Constant | Arabic Display | Description |
|
|
118
|
-
|-----------------|----------------|-------------|
|
|
119
|
-
| `'LOGIN'` | تسجيل دخـول | User login (auto-logged) |
|
|
120
|
-
| `'LOGOUT'` | تسجيل خـروج | User logout (auto-logged) |
|
|
121
|
-
| `'CREATE'` | انشـاء | Object creation |
|
|
122
|
-
| `'UPDATE'` | تعديـل | Object modification |
|
|
123
|
-
| `'DELETE'` | حــذف | Object deletion |
|
|
124
|
-
| `'VIEW'` | عـرض | Object viewing |
|
|
125
|
-
| `'DOWNLOAD'` | تحميل | File download |
|
|
126
|
-
| `'CONFIRM'` | تأكيـد | Action confirmation |
|
|
127
|
-
| `'REJECT'` | رفــض | Action rejection |
|
|
128
|
-
| `'RESET'` | اعادة ضبط | Password/Data reset |
|
|
87
|
+
The app provides a fully **automated** activity logging system. No manual configuration is required in your views.
|
|
129
88
|
|
|
130
|
-
|
|
89
|
+
- **Login/Logout**: Automatically tracked.
|
|
90
|
+
- **Create/Update/Delete**: Any change to any model in your app (including `Scope` and `User`) is automatically logged via Django Signals.
|
|
91
|
+
- **Log content**: Tracks the user, action type, model name, object ID, and timestamp.
|
|
92
|
+
- *Note*: `last_login` field updates are automatically filtered out to prevent redundant "Update" logs on login.
|
|
131
93
|
|
|
132
|
-
|
|
133
|
-
```python
|
|
134
|
-
def create_document(request):
|
|
135
|
-
# ... create logic ...
|
|
136
|
-
document = Document.objects.create(...)
|
|
137
|
-
|
|
138
|
-
# Log the action
|
|
139
|
-
from users.models import UserActivityLog
|
|
140
|
-
from users.signals import get_client_ip
|
|
141
|
-
|
|
142
|
-
UserActivityLog.objects.create(
|
|
143
|
-
user=request.user,
|
|
144
|
-
action='CREATE',
|
|
145
|
-
model_name='وثيقة',
|
|
146
|
-
object_id=document.pk,
|
|
147
|
-
number=document.number,
|
|
148
|
-
ip_address=get_client_ip(request),
|
|
149
|
-
user_agent=request.META.get("HTTP_USER_AGENT", ""),
|
|
150
|
-
)
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
2. **Using the helper function**:
|
|
154
|
-
```python
|
|
155
|
-
# Create a helper function in your app
|
|
156
|
-
def log_action(request, instance, action, model_name):
|
|
157
|
-
from users.models import UserActivityLog
|
|
158
|
-
from users.signals import get_client_ip
|
|
159
|
-
from django.utils import timezone
|
|
160
|
-
|
|
161
|
-
UserActivityLog.objects.create(
|
|
162
|
-
user=request.user,
|
|
163
|
-
action=action,
|
|
164
|
-
model_name=model_name,
|
|
165
|
-
object_id=instance.pk,
|
|
166
|
-
number=getattr(instance, 'number', ''),
|
|
167
|
-
timestamp=timezone.now(),
|
|
168
|
-
ip_address=get_client_ip(request),
|
|
169
|
-
user_agent=request.META.get("HTTP_USER_AGENT", ""),
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
# Usage in views
|
|
173
|
-
def update_order(request, order_id):
|
|
174
|
-
order = get_object_or_404(Order, pk=order_id)
|
|
175
|
-
# ... update logic ...
|
|
176
|
-
log_action(request, order, 'UPDATE', 'طلب')
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
3. **Logging without an instance** (for general actions):
|
|
180
|
-
```python
|
|
181
|
-
def log_general_action(request, action, model_name, description=''):
|
|
182
|
-
from users.models import UserActivityLog
|
|
183
|
-
from users.signals import get_client_ip
|
|
184
|
-
from django.utils import timezone
|
|
185
|
-
|
|
186
|
-
UserActivityLog.objects.create(
|
|
187
|
-
user=request.user,
|
|
188
|
-
action=action,
|
|
189
|
-
model_name=model_name,
|
|
190
|
-
object_id=None,
|
|
191
|
-
number=description,
|
|
192
|
-
timestamp=timezone.now(),
|
|
193
|
-
ip_address=get_client_ip(request),
|
|
194
|
-
user_agent=request.META.get("HTTP_USER_AGENT", ""),
|
|
195
|
-
)
|
|
196
|
-
|
|
197
|
-
# Usage
|
|
198
|
-
log_general_action(request, 'CONFIRM', 'نظام', 'تم تأكيد الإعدادات')
|
|
199
|
-
```
|
|
94
|
+
To view logs, navigate to `manage/logs/` or use the Django Admin interface ("حركات السجل").
|
|
200
95
|
|
|
201
96
|
## Available URLs
|
|
202
97
|
|
|
203
|
-
All user management URLs are prefixed with `manage/` as configured. Below is the complete list:
|
|
98
|
+
All user management URLs are prefixed with `manage/` as configured above. Below is the complete list:
|
|
204
99
|
|
|
205
100
|
| URL Pattern | View/Function | Description |
|
|
206
101
|
|-------------|---------------|-------------|
|
|
@@ -215,7 +110,7 @@ All user management URLs are prefixed with `manage/` as configured. Below is the
|
|
|
215
110
|
| `manage/profile/edit/` | `views.edit_profile` | Edit current profile |
|
|
216
111
|
| `manage/logs/` | `views.UserActivityLogView.as_view()` | View activity logs |
|
|
217
112
|
| `manage/reset_password/<int:pk>/` | `views.reset_password` | Reset user password |
|
|
218
|
-
| `manage/
|
|
113
|
+
| `manage/scopes/manage/` | `views.manage_scopes` | Scope Manager (Modal) |
|
|
219
114
|
|
|
220
115
|
## Structure
|
|
221
116
|
```
|
|
@@ -224,6 +119,7 @@ users/
|
|
|
224
119
|
├── urls.py # URL routing
|
|
225
120
|
├── tables.py # User and Activity Log tables
|
|
226
121
|
├── signals.py # Logging signals
|
|
122
|
+
├── middleware.py # Request capture for signals
|
|
227
123
|
├── models.py # User model, permissions, activity logs
|
|
228
124
|
├── forms.py # Creation, edit,. etc.
|
|
229
125
|
├── filter.py # Search filters
|
|
@@ -235,6 +131,27 @@ users/
|
|
|
235
131
|
└── migrations/ # Database migrations
|
|
236
132
|
```
|
|
237
133
|
|
|
134
|
+
## Customization
|
|
135
|
+
|
|
136
|
+
### Replacing Login Logo
|
|
137
|
+
To replace the default login logo, simply place your own `login_logo.webp` image in your project's static directory at `static/img/login_logo.webp`.
|
|
138
|
+
|
|
139
|
+
### Theme Configuration
|
|
140
|
+
You can configure the login page colors by defining `MICRO_USERS_THEME` in your project's `settings.py`. This dictionary overrides the default CSS variables.
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
MICRO_USERS_THEME = {
|
|
144
|
+
'right_bg': '#474745',
|
|
145
|
+
'left_bg': 'white',
|
|
146
|
+
'selection_bg': '#dbdbdb',
|
|
147
|
+
'gradient_start': '#a2a2a7',
|
|
148
|
+
'gradient_end': '#474745',
|
|
149
|
+
# Additional keys supported:
|
|
150
|
+
# 'selection_moz_bg', 'left_shadow', 'right_shadow', 'right_text',
|
|
151
|
+
# 'label_color', 'input_text', 'submit_color', 'submit_focus', 'submit_active'
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
238
155
|
## Version History
|
|
239
156
|
|
|
240
157
|
| Version | Changes |
|
|
@@ -255,4 +172,7 @@ users/
|
|
|
255
172
|
| v1.3.2 | • Minor table modifications |
|
|
256
173
|
| v1.4.0 | • Redesigned Permissions UI (Grouped by App/Action) <br> • Added Global Bulk Permission Selectors <br> • Improved Arabic Localization for Permissions <br> • Optimized printing (hidden forms/buttons) <br> • Fixed various bugs and crashes |
|
|
257
174
|
| v1.4.1 | • Changed "Administrative User" translation to "Responsible User" (مستخدم مسؤول) <br> • Enforced custom sorting order for Permissions (View -> Add -> Change -> Other) |
|
|
258
|
-
| v1.5.0 | • Department Management (Modal-based CRUD)<br> • Department field implementation<br> • Template refactoring (partials/, profile/, users/ for logs)<br> • Verbose names for models |
|
|
175
|
+
| v1.5.0 | • Department Management (Modal-based CRUD)<br> • Department field implementation<br> • Template refactoring (partials/, profile/, users/ for logs)<br> • Verbose names for models |
|
|
176
|
+
| v1.6.0 | • **Automated Activity Logging**: dynamic logging for all CREATE/UPDATE/DELETE actions via Middleware & Signals<br> • **Refactor**: Renamed `Department` model to `Scope` (Scope Management)<br> • Removed manual logging requirement<br> • **Architecture**: Decoupled models, forms, and tables using dynamic imports and `apps.get_model` <br> • **Soft Delete**: Users are now marked as inactive with a timestamp instead of being permanently deleted<br> • **Activity Log**: Deleted users appear with a strikethrough<br> • **CSS Refactor**: Extracted and cleaned up styling with CSS variables<br> • **Login**: Refactored login page with separated JS/CSS and a new modern default logo |
|
|
177
|
+
| v1.6.1 | • **Theme Configuration**: Added `MICRO_USERS_THEME` setting for easy color customization <br> • **Bug Fixes**: Explicitly excluded unwanted columns (id, ip_address, user_agent) from Activity Log table <br> • **UI**: Improved Scope Manager button visibility |
|
|
178
|
+
| v1.6.2 | • **UI**: Improved some tooltips for buttons and descriptions |
|