2_User_Management_Plugin - Anisan/osysHome-Users GitHub Wiki
Relevant source files
The following files were used as context for generating this wiki page:
The User Management Plugin provides a comprehensive set of tools for managing user accounts within the osysHome system. This plugin enables administrators to create, edit, and delete user accounts, set passwords, upload user avatars, and manage user roles and permissions. For detailed information about the user interface components, see User Interface Components and for specifics on forms and data models used by this plugin, see User Data Models and Forms.
The User Management Plugin is implemented as a Flask-based module that integrates with the core osysHome application. It follows a modular design pattern with clear separation of concerns between the controller logic, form handling, and template rendering.
graph TD
A["Users Plugin Class"] --> B["Administrative Interface"]
B --> C["User Operations"]
B --> D["Template Rendering"]
C --> C1["Add User"]
C --> C2["Edit User"]
C --> C3["Delete User"]
C --> C4["Set Password"]
C --> C5["Upload Avatar"]
D --> D1["users.html (User List)"]
D --> D2["user.html (User Form)"]
D --> D3["password.html (Password Form)"]
E["Forms"] --> E1["UserForm"]
E --> E2["PasswordForm"]
E1 --> D2
E2 --> D3
F["Core Data Interface"] --> F1["getObjectsByClass()"]
F --> F2["addObject()"]
F --> F3["getObject()"]
F --> F4["deleteObject()"]
F --> F5["setProperty()"]
A --> F
C1 --> F2
C2 --> F3
C2 --> F5
C3 --> F4
C4 --> F3
C4 --> F5
C5 --> F5
Sources: init.py:19-94, forms/UserForm.py:6-13, forms/PasswordForm.py:6-9
The User Management Plugin is initialized as a BasePlugin
subclass with metadata that describes its purpose, version, and category. The initialization process is straightforward but forms a critical part of how the plugin integrates with the parent application.
sequenceDiagram
participant App as "Main Application"
participant Plugin as "Users Plugin"
participant Core as "Core Services"
App->>Plugin: Initialize plugin
Plugin->>Plugin: Set metadata (title, description, version, category)
Plugin->>Plugin: Perform initialization tasks
App->>Plugin: Request admin interface
Plugin->>Core: Request user data
Core-->>Plugin: Return user objects
Plugin->>App: Render user management interface
The plugin is initialized with the following metadata:
- Title: "Users"
- Description: "This is a plugin edit users"
- Version: "0.3"
- Category: "System"
Sources: init.py:19-29
The User Management Plugin provides several administrative operations through its admin()
method. These operations are accessed via the op
query parameter in HTTP requests.
Operation | Query Parameter | Description |
---|---|---|
List Users | None | Displays a list of all users in the system |
Add User | op=add |
Shows a form to create a new user and processes form submissions |
Edit User | op=edit&user=username |
Shows a form to edit an existing user and processes form submissions |
Delete User | op=delete&user=username |
Removes a user from the system |
Set Password | op=setPassword&user=username |
Shows a form to set a new password and processes form submissions |
Upload Image | op=upload_image |
Processes avatar image uploads for users |
flowchart TD
A["Admin Request"] --> B{"Operation Type?"}
B -->|"No operation"| C["List All Users"]
B -->|"op=add"| D["Add User Flow"]
B -->|"op=edit"| E["Edit User Flow"]
B -->|"op=delete"| F["Delete User Flow"]
B -->|"op=setPassword"| G["Password Flow"]
B -->|"op=upload_image"| H["Avatar Upload Flow"]
subgraph "Add User Flow"
D1["Create UserForm"] --> D2{"Form Validated?"}
D2 -->|"Yes"| D3["addObject()"]
D3 --> D4["Set Properties"]
D4 --> D5["Redirect to User List"]
D2 -->|"No"| D6["Render user.html with Form"]
end
subgraph "Edit User Flow"
E1["Get User Object"] --> E2["Create UserForm with Data"]
E2 --> E3{"Form Validated?"}
E3 -->|"Yes"| E4["Update Properties"]
E4 --> E5["Redirect to User List"]
E3 -->|"No"| E6["Render user.html with Form"]
end
subgraph "Password Flow"
G1["Create PasswordForm"] --> G2{"Form Validated?"}
G2 -->|"Yes"| G3["Set User Password"]
G3 --> G4["Redirect to Home"]
G2 -->|"No"| G5["Render password.html with Form"]
end
D --> D1
E --> E1
F --> F1["Delete User Object"]
F1 --> F2["Redirect to User List"]
G --> G1
H --> H1["Process File Upload"]
H1 --> H2["Save to Avatars Directory"]
H2 --> H3["Update User Image Property"]
H3 --> H4["Return JSON Response with URL"]
Sources: init.py:31-94
When a user is added through the admin interface:
- A new
UserForm
is created and validated - If valid, a new user object is created using
addObject()
- User properties are set based on form data
- The administrator is redirected to the user list
This process is implemented in the admin()
method's "add" operation handler.
Sources: init.py:34-44
The user editing process:
- The existing user object is retrieved using
getObject()
- A
User
model instance is created from the object - A
UserForm
is populated with the user's data - If the form is submitted and valid, user properties are updated
- The administrator is redirected to the user list
This process is implemented in the admin()
method's "edit" operation handler.
Sources: init.py:45-56
User deletion is straightforward:
- The user object is deleted using
deleteObject()
- The administrator is redirected to the user list
Sources: init.py:57-59
The password setting process:
- A
PasswordForm
is created and validated - If valid and the password fields match, the user object is retrieved
- A new password hash is generated using the
User
model'sset_password()
method - The password hash is stored in the user object
- The administrator is redirected to the home page
Sources: init.py:60-69
The avatar upload process:
- The uploaded file is validated
- A directory is created for avatars if it doesn't exist
- The file is saved to the avatars directory
- The user's image property is updated with the file URL
- A JSON response containing the image URL is returned
Sources: init.py:70-87
The User Management Plugin interacts with the application's data model primarily through the following methods:
Method | Purpose |
---|---|
getObjectsByClass("Users") |
Retrieves all user objects for listing |
addObject(username, "Users") |
Creates a new user object |
getObject(username) |
Retrieves a specific user object |
deleteObject(username) |
Removes a user object |
setProperty(property, value) |
Updates a user property |
The plugin also uses the User
model from the core application to handle password hashing and other user-specific operations.
classDiagram
class BasePlugin {
+title: String
+description: String
+version: String
+category: String
+__init__(app)
+initialization()
+admin(request)
+render(template, content)
}
class Users {
+__init__(app)
+initialization()
+admin(request)
}
class User {
+set_password(password)
}
class CoreFunctions {
+getObjectsByClass(className)
+addObject(name, className)
+getObject(name)
+deleteObject(name)
+setProperty(property, value)
}
BasePlugin <|-- Users
Users --> User: uses
Users --> CoreFunctions: uses
Sources: init.py:11-16, init.py:38-66
The User Management Plugin provides a comprehensive set of tools for managing users within the osysHome system. It leverages the application's core functionality for object management while providing a customized administrative interface for user-specific operations. The plugin handles user creation, editing, deletion, password management, and avatar uploads through a clean, form-based interface.
For more information about the specific forms used by this plugin, see User Profile Form and Password Management Form. For details about the user interface components, see User Interface Components.
Sources: init.py:1-94, forms/UserForm.py:1-13, forms/PasswordForm.py:1-9