fairdm.contrib.contributors.access#

What a person may do on one project, dataset, sample or measurement, read from contribution levels.

Module Contents#

Classes#

RecordAccess

Answer what people may do on one record from the levels on its contributions.

Data#

API#

REQUIRED_LEVEL#

None

class RecordAccess(record)#

Answer what people may do on one record from the levels on its contributions.

A level is held on the record or on a record above it: a sample or measurement takes its dataset’s levels and the dataset’s project’s, a dataset takes its project’s. Contributions of an organization hold no level.

Args: record: A project, dataset, sample or measurement, of any registered type.

Initialization

static is_core_model(model)#

Say whether a class is the project, dataset, sample or measurement model.

Args: model: A model class.

Returns: True for one of the four core models, not for a registered subtype.

static is_core_record(obj)#

Say whether an object is a project, dataset, sample or measurement of any type.

Args: obj: Any object, or None.

Returns: True for an instance of one of the four core models or a registered subtype.

property model#

The core model the record belongs to, whatever registered type it is.

property kind#

The word for the record’s kind: project, dataset, sample or measurement.

above()#

The records this one takes levels from, nearest first.

A measurement follows its own dataset, not its sample’s.

static key(record)#

Return the pair that names a record on a contribution.

Args: record: A project, dataset, sample or measurement.

Returns: The content type id and the object id, as stored on a contribution.

required_level(perm)#

Return the level a permission needs on the record.

A registered subtype’s own default permissions, such as demo.view_rocksample, are read as the core model’s.

Args: perm: The permission, with or without its app label.

Returns: The level, or None for a permission the table does not know, which is refused.

on_chain(*, include_record)#

Narrow contributions to those on the record and the records above, or only above.

Args: include_record: Whether the record itself is part of the chain.

Returns: The contributions with a level, and the record each key stands for.

levels_held(person_id)#

Return each level a person holds on the record or above it, with where it is held.

Args: person_id: The id of the person.

Returns: (record, level) pairs, in one query.

levels_for(person_ids)#

Return each level the given people hold on the record or above it, in one query.

Args: person_ids: The ids of the people.

Returns: A dict of person id to the (record, level) pairs :meth:levels_held gives.

level_of(user)#

Return the highest level a user holds on the record or any record above it.

Args: user: The user, or an anonymous user for a visitor.

Returns: The level, or None for a visitor, an inactive user or someone who holds none.

own_level(person, held=None)#

Return the level a person holds from being listed on the record itself.

Args: person: The person. held: What :meth:levels_for returned for the person, when it was asked already.

Returns: The level, or None.

level_from_above(person, held=None)#

Return the highest level a person holds from a record above, and that record.

Args: person: The person. held: What :meth:levels_for returned for the person, when it was asked already.

Returns: (level, record), or (None, None).

people_above()#

Return everyone who holds a level from a record above, at the highest they hold.

Returns: (person, level, source record) for each person, by name.

managers()#

Return the ids of the people who count as able to manage the record.

A person counts when they can sign in and hold the manage level on the record or on a record above it. Holders of portal roles do not count.

Returns: A set of person ids.

refuse_move_without_manager(parent_field)#

Refuse a change of parent that leaves a record nobody can manage.

Compares the record’s parent with the one stored. A new record, a record whose parent did not change and a record that had no manager before are never refused.

Args: parent_field: The name of the field that holds the parent: project for a dataset, dataset for a sample or measurement.

Raises: ValidationError: Attached to parent_field with code no_manager.

can_manage(user)#

Say whether a user may change the record’s contributors.

Args: user: The user, or an anonymous user for a visitor.

Returns: True for the manage level on the record or above it, and for anyone holding change_<model> for the whole portal, which a superuser and a Data Curator do.