diff --git a/cmdb-api/api/commands/click_common_setting.py b/cmdb-api/api/commands/click_common_setting.py index ffd454f4..775548f3 100644 --- a/cmdb-api/api/commands/click_common_setting.py +++ b/cmdb-api/api/commands/click_common_setting.py @@ -216,10 +216,9 @@ def check_app(self, app_name): ) try: app = acl.validate_app() - if app: - return acl - - acl.create_app(payload) + if not app: + acl.create_app(payload) + return acl except Exception as e: current_app.logger.error(e) if '不存在' in str(e): diff --git a/cmdb-api/api/lib/common_setting/acl.py b/cmdb-api/api/lib/common_setting/acl.py index 3cdf6dc3..f705377f 100644 --- a/cmdb-api/api/lib/common_setting/acl.py +++ b/cmdb-api/api/lib/common_setting/acl.py @@ -1,13 +1,13 @@ # -*- coding:utf-8 -*- -from flask import abort from flask import current_app from api.lib.common_setting.resp_format import ErrFormat +from api.lib.perm.acl.app import AppCRUD from api.lib.perm.acl.cache import RoleCache, AppCache +from api.lib.perm.acl.permission import PermissionCRUD +from api.lib.perm.acl.resource import ResourceTypeCRUD, ResourceCRUD from api.lib.perm.acl.role import RoleCRUD, RoleRelationCRUD from api.lib.perm.acl.user import UserCRUD -from api.lib.perm.acl.resource import ResourceTypeCRUD, ResourceCRUD -from api.lib.perm.acl.permission import PermissionCRUD class ACLManager(object): @@ -133,3 +133,9 @@ def get_resource_by_type(self, q, u, rt_id, page=1, page_size=999999): def grant_resource(self, rid, resource_id, perms): PermissionCRUD.grant(rid, perms, resource_id=resource_id, group_id=None) + + @staticmethod + def create_app(payload): + rt = AppCRUD.add(**payload) + + return rt.to_dict()