-
Notifications
You must be signed in to change notification settings - Fork 95
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
feat: 添加ITSM上下文配置功能 #1452
Closed
Closed
feat: 添加ITSM上下文配置功能 #1452
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django.contrib import admin | ||
from .models import Context | ||
|
||
|
||
class ContextAdmin(admin.ModelAdmin): | ||
list_display = ("id", "key", "value", "created_at", "updated_at") | ||
search_fields = ("key", "value") | ||
list_filter = ("key",) | ||
|
||
|
||
admin.site.register(Context, ContextAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class MetaConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "itsm.meta" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Generated by Django 3.2.25 on 2024-12-06 14:55 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Context", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("updated_at", models.DateTimeField(auto_now=True)), | ||
("key", models.CharField(max_length=255, unique=True)), | ||
("value", models.TextField(blank=True)), | ||
], | ||
options={ | ||
"db_table": "meta_context", | ||
}, | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from django.core.cache import cache | ||
from django.db import models | ||
from django.db.models.signals import post_save | ||
from django.dispatch import receiver | ||
|
||
|
||
class Context(models.Model): | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
updated_at = models.DateTimeField(auto_now=True) | ||
key = models.CharField(max_length=255, unique=True) | ||
value = models.TextField(blank=True) | ||
|
||
def __str__(self): | ||
return self.key | ||
|
||
class Meta: | ||
db_table = "meta_context" | ||
|
||
|
||
@receiver(post_save, sender=Context) | ||
def update_cache(sender, instance, **kwargs): | ||
cache_key = f"meta_context_{instance.key}" | ||
cache.set(cache_key, instance.value, 30) | ||
|
||
|
||
class ContextService: | ||
@staticmethod | ||
def get_context_value(key): | ||
cache_key = f"meta_context_{key}" | ||
context_value = cache.get(cache_key) | ||
if not context_value: | ||
try: | ||
context_value = Context.objects.get(key=key).value | ||
except Context.DoesNotExist: | ||
context_value = "" | ||
cache.set(cache_key, context_value, 30) | ||
return context_value | ||
|
||
@staticmethod | ||
def get_context_value_list(key): | ||
context_value = ContextService.get_context_value(key) | ||
context_value = ( | ||
[item.strip() for item in context_value.split(",")] if context_value else [] | ||
) | ||
return context_value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
from django.conf import settings | ||
from django.core.cache import cache | ||
from itsm.component.constants import PROCESS_COUNT | ||
from itsm.meta.models import ContextService | ||
from itsm.ticket.models import Ticket, Status | ||
from pipeline.component_framework.component import Component | ||
|
||
|
@@ -61,7 +62,14 @@ def execute(self, data, parent_data): | |
) | ||
is_multi = ticket.flow.get_state(state_id)["is_multi"] | ||
user_count = str(self.get_user_count(ticket_id, state_id)) if is_multi else "1" | ||
ticket.create_moa_ticket(state_id) | ||
|
||
# 如果service_id不在service_approval_blacklist中,则创建moa单据 | ||
context_service = ContextService() | ||
service_approval_blacklist = context_service.get_context_value_list( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同样由 notice filter service 处理 |
||
"service_approval_blacklist" | ||
) | ||
if str(ticket.service_id) not in service_approval_blacklist: | ||
ticket.create_moa_ticket(state_id) | ||
|
||
# 如果是普通的审批节点,则自动生成条件 | ||
if not is_multi: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
notice_receiver_filter(receivers):此方法建议转到 meta 实现,主要考虑可以优化 utils 与 ContextService 的调用依赖,最好是:utils 是基础,由 ContextService 调用 utils