core.modules.history

Classes

HistorySkel

Skeleton used for a ViUR history entry to log any relevant changes

BigQueryHistory

Connector for BigQuery history entries.

HistoryAdapter

Generalized adapter for handling history events.

History

ViUR history module

Module Contents

class core.modules.history.HistorySkel(*args, **kwargs)

Bases: viur.core.skeleton.Skeleton

Skeleton used for a ViUR history entry to log any relevant changes in other Skeletons.

The ViurHistorySkel is also used as the base for a biquery logging table, see below.

kindName = 'viur-history'

Specifies the entity kind name this Skeleton is associated with. Will be determined automatically when not explicitly set.

version
action
tags
timestamp
user
name
descr
current_kind
current_key
current
changed_fields
diff
class core.modules.history.BigQueryHistory

Connector for BigQuery history entries.

PATH = 'Uninferable.history.default'

Path to the big query table for history entries.

SCHEMA

Schema used for the BigQuery table for its initial construction. Keep to the provided format!

client
table
select_or_create_table()
write_row(data)
class core.modules.history.HistoryAdapter(excludes=DEFAULT_EXCLUDES)

Bases: viur.core.skeleton.DatabaseAdapter

Generalized adapter for handling history events.

Parameters:

excludes (Iterable[str])

DEFAULT_EXCLUDES

Bones being ignored within history.

diff_excludes
prewrite(skel, is_add, change_list=())

Hook being called on a add, edit or delete operation before the skeleton-specific action is performed.

The hook can be used to modifiy the skeleton before writing. The raw entity can be obainted using skel.dbEntity.

Parameters:
  • action – Either contains “add”, “edit” or “delete”, depending on the operation.

  • skel – is the skeleton that is being read before written.

  • change_list – is a list of bone names which are being changed within the write.

write(skel, is_add, change_list=())

Hook being called on a write operations after the skeleton is written.

The raw entity can be obainted using skel.dbEntity.

Parameters:
  • action – Either contains “add” or “edit”, depending on the operation.

  • skel – is the skeleton that is being read before written.

  • change_list – is a list of bone names which are being changed within the write.

delete(skel)

Hook being called on a delete operation after the skeleton is deleted.

trigger(action, old_skel, new_skel, change_list=())
Parameters:
  • action (str)

  • old_skel (viur.core.skeleton.SkeletonInstance)

  • new_skel (viur.core.skeleton.SkeletonInstance)

  • change_list (Iterable[str])

Return type:

str | None

class core.modules.history.History(*args, **kwargs)

Bases: viur.core.prototypes.list.List

ViUR history module

kindName = 'viur-history'

Name of the datastore kind that is handled by this module.

This information is used to bind a specific viur.core.skeleton.Skeleton-class to this prototype. By default, it is automatically determined from the module’s class name, so a module named Animal refers to a Skeleton named AnimalSkel and its kindName is animal.

For more information, refer to the function _resolveSkelCls().

adminInfo

This is a dict holding the information necessary for the Vi/Admin to handle this module.

name: str

Human-readable module name that will be shown in the admin tool.

handler: str (list, tree or singleton):

Allows to override the handler provided by the module. Set this only when really necessary, otherwise it can be left out and is automatically injected by the Module’s prototype.

icon: str

(Optional) Either the Shoelace icon library name or a path relative to the project’s deploy folder (e.g. /static/icons/viur.svg) for the icon used in the admin tool for this module.

columns: List[str]

(Optional) List of columns (bone names) that are displayed by default. Used only by the List handler.

filter: Dict[str, str]

(Optional) Dictionary of additional parameters that will be send along when fetching entities from the server. Can be used to filter the entities being displayed on the client-side.

display: str (“default”, “hidden” or “group”)

(Optional) “hidden” will hide the module in the admin tool’s main bar. (itwill not be accessible directly, however it’s registered with the frontend so it can be used in a relational bone). “group” will show this module in the main bar, but it will not be clickable. Clicking it will just try to expand it (assuming there are additional views defined).

preview: Union[str, Dict[str, str]]

(Optional) A url that will be opened in a new tab and is expected to display the entity selected in the table. Can be “/{{module}}/view/{{key}}”, with {{module}} and {{key}} getting replaced as needed. If more than one preview-url is needed, supply a dictionary where the key is the URL and the value the description shown to the user.

views: List[Dict[str, t.Any]]

(Optional) List of nested adminInfo like dictionaries. Used to define additional views on the module. Useful f.e. for an order module, where you want separate list of “payed orders”, “unpayed orders”, “orders waiting for shipment”, etc. If such views are defined, the top-level entry in the menu bar will expand if clicked, revealing these additional filters.

actions: List[str]

(Optional) List of actions supported by this modules. Actions can be defined by the frontend (like “add”, “edit”, “delete” or “preview”); it can be an action defined by a plugin loaded by the frontend; or it can be a so called “server side action” (see “customActions” below)

customActions: Dict[str, dict]

(Optional) A mapping of names of server-defined actions that can be used in the actions list above to their definition dictionary. See …. for more details.

disabledActions: List[str, dict]

(Optional) A list of disabled actions. The frontend will inject default actions like add or edit even if they’re not listed in actions. Listing them here will prevent that. It’s up to the frontend to decide if that action won’t be visible at all or it’s button just being disabled.

sortIndex: int

(Optional) Defines the order in which the modules will appear in the main bar in ascrending order.

indexedBones: List[str]

