zrb 1.0.0b5__py3-none-any.whl → 1.0.0b7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- zrb/builtin/__init__.py +2 -0
- zrb/builtin/llm/tool/rag.py +6 -8
- zrb/builtin/project/add/fastapp/fastapp_task.py +3 -3
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/column/add_column_task.py +80 -1
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/add_entity_task.py +3 -3
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module/service/my_entity/my_entity_service.py +11 -13
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/add_module_task.py +3 -3
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/permission/permission_service.py +11 -13
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/role/role_service.py +20 -18
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/user_service.py +24 -14
- zrb/builtin/setup/tmux/tmux.py +1 -1
- zrb/builtin/setup/zsh/zsh.py +55 -0
- zrb/builtin/setup/zsh/zsh_config.sh +133 -0
- zrb/builtin/setup/zsh/zsh_helper.py +13 -0
- zrb/config.py +4 -2
- zrb/context/any_context.py +2 -0
- zrb/context/context.py +7 -5
- zrb/runner/web_route/static/resources/session/current-session.js +19 -12
- zrb/task/cmd_task.py +11 -1
- zrb/task/llm_task.py +0 -2
- zrb/task/rsync_task.py +6 -4
- zrb/util/cmd/command.py +25 -3
- zrb/util/git.py +9 -9
- zrb/util/git_subtree.py +3 -3
- {zrb-1.0.0b5.dist-info → zrb-1.0.0b7.dist-info}/METADATA +2 -1
- {zrb-1.0.0b5.dist-info → zrb-1.0.0b7.dist-info}/RECORD +28 -25
- {zrb-1.0.0b5.dist-info → zrb-1.0.0b7.dist-info}/WHEEL +0 -0
- {zrb-1.0.0b5.dist-info → zrb-1.0.0b7.dist-info}/entry_points.txt +0 -0
zrb/builtin/__init__.py
CHANGED
@@ -17,6 +17,7 @@ from zrb.builtin.setup.asdf.asdf import setup_asdf
|
|
17
17
|
from zrb.builtin.setup.latex.ubuntu import setup_latex_on_ubuntu
|
18
18
|
from zrb.builtin.setup.tmux.tmux import setup_tmux
|
19
19
|
from zrb.builtin.setup.ubuntu import setup_ubuntu
|
20
|
+
from zrb.builtin.setup.zsh.zsh import setup_zsh
|
20
21
|
from zrb.builtin.shell.autocomplete.bash import make_bash_autocomplete
|
21
22
|
from zrb.builtin.shell.autocomplete.subcmd import get_shell_subcommands
|
22
23
|
from zrb.builtin.shell.autocomplete.zsh import make_zsh_autocomplete
|
@@ -62,3 +63,4 @@ assert setup_ubuntu
|
|
62
63
|
assert setup_latex_on_ubuntu
|
63
64
|
assert setup_asdf
|
64
65
|
assert setup_tmux
|
66
|
+
assert setup_zsh
|
zrb/builtin/llm/tool/rag.py
CHANGED
@@ -3,7 +3,6 @@ import json
|
|
3
3
|
import os
|
4
4
|
import sys
|
5
5
|
|
6
|
-
import litellm
|
7
6
|
import ulid
|
8
7
|
|
9
8
|
from zrb.config import (
|
@@ -30,7 +29,9 @@ def create_rag_from_directory(
|
|
30
29
|
async def retrieve(query: str) -> str:
|
31
30
|
from chromadb import PersistentClient
|
32
31
|
from chromadb.config import Settings
|
32
|
+
from fastembed import TextEmbedding
|
33
33
|
|
34
|
+
embedding_model = TextEmbedding(model_name=model)
|
34
35
|
client = PersistentClient(
|
35
36
|
path=vector_db_path, settings=Settings(allow_reset=True)
|
36
37
|
)
|
@@ -75,10 +76,8 @@ def create_rag_from_directory(
|
|
75
76
|
),
|
76
77
|
file=sys.stderr,
|
77
78
|
)
|
78
|
-
|
79
|
-
|
80
|
-
)
|
81
|
-
vector = response["data"][0]["embedding"]
|
79
|
+
embedding_result = list(embedding_model.embed([chunk]))
|
80
|
+
vector = embedding_result[0]
|
82
81
|
collection.upsert(
|
83
82
|
ids=[chunk_id],
|
84
83
|
embeddings=[vector],
|
@@ -102,9 +101,8 @@ def create_rag_from_directory(
|
|
102
101
|
)
|
103
102
|
|
104
103
|
print(stylize_faint("Vectorizing query"), file=sys.stderr)
|
105
|
-
|
106
|
-
query_vector =
|
107
|
-
|
104
|
+
embedding_result = list(embedding_model.embed([query]))
|
105
|
+
query_vector = embedding_result[0]
|
108
106
|
print(stylize_faint("Searching documents"), file=sys.stderr)
|
109
107
|
results = collection.query(
|
110
108
|
query_embeddings=query_vector,
|
@@ -20,11 +20,11 @@ from zrb.util.string.name import get_random_name
|
|
20
20
|
|
21
21
|
|
22
22
|
@make_task(
|
23
|
-
name="validate-
|
23
|
+
name="validate-add-fastapp",
|
24
24
|
input=[project_dir_input, app_name_input],
|
25
25
|
retries=0,
|
26
26
|
)
|
27
|
-
async def
|
27
|
+
async def validate_add_fastapp(ctx: AnyContext):
|
28
28
|
project_dir = ctx.input.project_dir
|
29
29
|
if not os.path.isdir(project_dir):
|
30
30
|
raise ValueError(f"Project directory not exists: {project_dir}")
|
@@ -39,7 +39,7 @@ scaffold_fastapp = Scaffolder(
|
|
39
39
|
project_dir_input,
|
40
40
|
app_name_input,
|
41
41
|
],
|
42
|
-
upstream=
|
42
|
+
upstream=validate_add_fastapp,
|
43
43
|
source_path=os.path.join(os.path.dirname(__file__), "fastapp_template"),
|
44
44
|
render_source_path=False,
|
45
45
|
destination_path="{ctx.input.project_dir}",
|
@@ -1,14 +1,93 @@
|
|
1
|
+
import os
|
2
|
+
|
3
|
+
from my_app_name._zrb.config import APP_DIR
|
1
4
|
from my_app_name._zrb.format_task import format_my_app_name_code
|
2
5
|
from my_app_name._zrb.group import app_create_group
|
6
|
+
from my_app_name._zrb.input import (
|
7
|
+
existing_entity_input,
|
8
|
+
new_column_input,
|
9
|
+
new_column_type_input,
|
10
|
+
)
|
11
|
+
from my_app_name._zrb.util import get_existing_schema_names
|
12
|
+
|
13
|
+
from zrb import AnyContext, Task, make_task
|
14
|
+
from zrb.util.codemod.prepend_property_to_class import prepend_property_to_class
|
15
|
+
from zrb.util.file import read_file, write_file
|
16
|
+
from zrb.util.string.conversion import to_pascal_case, to_snake_case
|
17
|
+
|
18
|
+
|
19
|
+
@make_task(
|
20
|
+
name="validate-add-my-app-name-column",
|
21
|
+
input=existing_entity_input,
|
22
|
+
retries=0,
|
23
|
+
)
|
24
|
+
async def validate_add_my_app_name_column(ctx: AnyContext):
|
25
|
+
schema_name = ctx.input.entity
|
26
|
+
if schema_name not in get_existing_schema_names():
|
27
|
+
raise ValueError(f"Schema not exist: {schema_name}")
|
28
|
+
|
29
|
+
|
30
|
+
@make_task(
|
31
|
+
name="update-my-app-name-schema",
|
32
|
+
input=[
|
33
|
+
existing_entity_input,
|
34
|
+
new_column_input,
|
35
|
+
new_column_type_input,
|
36
|
+
],
|
37
|
+
retries=0,
|
38
|
+
upstream=validate_add_my_app_name_column,
|
39
|
+
)
|
40
|
+
def update_my_app_name_schema(ctx: AnyContext):
|
41
|
+
snake_entity_name = to_snake_case(ctx.input.entity)
|
42
|
+
pascal_entity_name = to_pascal_case(ctx.input.entity)
|
43
|
+
schema_file_path = os.path.join(APP_DIR, "schema", f"{snake_entity_name}.py")
|
44
|
+
existing_code = read_file(schema_file_path)
|
45
|
+
snake_column_name = to_snake_case(ctx.input.column)
|
46
|
+
column_type = ctx.input.type
|
47
|
+
# Base
|
48
|
+
new_code = prepend_property_to_class(
|
49
|
+
original_code=existing_code,
|
50
|
+
class_name=f"{pascal_entity_name}Base",
|
51
|
+
property_name=snake_column_name,
|
52
|
+
annotation=column_type,
|
53
|
+
default_value=_get_default_value(column_type),
|
54
|
+
)
|
55
|
+
# Update
|
56
|
+
new_code = prepend_property_to_class(
|
57
|
+
original_code=new_code,
|
58
|
+
class_name=f"{pascal_entity_name}Update",
|
59
|
+
property_name=snake_column_name,
|
60
|
+
annotation=f"{column_type} | None",
|
61
|
+
default_value="None",
|
62
|
+
)
|
63
|
+
# Table
|
64
|
+
new_code = prepend_property_to_class(
|
65
|
+
original_code=new_code,
|
66
|
+
class_name=f"{pascal_entity_name}",
|
67
|
+
property_name=snake_column_name,
|
68
|
+
annotation=f"{column_type} | None",
|
69
|
+
default_value="Field(index=False)",
|
70
|
+
)
|
71
|
+
write_file(schema_file_path, new_code)
|
3
72
|
|
4
|
-
from zrb import Task
|
5
73
|
|
6
74
|
add_my_app_name_column = app_create_group.add_task(
|
7
75
|
Task(
|
8
76
|
name="add-my-app-name-column",
|
9
77
|
description="📊 Create new column on an entity",
|
78
|
+
upstream=update_my_app_name_schema,
|
10
79
|
successor=format_my_app_name_code,
|
11
80
|
retries=0,
|
12
81
|
),
|
13
82
|
alias="column",
|
14
83
|
)
|
84
|
+
|
85
|
+
|
86
|
+
def _get_default_value(data_type: str) -> str:
|
87
|
+
if data_type == "str":
|
88
|
+
return '""'
|
89
|
+
if data_type in ("int", "float"):
|
90
|
+
return "0"
|
91
|
+
if data_type == "bool":
|
92
|
+
return "True"
|
93
|
+
return "None"
|
@@ -48,7 +48,7 @@ from zrb.util.string.conversion import to_snake_case
|
|
48
48
|
|
49
49
|
|
50
50
|
@make_task(
|
51
|
-
name="validate-
|
51
|
+
name="validate-add-my-app-name-entity",
|
52
52
|
input=[
|
53
53
|
existing_module_input,
|
54
54
|
new_entity_input,
|
@@ -57,7 +57,7 @@ from zrb.util.string.conversion import to_snake_case
|
|
57
57
|
],
|
58
58
|
retries=0,
|
59
59
|
)
|
60
|
-
async def
|
60
|
+
async def validate_add_my_app_name_entity(ctx: AnyContext):
|
61
61
|
module_name = to_snake_case(ctx.input.module)
|
62
62
|
if module_name not in get_existing_module_names():
|
63
63
|
raise ValueError(f"Module not exist: {module_name}")
|
@@ -147,7 +147,7 @@ scaffold_my_app_name_entity = Scaffolder(
|
|
147
147
|
),
|
148
148
|
],
|
149
149
|
retries=0,
|
150
|
-
upstream=
|
150
|
+
upstream=validate_add_my_app_name_entity,
|
151
151
|
)
|
152
152
|
|
153
153
|
create_my_app_name_entity_migration = CmdTask(
|
@@ -72,10 +72,8 @@ class MyEntityService(BaseService):
|
|
72
72
|
async def update_my_entity_bulk(
|
73
73
|
self, my_entity_ids: list[str], data: MyEntityUpdateWithAudit
|
74
74
|
) -> MyEntityResponse:
|
75
|
-
|
76
|
-
return await self.my_entity_repository.get_by_ids(
|
77
|
-
[my_entity.id for my_entity in my_entities]
|
78
|
-
)
|
75
|
+
await self.my_entity_repository.update_bulk(my_entity_ids, data)
|
76
|
+
return await self.my_entity_repository.get_by_ids(my_entity_ids)
|
79
77
|
|
80
78
|
@BaseService.route(
|
81
79
|
"/api/v1/my-entities/{my_entity_id}",
|
@@ -85,21 +83,20 @@ class MyEntityService(BaseService):
|
|
85
83
|
async def update_my_entity(
|
86
84
|
self, my_entity_id: str, data: MyEntityUpdateWithAudit
|
87
85
|
) -> MyEntityResponse:
|
88
|
-
|
89
|
-
return await self.my_entity_repository.get_by_id(
|
86
|
+
await self.my_entity_repository.update(my_entity_id, data)
|
87
|
+
return await self.my_entity_repository.get_by_id(my_entity_id)
|
90
88
|
|
91
89
|
@BaseService.route(
|
92
|
-
"/api/v1/my-entities/
|
90
|
+
"/api/v1/my-entities/bulk",
|
93
91
|
methods=["delete"],
|
94
92
|
response_model=MyEntityResponse,
|
95
93
|
)
|
96
94
|
async def delete_my_entity_bulk(
|
97
95
|
self, my_entity_ids: list[str], deleted_by: str
|
98
96
|
) -> MyEntityResponse:
|
99
|
-
my_entities = await self.my_entity_repository.
|
100
|
-
|
101
|
-
|
102
|
-
)
|
97
|
+
my_entities = await self.my_entity_repository.get_by_ids(my_entity_ids)
|
98
|
+
await self.my_entity_repository.delete_bulk(my_entity_ids)
|
99
|
+
return my_entities
|
103
100
|
|
104
101
|
@BaseService.route(
|
105
102
|
"/api/v1/my-entities/{my_entity_id}",
|
@@ -109,5 +106,6 @@ class MyEntityService(BaseService):
|
|
109
106
|
async def delete_my_entity(
|
110
107
|
self, my_entity_id: str, deleted_by: str
|
111
108
|
) -> MyEntityResponse:
|
112
|
-
my_entity = await self.my_entity_repository.
|
113
|
-
|
109
|
+
my_entity = await self.my_entity_repository.get_by_id(my_entity.id)
|
110
|
+
await self.my_entity_repository.delete(my_entity_id)
|
111
|
+
return my_entity
|
@@ -24,11 +24,11 @@ from zrb import AnyContext, ContentTransformer, Scaffolder, Task, make_task
|
|
24
24
|
|
25
25
|
|
26
26
|
@make_task(
|
27
|
-
name="validate-
|
27
|
+
name="validate-add-my-app-name-module",
|
28
28
|
input=new_module_input,
|
29
29
|
retries=0,
|
30
30
|
)
|
31
|
-
async def
|
31
|
+
async def validate_add_my_app_name_module(ctx: AnyContext):
|
32
32
|
if ctx.input.module in get_existing_module_names():
|
33
33
|
raise ValueError(f"Module already exists: {ctx.input.module}")
|
34
34
|
|
@@ -93,7 +93,7 @@ scaffold_my_app_name_module = Scaffolder(
|
|
93
93
|
),
|
94
94
|
],
|
95
95
|
retries=0,
|
96
|
-
upstream=
|
96
|
+
upstream=validate_add_my_app_name_module,
|
97
97
|
)
|
98
98
|
|
99
99
|
add_my_app_name_module = app_create_group.add_task(
|
@@ -76,10 +76,8 @@ class PermissionService(BaseService):
|
|
76
76
|
async def update_permission_bulk(
|
77
77
|
self, permission_ids: list[str], data: PermissionUpdateWithAudit
|
78
78
|
) -> PermissionResponse:
|
79
|
-
|
80
|
-
return await self.permission_repository.get_by_ids(
|
81
|
-
[permission.id for permission in permissions]
|
82
|
-
)
|
79
|
+
await self.permission_repository.update_bulk(permission_ids, data)
|
80
|
+
return await self.permission_repository.get_by_ids(permission_ids)
|
83
81
|
|
84
82
|
@BaseService.route(
|
85
83
|
"/api/v1/permissions/{permission_id}",
|
@@ -89,21 +87,20 @@ class PermissionService(BaseService):
|
|
89
87
|
async def update_permission(
|
90
88
|
self, permission_id: str, data: PermissionUpdateWithAudit
|
91
89
|
) -> PermissionResponse:
|
92
|
-
|
93
|
-
return await self.permission_repository.get_by_id(
|
90
|
+
await self.permission_repository.update(permission_id, data)
|
91
|
+
return await self.permission_repository.get_by_id(permission_id)
|
94
92
|
|
95
93
|
@BaseService.route(
|
96
|
-
"/api/v1/permissions/
|
94
|
+
"/api/v1/permissions/bulk",
|
97
95
|
methods=["delete"],
|
98
96
|
response_model=PermissionResponse,
|
99
97
|
)
|
100
98
|
async def delete_permission_bulk(
|
101
99
|
self, permission_ids: list[str], deleted_by: str
|
102
100
|
) -> PermissionResponse:
|
103
|
-
permissions = await self.permission_repository.
|
104
|
-
|
105
|
-
|
106
|
-
)
|
101
|
+
permissions = await self.permission_repository.get_by_ids(permission_ids)
|
102
|
+
await self.permission_repository.delete_bulk(permission_ids)
|
103
|
+
return permissions
|
107
104
|
|
108
105
|
@BaseService.route(
|
109
106
|
"/api/v1/permissions/{permission_id}",
|
@@ -113,5 +110,6 @@ class PermissionService(BaseService):
|
|
113
110
|
async def delete_permission(
|
114
111
|
self, permission_id: str, deleted_by: str
|
115
112
|
) -> PermissionResponse:
|
116
|
-
permission = await self.permission_repository.
|
117
|
-
|
113
|
+
permission = await self.permission_repository.get_by_id(permission_id)
|
114
|
+
await self.permission_repository.delete(permission_id)
|
115
|
+
return permission
|
@@ -87,17 +87,15 @@ class RoleService(BaseService):
|
|
87
87
|
) -> RoleResponse:
|
88
88
|
permission_ids = [row.get_permission_ids() for row in data]
|
89
89
|
data = [row.get_role_update_with_audit() for row in data]
|
90
|
-
|
91
|
-
if len(
|
92
|
-
updated_by =
|
93
|
-
await self.role_repository.remove_all_permissions(
|
94
|
-
[role.id for role in roles]
|
95
|
-
)
|
90
|
+
await self.role_repository.update_bulk(role_ids, data)
|
91
|
+
if len(role_ids) > 0:
|
92
|
+
updated_by = data[0].updated_by
|
93
|
+
await self.role_repository.remove_all_permissions(role_ids)
|
96
94
|
await self.role_repository.add_permissions(
|
97
|
-
data={
|
95
|
+
data={role_id: permission_ids[i] for i, role_id in enumerate(role_ids)},
|
98
96
|
created_by=updated_by,
|
99
97
|
)
|
100
|
-
return await self.role_repository.get_by_ids(
|
98
|
+
return await self.role_repository.get_by_ids(role_ids)
|
101
99
|
|
102
100
|
@BaseService.route(
|
103
101
|
"/api/v1/roles/{role_id}",
|
@@ -108,24 +106,26 @@ class RoleService(BaseService):
|
|
108
106
|
self, role_id: str, data: RoleUpdateWithPermissionsAndAudit
|
109
107
|
) -> RoleResponse:
|
110
108
|
permission_ids = data.get_permission_ids()
|
111
|
-
|
112
|
-
|
113
|
-
await self.role_repository.remove_all_permissions([
|
109
|
+
role_data = data.get_role_update_with_audit()
|
110
|
+
await self.role_repository.update(role_id, role_data)
|
111
|
+
await self.role_repository.remove_all_permissions([role_id])
|
114
112
|
await self.role_repository.add_permissions(
|
115
|
-
data={
|
113
|
+
data={role_id: permission_ids}, created_by=role_data.updated_by
|
116
114
|
)
|
117
|
-
return await self.role_repository.get_by_id(
|
115
|
+
return await self.role_repository.get_by_id(role_id)
|
118
116
|
|
119
117
|
@BaseService.route(
|
120
|
-
"/api/v1/roles/
|
118
|
+
"/api/v1/roles/bulk",
|
121
119
|
methods=["delete"],
|
122
120
|
response_model=RoleResponse,
|
123
121
|
)
|
124
122
|
async def delete_role_bulk(
|
125
123
|
self, role_ids: list[str], deleted_by: str
|
126
124
|
) -> RoleResponse:
|
127
|
-
roles = await self.role_repository.
|
128
|
-
|
125
|
+
roles = await self.role_repository.get_by_ids(role_ids)
|
126
|
+
await self.role_repository.delete_bulk(role_ids)
|
127
|
+
await self.role_repository.remove_all_permissions(role_ids)
|
128
|
+
return roles
|
129
129
|
|
130
130
|
@BaseService.route(
|
131
131
|
"/api/v1/roles/{role_id}",
|
@@ -133,5 +133,7 @@ class RoleService(BaseService):
|
|
133
133
|
response_model=RoleResponse,
|
134
134
|
)
|
135
135
|
async def delete_role(self, role_id: str, deleted_by: str) -> RoleResponse:
|
136
|
-
role = await self.role_repository.
|
137
|
-
|
136
|
+
role = await self.role_repository.get_by_id(role_id)
|
137
|
+
await self.role_repository.delete(role_id)
|
138
|
+
await self.role_repository.remove_all_permissions([role_id])
|
139
|
+
return role
|
@@ -84,16 +84,16 @@ class UserService(BaseService):
|
|
84
84
|
self, user_ids: list[str], data: UserUpdateWithRolesAndAudit
|
85
85
|
) -> UserResponse:
|
86
86
|
role_ids = [row.get_role_ids() for row in data]
|
87
|
-
|
88
|
-
|
89
|
-
if len(
|
90
|
-
updated_by =
|
91
|
-
await self.user_repository.remove_all_roles(
|
87
|
+
user_data = [row.get_user_create_with_audit() for row in data]
|
88
|
+
await self.user_repository.update_bulk(user_ids, user_data)
|
89
|
+
if len(user_ids) > 0:
|
90
|
+
updated_by = user_data[0].updated_by
|
91
|
+
await self.user_repository.remove_all_roles(user_ids)
|
92
92
|
await self.user_repository.add_roles(
|
93
|
-
data={
|
93
|
+
data={user_id: role_ids[i] for i, user_id in enumerate(user_ids)},
|
94
94
|
updated_by=updated_by,
|
95
95
|
)
|
96
|
-
return await self.user_repository.get_by_ids(
|
96
|
+
return await self.user_repository.get_by_ids(user_ids)
|
97
97
|
|
98
98
|
@BaseService.route(
|
99
99
|
"/api/v1/users/{user_id}",
|
@@ -103,19 +103,27 @@ class UserService(BaseService):
|
|
103
103
|
async def update_user(
|
104
104
|
self, user_id: str, data: UserUpdateWithRolesAndAudit
|
105
105
|
) -> UserResponse:
|
106
|
-
|
107
|
-
|
106
|
+
role_ids = data.get_role_ids()
|
107
|
+
user_data = data.get_user_update_with_audit()
|
108
|
+
await self.user_repository.update(user_id, user_data)
|
109
|
+
await self.user_repository.remove_all_roles([user_id])
|
110
|
+
await self.user_repository.add_roles(
|
111
|
+
data={user_id: role_ids}, created_by=user_data.updated_by
|
112
|
+
)
|
113
|
+
return await self.user_repository.get_by_id(user_id)
|
108
114
|
|
109
115
|
@BaseService.route(
|
110
|
-
"/api/v1/users/
|
116
|
+
"/api/v1/users/bulk",
|
111
117
|
methods=["delete"],
|
112
118
|
response_model=UserResponse,
|
113
119
|
)
|
114
120
|
async def delete_user_bulk(
|
115
121
|
self, user_ids: list[str], deleted_by: str
|
116
122
|
) -> UserResponse:
|
117
|
-
|
118
|
-
|
123
|
+
roles = await self.user_repository.get_by_ids(user_ids)
|
124
|
+
await self.user_repository.delete_bulk(user_ids)
|
125
|
+
await self.user_repository.remove_all_roles(user_ids)
|
126
|
+
return roles
|
119
127
|
|
120
128
|
@BaseService.route(
|
121
129
|
"/api/v1/users/{user_id}",
|
@@ -123,5 +131,7 @@ class UserService(BaseService):
|
|
123
131
|
response_model=UserResponse,
|
124
132
|
)
|
125
133
|
async def delete_user(self, user_id: str, deleted_by: str) -> UserResponse:
|
126
|
-
user = await self.user_repository.
|
127
|
-
|
134
|
+
user = await self.user_repository.get_by_id(user_id)
|
135
|
+
await self.user_repository.delete(user_id)
|
136
|
+
await self.user_repository.remove_all_roles([user_id])
|
137
|
+
return user
|
zrb/builtin/setup/tmux/tmux.py
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
import os
|
2
|
+
|
3
|
+
from zrb.builtin.group import setup_group
|
4
|
+
from zrb.builtin.setup.common_input import package_manager_input, use_sudo_input
|
5
|
+
from zrb.builtin.setup.zsh.zsh_helper import get_install_zsh_cmd
|
6
|
+
from zrb.context.any_context import AnyContext
|
7
|
+
from zrb.input.str_input import StrInput
|
8
|
+
from zrb.task.cmd_task import CmdTask
|
9
|
+
from zrb.task.make_task import make_task
|
10
|
+
from zrb.util.file import read_file, write_file
|
11
|
+
|
12
|
+
install_zsh = CmdTask(
|
13
|
+
name="install-zsh",
|
14
|
+
input=[package_manager_input, use_sudo_input],
|
15
|
+
cmd=get_install_zsh_cmd,
|
16
|
+
)
|
17
|
+
|
18
|
+
install_omz = CmdTask(
|
19
|
+
name="install-omz",
|
20
|
+
cmd='sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"', # noqa
|
21
|
+
upstream=install_zsh,
|
22
|
+
)
|
23
|
+
|
24
|
+
install_zinit = CmdTask(
|
25
|
+
name="install-zinit",
|
26
|
+
cmd='bash -c "$(curl --fail --show-error --silent --location https://raw.githubusercontent.com/zdharma-continuum/zinit/HEAD/scripts/install.sh)"', # noqa
|
27
|
+
upstream=install_zsh,
|
28
|
+
)
|
29
|
+
|
30
|
+
|
31
|
+
@make_task(
|
32
|
+
name="setup-zsh",
|
33
|
+
input=StrInput(
|
34
|
+
name="zsh-config",
|
35
|
+
description="zsh config file",
|
36
|
+
prompt="zsh config file",
|
37
|
+
default_str="~/.zshrc",
|
38
|
+
),
|
39
|
+
upstream=[install_omz, install_zinit],
|
40
|
+
description="💻 Setup `zsh`.",
|
41
|
+
group=setup_group,
|
42
|
+
alias="zsh",
|
43
|
+
)
|
44
|
+
def setup_zsh(ctx: AnyContext):
|
45
|
+
zsh_config = read_file(os.path.join(os.path.dirname(__file__), "zsh_config.sh"))
|
46
|
+
zsh_config_file = os.path.expanduser(ctx.input["zsh-config"])
|
47
|
+
# Make sure config file exists
|
48
|
+
if not os.path.isfile(zsh_config_file):
|
49
|
+
write_file(zsh_config_file, "")
|
50
|
+
content = read_file(zsh_config_file)
|
51
|
+
if zsh_config in content:
|
52
|
+
return
|
53
|
+
# Write config
|
54
|
+
write_file(zsh_config_file, [content, zsh_config, ""])
|
55
|
+
ctx.print("Setup complete, restart your terminal to continue")
|
@@ -0,0 +1,133 @@
|
|
1
|
+
# If you come from bash you might have to change your $PATH.
|
2
|
+
# export PATH=$HOME/bin:/usr/local/bin:$PATH
|
3
|
+
|
4
|
+
# Path to your oh-my-zsh installation.
|
5
|
+
export ZSH="$HOME/.oh-my-zsh"
|
6
|
+
|
7
|
+
# Set name of the theme to load --- if set to "random", it will
|
8
|
+
# load a random theme each time oh-my-zsh is loaded, in which case,
|
9
|
+
# to know which specific one was loaded, run: echo $RANDOM_THEME
|
10
|
+
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
|
11
|
+
ZSH_THEME="candy"
|
12
|
+
|
13
|
+
# Set list of themes to pick from when loading at random
|
14
|
+
# Setting this variable when ZSH_THEME=random will cause zsh to load
|
15
|
+
# a theme from this variable instead of looking in $ZSH/themes/
|
16
|
+
# If set to an empty array, this variable will have no effect.
|
17
|
+
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
|
18
|
+
|
19
|
+
# Uncomment the following line to use case-sensitive completion.
|
20
|
+
# CASE_SENSITIVE="true"
|
21
|
+
|
22
|
+
# Uncomment the following line to use hyphen-insensitive completion.
|
23
|
+
# Case-sensitive completion must be off. _ and - will be interchangeable.
|
24
|
+
# HYPHEN_INSENSITIVE="true"
|
25
|
+
|
26
|
+
# Uncomment one of the following lines to change the auto-update behavior
|
27
|
+
# zstyle ':omz:update' mode disabled # disable automatic updates
|
28
|
+
# zstyle ':omz:update' mode auto # update automatically without asking
|
29
|
+
# zstyle ':omz:update' mode reminder # just remind me to update when it's time
|
30
|
+
|
31
|
+
# Uncomment the following line to change how often to auto-update (in days).
|
32
|
+
# zstyle ':omz:update' frequency 13
|
33
|
+
|
34
|
+
# Uncomment the following line if pasting URLs and other text is messed up.
|
35
|
+
# DISABLE_MAGIC_FUNCTIONS="true"
|
36
|
+
|
37
|
+
# Uncomment the following line to disable colors in ls.
|
38
|
+
# DISABLE_LS_COLORS="true"
|
39
|
+
|
40
|
+
# Uncomment the following line to disable auto-setting terminal title.
|
41
|
+
# DISABLE_AUTO_TITLE="true"
|
42
|
+
|
43
|
+
# Uncomment the following line to enable command auto-correction.
|
44
|
+
# ENABLE_CORRECTION="true"
|
45
|
+
|
46
|
+
# Uncomment the following line to display red dots whilst waiting for completion.
|
47
|
+
# You can also set it to another string to have that shown instead of the default red dots.
|
48
|
+
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
|
49
|
+
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
|
50
|
+
# COMPLETION_WAITING_DOTS="true"
|
51
|
+
|
52
|
+
# Uncomment the following line if you want to disable marking untracked files
|
53
|
+
# under VCS as dirty. This makes repository status check for large repositories
|
54
|
+
# much, much faster.
|
55
|
+
# DISABLE_UNTRACKED_FILES_DIRTY="true"
|
56
|
+
|
57
|
+
# Uncomment the following line if you want to change the command execution time
|
58
|
+
# stamp shown in the history command output.
|
59
|
+
# You can set one of the optional three formats:
|
60
|
+
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
|
61
|
+
# or set a custom format using the strftime function format specifications,
|
62
|
+
# see 'man strftime' for details.
|
63
|
+
# HIST_STAMPS="mm/dd/yyyy"
|
64
|
+
|
65
|
+
# Would you like to use another custom folder than $ZSH/custom?
|
66
|
+
# ZSH_CUSTOM=/path/to/new-custom-folder
|
67
|
+
|
68
|
+
# Which plugins would you like to load?
|
69
|
+
# Standard plugins can be found in $ZSH/plugins/
|
70
|
+
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
|
71
|
+
# Example format: plugins=(rails git textmate ruby lighthouse)
|
72
|
+
# Add wisely, as too many plugins slow down shell startup.
|
73
|
+
plugins=(
|
74
|
+
git
|
75
|
+
kubectl
|
76
|
+
)
|
77
|
+
|
78
|
+
source $ZSH/oh-my-zsh.sh
|
79
|
+
|
80
|
+
# User configuration
|
81
|
+
|
82
|
+
# export MANPATH="/usr/local/man:$MANPATH"
|
83
|
+
|
84
|
+
# You may need to manually set your language environment
|
85
|
+
# export LANG=en_US.UTF-8
|
86
|
+
|
87
|
+
# Preferred editor for local and remote sessions
|
88
|
+
# if [[ -n $SSH_CONNECTION ]]; then
|
89
|
+
# export EDITOR='vim'
|
90
|
+
# else
|
91
|
+
# export EDITOR='mvim'
|
92
|
+
# fi
|
93
|
+
|
94
|
+
# Compilation flags
|
95
|
+
# export ARCHFLAGS="-arch x86_64"
|
96
|
+
|
97
|
+
# Set personal aliases, overriding those provided by oh-my-zsh libs,
|
98
|
+
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
|
99
|
+
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
|
100
|
+
# For a full list of active aliases, run `alias`.
|
101
|
+
#
|
102
|
+
# Example aliases
|
103
|
+
# alias zshconfig="mate ~/.zshrc"
|
104
|
+
# alias ohmyzsh="mate ~/.oh-my-zsh"
|
105
|
+
|
106
|
+
source "$HOME/.local/share/zinit/zinit.git/zinit.zsh"
|
107
|
+
autoload -Uz _zinit
|
108
|
+
(( ${+_comps} )) && _comps[zinit]=_zinit
|
109
|
+
|
110
|
+
# Load a few important annexes, without Turbo
|
111
|
+
# (this is currently required for annexes)
|
112
|
+
zinit light-mode for \
|
113
|
+
zdharma-continuum/zinit-annex-as-monitor \
|
114
|
+
zdharma-continuum/zinit-annex-bin-gem-node \
|
115
|
+
zdharma-continuum/zinit-annex-patch-dl \
|
116
|
+
zdharma-continuum/zinit-annex-rust
|
117
|
+
### End of Zinit's installer chunk
|
118
|
+
|
119
|
+
# Plugin history-search-multi-word loaded with investigating.
|
120
|
+
zinit load zdharma-continuum/history-search-multi-word
|
121
|
+
|
122
|
+
# Two regular plugins loaded without investigating.
|
123
|
+
zinit light zsh-users/zsh-autosuggestions
|
124
|
+
zinit light zdharma-continuum/fast-syntax-highlighting
|
125
|
+
|
126
|
+
zinit light jonmosco/kube-ps1
|
127
|
+
KUBE_PS1_SYMBOL_ENABLE=false
|
128
|
+
KUBE_PS1_PREFIX=''
|
129
|
+
KUBE_PS1_SUFFIX=' '
|
130
|
+
KUBE_PS1_CTX_COLOR=cyan
|
131
|
+
PROMPT='$(kube_ps1)'$PROMPT
|
132
|
+
|
133
|
+
export COLORTERM=truecolor
|