Skip to content

component_settings

panel_flowdash.component_settings

The project file's components section: which components are offered, and to whom.

components:
  panel_flowdash/image:
    enabled: false
  wind_maps/turbine_map:
    placed_by: [analysts]
    approval: true

A component with enabled: false is turned off: it is left out of the component list, the command palette and what the agent is offered, and nobody may add it to a dashboard. Dashboards that already place it keep working, and their editors are told it is turned off. placed_by limits who may add it to members of those groups (people may still view and edit dashboards that have it), and approval: true makes the agent ask before placing or changing it, like a pattern in the app's agent_sensitive_components. Keys are component ids; a former id (aliases) is read as the component's current id.

KEYS = ('enabled', 'placed_by', 'approval') module-attribute

TURNED_OFF = 'turned off by an admin' module-attribute

_LAST = {} module-attribute

_LAST_LOCK = threading.Lock() module-attribute

_parse = parse_project_data module-attribute

logger = logging.getLogger(__name__) module-attribute

ComponentSettingsUnavailable

Bases: RuntimeError

The project file's component settings cannot be read and none were read from it before.

Identity dataclass

The resolved principal for a session.

groups = field(default_factory=frozenset) class-attribute instance-attribute

oauth_user = None class-attribute instance-attribute

system_user = None class-attribute instance-attribute

user instance-attribute

user_info = field(default_factory=dict) class-attribute instance-attribute

user_names property

All names this identity may be referenced by in a rule.

in_groups(groups)

Whether the identity belongs to any of groups.

is_user(users)

Whether the identity matches any of users (OAuth or system name).

Project dataclass

A loaded project file.

It holds the raw data, where each key and value is written, by path (e.g. ("metrics", "capacity", "table")), the value each registered loader made of its section, the warnings found while loading and the context the loaders were given.

context = field(default_factory=dict) class-attribute instance-attribute

data = field(default_factory=dict) class-attribute instance-attribute

directory property

Return the directory the file is in, against which paths it names resolve.

path = None class-attribute instance-attribute

positions = field(default_factory=dict) class-attribute instance-attribute

warnings = field(default_factory=list) class-attribute instance-attribute

get(name, default=None)

Return the value of section name, or default if the file has none.

The value is what the section's loader returned. A section whose loader was registered after the file was loaded is loaded now (raising ProjectError); a section no loader is registered for gives its raw data.

load_all()

Load every section a loader is registered for, warning about the others.

Raises ProjectError with every problem the loaders found.

position(path)

Return the 1-based line and column of the value at path.

A path that is not in the file gives the position of its nearest enclosing value.

problem(path, message, key=False)

Return a problem at the value at path (with key, at the key naming it).

raw(name, default=None)

Return the raw YAML data of section name.

set(name, value)

Set section name to value and write it to the project's file.

The value goes through the section's dump and the result through its loader, so a value the loader rejects raises ProjectError, positioned where it would be written, and the file is left alone. Only the lines of this section change in the file; comments inside it are not kept. Text a YAML 1.1 reader would take for something else, such as no or 1:20, is quoted.

update(name, change)

Change section name from its raw data as the file has it now, and write it.

change is called with a copy of the section's raw YAML data, read again from the file (None when the file has no such section), and returns the new value, which is written as set writes it. The read, change and the write happen under FILE_LOCK, so no other write from this process comes in between. An exception from change leaves the file alone. Returns the value written.

ProjectError

Bases: ValueError

The problems of a project file, each with the file, line and column it concerns.

problems = list(problems) instance-attribute

Section dataclass

One top-level section of a project file, as a loader receives it.

context property

Return what the app loaded the project with, e.g. its data sources.

name instance-attribute

project instance-attribute

value instance-attribute

position(path=())

Return the line and column of the value at path in this section.

problem(path, message, key=False)

Return a problem at the value at path in this section (with key, at its key).

warn(path, message, key=False)

Report a problem at path that does not stop the section from loading.

SectionError

Bases: ValueError

A section loader's problem at path inside its section.

path is e.g. ("capacity", "table"). With key=True the problem is reported where the last key of path is written instead of its value.

key = key instance-attribute

message = message instance-attribute

path = tuple(path) instance-attribute

approval_ids(settings)

Return the ids of the components the agent needs approval to place or change.

disabled_ids(settings)

Return the ids of the components turned off.

dump_components(value)

Drop the settings left at their defaults, and components with none left.

load_components(section)

Check the components section and return it as plain data.

placement_refusal(settings, component_id, identity)

Return why identity may not add component_id to a dashboard, or None.

project_components(project)

Return the components section of project, read again when its file changes.

It fails closed: a file that cannot be read keeps the settings last read from it, so a half-written file does not turn components back on, and with none read before ComponentSettingsUnavailable is raised, so callers refuse placing components rather than offer every one.