Skip to content

model_policy

Define model policies.

create_model_policies_if_needed(artifact_store, policy_store)

Function that checks, for all models, if policies have not been created. This is for cases where the model may have been created without the API.

Source code in mlte/store/user/policy/model_policy.py
11
12
13
14
15
16
17
18
19
20
21
22
def create_model_policies_if_needed(
    artifact_store: ArtifactStoreSession, policy_store: PolicyStoreService
):
    """
    Function that checks, for all models, if policies have not been created.
    This is for cases where the model may have been created without the API.
    """
    models = artifact_store.model_mapper.list()
    for model_id in models:
        policy = Policy(ResourceType.MODEL, model_id)
        if not policy_store.is_stored(policy):
            policy_store.save_to_store(policy)

create_model_policy(model_id, current_user, policy_store)

Create a basic policy for a model for the user, and returns the updated user.

Source code in mlte/store/user/policy/model_policy.py
25
26
27
28
29
30
31
32
33
34
35
36
37
def create_model_policy(
    model_id: str,
    current_user: Union[UserWithPassword, BasicUser],
    policy_store: PolicyStoreService,
) -> Union[UserWithPassword, BasicUser]:
    """Create a basic policy for a model for the user, and returns the updated user."""
    policy = Policy(ResourceType.MODEL, model_id)
    policy_store.save_to_store(policy)

    # Also make user have access to CRUD for this model, since they are its creator.
    user = policy.assign_to_user(current_user)

    return user

remove_model_polcy(model_id, policy_store)

Removes a basic policy for a model.

Source code in mlte/store/user/policy/model_policy.py
40
41
42
43
def remove_model_polcy(model_id: str, policy_store: PolicyStoreService):
    """Removes a basic policy for a model."""
    policy = Policy(ResourceType.MODEL, resource_id=model_id)
    policy_store.remove_from_store(policy)