Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解决不匹配租户的问题,增加了一个取消注册字段注册方法,创建分组,修改分组更换了方式 #1386

Merged
merged 2 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/v1/views/tenant_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def toggle_tenant_extension_status(request, tenant_id: str, id: str):
""" 租户插件列表
"""
extension= ExtensionModel.active_objects.get(id=id)
tenant_extension = TenantExtension.valid_objects.get(extension=extension)
tenant_extension = TenantExtension.valid_objects.get(tenant=request.tenant, extension=extension)
tenant_extension.is_active = True if tenant_extension.is_active is False else False
tenant_extension.save()
return ErrorDict(ErrorCode.OK)
Expand Down
21 changes: 17 additions & 4 deletions api/v1/views/user_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,20 @@ def create_group(request, tenant_id: str, data: UserGroupCreateIn):
'''
分组创建
'''
data_dict = data.dict()
group = UserGroup()

group.tenant_id = tenant_id
group.name = data.name
parent = data.dict().get("parent",None)
group.name = data_dict.pop('name', '')
parent = data_dict.pop("parent",None)
parent_id = parent.get("id",None) if parent else None
group.parent = get_object_or_404(UserGroup, id=parent_id) if parent_id else None
group.save()
# 需要注意额外的字段
for key,value in data_dict.items():
if value:
setattr(group,key,value)
group.save()
# 分发事件开始
result = dispatch_event(
Event(
Expand Down Expand Up @@ -107,15 +114,21 @@ def update_group(request, tenant_id: str, id: str, data: UserGroupUpdateIn):
'''
修改分组
'''
data_dict = data.dict()
group = get_object_or_404(UserGroup.active_objects, id=id)
group.name = data.dict().get("name",None)
parent = data.dict().get("parent",None)
group.name = data_dict.pop("name",None)
parent = data_dict.pop("parent",None)
parent_id = parent.get("id",None) if parent else None
group.parent = get_object_or_404(UserGroup.active_objects, id=parent_id) if parent_id else None

if group.parent == group:
return ErrorDict(ErrorCode.USER_GROUP_PARENT_CANT_BE_ITSELF)
group.save()
# 需要注意额外的字段
for key,value in data_dict.items():
if value:
setattr(group,key,value)
group.save()
# 分发事件开始
dispatch_event(Event(tag=UPDATE_GROUP, tenant=request.tenant,
request=request, data=group))
Expand Down
19 changes: 19 additions & 0 deletions arkid/core/extension/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,25 @@ def register_extend_api(self, *api_schema_cls, **field_definitions):
for schema_cls in api_schema_cls:
core_api.add_fields(schema_cls, **field_definitions)
self.extend_apis.append((schema_cls, list(field_definitions.keys())))

def unregister_extend_api(self, *api_schema_cls, field_keys=[]):
"""移除扩展内核API
Args:
api_schema_cls (class): API Schema Class
field_keys (list): 需要移除的字段名称,example:field_keys=['nickname','mobile'])
"""
# 遍历需要移除的schema
for schema_cls in api_schema_cls:
# 遍历所有的extend_apis
for api_schema_cls, fields in self.extend_apis:
if schema_cls == schema_cls:
# 遍历需要移除的keys
for key in field_keys:
if key in fields:
# 从self.extend_apis移除
fields.remove(key)
# 从core_api移除
core_api.remove_fields(api_schema_cls, key)

def register_front_routers(self, router, primary:core_routers.FrontRouter=None):
"""注册前端路由
Expand Down