1.2.1.2. models
¶
This module provides the models for the data stored in the database as well as functionality for defining and managing the models themselves.
1.2.1.2.1. Data¶
1.2.1.2.2. Functions¶
-
current_timestamp
(*args, **kwargs)[source]¶ The function used for creating the timestamp used by database objects.
Returns: The current timestamp. Return type: datetime.datetime
-
get_tables_with_column_id
(column_id)[source]¶ Get all tables which contain a column named column_id.
Parameters: column_id (str) – The column name to get all the tables of. Returns: The list of matching tables. Return type: set
1.2.1.2.3. Classes¶
-
class
BaseRowCls
[source]¶ Bases:
object
The base class from which other database table objects inherit from. Provides a standard
__repr__
method and default permission checks which are to be overridden as desired by subclasses.Warning
Subclasses should not directly override the
session_has_*_access
methods. These contain wrapping logic to do things like checking if the session is an administrator, etc. Instead subclasses looking to control access should override the individual private variants_session_has_*_access
. Each of these use the same call signature as their public counterparts.-
assert_session_has_permissions
(*args, **kwargs)[source]¶ A convenience function which wraps
session_has_permissions()
and raises aKingPhisherPermissionError
if the session does not have the specified permissions.
-
classmethod
metatable
()[source]¶ Generate a
MetaTable
instance for this model class.Returns: The appropriate metadata for the table represented by this model. Return type: MetaTable
-
classmethod
session_has_create_access
(session, instance=None)[source]¶ Check that the authenticated session has access to create the specified model instance.
Parameters: - session – The authenticated session to check access for.
- instance – The optional model instance to inspect.
Returns: Whether the session has the desired permissions.
Return type:
-
classmethod
session_has_delete_access
(session, instance=None)[source]¶ Check that the authenticated session has access to delete the specified model instance.
Parameters: - session – The authenticated session to check access for.
- instance – The optional model instance to inspect.
Returns: Whether the session has the desired permissions.
Return type:
-
session_has_permissions
(access, session)[source]¶ Check that the authenticated session has the permissions specified in access. The permissions in access are abbreviated with the first letter of create, read, update, and delete. For example, to check for read and update permissions, access would be
'ru'
.Note
This will always return
True
for sessions which are for administrative users. To maintain this logic, this method should not be overridden in subclasses. Instead override the specific_session_has_*_access
methods as necessary.Parameters: - access (str) – The desired permissions.
- session – The authenticated session to check access for.
Returns: Whether the session has the desired permissions.
Return type:
-
classmethod
session_has_read_access
(session, instance=None)[source]¶ Check that the authenticated session has access to read the specified model instance.
Parameters: - session – The authenticated session to check access for.
- instance – The optional model instance to inspect.
Returns: Whether the session has the desired permissions.
Return type:
-
classmethod
session_has_read_prop_access
(session, prop, instance=None)[source]¶ Check that the authenticated session has access to read the property of the specified model instance. This allows models to only explicitly control which of their attributes can be read by a particular session.
Parameters: - session – The authenticated session to check access for.
- instance – The optional model instance to inspect.
Returns: Whether the session has the desired permissions.
Return type:
-
classmethod
session_has_update_access
(session, instance=None)[source]¶ Check that the authenticated session has access to update the specified model instance.
Parameters: - session – The authenticated session to check access for.
- instance – The optional model instance to inspect.
Returns: Whether the session has the desired permissions.
Return type:
-