(Optional) List of bones, for which an (composite?) index exists in this view. This allows the fronted to signal the user that a given list can be sorted or filtered by this bone. If no additional filters are enforced by the listFilter and filter is not set, this should be all bones which are marked as indexed.

changeInvalidates: List[str]

(Optional) A list of module-names which depend on the entities handled from this module. This allows the frontend to invalidate any caches in these depended modules if the data in this module changes. Example: This module may be a list-module handling the file_rootNode entities for the file module, so a edit/add/deletion action on this module should be reflected in the rootNode-selector in the file-module itself. In this case, this property should be set to ["file"].

moduleGroup: str

(Optional) If set, should be a key of a moduleGroup defined in …. .

editViews: Dict[str, t.Any]

(Optional) If set, will embed another list-widget in the edit forms for a given entity. See …. for more details.

If this is a function, it must take no parameters and return the dictionary as shown above. This can be used to customize the appearance of the Vi/Admin to individual users.

roles

Allows to specify role settings for a module.

Defaults to no role definition, which ignores the module entirely in the role-system. In this case, access rights can still be set individually on the user’s access bone.

A “*” wildcard can either be used as key or as value to allow for “all roles”, or “all rights”.

# Example
roles = {
    "*": "view",                # Any role may only "view"
    "editor": ("add", "edit"),  # Role "editor" may "add" or "edit", but not "delete"
    "admin": "*",               # Role "admin" can do everything
}
HISTORY_VERSION = 1

History format version.

BigQueryHistoryCls

The connector class used to store entries to BigQuery.

skel(**kwargs)

Retrieve module-specific skeleton, optionally as subskel.

Parameters:
  • allow_client_defined – Evaluates header X-VIUR-BONELIST to contain a comma-separated list of bones. Using this parameter enforces that the Skeleton class has a subskel named “*” for required bones that must exist.

  • bones – Allows to specify a list of bones to form a subskel.

  • exclude_bones – Provide a list of bones which are always excluded.

The parameters bones and allow_client_defined can be combined.

canEdit(skel)

Access control function for modification permission.

Checks if the current user has the permission to edit an entry.

The default behavior is: - If no user is logged in, editing is generally refused. - If the user has “root” access, editing is generally allowed. - If the user has the modules “edit” permission (module-edit) enabled, editing is allowed.

It should be overridden for a module-specific behavior.

See also

edit()

Parameters:

skel – The Skeleton that should be edited.

Returns:

True, if editing entries is allowed, False otherwise.

canDelete(_skel)

Access control function for delete permission.

Checks if the current user has the permission to delete an entry.

The default behavior is: - If no user is logged in, deleting is generally refused. - If the user has “root” access, deleting is generally allowed. - If the user has the modules “deleting” permission (module-delete) enabled, deleting is allowed.

It should be overridden for a module-specific behavior.

Parameters:

skel – The Skeleton that should be deleted.

See also

delete()

Returns:

True, if deleting entries is allowed, False otherwise.

canAdd()

Access control function for adding permission.

Checks if the current user has the permission to add a new entry.

The default behavior is: - If no user is logged in, adding is generally refused. - If the user has “root” access, adding is generally allowed. - If the user has the modules “add” permission (module-add) enabled, adding is allowed.

It should be overridden for a module-specific behavior.

See also

add()

Returns:

True, if adding entries is allowed, False otherwise.

static _create_diff(new, old, diff_excludes=set())

Creates a textual diff format string from the contents of two dicts.

Parameters:
  • new (dict)

  • old (dict)

  • diff_excludes (Iterable[str])

build_name(skel)

Helper function to figure out a name from the skeleton

Parameters:

skel (viur.core.skeleton.SkeletonInstance)

Return type:

str | None

build_descr(action, skel, change_list)

Helper function to build a description about the change to the skeleton

Parameters:
  • action (str)

  • skel (viur.core.skeleton.SkeletonInstance)

  • change_list (Iterable[str])

Return type:

str | None

create_history_entry(action, old_skel, new_skel, change_list=(), descr=None, user=None, tags=(), diff_excludes=set())

Internal helper function that constructs a JSON-serializable form of the entry that can either be written to datastore or another database.

Parameters:
  • action (str)

  • old_skel (viur.core.skeleton.SkeletonInstance)

  • new_skel (viur.core.skeleton.SkeletonInstance)

  • change_list (Iterable[str])

  • descr (Optional[str])

  • user (Optional[viur.core.skeleton.SkeletonInstance])

  • tags (Iterable[str])

  • diff_excludes (Set[str])

write_diff(action, old_skel=None, new_skel=None, change_list=(), descr=None, user=None, tags=(), diff_excludes=set())
Parameters:
  • action (str)

  • old_skel (viur.core.skeleton.SkeletonInstance)

  • new_skel (viur.core.skeleton.SkeletonInstance)

  • change_list (Iterable[str])

  • descr (Optional[str])

  • user (Optional[viur.core.skeleton.SkeletonInstance])

  • tags (Iterable[str])

  • diff_excludes (Set[str])

Return type:

str | None

write(key, entry)

Write a history entry generated from an HistoryAdapter.

Parameters:
  • key (str)

  • entry (dict)

write_deferred(key, entry)
Parameters:
  • key (str)

  • entry (dict)

write_to_bigquery(key, entry)
Parameters:
  • key (str)

  • entry (dict)

write_to_bigquery_deferred(key, entry)
Parameters:
  • key (str)

  • entry (dict)