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

minor: 草稿功能支持 #7153

Merged
merged 3 commits into from
Nov 14, 2023
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
18 changes: 18 additions & 0 deletions bksops_iam_migrations/migrations/0016_bk_sops_202311031103.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-

from django.db import migrations
from iam.contrib.iam_migration.migrator import IAMMigrator


def forward_func(apps, schema_editor):
migrator = IAMMigrator(Migration.migration_json)
migrator.migrate()


class Migration(migrations.Migration):
migration_json = "16_add_publish_draft_actions.json"

dependencies = [("bksops_iam_migrations", "0015_bk_sops_202212122120")]

operations = [migrations.RunPython(forward_func)]
1 change: 1 addition & 0 deletions config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ def monitor_report_config():

from bk_monitor_report import MonitorReporter # noqa
from bk_monitor_report.contrib.celery import MonitorReportStep # noqa

from blueapps.core.celery import celery_app # noqa

reporter = MonitorReporter(
Expand Down
20 changes: 10 additions & 10 deletions gcloud/apigw/views/create_and_start_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,14 @@

import env
from gcloud import err_code
from gcloud.apigw.decorators import (
mark_request_whether_is_trust,
project_inject,
return_json_response,
)
from gcloud.apigw.decorators import mark_request_whether_is_trust, project_inject, return_json_response
from gcloud.apigw.schemas import APIGW_CREATE_AND_START_TASK_PARAMS
from gcloud.apigw.validators import CreateTaskValidator
from gcloud.apigw.views.utils import logger
from gcloud.common_template.models import CommonTemplate
from gcloud.conf import settings
from gcloud.constants import BUSINESS, COMMON, TaskCreateMethod
from gcloud.contrib.operate_record.constants import (
OperateSource,
OperateType,
RecordType,
)
from gcloud.contrib.operate_record.constants import OperateSource, OperateType, RecordType
from gcloud.contrib.operate_record.decorators import record_operation
from gcloud.core.models import EngineConfig
from gcloud.iam_auth.intercept import iam_intercept
Expand Down Expand Up @@ -102,6 +94,14 @@ def create_and_start_task(request, template_id, project_id):
}
return result

if not tmpl.published:
result = {
"result": False,
"message": "the template is not published",
"code": err_code.CONTENT_NOT_EXIST.code,
}
return result

