Skip to content

Commit

Permalink
feat: 调整常用操作 --story=119850967
Browse files Browse the repository at this point in the history
  • Loading branch information
benero committed Sep 30, 2024
1 parent c039931 commit 5adcea4
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 128 deletions.
69 changes: 69 additions & 0 deletions itsm/auth_iam/migrations/0003_update_common_actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*-
"""
Tencent is pleased to support the open source community by making BK-ITSM 蓝鲸流程服务 available.
Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
BK-ITSM 蓝鲸流程服务 is licensed under the MIT License.
License for BK-ITSM 蓝鲸流程服务:
--------------------------------------------------------------------
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""


import os
import json
import codecs

from django.db import migrations


def add_common_actions(apps, schema_editor):
"""
添加常用的操作动作
"""

from iam.contrib.iam_migration.utils import do_migrate
from iam.contrib.iam_migration import exceptions
from django.conf import settings

iam_host = settings.BK_IAM_INNER_HOST
app_code = settings.APP_CODE
app_secret = settings.SECRET_KEY

json_path = getattr(settings, "BK_IAM_MIGRATION_JSON_PATH", "support-files/iam/")
file_path = os.path.join(settings.BASE_DIR, json_path, "initial_common_actions.json")

with codecs.open(file_path, mode="r", encoding="utf-8") as fp:
data = json.load(fp=fp)

ok, _ = do_migrate.api_ping(iam_host)
if not ok:
raise exceptions.NetworkUnreachableError("bk iam ping error")

client = do_migrate.Client(app_code, app_secret, iam_host)

ok, message = client.batch_update_common_actions(settings.BK_IAM_SYSTEM_ID, data)
if not ok:
raise exceptions.MigrationFailError("iam migrate fail %s" % message)


class Migration(migrations.Migration):
dependencies = [
('auth_iam', '0002_insert_common_actions'),
]

operations = [migrations.RunPython(add_common_actions)]
128 changes: 0 additions & 128 deletions support-files/iam/initial.json
Original file line number Diff line number Diff line change
Expand Up @@ -2686,134 +2686,6 @@
}
]
}
},
{
"operation":"upsert_common_actions",
"data": [
{
"name": "项目管理员",
"name_en": "service_superuser",
"actions": [
{
"id": "project_view"
},
{
"id": "project_edit"
},
{
"id": "system_settings_manage"
},
{
"id": "service_create"
},
{
"id": "service_manage"
},
{
"id": "service_view"
},
{
"id": "catalog_create"
},
{
"id": "catalog_edit"
},
{
"id": "catalog_delete"
},
{
"id": "field_create"
},
{
"id": "field_view"
},
{
"id": "field_edit"
},
{
"id": "field_delete"
},
{
"id": "user_group_create"
},
{
"id": "user_group_edit"
},
{
"id": "user_group_delete"
},
{
"id": "user_group_view"
},
{
"id": "triggers_create"
},
{
"id": "triggers_view"
},
{
"id": "triggers_manage"
}
]
},
{
"name": "平台管理员",
"name_en": "system_manager",
"actions": [
{
"id": "project_create"
},
{
"id": "platform_manage_access"
},
{
"id": "public_fields_manage"
},
{
"id": "public_apis_manage"
},
{
"id": "public_task_template_manage"
},
{
"id": "global_settings_view"
},
{
"id": "global_settings_manage"
},
{
"id": "notification_view"
},
{
"id": "notification_manage"
},
{
"id": "sla_priority_view"
},
{
"id": "sla_priority_manage"
},
{
"id": "ticket_state_view"
},
{
"id": "ticket_state_manage"
}
]
},
{
"name": "统计信息查看",
"name_en": "operational_data_view",
"actions": [
{
"id": "ticket_view"
},
{
"id": "operational_data_view"
}
]
}
]
}
]
}

0 comments on commit 5adcea4

Please sign in to comment.