Skip to content

group

mlte/backend/api/endpoints/group.py

Group CRUD endpoint.

create_group(*, group, current_user)

Create a MLTE group.

Parameters:

Name Type Description Default
group Group

The group to create

required

Returns:

Type Description
Group

The created group

Source code in mlte/backend/api/endpoints/group.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
@router.post("")
def create_group(
    *,
    group: Group,
    current_user: AuthorizedUser,
) -> Group:
    """
    Create a MLTE group.
    :param group: The group to create
    :return: The created group
    """
    with state_stores.user_store_session() as user_store:
        try:
            return user_store.group_mapper.create(group)
        except errors.ErrorAlreadyExists as e:
            raise HTTPException(
                status_code=codes.ALREADY_EXISTS, detail=f"{e} already exists."
            )
        except Exception as e:
            raise_http_internal_error(e)

delete_group(*, group_name, current_user)

Delete a MLTE group.

Parameters:

Name Type Description Default
group_name str

The group name

required

Returns:

Type Description
Group

The deleted group

Source code in mlte/backend/api/endpoints/group.py
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
@router.delete("/{group_name}")
def delete_group(
    *,
    group_name: str,
    current_user: AuthorizedUser,
) -> Group:
    """
    Delete a MLTE group.
    :param group_name: The group name
    :return: The deleted group
    """
    with state_stores.user_store_session() as user_store:
        try:
            return user_store.group_mapper.delete(group_name)
        except errors.ErrorNotFound as e:
            raise HTTPException(
                status_code=codes.NOT_FOUND, detail=f"{e} not found."
            )
        except Exception as e:
            raise_http_internal_error(e)

edit_group(*, group, current_user)

Edit a MLTE group.

Parameters:

Name Type Description Default
group Group

The group to edit

required

Returns:

Type Description
Group

The edited group

Source code in mlte/backend/api/endpoints/group.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
@router.put("")
def edit_group(
    *,
    group: Group,
    current_user: AuthorizedUser,
) -> Group:
    """
    Edit a MLTE group.
    :param group: The group to edit
    :return: The edited group
    """
    with state_stores.user_store_session() as user_store:
        try:
            return user_store.group_mapper.edit(group)
        except errors.ErrorNotFound as e:
            raise HTTPException(
                status_code=codes.NOT_FOUND, detail=f"{e} not found."
            )
        except Exception as e:
            raise_http_internal_error(e)

list_group_details(current_user)

List MLTE group, with details for each group.

Returns:

Type Description
List[Group]

A collection of groups with their details.

Source code in mlte/backend/api/endpoints/group.py
105
106
107
108
109
110
111
112
113
114
115
116
117
@router.get("s/details")
def list_group_details(
    current_user: AuthorizedUser,
) -> List[Group]:
    """
    List MLTE group, with details for each group.
    :return: A collection of groups with their details.
    """
    with state_stores.user_store_session() as user_store:
        try:
            return user_store.group_mapper.list_details()
        except Exception as e:
            raise_http_internal_error(e)

list_groups(current_user)

List MLTE group.

Returns:

Type Description
List[str]

A collection of group names

Source code in mlte/backend/api/endpoints/group.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
@router.get("")
def list_groups(
    current_user: AuthorizedUser,
) -> List[str]:
    """
    List MLTE group.
    :return: A collection of group names
    """
    with state_stores.user_store_session() as user_store:
        try:
            return user_store.group_mapper.list()
        except Exception as e:
            raise_http_internal_error(e)

list_permission_details(current_user)

List MLTE permissions, with details.

Returns:

Type Description
List[Permission]

A collection of permissions, with details.

Source code in mlte/backend/api/endpoints/group.py
157
158
159
160
161
162
163
164
165
166
167
168
169
@router.get("s/permissions/details")
def list_permission_details(
    current_user: AuthorizedUser,
) -> List[Permission]:
    """
    List MLTE permissions, with details.
    :return: A collection of permissions, with details.
    """
    with state_stores.user_store_session() as user_store:
        try:
            return user_store.permission_mapper.list_details()
        except Exception as e:
            raise_http_internal_error(e)

list_permissions(current_user)

List MLTE permissions.

Returns:

Type Description
List[str]

A collection of permissions

Source code in mlte/backend/api/endpoints/group.py
142
143
144
145
146
147
148
149
150
151
152
153
154
@router.get("s/permissions")
def list_permissions(
    current_user: AuthorizedUser,
) -> List[str]:
    """
    List MLTE permissions.
    :return: A collection of permissions
    """
    with state_stores.user_store_session() as user_store:
        try:
            return user_store.permission_mapper.list()
        except Exception as e:
            raise_http_internal_error(e)

read_group(*, group_name, current_user)

Read a MLTE group.

Parameters:

Name Type Description Default
group_name str

The group name

required

Returns:

Type Description
Group

The read group

Source code in mlte/backend/api/endpoints/group.py
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
@router.get("/{group_name}")
def read_group(
    *,
    group_name: str,
    current_user: AuthorizedUser,
) -> Group:
    """
    Read a MLTE group.
    :param group_name: The group name
    :return: The read group
    """
    with state_stores.user_store_session() as user_store:
        try:
            return user_store.group_mapper.read(group_name)
        except errors.ErrorNotFound as e:
            raise HTTPException(
                status_code=codes.NOT_FOUND, detail=f"{e} not found."
            )
        except Exception as e:
            raise_http_internal_error(e)