# 检查app_code是否存在
app_code = getattr(request.app, settings.APIGW_MANAGER_APP_CODE_KEY)
if not app_code:
Expand Down
27 changes: 19 additions & 8 deletions gcloud/apigw/views/create_clocked_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,23 @@
"""

import ujson as json
from apigw_manager.apigw.decorators import apigw_require
from blueapps.account.decorators import login_exempt
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
from rest_framework.exceptions import ValidationError

from blueapps.account.decorators import login_exempt
from gcloud import err_code
from gcloud.apigw.decorators import mark_request_whether_is_trust, return_json_response
from gcloud.apigw.decorators import project_inject
from gcloud.apigw.decorators import mark_request_whether_is_trust, project_inject, return_json_response
from gcloud.apigw.validators import CreateTaskValidator
from gcloud.apigw.views.utils import logger
from gcloud.clocked_task.models import ClockedTask
from gcloud.clocked_task.serializer import ClockedTaskSerializer
from gcloud.constants import PROJECT
from gcloud.iam_auth.intercept import iam_intercept
from gcloud.iam_auth.view_interceptors.apigw.create_clocked_task import CreateClockedTaskInterceptor
from gcloud.tasktmpl3.models import TaskTemplate
from gcloud.apigw.views.utils import logger
from gcloud.apigw.validators import CreateTaskValidator
from gcloud.utils.decorators import request_validate
from gcloud.iam_auth.intercept import iam_intercept
from apigw_manager.apigw.decorators import apigw_require


@login_exempt
Expand Down Expand Up @@ -59,7 +58,19 @@ def create_clocked_task(request, template_id, project_id):
result = {
"result": False,
"message": "template[id={template_id}] of project[project_id={project_id} , biz_id{biz_id}] "
"does not exist".format(template_id=template_id, project_id=project.id, biz_id=project.bk_biz_id,),
"does not exist".format(
template_id=template_id,
project_id=project.id,
biz_id=project.bk_biz_id,
),
"code": err_code.CONTENT_NOT_EXIST.code,
}
return result

if not template.published:
result = {
"result": False,
"message": "the template is not published",
"code": err_code.CONTENT_NOT_EXIST.code,
}
return result
Expand Down
29 changes: 17 additions & 12 deletions gcloud/apigw/views/create_periodic_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,26 @@

import jsonschema
import ujson as json
from apigw_manager.apigw.decorators import apigw_require
from blueapps.account.decorators import login_exempt
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST

import env
from blueapps.account.decorators import login_exempt
from gcloud import err_code
from gcloud.apigw.decorators import mark_request_whether_is_trust, return_json_response
from gcloud.apigw.decorators import project_inject
from gcloud.apigw.decorators import mark_request_whether_is_trust, project_inject, return_json_response
from gcloud.apigw.schemas import APIGW_CREATE_PERIODIC_TASK_PARAMS
from gcloud.apigw.validators import CreatePriodicTaskValidator
from gcloud.apigw.views.utils import info_data_from_period_task, logger
from gcloud.common_template.models import CommonTemplate
from gcloud.template_base.utils import replace_template_id
from gcloud.constants import PROJECT
from gcloud.constants import NON_COMMON_TEMPLATE_TYPES, PROJECT
from gcloud.core.models import ProjectConfig
from gcloud.iam_auth.intercept import iam_intercept
from gcloud.iam_auth.view_interceptors.apigw import CreatePeriodicTaskInterceptor
from gcloud.periodictask.models import PeriodicTask
from gcloud.constants import NON_COMMON_TEMPLATE_TYPES
from gcloud.tasktmpl3.models import TaskTemplate
from gcloud.apigw.views.utils import logger, info_data_from_period_task
from gcloud.apigw.validators import CreatePriodicTaskValidator
from gcloud.template_base.utils import replace_template_id
from gcloud.utils.decorators import request_validate
from gcloud.iam_auth.intercept import iam_intercept
from gcloud.iam_auth.view_interceptors.apigw import CreatePeriodicTaskInterceptor
from apigw_manager.apigw.decorators import apigw_require

from pipeline_web.preview_base import PipelineTemplateWebPreviewer


Expand Down Expand Up @@ -93,6 +90,14 @@ def create_periodic_task(request, template_id, project_id):
}
return result

if not template.published:
result = {
"result": False,
"message": "the template is not published",
"code": err_code.CONTENT_NOT_EXIST.code,
}
return result

params.setdefault("constants", {})
params.setdefault("exclude_task_nodes_id", [])
try:
Expand Down
26 changes: 11 additions & 15 deletions gcloud/apigw/views/create_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,20 @@
from pipeline.exceptions import PipelineException

from gcloud import err_code
from gcloud.apigw.decorators import (
mark_request_whether_is_trust,
project_inject,
return_json_response,
)
from gcloud.apigw.decorators import mark_request_whether_is_trust, project_inject, return_json_response
from gcloud.apigw.schemas import APIGW_CREATE_TASK_PARAMS
from gcloud.apigw.validators import CreateTaskValidator
from gcloud.apigw.views.utils import logger
from gcloud.common_template.models import CommonTemplate
from gcloud.conf import settings
from gcloud.constants import NON_COMMON_TEMPLATE_TYPES, PROJECT, TaskCreateMethod
from gcloud.contrib.operate_record.constants import (
OperateSource,
OperateType,
RecordType,
)
from gcloud.contrib.operate_record.constants import OperateSource, OperateType, RecordType
from gcloud.contrib.operate_record.decorators import record_operation
from gcloud.core.models import EngineConfig
from gcloud.iam_auth.intercept import iam_intercept
from gcloud.iam_auth.view_interceptors.apigw import CreateTaskInterceptor
from gcloud.taskflow3.domains.auto_retry import AutoRetryNodeStrategyCreator
from gcloud.taskflow3.models import (
TaskCallBackRecord,
TaskFlowInstance,
TimeoutNodeConfig,
)
from gcloud.taskflow3.models import TaskCallBackRecord, TaskFlowInstance, TimeoutNodeConfig
from gcloud.tasktmpl3.models import TaskTemplate
from gcloud.utils.decorators import request_validate
from gcloud.utils.strings import standardize_pipeline_node_name
Expand Down Expand Up @@ -128,6 +116,14 @@ def create_task(request, template_id, project_id):
}
return result

if not tmpl.published:
result = {
"result": False,
"message": "the template is not published",
"code": err_code.CONTENT_NOT_EXIST.code,
}
return result

app_code = getattr(request.app, settings.APIGW_MANAGER_APP_CODE_KEY)
if not app_code:
message = "app_code cannot be empty, make sure api gateway has sent correct params"
Expand Down
10 changes: 6 additions & 4 deletions gcloud/apigw/views/get_common_template_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
"""


