Improve tasks and align page elements
This commit is contained in:
@@ -41,6 +41,7 @@ from core.models import (
|
||||
Message,
|
||||
MessageEvent,
|
||||
PatternMitigationPlan,
|
||||
ChatTaskSource,
|
||||
Person,
|
||||
PersonIdentifier,
|
||||
PlatformChatLink,
|
||||
@@ -1787,9 +1788,66 @@ def _command_options_for_channel(user, service: str, identifier: str) -> list[di
|
||||
"profile_enabled": bool(profile.enabled),
|
||||
}
|
||||
)
|
||||
task_announce_enabled = False
|
||||
if variants:
|
||||
source = (
|
||||
ChatTaskSource.objects.filter(
|
||||
user=user,
|
||||
service=service_key,
|
||||
channel_identifier__in=list(variants),
|
||||
enabled=True,
|
||||
)
|
||||
.order_by("-updated_at")
|
||||
.first()
|
||||
)
|
||||
settings_row = dict(getattr(source, "settings", {}) or {}) if source else {}
|
||||
task_announce_enabled = str(settings_row.get("announce_task_id", "")).strip().lower() in {
|
||||
"1",
|
||||
"true",
|
||||
"yes",
|
||||
"on",
|
||||
}
|
||||
options.append(
|
||||
{
|
||||
"slug": "task_announce",
|
||||
"name": "Announce Task IDs",
|
||||
"trigger_token": "",
|
||||
"enabled_here": bool(task_announce_enabled),
|
||||
"profile_enabled": True,
|
||||
}
|
||||
)
|
||||
return options
|
||||
|
||||
|
||||
def _toggle_task_announce_for_channel(
|
||||
*,
|
||||
user,
|
||||
service: str,
|
||||
identifier: str,
|
||||
enabled: bool,
|
||||
) -> tuple[bool, str]:
|
||||
service_key = _default_service(service)
|
||||
canonical_identifier = _canonical_command_channel_identifier(service_key, identifier)
|
||||
if not canonical_identifier:
|
||||
return (False, "missing_identifier")
|
||||
variants = _command_channel_identifier_variants(service_key, canonical_identifier)
|
||||
rows = list(
|
||||
ChatTaskSource.objects.filter(
|
||||
user=user,
|
||||
service=service_key,
|
||||
channel_identifier__in=list(variants),
|
||||
).order_by("-updated_at")
|
||||
)
|
||||
if not rows:
|
||||
return (False, "task_source_mapping_missing")
|
||||
for row in rows:
|
||||
settings_row = dict(row.settings or {})
|
||||
settings_row["announce_task_id"] = bool(enabled)
|
||||
row.settings = settings_row
|
||||
row.save(update_fields=["settings", "updated_at"])
|
||||
return (True, "")
|
||||
|
||||
|
||||
def _compose_urls(service, identifier, person_id):
|
||||
service_key = _default_service(service)
|
||||
identifier_value = str(identifier or "").strip()
|
||||
@@ -3314,13 +3372,21 @@ class ComposeToggleCommand(LoginRequiredMixin, View):
|
||||
"yes",
|
||||
"on",
|
||||
}
|
||||
ok, error = _toggle_command_for_channel(
|
||||
user=request.user,
|
||||
service=service,
|
||||
identifier=channel_identifier,
|
||||
slug=slug,
|
||||
enabled=enabled,
|
||||
)
|
||||
if slug == "task_announce":
|
||||
ok, error = _toggle_task_announce_for_channel(
|
||||
user=request.user,
|
||||
service=service,
|
||||
identifier=channel_identifier,
|
||||
enabled=enabled,
|
||||
)
|
||||
else:
|
||||
ok, error = _toggle_command_for_channel(
|
||||
user=request.user,
|
||||
service=service,
|
||||
identifier=channel_identifier,
|
||||
slug=slug,
|
||||
enabled=enabled,
|
||||
)
|
||||
if not ok:
|
||||
return JsonResponse(
|
||||
{
|
||||
@@ -3347,7 +3413,11 @@ class ComposeToggleCommand(LoginRequiredMixin, View):
|
||||
"slug": slug,
|
||||
"enabled": bool(enabled),
|
||||
"command_options": command_options,
|
||||
"settings_url": reverse("command_routing"),
|
||||
"settings_url": (
|
||||
f"{reverse('tasks_settings')}?{urlencode({'service': service, 'identifier': channel_identifier})}"
|
||||
if slug == "task_announce"
|
||||
else reverse("command_routing")
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user