3_Plugin_Structure - Anisan/osysHome-Users GitHub Wiki
Relevant source files
The following files were used as context for generating this wiki page:
This page details the internal structure of the osysHome-Users plugin, focusing on its architecture, initialization process, and integration with the parent application. For information about specific administrative operations performed by the plugin, see Administrative Operations.
The osysHome-Users plugin is a Flask-based user management module that provides a complete interface for administering user accounts. The plugin follows a standard structure with clear separation between controller logic, forms, templates, and static assets.
classDiagram
class BasePlugin {
+__init__(app, name)
+initialization()
+admin(request)
+render(template, content)
}
class Users {
+String title
+String description
+String version
+String category
+__init__(app)
+initialization()
+admin(request)
}
BasePlugin <|-- Users
Sources: init.py:19-29
The core of the plugin is the Users
class defined in __init__.py
, which extends the BasePlugin
class from the application core. This class encapsulates all functionality required for user management operations.
Key attributes and methods of the plugin class:
Attribute/Method | Description |
---|---|
title |
Display name of the plugin ("Users") |
description |
Brief plugin description |
version |
Plugin version number (0.3) |
category |
Plugin category ("System") |
__init__(app) |
Constructor that initializes the plugin with the application instance |
initialization() |
Method called during plugin startup |
admin(request) |
Main method handling administrative operations |
Sources: init.py:19-29, init.py:31-94
The osysHome-Users plugin integrates with the parent application through the BasePlugin inheritance mechanism. This allows the plugin to access application resources while maintaining separation of concerns.
graph TD
A["Flask Application"] --> B["Plugin Manager"]
B --> C["Users Plugin (Users Class)"]
C --> D["Forms Layer"]
C --> E["Templates Layer"]
C --> F["Static Assets"]
C <--> G["Core API"]
G --> H["Object Management API"]
G --> I["User Model (User Class)"]
H --> J["getObjectsByClass()"]
H --> K["addObject()"]
H --> L["getObject()"]
H --> M["deleteObject()"]
H --> N["setProperty()"]
Sources: init.py:9-17, init.py:19-29
The plugin initialization process occurs in two phases:
-
Construction: When the
Users
class is instantiated with the application object -
Initialization: When the
initialization()
method is called
The constructor sets up basic plugin metadata like title, description, version, and category, while the initialization()
method (which is currently empty) is reserved for any startup tasks that need to be performed.
sequenceDiagram
participant App as "Flask App"
participant PM as "Plugin Manager"
participant UP as "Users Plugin"
App->>PM: Load plugins
PM->>UP: Create instance (app)
UP->>UP: Set metadata (title, description, etc.)
PM->>UP: Call initialization()
App->>PM: Register plugin routes
App->>UP: Route admin requests
Sources: init.py:21-26, init.py:28-29
The plugin follows a modular organizational structure with clear separation between different types of components.
graph TD
A["plugins/Users/"] --> B["__init__.py (Plugin Controller)"]
A --> C["forms/"]
A --> D["templates/"]
A --> E["static/"]
C --> C1["UserForm.py"]
C --> C2["PasswordForm.py"]
D --> D1["users.html"]
D --> D2["user.html"]
D --> D3["password.html"]
E --> E1["Users.png (Default Avatar)"]
Sources: init.py:14-15, static/Users.png
The primary controller logic is contained in the admin()
method of the Users
class. This method handles different operations based on the op
parameter in the request:
Operation | Description |
---|---|
add |
Creates a new user |
edit |
Modifies an existing user |
delete |
Removes a user |
setPassword |
Changes a user's password |
upload_image |
Uploads and sets a user avatar |
(default) | Lists all users |
Sources: init.py:31-94
The plugin doesn't directly interact with a database but instead uses abstraction methods from the core application:
sequenceDiagram
participant C as "Controller (Users)"
participant O as "Object API"
participant D as "Data Storage"
C->>O: getObjectsByClass("Users")
O->>D: Query Users
D-->>O: Return User Objects
O-->>C: Return User Objects
C->>O: addObject(username, "Users")
O->>D: Create User
D-->>O: Confirm Creation
O-->>C: Return New Object
C->>O: getObject(username)
O->>D: Query User
D-->>O: Return User Data
O-->>C: Return User Object
C->>O: deleteObject(username)
O->>D: Delete User
D-->>O: Confirm Deletion
O-->>C: Return Success
Sources: init.py:16, init.py:37-41, init.py:46-53, init.py:58, init.py:63-67, init.py:89
The plugin uses Flask-WTF forms (UserForm and PasswordForm) for data validation and collection, and Jinja2 templates for UI rendering.
Form | Purpose | Template |
---|---|---|
UserForm | Creating and editing user profiles | user.html |
PasswordForm | Changing user passwords | password.html |
(None) | Listing all users | users.html |
The render()
method (inherited from BasePlugin) is used to render these templates with the appropriate context data.
Sources: init.py:14-15, init.py:35-36, init.py:44, init.py:48, init.py:56, init.py:61, init.py:69, init.py:94
For avatar uploads, the plugin handles file uploads directly, saving files to a configured directory and updating the user's image property:
graph TD
A["Client"] -->|"POST with file"| B["upload_image handler"]
B -->|"Validate request"| C{"File present?"}
C -->|"No"| D["Return error"]
C -->|"Yes"| E["Create directory if needed"]
E --> F["Save file"]
F --> G["Update user.image property"]
G --> H["Return success with URL"]
Sources: init.py:70-87
The osysHome-Users plugin follows a modular architecture that separates concerns between controller logic, data access, forms, and templates. It integrates with the parent application through the BasePlugin inheritance mechanism and uses abstraction methods for data operations.
The plugin's structure allows for easy extension and maintenance while providing a complete interface for user management operations. Its well-defined integration points with the core application make it a cohesive part of the larger system while maintaining separation of concerns.