from apigw_manager.apigw.decorators import apigw_require
from blueapps.account.decorators import login_exempt
from django.views.decorators.http import require_GET

from blueapps.account.decorators import login_exempt
from gcloud import err_code
from gcloud.apigw.decorators import mark_request_whether_is_trust, return_json_response
from gcloud.common_template.models import CommonTemplate
from gcloud.apigw.views.utils import format_template_data
from gcloud.common_template.models import CommonTemplate
from gcloud.iam_auth.intercept import iam_intercept
from gcloud.iam_auth.view_interceptors.apigw import CommonFlowViewInterceptor
from apigw_manager.apigw.decorators import apigw_require


@login_exempt
Expand All @@ -32,7 +32,9 @@
@iam_intercept(CommonFlowViewInterceptor())
def get_common_template_info(request, template_id):
try:
tmpl = CommonTemplate.objects.select_related("pipeline_template").get(id=template_id, is_deleted=False)
tmpl = CommonTemplate.objects.select_related("pipeline_template").get(
id=template_id, is_deleted=False, published=True
)
except CommonTemplate.DoesNotExist:
result = {
"result": False,
Expand Down
14 changes: 8 additions & 6 deletions gcloud/apigw/views/get_common_template_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
from apigw_manager.apigw.decorators import apigw_require
from blueapps.account.decorators import login_exempt
from django.views.decorators.http import require_GET

from blueapps.account.decorators import login_exempt
from gcloud import err_code
from gcloud.apigw.decorators import mark_request_whether_is_trust, timezone_inject, return_json_response
from gcloud.common_template.models import CommonTemplate
from gcloud.apigw.decorators import mark_request_whether_is_trust, return_json_response, timezone_inject
from gcloud.apigw.views.utils import format_template_list_data
from gcloud.common_template.models import CommonTemplate
from gcloud.iam_auth.conf import COMMON_FLOW_ACTIONS
from gcloud.iam_auth.utils import get_common_flow_allowed_actions_for_user
from apigw_manager.apigw.decorators import apigw_require


@login_exempt
Expand All @@ -29,11 +29,13 @@
@mark_request_whether_is_trust
@timezone_inject
def get_common_template_list(request):
templates = CommonTemplate.objects.select_related("pipeline_template").filter(is_deleted=False)
templates = CommonTemplate.objects.select_related("pipeline_template").filter(is_deleted=False, published=True)
templates_data, common_templates_id_list = format_template_list_data(templates, return_id_list=True, tz=request.tz)
# 注入用户有权限的actions
common_templates_allowed_actions = get_common_flow_allowed_actions_for_user(
request.user.username, COMMON_FLOW_ACTIONS, common_templates_id_list,
request.user.username,
COMMON_FLOW_ACTIONS,
common_templates_id_list,
)
for template in templates_data:
template_id = template["id"]
Expand Down
16 changes: 7 additions & 9 deletions gcloud/apigw/views/get_template_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,18 @@
"""


from apigw_manager.apigw.decorators import apigw_require
from blueapps.account.decorators import login_exempt
from django.views.decorators.http import require_GET

from blueapps.account.decorators import login_exempt
from gcloud import err_code
from gcloud.apigw.decorators import mark_request_whether_is_trust, return_json_response
from gcloud.apigw.decorators import project_inject
from gcloud.common_template.models import CommonTemplate
from gcloud.constants import PROJECT
from gcloud.constants import NON_COMMON_TEMPLATE_TYPES
from gcloud.tasktmpl3.models import TaskTemplate
from gcloud.apigw.decorators import mark_request_whether_is_trust, project_inject, return_json_response
from gcloud.apigw.views.utils import format_template_data
from gcloud.common_template.models import CommonTemplate
from gcloud.constants import NON_COMMON_TEMPLATE_TYPES, PROJECT
from gcloud.iam_auth.intercept import iam_intercept
from gcloud.iam_auth.view_interceptors.apigw import GetTemplateInfoInterceptor
from apigw_manager.apigw.decorators import apigw_require
from gcloud.tasktmpl3.models import TaskTemplate


@login_exempt
Expand All @@ -41,7 +39,7 @@ def get_template_info(request, template_id, project_id):
if template_source in NON_COMMON_TEMPLATE_TYPES:
try:
tmpl = TaskTemplate.objects.select_related("pipeline_template").get(
id=template_id, project_id=project.id, is_deleted=False
id=template_id, project_id=project.id, is_deleted=False, published=True
)
except TaskTemplate.DoesNotExist:
result = {
Expand Down
18 changes: 8 additions & 10 deletions gcloud/apigw/views/get_template_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,20 @@
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
from apigw_manager.apigw.decorators import apigw_require
from blueapps.account.decorators import login_exempt
from django.views.decorators.http import require_GET

from blueapps.account.decorators import login_exempt
from gcloud import err_code
from gcloud.apigw.decorators import mark_request_whether_is_trust, timezone_inject, return_json_response
from gcloud.apigw.decorators import project_inject
from gcloud.apigw.decorators import mark_request_whether_is_trust, project_inject, return_json_response, timezone_inject
from gcloud.apigw.views.utils import format_template_list_data, logger
from gcloud.common_template.models import CommonTemplate
from gcloud.constants import PROJECT
from gcloud.constants import NON_COMMON_TEMPLATE_TYPES
from gcloud.tasktmpl3.models import TaskTemplate
from gcloud.apigw.views.utils import logger, format_template_list_data
from gcloud.iam_auth.intercept import iam_intercept
from gcloud.constants import NON_COMMON_TEMPLATE_TYPES, PROJECT
from gcloud.iam_auth.conf import FLOW_ACTIONS
from gcloud.iam_auth.intercept import iam_intercept
from gcloud.iam_auth.utils import get_flow_allowed_actions_for_user
from gcloud.iam_auth.view_interceptors.apigw import ProjectViewInterceptor
from apigw_manager.apigw.decorators import apigw_require
from gcloud.tasktmpl3.models import TaskTemplate


@login_exempt
Expand All @@ -48,7 +46,7 @@ def get_template_list(request, project_id):
id_in = None
logger.exception("[API] id_in[{}] resolve fail, ignore.".format(id_in))

filter_kwargs = dict(is_deleted=False)
filter_kwargs = dict(is_deleted=False, published=True)
if id_in:
filter_kwargs["id__in"] = id_in
if name_keyword and name_keyword != "":
Expand Down
Loading