Skip to content

Commit

Permalink
Merge pull request #1386 from longguikeji/feature-402
Browse files Browse the repository at this point in the history
解决不匹配租户的问题,增加了一个取消注册字段注册方法,创建分组,修改分组更换了方式
  • Loading branch information
hanbinloop committed Nov 2, 2022
2 parents 0f322a5 + 926ce84 commit 17a4e47
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
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

0 comments on commit 17a4e47

Please sign in to comment.