mass reorganization,
This commit is contained in:
parent
13644e00af
commit
7099dbae9c
|
|
@ -0,0 +1,48 @@
|
|||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16
|
||||
env:
|
||||
POSTGRES_DB: wanitil
|
||||
POSTGRES_USER: wanitil
|
||||
POSTGRES_PASSWORD: wanitilpass
|
||||
ports:
|
||||
- 5432:5432
|
||||
options: >-
|
||||
--health-cmd "pg_isready -U wanitil"
|
||||
--health-interval 5s
|
||||
--health-timeout 5s
|
||||
--health-retries 10
|
||||
env:
|
||||
ENVIRONMENT: test
|
||||
DEBUG: "False"
|
||||
SECRET_KEY: ci-only-secret-key-with-more-than-fifty-random-characters-123456789
|
||||
ALLOWED_HOSTS: localhost,127.0.0.1,testserver
|
||||
SQL_ENGINE: django.db.backends.postgresql
|
||||
SQL_DATABASE: wanitil
|
||||
SQL_USER: wanitil
|
||||
SQL_PASSWORD: wanitilpass
|
||||
SQL_HOST: 127.0.0.1
|
||||
SQL_PORT: "5432"
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.12"
|
||||
cache: pip
|
||||
- run: python -m pip install --upgrade pip
|
||||
- run: python -m pip install -e '.[dev]'
|
||||
- run: ruff check .
|
||||
- run: python manage.py makemigrations --check --dry-run
|
||||
- run: python manage.py migrate --noinput
|
||||
- run: ENVIRONMENT=production python manage.py check --deploy --fail-level WARNING
|
||||
- run: python manage.py spectacular --validate --fail-on-warn --file /tmp/schema.yaml
|
||||
- run: python manage.py test wanitil.testapi
|
||||
22
Dockerfile
22
Dockerfile
|
|
@ -2,23 +2,12 @@
|
|||
#podman image list
|
||||
#podman image rm wanitilserver
|
||||
# Stage 1: Base build stage
|
||||
FROM python:3.11.2 AS builder
|
||||
FROM python:3.12-slim AS builder
|
||||
|
||||
# Set environment variables to optimize Python
|
||||
ENV PYTHONDONTWRITEBYTECODE=1
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
ENV ENVIRONMENT=development
|
||||
ENV DEBUG=True
|
||||
ENV SECRET_KEY='5s533n3lwg80lub2xsimo0ooty94gjdj3igndfbe'
|
||||
|
||||
ENV SQL_ENGINE=django.db.backends.postgresql
|
||||
ENV SQL_DATABASE=wanitil
|
||||
ENV SQL_USER=wanitil
|
||||
ENV SQL_PASSWORD=wanitilpass
|
||||
ENV SQL_HOST=localhost
|
||||
ENV SQL_PORT=5432
|
||||
|
||||
# Create the app directory
|
||||
RUN mkdir /app
|
||||
|
||||
|
|
@ -32,13 +21,12 @@ RUN useradd -m -r appuser && \
|
|||
RUN pip install --upgrade pip
|
||||
|
||||
# Copy the requirements file first (better caching)
|
||||
COPY requirements.txt /app/
|
||||
COPY requirements.txt pyproject.toml README.md /app/
|
||||
COPY --chown=appuser:appuser . /app/
|
||||
|
||||
# Install Python dependencies
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
RUN pip install --no-cache-dir .
|
||||
|
||||
# Copy application code
|
||||
COPY --chown=appuser:appuser . /app/
|
||||
RUN chmod -R 770 /app/log
|
||||
|
||||
# copy entrypoint.sh
|
||||
|
|
@ -57,4 +45,4 @@ EXPOSE 10000
|
|||
# Start the application using Gunicorn
|
||||
#CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "3", "main.wsgi:application"]
|
||||
COPY --chown=appuser:appuser --chmod=551 ./docker-entrypoint.sh /
|
||||
ENTRYPOINT ["/docker-entrypoint.sh"]
|
||||
ENTRYPOINT ["/docker-entrypoint.sh"]
|
||||
|
|
|
|||
|
|
@ -4,11 +4,8 @@
|
|||
#echo "flush"
|
||||
#python manage.py flush --no-input
|
||||
|
||||
echo "Apply database migrations"
|
||||
python manage.py makemigrations
|
||||
|
||||
echo "Apply database migrate"
|
||||
python manage.py migrate
|
||||
python manage.py migrate --noinput
|
||||
|
||||
echo "Run init data script"
|
||||
python manage.py runscript init.init_data
|
||||
|
|
@ -17,9 +14,8 @@ python manage.py runscript init.init_data
|
|||
echo "Starting gunicorn server"
|
||||
gunicorn --bind 0.0.0.0:10000 \
|
||||
--workers 3 \
|
||||
--access-logfile log/gunicorn_access.log \
|
||||
--error-logfile log/gunicorn_error.log \
|
||||
--reload \
|
||||
--access-logfile - \
|
||||
--error-logfile - \
|
||||
--timeout 120 \
|
||||
main.wsgi:application
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,58 @@
|
|||
[
|
||||
{
|
||||
"filter_name": "id",
|
||||
"filter_type": "integer"
|
||||
},
|
||||
{
|
||||
"filter_name": "con_person__id",
|
||||
"filter_type": "integer"
|
||||
},
|
||||
{
|
||||
"filter_name": "con_person__display_name",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "type",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "purpose",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "value",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "normalized_value",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "label",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "is_primary",
|
||||
"filter_type": "boolean"
|
||||
},
|
||||
{
|
||||
"filter_name": "is_verified",
|
||||
"filter_type": "boolean"
|
||||
},
|
||||
{
|
||||
"filter_name": "verified_at",
|
||||
"filter_type": "datetime"
|
||||
},
|
||||
{
|
||||
"filter_name": "is_active",
|
||||
"filter_type": "boolean"
|
||||
},
|
||||
{
|
||||
"filter_name": "created_at",
|
||||
"filter_type": "datetime"
|
||||
},
|
||||
{
|
||||
"filter_name": "updated_at",
|
||||
"filter_type": "datetime"
|
||||
}
|
||||
]
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
[
|
||||
{
|
||||
"filter_name": "id",
|
||||
"filter_type": "integer"
|
||||
},
|
||||
{
|
||||
"filter_name": "name",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "value",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "is_owner",
|
||||
"filter_type": "boolean"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__id",
|
||||
"filter_type": "integer"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__username",
|
||||
"filter_type": "string"
|
||||
}
|
||||
]
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
[
|
||||
{
|
||||
"filter_name": "id",
|
||||
"filter_type": "integer"
|
||||
},
|
||||
{
|
||||
"filter_name": "type",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "display_name",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "is_active",
|
||||
"filter_type": "boolean"
|
||||
}
|
||||
]
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
[
|
||||
{
|
||||
"filter_name": "id",
|
||||
"filter_type": "integer"
|
||||
},
|
||||
{
|
||||
"filter_name": "name",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "value",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "phone_type",
|
||||
"filter_type": "integer"
|
||||
},
|
||||
{
|
||||
"filter_name": "is_owner",
|
||||
"filter_type": "boolean"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__id",
|
||||
"filter_type": "integer"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__username",
|
||||
"filter_type": "string"
|
||||
}
|
||||
]
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
[
|
||||
{
|
||||
"filter_name": "id",
|
||||
"filter_type": "integer"
|
||||
},
|
||||
{
|
||||
"filter_name": "name",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "value",
|
||||
"filter_type": "integer"
|
||||
},
|
||||
{
|
||||
"filter_name": "bot_name",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "is_owner",
|
||||
"filter_type": "boolean"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__id",
|
||||
"filter_type": "integer"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__username",
|
||||
"filter_type": "string"
|
||||
}
|
||||
]
|
||||
|
|
@ -56,49 +56,57 @@
|
|||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__con_phone__value",
|
||||
"filter_name": "sys_user__con_person__con_contact__type",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__con_person__con_contact__purpose",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__con_person__con_contact__value",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__con_person__con_contact__normalized_value",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__con_person__con_contact__label",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__con_person__con_contact__is_primary",
|
||||
"filter_type": "boolean"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__con_person__con_contact__is_verified",
|
||||
"filter_type": "boolean"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__con_person__con_contact__is_active",
|
||||
"filter_type": "boolean"
|
||||
},
|
||||
{
|
||||
"filter_name": "con_person__id",
|
||||
"filter_type": "integer"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__con_phone__name",
|
||||
"filter_name": "con_person__display_name",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__con_phone__phone_type",
|
||||
"filter_name": "con_contact__id",
|
||||
"filter_type": "integer"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__con_phone__is_owner",
|
||||
"filter_type": "boolean"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__con_telegram__value",
|
||||
"filter_name": "con_contact__type",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__con_telegram__bot_name",
|
||||
"filter_name": "con_contact__value",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__con_telegram__name",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__con_telegram__is_owner",
|
||||
"filter_type": "boolean"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__con_email__value",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__con_email__name",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__con_email__is_owner",
|
||||
"filter_type": "boolean"
|
||||
},
|
||||
{
|
||||
"filter_name": "house_id",
|
||||
"filter_type": "integer"
|
||||
|
|
@ -123,4 +131,4 @@
|
|||
"filter_name": "lon",
|
||||
"filter_type": "float"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
[
|
||||
{"filter_name": "id", "filter_type": "integer"},
|
||||
{"filter_name": "name", "filter_type": "string"},
|
||||
{"filter_name": "status", "filter_type": "string"},
|
||||
{"filter_name": "source", "filter_type": "string"},
|
||||
{"filter_name": "budget", "filter_type": "float"},
|
||||
{"filter_name": "need", "filter_type": "string"},
|
||||
{"filter_name": "comment", "filter_type": "string"},
|
||||
{"filter_name": "responsible__id", "filter_type": "integer"},
|
||||
{"filter_name": "responsible__name", "filter_type": "string"},
|
||||
{"filter_name": "responsible__sys_user__username", "filter_type": "string"},
|
||||
{"filter_name": "con_person__id", "filter_type": "integer"},
|
||||
{"filter_name": "con_person__display_name", "filter_type": "string"},
|
||||
{"filter_name": "con_contact__id", "filter_type": "integer"},
|
||||
{"filter_name": "con_contact__type", "filter_type": "string"},
|
||||
{"filter_name": "con_contact__purpose", "filter_type": "string"},
|
||||
{"filter_name": "con_contact__value", "filter_type": "string"},
|
||||
{"filter_name": "con_contact__normalized_value", "filter_type": "string"},
|
||||
{"filter_name": "created_at", "filter_type": "datetime"},
|
||||
{"filter_name": "updated_at", "filter_type": "datetime"}
|
||||
]
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
[
|
||||
{
|
||||
"filter_name": "id",
|
||||
"filter_type": "integer"
|
||||
},
|
||||
{
|
||||
"filter_name": "name",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "description",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__id",
|
||||
"filter_type": "integer"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__username",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "firstname",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "secondname",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "surname",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "department",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "is_leader",
|
||||
"filter_type": "boolean"
|
||||
},
|
||||
{
|
||||
"filter_name": "inc_group__id",
|
||||
"filter_type": "integer"
|
||||
},
|
||||
{
|
||||
"filter_name": "inc_group__name",
|
||||
"filter_type": "string"
|
||||
}
|
||||
]
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
[
|
||||
{
|
||||
"filter_name": "id",
|
||||
"filter_type": "integer"
|
||||
},
|
||||
{
|
||||
"filter_name": "name",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "description",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__id",
|
||||
"filter_type": "integer"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user__username",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "firstname",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "secondname",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "surname",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "department",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "is_leader",
|
||||
"filter_type": "boolean"
|
||||
}
|
||||
]
|
||||
|
|
@ -12,71 +12,59 @@
|
|||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user_info__name",
|
||||
"filter_name": "sys_employee__display_name",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "con_phone__value",
|
||||
"filter_name": "con_person__con_contact__type",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "con_person__con_contact__purpose",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "con_person__con_contact__value",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "con_person__con_contact__normalized_value",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "con_person__con_contact__label",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "con_person__con_contact__is_primary",
|
||||
"filter_type": "boolean"
|
||||
},
|
||||
{
|
||||
"filter_name": "con_person__con_contact__is_verified",
|
||||
"filter_type": "boolean"
|
||||
},
|
||||
{
|
||||
"filter_name": "con_person__con_contact__is_active",
|
||||
"filter_type": "boolean"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_employee__lang",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_employee__status",
|
||||
"filter_type": "integer"
|
||||
},
|
||||
{
|
||||
"filter_name": "con_phone__name",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "con_phone__phone_type",
|
||||
"filter_type": "integer"
|
||||
},
|
||||
{
|
||||
"filter_name": "con_phone__is_owner",
|
||||
"filter_name": "sys_employee__theme_is_light",
|
||||
"filter_type": "boolean"
|
||||
},
|
||||
{
|
||||
"filter_name": "con_telegram__value",
|
||||
"filter_name": "sys_employee__theme_color",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "con_telegram__bot_name",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "con_telegram__name",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "con_telegram__is_owner",
|
||||
"filter_type": "boolean"
|
||||
},
|
||||
{
|
||||
"filter_name": "con_email__value",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "con_email__name",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "con_email__is_owner",
|
||||
"filter_type": "boolean"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user_profile__lang",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user_profile__status",
|
||||
"filter_type": "integer"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user_profile__theme_is_light",
|
||||
"filter_type": "boolean"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user_profile__theme_color",
|
||||
"filter_type": "string"
|
||||
},
|
||||
{
|
||||
"filter_name": "sys_user_profile__timezone",
|
||||
"filter_name": "sys_employee__timezone",
|
||||
"filter_type": "integer"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ For the full list of settings and their values, see
|
|||
https://docs.djangoproject.com/en/4.0/ref/settings/
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
# BEGIN ANSIBLE MANAGED BLOCK turn on django-environ module
|
||||
import environ
|
||||
import os
|
||||
import dotenv
|
||||
from datetime import timedelta
|
||||
from pathlib import Path
|
||||
|
||||
import environ
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from rest_framework.settings import api_settings
|
||||
|
||||
# env = environ.Env(
|
||||
|
|
@ -30,11 +30,21 @@ from rest_framework.settings import api_settings
|
|||
# SQL_HOST=(str, 'localhost'),
|
||||
# SQL_PORT=(str, '5432'),
|
||||
# )
|
||||
env = environ.Env(
|
||||
DEBUG=(bool, False),
|
||||
ENVIRONMENT=(str, "development"),
|
||||
ALLOWED_HOSTS=(list, ["localhost", "127.0.0.1"]),
|
||||
)
|
||||
environ.Env.read_env()
|
||||
|
||||
DEBUG = os.getenv('DEBUG')
|
||||
SECRET_KEY = os.getenv('SECRET_KEY')
|
||||
ENVIRONMENT = os.getenv('ENVIRONMENT')
|
||||
DEBUG = env.bool("DEBUG")
|
||||
ENVIRONMENT = env("ENVIRONMENT").lower()
|
||||
SECRET_KEY = env("SECRET_KEY", default="")
|
||||
|
||||
if ENVIRONMENT == "production" and not SECRET_KEY:
|
||||
raise ImproperlyConfigured("SECRET_KEY is required in production")
|
||||
if not SECRET_KEY:
|
||||
SECRET_KEY = "development-only-insecure-secret-key"
|
||||
|
||||
|
||||
# print('skey',SECRET_KEY)
|
||||
|
|
@ -42,8 +52,7 @@ ENVIRONMENT = os.getenv('ENVIRONMENT')
|
|||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent
|
||||
|
||||
ALLOWED_HOSTS = ['wanitil.lan', 'wanitil', 'localhost', 'wanitil.wanservice.ru', 'wanitil2.wanservice.ru',
|
||||
'wanitil2', '127.0.0.1', "chrome-extension://eipdnjedkpcnlmmdfdkgfpljanehloah", '*']
|
||||
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS")
|
||||
|
||||
|
||||
# Application definition
|
||||
|
|
@ -77,6 +86,8 @@ MIDDLEWARE = [
|
|||
# 'simple_history.middleware.HistoryRequestMiddleware',
|
||||
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'wanitil.observability.RequestContextMiddleware',
|
||||
'wanitil.observability.DatabaseMetricsMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'wanitil.middleware.ApiErrorContractMiddleware',
|
||||
|
|
@ -125,11 +136,13 @@ WSGI_APPLICATION = 'main.wsgi.application'
|
|||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': os.getenv('SQL_ENGINE', 'django.db.backends.postgresql'),
|
||||
'NAME': os.getenv('SQL_DATABASE', 'wanitil'),
|
||||
'USER': os.getenv('SQL_USER', 'wanitil'),
|
||||
'PASSWORD': os.getenv('SQL_PASSWORD', 'wanitilpass'),
|
||||
'HOST': os.getenv('SQL_HOST', 'localhost'),
|
||||
'PORT': os.getenv('SQL_PORT', '5432'),
|
||||
'NAME': env('SQL_DATABASE', default='wanitil'),
|
||||
'USER': env('SQL_USER', default='wanitil'),
|
||||
'PASSWORD': env('SQL_PASSWORD', default='wanitilpass'),
|
||||
'HOST': env('SQL_HOST', default='localhost'),
|
||||
'PORT': env('SQL_PORT', default='5432'),
|
||||
'CONN_MAX_AGE': env.int('SQL_CONN_MAX_AGE', default=60),
|
||||
'CONN_HEALTH_CHECKS': True,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -236,31 +249,47 @@ USE_X_FORWARDED_HOST = True
|
|||
|
||||
if ENVIRONMENT == 'production':
|
||||
DEBUG = False
|
||||
# SECRET_KEY = os.getenv('SECRET_KEY')
|
||||
# SESSION_COOKIE_SECURE = True
|
||||
required_database_variables = (
|
||||
'SQL_DATABASE', 'SQL_USER', 'SQL_PASSWORD', 'SQL_HOST',
|
||||
)
|
||||
missing_database_variables = [
|
||||
name for name in required_database_variables if not env(name, default='')
|
||||
]
|
||||
if missing_database_variables:
|
||||
raise ImproperlyConfigured(
|
||||
'Missing production database settings: '
|
||||
+ ', '.join(missing_database_variables)
|
||||
)
|
||||
SESSION_COOKIE_SECURE = True
|
||||
CSRF_COOKIE_SECURE = True
|
||||
SECURE_CONTENT_TYPE_NOSNIFF = True
|
||||
# SECURE_BROWSER_XSS_FILTER = True
|
||||
# SECURE_CONTENT_TYPE_NOSNIFF = True
|
||||
# SECURE_HSTS_INCLUDE_SUBDOMAINS = True
|
||||
# SECURE_HSTS_SECONDS = 31536000
|
||||
# SECURE_REDIRECT_EXEMPT = []
|
||||
SECURE_SSL_REDIRECT = False
|
||||
SECURE_SSL_REDIRECT = env.bool('SECURE_SSL_REDIRECT', default=True)
|
||||
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
||||
# 'django_ace',
|
||||
|
||||
LOG_LEVEL = env('LOG_LEVEL', default='INFO')
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'handlers': {
|
||||
'main_log_file': {
|
||||
'class': 'logging.handlers.RotatingFileHandler',
|
||||
'filename': 'log/django.log',
|
||||
'maxBytes': 1024 * 1024 * 100, # 100 MB
|
||||
'backupCount': 10,
|
||||
'console': {
|
||||
'class': 'logging.StreamHandler',
|
||||
'formatter': 'json',
|
||||
},
|
||||
},
|
||||
'formatters': {
|
||||
'json': {
|
||||
'()': 'wanitil.observability.JsonFormatter',
|
||||
},
|
||||
},
|
||||
'root': {
|
||||
'handlers': ['main_log_file'],
|
||||
'level': 'WARNING',
|
||||
'handlers': ['console'],
|
||||
'level': LOG_LEVEL,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,10 +16,13 @@ Including another URLconf
|
|||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
from django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
from django.conf.urls.static import static
|
||||
from wanitil import health
|
||||
#from settings import DEBUG, STATIC_URL, STATIC_ROOT, MEDIA_URL, MEDIA_ROOT
|
||||
|
||||
urlpatterns = [
|
||||
urlpatterns = [
|
||||
path('health/live/', health.live, name='health-live'),
|
||||
path('health/ready/', health.ready, name='health-ready'),
|
||||
path('', include('wanitil.urls')),
|
||||
path('admin/', admin.site.urls),
|
||||
]
|
||||
|
|
@ -32,4 +35,4 @@ urlpatterns = [
|
|||
# urlpatterns += static(MEDIA_URL,
|
||||
# document_root=MEDIA_ROOT)
|
||||
#urlpatterns += static(settings.APPQAR_URL,
|
||||
# document_root=settings.APPQAR_ROOT)
|
||||
# document_root=settings.APPQAR_ROOT)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
[build-system]
|
||||
requires = ["setuptools>=75", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "wanitilserver"
|
||||
version = "0.1.0"
|
||||
description = "WANITIL service management REST API"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.12"
|
||||
dynamic = ["dependencies"]
|
||||
|
||||
[project.optional-dependencies]
|
||||
dev = [
|
||||
"pip-audit>=2.7",
|
||||
"ruff>=0.8",
|
||||
]
|
||||
|
||||
[tool.setuptools]
|
||||
packages = {find = {include = ["main*", "wanitil*"]}}
|
||||
|
||||
[tool.setuptools.dynamic]
|
||||
dependencies = {file = ["requirements.txt"]}
|
||||
|
||||
[tool.ruff]
|
||||
target-version = "py312"
|
||||
line-length = 100
|
||||
exclude = ["wanitil/migrations"]
|
||||
|
||||
[tool.ruff.lint]
|
||||
# Start with correctness rules for the legacy codebase. Style families can be
|
||||
# enabled per domain as each three-letter package is migrated.
|
||||
select = ["E9", "F63", "F7", "F82"]
|
||||
|
||||
[tool.coverage.run]
|
||||
source = ["wanitil"]
|
||||
omit = ["wanitil/migrations/*"]
|
||||
|
||||
[tool.coverage.report]
|
||||
show_missing = true
|
||||
skip_covered = true
|
||||
fail_under = 70
|
||||
64057
schema.yaml
64057
schema.yaml
File diff suppressed because it is too large
Load Diff
|
|
@ -40,8 +40,8 @@ LOOKUP_DESCRIPTIONS = {
|
|||
# resources get different OpenAPI components and may evolve independently.
|
||||
ACTION_REQUESTS = {
|
||||
# Contacts and notifications
|
||||
"ConTelegramViewSet.createcode": {"code": I, "telegramid": I, "botname": S},
|
||||
"ConTelegramViewSet.register": {"code": I},
|
||||
"ConContactPointViewSet.createcode": {"code": I, "telegramid": I, "botname": S},
|
||||
"ConContactPointViewSet.register": {"code": I},
|
||||
# Incident relations
|
||||
"IncIncidentViewSet.addci": {
|
||||
"ci_id": I, "ci_name": S, "model_id": I, "model_name": S,
|
||||
|
|
@ -86,7 +86,6 @@ URL_ID_EMPTY_ACTIONS = {
|
|||
"AdrStreetViewSet.zone",
|
||||
"AdrHouseViewSet.zone",
|
||||
"RepChartOnlineViewSet.collection",
|
||||
"IncEmployeeViewSet.group",
|
||||
"SysHolidayElementViewSet.group",
|
||||
"SysViewViewSet.role",
|
||||
"SysViewViewSet.user",
|
||||
|
|
|
|||
|
|
@ -104,10 +104,6 @@ ACTION_SUMMARIES = {
|
|||
"updatepassword": "Изменить пароль",
|
||||
"updateprofile": "Обновить профиль",
|
||||
"logout": "Завершить сессии пользователя",
|
||||
"addrole": "Добавить роль",
|
||||
"deleterole": "Удалить роль",
|
||||
"deleteallrole": "Удалить все роли",
|
||||
"addrolekit": "Добавить набор ролей",
|
||||
"adduser": "Добавить пользователя",
|
||||
"deleteuser": "Удалить пользователя",
|
||||
"addperiod": "Добавить период расписания",
|
||||
|
|
@ -175,13 +171,6 @@ ACTION_DESCRIPTIONS = {
|
|||
"updateprofile": (
|
||||
"Частично обновляет настройки профиля. Непереданные поля не изменяются."
|
||||
),
|
||||
"deleteallrole": (
|
||||
"Удаляет у пользователя все назначенные роли. Операция идемпотентна."
|
||||
),
|
||||
"addrolekit": (
|
||||
"Назначает пользователю все роли из выбранного набора. Уже назначенные "
|
||||
"роли повторно не создаются."
|
||||
),
|
||||
"sendmessage": (
|
||||
"Отправляет сообщение выбранным пользователям через указанные каналы. "
|
||||
"Повторный вызов выполняет повторную отправку."
|
||||
|
|
@ -234,18 +223,17 @@ CRUD = {
|
|||
RESOURCE_TITLES = {
|
||||
"areas": "районы",
|
||||
"houses": "дома",
|
||||
"housetypes": "типы домов",
|
||||
"house-types": "типы домов",
|
||||
"regions": "регионы",
|
||||
"streets": "улицы",
|
||||
"streettypes": "типы улиц",
|
||||
"street-types": "типы улиц",
|
||||
"towns": "населённые пункты",
|
||||
"towntypes": "типы населённых пунктов",
|
||||
"town-types": "типы населённых пунктов",
|
||||
"zones": "зоны",
|
||||
"zonetypes": "типы зон",
|
||||
"appsends": "уведомления",
|
||||
"emails": "адреса электронной почты",
|
||||
"phones": "телефоны",
|
||||
"telegrams": "контакты Telegram",
|
||||
"zone-types": "типы зон",
|
||||
"app-deliveries": "уведомления",
|
||||
"parties": "лица и организации",
|
||||
"contact-points": "контактные данные",
|
||||
"clients": "клиенты",
|
||||
"contracts": "договоры",
|
||||
"requests": "заявки",
|
||||
|
|
@ -261,8 +249,8 @@ RESOURCE_TITLES = {
|
|||
"requesthistcalcs": "расчёты SLA",
|
||||
"requesthistcalctotals": "итоговые расчёты SLA",
|
||||
"users": "пользователи",
|
||||
"userprofiles": "профили пользователей",
|
||||
"userinfos": "карточки пользователей",
|
||||
"user-profiles": "профили пользователей",
|
||||
"user-info": "карточки пользователей",
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -275,8 +263,8 @@ CLIENT_SCOPED_PREFIXES = (
|
|||
"/api/v1/client/srv/services",
|
||||
"/api/v1/client/sla/",
|
||||
"/api/v1/client/sys/users",
|
||||
"/api/v1/client/sys/userprofiles",
|
||||
"/api/v1/client/sys/userinfos",
|
||||
"/api/v1/client/sys/user-profiles",
|
||||
"/api/v1/client/sys/user-info",
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ from django.core.cache import cache
|
|||
from django.db import models
|
||||
|
||||
from .models.modelSys import SysManagment
|
||||
#, SysObject, SysContactType, SysUserProfile, SysStatus, SysRole, SysField, SysStatus, SysHolidayElement, SysHolidayGroup
|
||||
|
||||
from .cast import safeCast
|
||||
|
||||
|
|
@ -27,4 +26,4 @@ def get_cache_value(nameIn):
|
|||
return cache.get(nameIn)
|
||||
|
||||
return tmpVal
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
from django.core.cache import cache
|
||||
from django.db import models
|
||||
|
||||
from .models.modelSys import SysManagment
|
||||
from .models.modelSys import SysObject, SysContactType, SysUserProfile, SysRole, SysRoleKit, SysField, SysHolidayElement, SysHolidayGroup
|
||||
|
||||
from .cast import safeCast
|
||||
def get_prefix_object(objectname):
|
||||
from .models.modelSys import SysObject
|
||||
|
||||
|
||||
def get_prefix_object(objectname):
|
||||
el_prefix = SysObject.objects.filter(name=objectname).first()
|
||||
if el_prefix is None:
|
||||
return ""
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ def getObject(data, name, cls):
|
|||
return False, obj_obj
|
||||
else:
|
||||
return True, obj_obj
|
||||
except Exception as e:
|
||||
except (AttributeError, KeyError, TypeError):
|
||||
return False, None
|
||||
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ def getValInt(data, name, val=None):
|
|||
try:
|
||||
obj = data.pop(name)
|
||||
return safeCast(obj, int, val)
|
||||
except Exception as e:
|
||||
except (KeyError, TypeError):
|
||||
return val
|
||||
return val
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ def getValFloat(data, name, val=None):
|
|||
try:
|
||||
obj = data.pop(name)
|
||||
return safeCast(obj, float, val)
|
||||
except Exception as e:
|
||||
except (KeyError, TypeError):
|
||||
return val
|
||||
return val
|
||||
|
||||
|
|
@ -44,6 +44,6 @@ def getValStr(data, name, val=None):
|
|||
try:
|
||||
obj = data.pop(name)
|
||||
return safeCast(obj, str, val)
|
||||
except Exception as e:
|
||||
except (KeyError, TypeError):
|
||||
return val
|
||||
return val
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
from .models.modelSys import SysRole
|
||||
|
||||
def hasRole(user,role_list=[]):
|
||||
role_admin = SysRole.objects.filter(sys_user=user).filter(name__in=role_list).first()
|
||||
if (role_admin is None):
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
# Domain layout
|
||||
|
||||
Every subsystem uses its existing three-letter API code as the package name.
|
||||
|
||||
- `services.py`: state-changing use cases and transaction boundaries.
|
||||
- `selectors.py`: read-only ORM queries and query optimization.
|
||||
- `policies.py`: authorization and valid state-transition decisions.
|
||||
- `notifications.py`: messages scheduled with `transaction.on_commit`.
|
||||
|
||||
Views validate HTTP input and delegate to these modules. Serializers only
|
||||
translate representations; they must not own workflows or notification calls.
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
"""Domain boundaries for WANITIL subsystems.
|
||||
|
||||
Legacy modules remain as compatibility adapters while behavior is moved here
|
||||
incrementally. New cross-domain imports must target a domain public API.
|
||||
"""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""ADR domain public API."""
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
"""Post-commit notification orchestration for the ADR domain."""
|
||||
|
||||
from django.db import transaction
|
||||
|
||||
|
||||
def after_commit(callback, *args, **kwargs):
|
||||
"""Schedule external side effects only after a successful DB commit."""
|
||||
|
||||
transaction.on_commit(lambda: callback(*args, **kwargs))
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Authorization and state-transition policies for the ADR domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Read-only, optimized ORM queries for the ADR domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Transactional state-changing use cases for the ADR domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""CHN domain public API."""
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
"""Post-commit notification orchestration for the CHN domain."""
|
||||
|
||||
from django.db import transaction
|
||||
|
||||
|
||||
def after_commit(callback, *args, **kwargs):
|
||||
"""Schedule external side effects only after a successful DB commit."""
|
||||
|
||||
transaction.on_commit(lambda: callback(*args, **kwargs))
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Authorization and state-transition policies for the CHN domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Read-only, optimized ORM queries for the CHN domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Transactional state-changing use cases for the CHN domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""CIM domain public API."""
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
"""Post-commit notification orchestration for the CIM domain."""
|
||||
|
||||
from django.db import transaction
|
||||
|
||||
|
||||
def after_commit(callback, *args, **kwargs):
|
||||
"""Schedule external side effects only after a successful DB commit."""
|
||||
|
||||
transaction.on_commit(lambda: callback(*args, **kwargs))
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Authorization and state-transition policies for the CIM domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Read-only, optimized ORM queries for the CIM domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Transactional state-changing use cases for the CIM domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""CON domain public API."""
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
"""Post-commit notification orchestration for the CON domain."""
|
||||
|
||||
from django.db import transaction
|
||||
|
||||
|
||||
def after_commit(callback, *args, **kwargs):
|
||||
"""Schedule external side effects only after a successful DB commit."""
|
||||
|
||||
transaction.on_commit(lambda: callback(*args, **kwargs))
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Authorization and state-transition policies for the CON domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Read-only, optimized ORM queries for the CON domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Transactional state-changing use cases for the CON domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""CRM domain public API."""
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
"""Post-commit notification orchestration for the CRM domain."""
|
||||
|
||||
from django.db import transaction
|
||||
|
||||
|
||||
def after_commit(callback, *args, **kwargs):
|
||||
"""Schedule external side effects only after a successful DB commit."""
|
||||
|
||||
transaction.on_commit(lambda: callback(*args, **kwargs))
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Authorization and state-transition policies for the CRM domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Read-only, optimized ORM queries for the CRM domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Transactional state-changing use cases for the CRM domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""DEV domain public API."""
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
"""Post-commit notification orchestration for the DEV domain."""
|
||||
|
||||
from django.db import transaction
|
||||
|
||||
|
||||
def after_commit(callback, *args, **kwargs):
|
||||
"""Schedule external side effects only after a successful DB commit."""
|
||||
|
||||
transaction.on_commit(lambda: callback(*args, **kwargs))
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Authorization and state-transition policies for the DEV domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Read-only, optimized ORM queries for the DEV domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Transactional state-changing use cases for the DEV domain."""
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
"""Explicit errors shared by domain services and translated at the API edge."""
|
||||
|
||||
|
||||
class DomainError(Exception):
|
||||
code = "domain_error"
|
||||
|
||||
|
||||
class InvalidTransition(DomainError):
|
||||
code = "invalid_transition"
|
||||
|
||||
|
||||
class AccessDenied(DomainError):
|
||||
code = "access_denied"
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""INC domain public API."""
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
"""Post-commit notification orchestration for the INC domain."""
|
||||
|
||||
from django.db import transaction
|
||||
|
||||
from wanitil.funcs.funcInc import IncCommentSendNotify, IncIncidentSendNotify
|
||||
|
||||
|
||||
def after_commit(callback, *args, **kwargs):
|
||||
"""Schedule external side effects only after a successful DB commit."""
|
||||
|
||||
transaction.on_commit(lambda: callback(*args, **kwargs))
|
||||
|
||||
|
||||
def incident_after_commit(incident_id, created):
|
||||
after_commit(IncIncidentSendNotify, incident_id, created)
|
||||
|
||||
|
||||
def comment_after_commit(comment_id, created):
|
||||
after_commit(IncCommentSendNotify, comment_id, created)
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Authorization and state-transition policies for the INC domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Read-only, optimized ORM queries for the INC domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Transactional state-changing use cases for the INC domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""REP domain public API."""
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
"""Post-commit notification orchestration for the REP domain."""
|
||||
|
||||
from django.db import transaction
|
||||
|
||||
|
||||
def after_commit(callback, *args, **kwargs):
|
||||
"""Schedule external side effects only after a successful DB commit."""
|
||||
|
||||
transaction.on_commit(lambda: callback(*args, **kwargs))
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Authorization and state-transition policies for the REP domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Read-only, optimized ORM queries for the REP domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Transactional state-changing use cases for the REP domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""REQ domain public API."""
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
"""Post-commit notification orchestration for the REQ domain."""
|
||||
|
||||
from django.db import transaction
|
||||
|
||||
from wanitil.funcs.funcReq import ReqCommentSendNotify, ReqRequestSendNotify
|
||||
|
||||
|
||||
def after_commit(callback, *args, **kwargs):
|
||||
"""Schedule external side effects only after a successful DB commit."""
|
||||
|
||||
transaction.on_commit(lambda: callback(*args, **kwargs))
|
||||
|
||||
|
||||
def request_after_commit(request_id, created):
|
||||
after_commit(ReqRequestSendNotify, request_id, created)
|
||||
|
||||
|
||||
def comment_after_commit(comment_id, created):
|
||||
after_commit(ReqCommentSendNotify, comment_id, created)
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Authorization and state-transition policies for the REQ domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Read-only, optimized ORM queries for the REQ domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Transactional state-changing use cases for the REQ domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""SLA domain public API."""
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
"""Post-commit notification orchestration for the SLA domain."""
|
||||
|
||||
from django.db import transaction
|
||||
|
||||
|
||||
def after_commit(callback, *args, **kwargs):
|
||||
"""Schedule external side effects only after a successful DB commit."""
|
||||
|
||||
transaction.on_commit(lambda: callback(*args, **kwargs))
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Authorization and state-transition policies for the SLA domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Read-only, optimized ORM queries for the SLA domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Transactional state-changing use cases for the SLA domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""SRV domain public API."""
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
"""Post-commit notification orchestration for the SRV domain."""
|
||||
|
||||
from django.db import transaction
|
||||
|
||||
|
||||
def after_commit(callback, *args, **kwargs):
|
||||
"""Schedule external side effects only after a successful DB commit."""
|
||||
|
||||
transaction.on_commit(lambda: callback(*args, **kwargs))
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Authorization and state-transition policies for the SRV domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Read-only, optimized ORM queries for the SRV domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""Transactional state-changing use cases for the SRV domain."""
|
||||
|
|
@ -0,0 +1 @@
|
|||
"""SYS domain public API."""
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
"""Post-commit notification orchestration for the SYS domain."""
|
||||
|
||||
from django.db import transaction
|
||||
|
||||
|
||||
def after_commit(callback, *args, **kwargs):
|
||||
"""Schedule external side effects only after a successful DB commit."""
|
||||
|
||||
transaction.on_commit(lambda: callback(*args, **kwargs))
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
"""Authorization and state-transition policies for the SYS domain."""
|
||||
|
||||
from wanitil.funcs.funcSysEmployee import user_has_permission_code
|
||||
|
||||
__all__ = ["user_has_permission_code"]
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
"""Read-only, optimized ORM queries for the SYS domain."""
|
||||
|
||||
from wanitil.funcs.funcSysEmployee import (
|
||||
get_user_module_membership,
|
||||
get_user_permission_codes,
|
||||
user_has_module_profile,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"get_user_module_membership",
|
||||
"get_user_permission_codes",
|
||||
"user_has_module_profile",
|
||||
]
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
"""Transactional state-changing use cases for the SYS domain."""
|
||||
|
||||
from wanitil.funcs.funcSysEmployee import (
|
||||
apply_access_profile,
|
||||
apply_access_profiles,
|
||||
revoke_access_profiles,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"apply_access_profile",
|
||||
"apply_access_profiles",
|
||||
"revoke_access_profiles",
|
||||
]
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
from .filterUtils import BaseFilterSet, boolLookUp, datetimeLookUp, intLookUp, strLookUp
|
||||
from ..models.modelChn import Task, TaskCategory, TaskPriority, TaskStatus, TaskType
|
||||
|
||||
|
||||
class ChnReferenceFilter(BaseFilterSet):
|
||||
class Meta:
|
||||
fields = {"id": intLookUp, "name": strLookUp, "is_active": boolLookUp}
|
||||
|
||||
|
||||
class TaskTypeFilter(ChnReferenceFilter):
|
||||
class Meta(ChnReferenceFilter.Meta): model = TaskType
|
||||
|
||||
|
||||
class TaskStatusFilter(ChnReferenceFilter):
|
||||
class Meta(ChnReferenceFilter.Meta):
|
||||
model = TaskStatus
|
||||
fields = {**ChnReferenceFilter.Meta.fields, "is_closed": boolLookUp}
|
||||
|
||||
|
||||
class TaskPriorityFilter(ChnReferenceFilter):
|
||||
class Meta(ChnReferenceFilter.Meta): model = TaskPriority
|
||||
|
||||
|
||||
class TaskCategoryFilter(ChnReferenceFilter):
|
||||
class Meta(ChnReferenceFilter.Meta):
|
||||
model = TaskCategory
|
||||
fields = {**ChnReferenceFilter.Meta.fields, "parent__id": intLookUp}
|
||||
|
||||
|
||||
class TaskFilter(BaseFilterSet):
|
||||
class Meta:
|
||||
model = Task
|
||||
fields = {
|
||||
"id": intLookUp, "title": strLookUp, "external_id": strLookUp,
|
||||
"task_type__id": intLookUp, "status__id": intLookUp,
|
||||
"priority__id": intLookUp, "category__id": intLookUp,
|
||||
"assignee__id": intLookUp, "initiator__id": intLookUp,
|
||||
"planned_start_at": datetimeLookUp, "planned_finish_at": datetimeLookUp,
|
||||
"actual_start_at": datetimeLookUp, "actual_finish_at": datetimeLookUp,
|
||||
"progress": intLookUp,
|
||||
}
|
||||
|
|
@ -2,33 +2,71 @@ import django_filters
|
|||
from .filterUtils import strLookUp, intLookUp, datetimeLookUp, boolLookUp, floatLookUp, BaseFilterSet
|
||||
|
||||
from ..models.modelCon import ConAppMessage, ConAppSend, ConTelegramSend
|
||||
from ..models.modelCon import ConPhone, ConEmail, ConTelegram
|
||||
from ..models.modelCon import ConCall, ConContactPoint, ConParty
|
||||
|
||||
|
||||
class ConPhoneFilter(BaseFilterSet):
|
||||
class ConPartyFilter(BaseFilterSet):
|
||||
"""Filters for people and organizations managed by the contacts module."""
|
||||
|
||||
class Meta:
|
||||
model = ConPhone
|
||||
model = ConParty
|
||||
fields = {
|
||||
"id": intLookUp, "name": strLookUp, "value": strLookUp, "phone_type": intLookUp, "is_owner": boolLookUp, "sys_user__id": intLookUp, "sys_user__username": strLookUp
|
||||
"id": intLookUp,
|
||||
"type": strLookUp,
|
||||
"display_name": strLookUp,
|
||||
"sys_user__id": intLookUp,
|
||||
"sys_user__username": strLookUp,
|
||||
"is_active": boolLookUp,
|
||||
}
|
||||
|
||||
|
||||
class ConEmailFilter(BaseFilterSet):
|
||||
class ConContactPointFilter(BaseFilterSet):
|
||||
"""Filters for contact points, including their owning person."""
|
||||
|
||||
class Meta:
|
||||
model = ConEmail
|
||||
model = ConContactPoint
|
||||
fields = {
|
||||
"id": intLookUp, "name": strLookUp, "value": strLookUp, "is_owner": boolLookUp, "sys_user__id": intLookUp, "sys_user__username": strLookUp
|
||||
"id": intLookUp,
|
||||
"con_person__id": intLookUp,
|
||||
"con_person__display_name": strLookUp,
|
||||
"type": strLookUp,
|
||||
"purpose": strLookUp,
|
||||
"value": strLookUp,
|
||||
"normalized_value": strLookUp,
|
||||
"label": strLookUp,
|
||||
"is_primary": boolLookUp,
|
||||
"is_verified": boolLookUp,
|
||||
"verified_at": datetimeLookUp,
|
||||
"is_active": boolLookUp,
|
||||
"created_at": datetimeLookUp,
|
||||
"updated_at": datetimeLookUp,
|
||||
}
|
||||
|
||||
|
||||
class ConTelegramFilter(BaseFilterSet):
|
||||
class ConCallFilter(BaseFilterSet):
|
||||
class Meta:
|
||||
model = ConTelegram
|
||||
model = ConCall
|
||||
fields = {
|
||||
"id": intLookUp, "name": strLookUp, "value": intLookUp, "bot_name": strLookUp, "is_owner": boolLookUp, "sys_user__id": intLookUp, "sys_user__username": strLookUp
|
||||
"id": intLookUp,
|
||||
"direction": strLookUp,
|
||||
"status": strLookUp,
|
||||
"caller_number": strLookUp,
|
||||
"caller_normalized_number": strLookUp,
|
||||
"callee_number": strLookUp,
|
||||
"callee_normalized_number": strLookUp,
|
||||
"caller_contact__id": intLookUp,
|
||||
"caller_contact__con_person__id": intLookUp,
|
||||
"callee_contact__id": intLookUp,
|
||||
"callee_contact__con_person__id": intLookUp,
|
||||
"provider": strLookUp,
|
||||
"external_id": strLookUp,
|
||||
"started_at": datetimeLookUp,
|
||||
"answered_at": datetimeLookUp,
|
||||
"ended_at": datetimeLookUp,
|
||||
"duration_seconds": intLookUp,
|
||||
"created_at": datetimeLookUp,
|
||||
"updated_at": datetimeLookUp,
|
||||
}
|
||||
|
||||
|
||||
class ConAppSendFilter(BaseFilterSet):
|
||||
con_app_message_sysdatecreate__gtn = django_filters.CharFilter(
|
||||
method='datetime_gtn')
|
||||
|
|
@ -48,6 +86,11 @@ class ConAppSendFilter(BaseFilterSet):
|
|||
}
|
||||
|
||||
|
||||
# Deprecated compatibility aliases.
|
||||
ConPersonFilter = ConPartyFilter
|
||||
ConContactFilter = ConContactPointFilter
|
||||
|
||||
|
||||
class ConTelegramSendFilter(BaseFilterSet):
|
||||
con_telegram_message_sysdatecreate__gtn = django_filters.CharFilter(
|
||||
method='datetime_gtn')
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import django_filters
|
||||
from .filterUtils import strLookUp, intLookUp, datetimeLookUp, boolLookUp, floatLookUp, BaseFilterSet
|
||||
|
||||
from ..models.modelCrm import CrmClient, CrmContract, CrmType, CrmCategory
|
||||
from ..models.modelCrm import CrmActivity, CrmClient, CrmContract, CrmLead, CrmType, CrmCategory
|
||||
|
||||
|
||||
class CrmTypeFilter(BaseFilterSet):
|
||||
|
|
@ -20,6 +20,39 @@ class CrmCategoryFilter(BaseFilterSet):
|
|||
}
|
||||
|
||||
|
||||
class CrmLeadFilter(BaseFilterSet):
|
||||
class Meta:
|
||||
model = CrmLead
|
||||
fields = {
|
||||
"id": intLookUp, "name": strLookUp, "status": strLookUp,
|
||||
"source": strLookUp, "budget": floatLookUp,
|
||||
"need": strLookUp, "comment": strLookUp,
|
||||
"responsible__id": intLookUp,
|
||||
"responsible__employee__display_name": strLookUp,
|
||||
"responsible__employee__sys_user__username": strLookUp,
|
||||
"con_person__id": intLookUp,
|
||||
"con_person__display_name": strLookUp,
|
||||
"con_contact__id": intLookUp,
|
||||
"con_contact__type": strLookUp,
|
||||
"con_contact__purpose": strLookUp,
|
||||
"con_contact__value": strLookUp,
|
||||
"con_contact__normalized_value": strLookUp,
|
||||
"created_at": datetimeLookUp, "updated_at": datetimeLookUp,
|
||||
}
|
||||
|
||||
|
||||
class CrmActivityFilter(BaseFilterSet):
|
||||
class Meta:
|
||||
model = CrmActivity
|
||||
fields = {
|
||||
"id": intLookUp, "type": strLookUp,
|
||||
"subject_type": strLookUp, "subject_id": intLookUp,
|
||||
"reference_type": strLookUp, "reference_id": intLookUp,
|
||||
"title": strLookUp, "text": strLookUp,
|
||||
"occurred_at": datetimeLookUp, "created_at": datetimeLookUp,
|
||||
}
|
||||
|
||||
|
||||
class CrmClientFilter(BaseFilterSet):
|
||||
class Meta:
|
||||
model = CrmClient
|
||||
|
|
@ -28,9 +61,18 @@ class CrmClientFilter(BaseFilterSet):
|
|||
"crm_category__name": strLookUp, "crm_category__description": strLookUp,
|
||||
"name": strLookUp, "fullname": strLookUp, "firstname": strLookUp, "secondname": strLookUp, "surname": strLookUp,
|
||||
"sys_user__id": intLookUp, "sys_user__username": strLookUp,
|
||||
"sys_user__con_phone__value": intLookUp, "sys_user__con_phone__name": strLookUp, "sys_user__con_phone__phone_type": intLookUp, "sys_user__con_phone__is_owner": boolLookUp,
|
||||
"sys_user__con_telegram__value": strLookUp, "sys_user__con_telegram__bot_name": strLookUp, "sys_user__con_telegram__name": strLookUp, "sys_user__con_telegram__is_owner": boolLookUp,
|
||||
"sys_user__con_email__value": strLookUp, "sys_user__con_email__name": strLookUp, "sys_user__con_email__is_owner": boolLookUp,
|
||||
"sys_user__con_person__con_contact__type": strLookUp,
|
||||
"sys_user__con_person__con_contact__purpose": strLookUp,
|
||||
"sys_user__con_person__con_contact__value": strLookUp,
|
||||
"sys_user__con_person__con_contact__normalized_value": strLookUp,
|
||||
"sys_user__con_person__con_contact__label": strLookUp,
|
||||
"sys_user__con_person__con_contact__is_primary": boolLookUp,
|
||||
"sys_user__con_person__con_contact__is_verified": boolLookUp,
|
||||
"sys_user__con_person__con_contact__is_active": boolLookUp,
|
||||
"con_person__id": intLookUp, "con_person__display_name": strLookUp,
|
||||
"con_contact__id": intLookUp, "con_contact__type": strLookUp,
|
||||
"con_contact__purpose": strLookUp, "con_contact__value": strLookUp,
|
||||
"con_contact__normalized_value": strLookUp, "con_contact__is_active": boolLookUp,
|
||||
"house_id": intLookUp, "house_extid": strLookUp, "house_name": strLookUp, "flat": strLookUp, "lat": floatLookUp, "lon": floatLookUp
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,25 +1,16 @@
|
|||
import django_filters
|
||||
from .filterUtils import strLookUp, intLookUp, datetimeLookUp, boolLookUp, floatLookUp, BaseFilterSet
|
||||
|
||||
from ..models.modelInc import IncEmployee, IncGroup, IncImpact, IncPriority, IncStatus, IncStatusTransit, IncCategory, IncSubcategory, IncSolution, IncSourceType
|
||||
from ..models.modelInc import IncGroup, IncImpact, IncPriority, IncStatus, IncStatusTransit, IncCategory, IncSubcategory, IncSolution, IncSourceType
|
||||
from ..models.modelInc import IncIncident, IncIncidentHistorical, IncCi, IncComment, IncCommentFile, IncIncidentFile, IncGetPreferenceValue
|
||||
from ..models.modelInc import IncIncidentNotify, IncIncidentNotifyField, IncCommentNotify, IncCommentNotifyField
|
||||
|
||||
|
||||
class IncEmployeeFilter(BaseFilterSet):
|
||||
class Meta:
|
||||
model = IncEmployee
|
||||
fields = {
|
||||
"id": intLookUp, "name": strLookUp, "description": strLookUp, "sys_user__id": intLookUp, "sys_user__username": strLookUp, "firstname": strLookUp, "secondname": strLookUp, "surname": strLookUp, "department": strLookUp, "is_leader": boolLookUp, "inc_group__id": intLookUp, "inc_group__name": strLookUp
|
||||
|
||||
}
|
||||
|
||||
|
||||
class IncGroupFilter(BaseFilterSet):
|
||||
class Meta:
|
||||
model = IncGroup
|
||||
fields = {
|
||||
"id": intLookUp, "name": strLookUp, "description": strLookUp, "manager__id": intLookUp, "manager__name": strLookUp, "inc_employee__id": intLookUp, "inc_employee__name": strLookUp
|
||||
"id": intLookUp, "name": strLookUp, "description": strLookUp, "manager__id": intLookUp, "manager__employee__display_name": strLookUp, "inc_employee__id": intLookUp, "inc_employee__employee__display_name": strLookUp
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -102,7 +93,7 @@ class IncIncidentFilter(BaseFilterSet):
|
|||
model = IncIncident
|
||||
fields = {
|
||||
"id": intLookUp, "datecreate": datetimeLookUp, "dateclose": datetimeLookUp, "inc_subcategory__id": intLookUp, "inc_subcategory__name": strLookUp, "inc_solution__id": intLookUp, "inc_solution__name": strLookUp, "inc_status__id": intLookUp, "inc_status__name": strLookUp, "inc_impact__id": intLookUp, "inc_impact__name": strLookUp, "inc_priority__id": intLookUp, "inc_priority__name": strLookUp, "inc_source_type__id": intLookUp, "inc_source_type__name": strLookUp # 3551 - Incident, 2551- Incident
|
||||
, "inc_employee__id": intLookUp, "inc_employee__name": strLookUp, "inc_group__id": intLookUp, "inc_group__name": strLookUp, "request_text": strLookUp, "solution_text": strLookUp, "escalate_type": intLookUp, "escalate_id": intLookUp, "escalate_extid": strLookUp
|
||||
, "inc_employee__id": intLookUp, "inc_employee__employee__display_name": strLookUp, "inc_group__id": intLookUp, "inc_group__name": strLookUp, "request_text": strLookUp, "solution_text": strLookUp, "escalate_type": intLookUp, "escalate_id": intLookUp, "escalate_extid": strLookUp
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import django_filters
|
||||
|
||||
from ..models.modelReq import ReqComment, ReqRequestFile, ReqCommentFile, ReqEmployee, ReqSourceType, ReqDepend, ReqGetPreferenceValue
|
||||
from ..models.modelReq import ReqComment, ReqRequestFile, ReqCommentFile, ReqSourceType, ReqDepend, ReqGetPreferenceValue
|
||||
from ..models.modelReq import ReqStatus, ReqStatusTransit, ReqCriticality, ReqRequest, ReqRequestHistorical
|
||||
from ..models.modelReq import ReqCommentNotify, ReqCommentNotifyField, ReqRequestNotify, ReqRequestNotifyField
|
||||
from ..models.modelReq import ReqReportRequestStampActiveM, ReqReportRequestStampCreateCloseM, ReqReportRequestStampSlaM
|
||||
|
|
@ -8,14 +8,6 @@ from ..models.modelReq import ReqReportRequestStampActiveH, ReqReportRequestStam
|
|||
from .filterUtils import strLookUp, intLookUp, datetimeLookUp, boolLookUp, BaseFilterSet, floatLookUp
|
||||
|
||||
|
||||
class ReqEmployeeFilter(BaseFilterSet):
|
||||
class Meta:
|
||||
model = ReqEmployee
|
||||
fields = {
|
||||
"id": intLookUp, "name": strLookUp, "description": strLookUp, "sys_user__id": intLookUp, "sys_user__username": strLookUp, "firstname": strLookUp, "secondname": strLookUp, "surname": strLookUp, "department": strLookUp, "is_leader": boolLookUp
|
||||
}
|
||||
|
||||
|
||||
class ReqRequestFilter(BaseFilterSet):
|
||||
datecreate__gtn = django_filters.CharFilter(method='datetime_gtn')
|
||||
datecreate__gten = django_filters.CharFilter(method='datetime_gten')
|
||||
|
|
@ -43,7 +35,7 @@ class ReqRequestFilter(BaseFilterSet):
|
|||
"id": intLookUp, "datecreate": datetimeLookUp, "dateclose": datetimeLookUp,
|
||||
"req_status__id": intLookUp, "req_status__name": strLookUp, "req_criticality__id": intLookUp, "req_criticality__name": strLookUp,
|
||||
"req_source_type__id": intLookUp, "req_source_type__name": strLookUp,
|
||||
"req_employee__id": intLookUp, "req_employee__name": strLookUp, "req_employee__sys_user__id": intLookUp, "req_employee__sys_user__username": strLookUp,
|
||||
"req_employee__id": intLookUp, "req_employee__employee__display_name": strLookUp, "req_employee__employee__sys_user__id": intLookUp, "req_employee__employee__sys_user__username": strLookUp,
|
||||
"client_id": intLookUp, "client_extid": strLookUp, "client_name": strLookUp,
|
||||
"client_type_id": intLookUp, "client_type_extid": strLookUp, "client_type_name": strLookUp,
|
||||
"client_category_id": intLookUp, "client_category_extid": strLookUp, "client_category_name": strLookUp,
|
||||
|
|
|
|||
|
|
@ -4,9 +4,12 @@ from wanitil.models.modelLogin import KnoxAuthToken
|
|||
from .filterUtils import strLookUp, intLookUp, datetimeLookUp, boolLookUp, floatLookUp, BaseFilterSet
|
||||
|
||||
|
||||
from ..models.modelSys import SysGetPreferenceValue, SysSetting
|
||||
from ..models.modelSys import SysManagment, SysObject, SysContactType, SysUserProfile, SysRole, SysRoleKit, SysFieldSearch, SysField, SysHolidayElement, SysHolidayGroup
|
||||
from ..models.modelSys import SysView, SysViewField, SysUserInfo
|
||||
from ..models.modelSys import (
|
||||
SysDepartment, SysEmployee, SysGetPreferenceValue, SysModuleAccessProfile,
|
||||
SysModuleMembership, SysPermission, SysSetting,
|
||||
)
|
||||
from ..models.modelSys import SysManagment, SysObject, SysContactType, SysFieldSearch, SysField, SysHolidayElement, SysHolidayGroup
|
||||
from ..models.modelSys import SysView, SysViewField
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
|
|
@ -27,6 +30,69 @@ class SysManagmentFilter(BaseFilterSet):
|
|||
}
|
||||
|
||||
|
||||
class SysEmployeeFilter(BaseFilterSet):
|
||||
class Meta:
|
||||
model = SysEmployee
|
||||
fields = {
|
||||
"id": intLookUp, "sys_user__id": intLookUp,
|
||||
"sys_user__username": strLookUp, "con_person__id": intLookUp,
|
||||
"display_name": strLookUp, "firstname": strLookUp,
|
||||
"secondname": strLookUp, "surname": strLookUp,
|
||||
"department__id": intLookUp, "department__name": strLookUp,
|
||||
"is_active": boolLookUp,
|
||||
}
|
||||
|
||||
|
||||
class SysDepartmentFilter(BaseFilterSet):
|
||||
class Meta:
|
||||
model = SysDepartment
|
||||
fields = {
|
||||
"id": intLookUp, "name": strLookUp, "code": strLookUp,
|
||||
"parent__id": intLookUp, "parent__name": strLookUp,
|
||||
"managers__id": intLookUp,
|
||||
"employees__id": intLookUp, "is_active": boolLookUp,
|
||||
}
|
||||
|
||||
|
||||
class SysModuleAccessProfileFilter(BaseFilterSet):
|
||||
class Meta:
|
||||
model = SysModuleAccessProfile
|
||||
fields = {
|
||||
"id": intLookUp, "module__id": intLookUp,
|
||||
"module__name": strLookUp, "code": strLookUp,
|
||||
"name": strLookUp, "scope": strLookUp,
|
||||
"permissions__id": intLookUp,
|
||||
"permissions__module": strLookUp,
|
||||
"permissions__action": strLookUp,
|
||||
"permissions__resource": strLookUp, "is_system": boolLookUp,
|
||||
"is_active": boolLookUp,
|
||||
}
|
||||
|
||||
|
||||
class SysPermissionFilter(BaseFilterSet):
|
||||
class Meta:
|
||||
model = SysPermission
|
||||
fields = {
|
||||
"id": intLookUp, "module": strLookUp,
|
||||
"action": strLookUp, "resource": strLookUp,
|
||||
}
|
||||
|
||||
|
||||
class SysModuleMembershipFilter(BaseFilterSet):
|
||||
class Meta:
|
||||
model = SysModuleMembership
|
||||
fields = {
|
||||
"id": intLookUp, "employee__id": intLookUp,
|
||||
"employee__sys_user__id": intLookUp,
|
||||
"employee__display_name": strLookUp, "module__id": intLookUp,
|
||||
"module__name": strLookUp, "profiles__id": intLookUp,
|
||||
"profiles__code": strLookUp, "profiles__scope": strLookUp,
|
||||
"profiles__permissions__id": intLookUp,
|
||||
"is_active": boolLookUp, "valid_from": datetimeLookUp,
|
||||
"valid_until": datetimeLookUp,
|
||||
}
|
||||
|
||||
|
||||
class SysObjectFilter(BaseFilterSet):
|
||||
class Meta:
|
||||
model = SysObject
|
||||
|
|
@ -51,23 +117,6 @@ class SysFieldSearchFilter(BaseFilterSet):
|
|||
}
|
||||
|
||||
|
||||
class SysRoleFilter(BaseFilterSet):
|
||||
class Meta:
|
||||
model = SysRole
|
||||
fields = {
|
||||
|
||||
"id": intLookUp, "name": strLookUp, "sys_managment__id": intLookUp, "sys_managment__name": strLookUp, "sys_user__id": intLookUp, "sys_user__username": strLookUp
|
||||
}
|
||||
|
||||
|
||||
class SysRoleKitFilter(BaseFilterSet):
|
||||
class Meta:
|
||||
model = SysRoleKit
|
||||
fields = {
|
||||
"id": intLookUp, "name": strLookUp, "sys_role__id": intLookUp, "sys_role__name": strLookUp
|
||||
}
|
||||
|
||||
|
||||
class SysHolidayGroupFilter(BaseFilterSet):
|
||||
class Meta:
|
||||
model = SysHolidayGroup
|
||||
|
|
@ -99,7 +148,7 @@ class SysViewFilter(BaseFilterSet):
|
|||
class Meta:
|
||||
model = SysView
|
||||
fields = {
|
||||
"id": intLookUp, "name": strLookUp, "sys_object__id": intLookUp, "sys_object__name": strLookUp, "sys_user__id": intLookUp, "sys_user__username": strLookUp, "sys_role__id": intLookUp, "sys_role__name": strLookUp, "is_all": boolLookUp, "is_main_menu": boolLookUp
|
||||
"id": intLookUp, "name": strLookUp, "sys_object__id": intLookUp, "sys_object__name": strLookUp, "sys_user__id": intLookUp, "sys_user__username": strLookUp, "is_all": boolLookUp, "is_main_menu": boolLookUp
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -111,33 +160,26 @@ class SysViewFieldFilter(BaseFilterSet):
|
|||
}
|
||||
|
||||
|
||||
class SysUserProfileFilter(BaseFilterSet):
|
||||
class Meta:
|
||||
model = SysUserProfile
|
||||
fields = {
|
||||
"sys_user__id": intLookUp, "sys_user__username": strLookUp, "lang": strLookUp, "status": intLookUp, "theme_is_light": boolLookUp, "theme_color": strLookUp, "timezone": intLookUp
|
||||
}
|
||||
|
||||
|
||||
class SysUserInfoFilter(BaseFilterSet):
|
||||
class Meta:
|
||||
model = SysUserInfo
|
||||
fields = {
|
||||
"name": strLookUp, "sys_user__id": intLookUp, "sys_user__username": strLookUp
|
||||
|
||||
}
|
||||
|
||||
|
||||
class SysUserFilter(BaseFilterSet):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = {
|
||||
"id": intLookUp, "username": strLookUp, "email": strLookUp, 'sys_user_info__name': strLookUp,
|
||||
"con_phone__value": intLookUp, "con_phone__name": strLookUp, "con_phone__phone_type": intLookUp, "con_phone__is_owner": boolLookUp,
|
||||
"con_telegram__value": strLookUp, "con_telegram__bot_name": strLookUp, "con_telegram__name": strLookUp, "con_telegram__is_owner": boolLookUp,
|
||||
"con_email__value": strLookUp, "con_email__name": strLookUp, "con_email__is_owner": boolLookUp,
|
||||
"id": intLookUp, "username": strLookUp, "email": strLookUp,
|
||||
"sys_employee__display_name": strLookUp,
|
||||
"con_person__con_contact__type": strLookUp,
|
||||
"con_person__con_contact__purpose": strLookUp,
|
||||
"con_person__con_contact__value": strLookUp,
|
||||
"con_person__con_contact__normalized_value": strLookUp,
|
||||
"con_person__con_contact__label": strLookUp,
|
||||
"con_person__con_contact__is_primary": boolLookUp,
|
||||
"con_person__con_contact__is_verified": boolLookUp,
|
||||
"con_person__con_contact__is_active": boolLookUp,
|
||||
|
||||
"sys_user_profile__lang": strLookUp, "sys_user_profile__status": intLookUp, "sys_user_profile__theme_is_light": boolLookUp, "sys_user_profile__theme_color": strLookUp, "sys_user_profile__timezone": intLookUp
|
||||
"sys_employee__lang": strLookUp,
|
||||
"sys_employee__status": intLookUp,
|
||||
"sys_employee__theme_is_light": boolLookUp,
|
||||
"sys_employee__theme_color": strLookUp,
|
||||
"sys_employee__timezone": intLookUp,
|
||||
}
|
||||
|
||||
class SysAuthFilter(BaseFilterSet):
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import pytz
|
|||
from django.db.models import Q
|
||||
from ..cast import safeCast
|
||||
|
||||
from ..models.modelCon import ConPhone, ConEmail, ConTelegram, ConEmailSend, ConTelegramSend, ConEmailMessage, ConTelegramMessage, ConAppMessage, ConAppSend
|
||||
from ..models.modelCon import ConContactPoint, ConContactPointType, ConEmailSend, ConTelegramSend, ConEmailMessage, ConTelegramMessage, ConAppMessage, ConAppSend
|
||||
from ..models.modelCrm import CrmClient
|
||||
#from ..models.modelEmp import EmpEmployee
|
||||
from django.contrib.auth.models import User
|
||||
|
|
@ -14,12 +14,17 @@ from django.utils import timezone
|
|||
from ..models.modelCon import ConAppSendStatus, ConNotificationDispatch
|
||||
|
||||
|
||||
def ConGetUserByPhone(phone):
|
||||
# list = ConPhone.objects.filter(value=safeCast(phone,int,0))
|
||||
# id = safeCast(phone,'int',0)
|
||||
# for el in list:
|
||||
# id = el.id
|
||||
return ConPhone.objects.filter(value=safeCast(phone,int,0)).values('sys_user__id','sys_user__username')
|
||||
def ConGetUserByPhone(phone):
|
||||
"""Return users associated with all matching phone contacts."""
|
||||
normalized = str(phone).strip()
|
||||
return ConContactPoint.objects.filter(
|
||||
type=ConContactPointType.PHONE,
|
||||
normalized_value=normalized,
|
||||
is_active=True,
|
||||
).values(
|
||||
"con_person__sys_user__id",
|
||||
"con_person__sys_user__username",
|
||||
)
|
||||
|
||||
|
||||
def emailDistr(body_, subject_, user_):
|
||||
|
|
@ -38,7 +43,7 @@ def ConSendEmailMessageToUserListId(title, body, user_list, object_type=None, ob
|
|||
user_name = ''
|
||||
try:
|
||||
if from_user is not None:
|
||||
user_name = from_user.sys_user_info.name
|
||||
user_name = from_user.sys_employee.display_name
|
||||
except:
|
||||
None
|
||||
if user_name != '':
|
||||
|
|
@ -59,7 +64,7 @@ def ConSendTelegramMessageToUserListId( body, user_list, object_type=None, objec
|
|||
user_name = ''
|
||||
try:
|
||||
if from_user is not None:
|
||||
user_name = from_user.sys_user_info.name
|
||||
user_name = from_user.sys_employee.display_name
|
||||
except:
|
||||
None
|
||||
if user_name != '':
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ from datetime import datetime, timedelta
|
|||
import pytz
|
||||
|
||||
from ..models.modelInc import IncIncident, IncCi, IncComment
|
||||
from ..models.modelInc import IncStatus, IncSubcategory, IncImpact, IncPriority, IncGroup, IncEmployee, IncSourceType, IncGetPreferenceValue
|
||||
from ..models.modelInc import IncStatus, IncSubcategory, IncImpact, IncPriority, IncGroup, IncSourceType, IncGetPreferenceValue
|
||||
from ..models.modelSys import SysModuleMembership
|
||||
from ..models.modelInc import IncIncidentNotify, IncIncidentNotifyField, IncCommentNotify, IncCommentNotifyField
|
||||
|
||||
from ..filters.filterInc import IncIncidentFilter, IncCommentFilter
|
||||
|
|
@ -212,7 +213,7 @@ def IncIncidentSendNotify(idInc_, iscreate):
|
|||
dict_["inc_source_type"] = dict(tmp_dict_)
|
||||
|
||||
if instance.inc_employee is not None:
|
||||
tmp_dict_ = model_to_dict(instance.inc_employee, fields=('id', 'name'))
|
||||
tmp_dict_ = {"id": instance.inc_employee_id, "name": instance.inc_employee.name}
|
||||
dictp_['inc_employee__id'] = tmp_dict_['id']
|
||||
dictp_['inc_employee__name'] = tmp_dict_['name']
|
||||
dict_["inc_employee"] = dict(tmp_dict_)
|
||||
|
|
@ -266,8 +267,8 @@ def IncIncidentSendNotify(idInc_, iscreate):
|
|||
if (notify_el['is_group'] == True):
|
||||
grp_list_id = []
|
||||
try:
|
||||
grp_list_id = list(IncEmployee.objects.filter(
|
||||
inc_group__id=inst.inc_group.id).values_list('sys_user__id', flat=True))
|
||||
grp_list_id = list(SysModuleMembership.objects.filter(module_id=MANAGMENT_INC,
|
||||
inc_group__id=inst.inc_group.id).values_list('employee__sys_user__id', flat=True))
|
||||
except Exception as e:
|
||||
None
|
||||
grp_list_tmp = grp_list_id.copy()
|
||||
|
|
@ -282,8 +283,8 @@ def IncIncidentSendNotify(idInc_, iscreate):
|
|||
if (notify_el['is_leader'] == True):
|
||||
man_list_id = []
|
||||
try:
|
||||
man_list_id = list(IncEmployee.objects.filter(
|
||||
is_leader=True).values_list('sys_user__id', flat=True))
|
||||
man_list_id = list(SysModuleMembership.objects.filter(module_id=MANAGMENT_INC,
|
||||
profiles__code="manager").values_list('employee__sys_user__id', flat=True))
|
||||
except Exception as e:
|
||||
None
|
||||
man_list_tmp = man_list_id.copy()
|
||||
|
|
@ -384,8 +385,10 @@ def IncCommentSendNotify(idCom_, iscreate):
|
|||
dict_["inc_source_type"] = dict(tmp_dict_)
|
||||
|
||||
if instance.inc_incident.inc_employee is not None:
|
||||
tmp_dict_ = model_to_dict(
|
||||
instance.inc_incident.inc_employee, fields=('id', 'name'))
|
||||
tmp_dict_ = {
|
||||
"id": instance.inc_incident.inc_employee_id,
|
||||
"name": instance.inc_incident.inc_employee.name,
|
||||
}
|
||||
dictp_['inc_incident__inc_employee__id'] = tmp_dict_['id']
|
||||
dictp_['inc_incident__inc_employee__name'] = tmp_dict_['name']
|
||||
dict_["inc_employee"] = dict(tmp_dict_)
|
||||
|
|
@ -440,8 +443,8 @@ def IncCommentSendNotify(idCom_, iscreate):
|
|||
if (notify_el['is_group'] == True):
|
||||
grp_list_id = []
|
||||
try:
|
||||
grp_list_id = list(IncEmployee.objects.filter(
|
||||
inc_group__id=inst.inc_incident.inc_group.id).values_list('sys_user__id', flat=True))
|
||||
grp_list_id = list(SysModuleMembership.objects.filter(module_id=MANAGMENT_INC,
|
||||
inc_group__id=inst.inc_incident.inc_group.id).values_list('employee__sys_user__id', flat=True))
|
||||
except Exception as e:
|
||||
None
|
||||
grp_list_tmp = grp_list_id.copy()
|
||||
|
|
@ -456,8 +459,8 @@ def IncCommentSendNotify(idCom_, iscreate):
|
|||
if (notify_el['is_leader'] == True):
|
||||
man_list_id = []
|
||||
try:
|
||||
man_list_id = list(IncEmployee.objects.filter(
|
||||
is_leader=True).values_list('sys_user__id', flat=True))
|
||||
man_list_id = list(SysModuleMembership.objects.filter(module_id=MANAGMENT_INC,
|
||||
profiles__code="manager").values_list('employee__sys_user__id', flat=True))
|
||||
except Exception as e:
|
||||
None
|
||||
man_list_tmp = man_list_id.copy()
|
||||
|
|
|
|||
|
|
@ -8,11 +8,12 @@ from django.forms.models import model_to_dict
|
|||
from ..cast import safeCast
|
||||
from ..apps_preference import get_prefix_object
|
||||
|
||||
from ..models.modelReq import ReqDepend, ReqRequest, ReqRequestSla, ReqStatus, ReqSourceType, ReqCriticality, ReqComment, ReqGetPreferenceValue, ReqEmployee
|
||||
from ..models.modelReq import ReqDepend, ReqRequest, ReqRequestSla, ReqStatus, ReqSourceType, ReqCriticality, ReqComment, ReqGetPreferenceValue
|
||||
from ..models.modelSys import SysModuleMembership
|
||||
from ..models.modelReq import ReqRequestNotify, ReqRequestNotifyField, ReqCommentNotify, ReqCommentNotifyField
|
||||
from ..filters.filterReq import ReqRequestNotifyFilter, ReqRequestNotifyFieldFilter, ReqRequestFilter, ReqCommentFilter
|
||||
|
||||
from ..models.modelCon import ConPhone, ConEmail, ConTelegram
|
||||
from ..models.modelCon import ConContactPoint, ConContactPointType
|
||||
from ..models.modelCrm import CrmClient
|
||||
from ..models.modelSrv import SrvService
|
||||
from django.contrib.auth.models import User
|
||||
|
|
@ -23,17 +24,29 @@ from .funcSrv import SrvGetServiceByCiList
|
|||
from .funcCon import ConSendAppMessageToUserListId, ConSendEmailMessageToUserListId, ConSendTelegramMessageToUserListId
|
||||
|
||||
from ..global_constants import MMANAGMENT_SYS, MANAGMENT_CON, MANAGMENT_EMP, MANAGMENT_ADR, MANAGMENT_CRM, MANAGMENT_SRV
|
||||
from ..global_constants import MANAGMENT_DEV, MANAGMENT_CI, MANAGMENT_REQ, MANAGMENT_INC, MANAGMENT_SLA
|
||||
from ..global_constants import MANAGMENT_DEV, MANAGMENT_CI, MANAGMENT_REQ, MANAGMENT_INC, MANAGMENT_SLA
|
||||
|
||||
|
||||
def _find_client_by_contact(contact_type, value):
|
||||
"""Resolve a CRM client through an active normalized contact."""
|
||||
normalized = str(value).strip()
|
||||
if contact_type == ConContactPointType.EMAIL:
|
||||
normalized = normalized.lower()
|
||||
contact = ConContactPoint.objects.filter(
|
||||
type=contact_type,
|
||||
normalized_value=normalized,
|
||||
is_active=True,
|
||||
con_person__sys_user__isnull=False,
|
||||
).select_related("con_person__sys_user").first()
|
||||
if contact is None:
|
||||
return None
|
||||
return CrmClient.objects.filter(sys_user=contact.con_person.sys_user).first()
|
||||
|
||||
|
||||
def ReqCreateFromPhone(senderid, recieverid, user):
|
||||
client_obj = None
|
||||
try:
|
||||
phone_ = ConPhone.objects.filter(
|
||||
value=safeCast(senderid, int, 0)).first()
|
||||
if phone_ is not None:
|
||||
client_obj = CrmClient.objects.filter(
|
||||
user_id=phone_.sys_user.id).first()
|
||||
client_obj = _find_client_by_contact(ConContactPointType.PHONE, senderid)
|
||||
except Exception as e:
|
||||
None
|
||||
|
||||
|
|
@ -81,10 +94,7 @@ def ReqCreateFromPhone(senderid, recieverid, user):
|
|||
def ReqCreateFromEmail(senderid, title, text, user):
|
||||
client_obj = None
|
||||
try:
|
||||
email_ = ConEmail.objects.filter(value=senderid).first()
|
||||
if email_ is not None:
|
||||
client_obj = CrmClient.objects.filter(
|
||||
user__id=email_.sys_user.id).first()
|
||||
client_obj = _find_client_by_contact(ConContactPointType.EMAIL, senderid)
|
||||
except Exception as e:
|
||||
None
|
||||
|
||||
|
|
@ -148,10 +158,7 @@ def ReqCreateFromEmail(senderid, title, text, user):
|
|||
def ReqCreateFromtTelegram(senderid, recieverid, text):
|
||||
client_obj = None
|
||||
try:
|
||||
telegram_ = ConTelegram.objects.filter(value=senderid).first()
|
||||
if telegram_ is not None:
|
||||
client_obj = CrmClient.objects.filter(
|
||||
user__id=telegram_.sys_user.id).first()
|
||||
client_obj = _find_client_by_contact(ConContactPointType.TELEGRAM, senderid)
|
||||
except Exception as e:
|
||||
None
|
||||
|
||||
|
|
@ -311,11 +318,10 @@ def ReqRequestSendNotify(idReq_, iscreate):
|
|||
instance.req_source_type, fields=('id', 'name'))
|
||||
|
||||
if instance.req_employee is not None:
|
||||
tmp_dict_ = model_to_dict(instance.req_employee, fields=('id', 'name'))
|
||||
tmp_dict_ = {"id": instance.req_employee_id, "name": instance.req_employee.name}
|
||||
dictp_['req_employee__id'] = tmp_dict_['id']
|
||||
dictp_['req_employee__name'] = tmp_dict_['name']
|
||||
dict_["req_employee"] = model_to_dict(
|
||||
instance.req_employee, fields=('id', 'name'))
|
||||
dict_["req_employee"] = dict(tmp_dict_)
|
||||
|
||||
notify_list = ReqRequestNotify.objects.filter(Q(is_oncreate=iscreate) | ~Q(is_onupdate=iscreate)).values('id', 'name', 'title', 'body', 'is_app', 'is_email', 'is_telegram', 'is_employee', 'is_group', 'is_leader', 'is_client', 'is_notify_author', 'is_oncreate', 'is_onupdate'
|
||||
)
|
||||
|
|
@ -360,8 +366,8 @@ def ReqRequestSendNotify(idReq_, iscreate):
|
|||
if (notify_el['is_leader'] == True):
|
||||
man_list_id = []
|
||||
try:
|
||||
man_list_id = list(ReqEmployee.objects.filter(
|
||||
is_leader=True).values_list('sys_user__id', flat=True))
|
||||
man_list_id = list(SysModuleMembership.objects.filter(module_id=MANAGMENT_REQ,
|
||||
profiles__code="manager").values_list('employee__sys_user__id', flat=True))
|
||||
except Exception as e:
|
||||
None
|
||||
man_list_tmp = man_list_id.copy()
|
||||
|
|
@ -454,8 +460,10 @@ def ReqCommentSendNotify(idCom_, iscreate):
|
|||
dict_["req_source_type"] = dict(tmp_dict_)
|
||||
|
||||
if instance.req_request.req_employee is not None:
|
||||
tmp_dict_ = model_to_dict(
|
||||
instance.req_request.req_employee, fields=('id', 'name'))
|
||||
tmp_dict_ = {
|
||||
"id": instance.req_request.req_employee_id,
|
||||
"name": instance.req_request.req_employee.name,
|
||||
}
|
||||
dictp_['req_request__req_employee__id'] = tmp_dict_['id']
|
||||
dictp_['req_request__req_employee__name'] = tmp_dict_['name']
|
||||
dict_["req_employee"] = dict(tmp_dict_)
|
||||
|
|
@ -503,8 +511,8 @@ def ReqCommentSendNotify(idCom_, iscreate):
|
|||
if (notify_el['is_leader'] == True):
|
||||
man_list_id = []
|
||||
try:
|
||||
man_list_id = list(ReqEmployee.objects.filter(
|
||||
is_leader=True).values_list('sys_user__id', flat=True))
|
||||
man_list_id = list(SysModuleMembership.objects.filter(module_id=MANAGMENT_REQ,
|
||||
profiles__code="manager").values_list('employee__sys_user__id', flat=True))
|
||||
except Exception as e:
|
||||
None
|
||||
man_list_tmp = man_list_id.copy()
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from wanitil.models.modelDev import DevHardwareVersion, DevManufacturer, DevMode
|
|||
from wanitil.models.modelSla import SlaRequestAgreement, SlaRequestStatus
|
||||
from ..models.modelSys import SysModuleSettings, SysGetPreferenceValue, SysSetting
|
||||
from django.contrib.auth.models import User
|
||||
from wanitil.models.modelSys import SysRole, SysRoleKit, SysUserProfile, SysView, SysViewField
|
||||
from wanitil.models.modelSys import SysEmployee, SysModuleMembership, SysView, SysViewField
|
||||
from wanitil.models.modelReq import ReqStatus, ReqStatusTransit, ReqCriticality, ReqSourceType, ReqSettings
|
||||
from wanitil.models.modelInc import IncStatus, IncStatusTransit, IncSourceType, IncSettings, IncImpact, IncPriority
|
||||
from wanitil.models.modelCon import ConSettings
|
||||
|
|
@ -82,7 +82,7 @@ def clearSystem():
|
|||
from wanitil.models.modelInc import IncCommentNotifyField, IncCommentNotify, IncCommentFile, IncComment
|
||||
from wanitil.models.modelInc import IncIncidentNotifyField, IncIncidentNotify, IncIncidentFile
|
||||
from wanitil.models.modelInc import IncCi, IncIncident, IncIncidentHistorical
|
||||
from wanitil.models.modelInc import IncEmployee, IncGroup
|
||||
from wanitil.models.modelInc import IncGroup
|
||||
from wanitil.models.modelInc import IncCategory, IncImpact, IncPriority, IncSolution, IncSourceType, IncSubcategory, IncStatusTransit, IncStatus
|
||||
from wanitil.models.modelInc import IncSettings
|
||||
|
||||
|
|
@ -108,7 +108,7 @@ def clearSystem():
|
|||
del_cnt, _ = IncStatus.objects.all().delete()
|
||||
del_cnt, _ = IncSourceType.objects.all().delete()
|
||||
|
||||
del_cnt, _ = IncEmployee.objects.all().delete()
|
||||
del_cnt, _ = SysModuleMembership.objects.filter(module_id=11200).delete()
|
||||
del_cnt, _ = IncGroup.objects.all().delete()
|
||||
|
||||
|
||||
|
|
@ -116,7 +116,6 @@ def clearSystem():
|
|||
from wanitil.models.modelReq import ReqRequestNotifyField, ReqRequestNotify, ReqRequestFile
|
||||
from wanitil.models.modelReq import ReqRequest, ReqRequestHistorical, ReqDepend
|
||||
from wanitil.models.modelReq import ReqCriticality, ReqSourceType, ReqStatusTransit, ReqStatus
|
||||
from wanitil.models.modelReq import ReqEmployee
|
||||
from wanitil.models.modelReq import ReqSettings
|
||||
|
||||
del_cnt, _ = ReqCommentNotifyField.objects.all().delete()
|
||||
|
|
@ -131,7 +130,7 @@ def clearSystem():
|
|||
del_cnt, _ = ReqRequest.objects.all().delete()
|
||||
del_cnt, _ = ReqRequestHistorical.objects.all().delete()
|
||||
|
||||
del_cnt, _ = ReqEmployee.objects.all().delete()
|
||||
del_cnt, _ = SysModuleMembership.objects.filter(module_id=11100).delete()
|
||||
|
||||
del_cnt, _ = ReqSettings.objects.all().delete()
|
||||
del_cnt, _ = ReqCriticality.objects.all().delete()
|
||||
|
|
@ -172,7 +171,7 @@ def clearSystem():
|
|||
|
||||
from wanitil.models.modelCon import ConAppSend, ConEmailSend, ConTelegramSend
|
||||
from wanitil.models.modelCon import ConAppMessage, ConTelegramMessage,ConEmailMessage
|
||||
from wanitil.models.modelCon import ConEmail, ConPhone, ConTelegram, ConTelegramRegister
|
||||
from wanitil.models.modelCon import ConContactPoint, ConParty, ConTelegramRegister
|
||||
from wanitil.models.modelCon import ConSettings
|
||||
|
||||
del_cnt, _ = ConAppSend.objects.all().delete()
|
||||
|
|
@ -181,10 +180,9 @@ def clearSystem():
|
|||
del_cnt, _ = ConAppMessage.objects.all().delete()
|
||||
del_cnt, _ = ConTelegramMessage.objects.all().delete()
|
||||
del_cnt, _ = ConEmailMessage.objects.all().delete()
|
||||
del_cnt, _ = ConEmail.objects.all().delete()
|
||||
del_cnt, _ = ConPhone.objects.all().delete()
|
||||
del_cnt, _ = ConContactPoint.objects.all().delete()
|
||||
del_cnt, _ = ConTelegramRegister.objects.all().delete()
|
||||
del_cnt, _ = ConTelegram.objects.all().delete()
|
||||
del_cnt, _ = ConParty.objects.all().delete()
|
||||
del_cnt, _ = ConSettings.objects.all().delete()
|
||||
|
||||
from wanitil.models.modelAdr import AdrZone, AdrZoneType
|
||||
|
|
@ -209,17 +207,15 @@ def clearSystem():
|
|||
|
||||
|
||||
from wanitil.models.modelSys import SysHolidayElement, SysHolidayGroup
|
||||
from wanitil.models.modelSys import SysUserProfile, SysUserInfo, SysUserNotify
|
||||
from wanitil.models.modelSys import SysEmployee, SysUserNotify
|
||||
from wanitil.models.modelSys import SysViewField, SysView
|
||||
from wanitil.models.modelSys import SysFieldSearch, SysField, SysObject, SysManagment
|
||||
from wanitil.models.modelSys import SysRoleKit, SysRole
|
||||
from wanitil.models.modelSys import SysModuleSettings,SysSetting
|
||||
from wanitil.models.modelSys import SysContactType
|
||||
|
||||
del_cnt, _ = SysHolidayElement.objects.all().delete()
|
||||
del_cnt, _ = SysHolidayGroup.objects.all().delete()
|
||||
del_cnt, _ = SysUserProfile.objects.filter(sys_user__id__gte=USER_SYSTEM_MAX_ID).delete()
|
||||
del_cnt, _ = SysUserInfo.objects.filter(sys_user__id__gte=USER_SYSTEM_MAX_ID).delete()
|
||||
del_cnt, _ = SysEmployee.objects.filter(sys_user__id__gte=USER_SYSTEM_MAX_ID).delete()
|
||||
del_cnt, _ = SysUserNotify.objects.filter(sys_user__id__gte=USER_SYSTEM_MAX_ID).delete()
|
||||
del_cnt, _ = User.objects.filter(id__gte=USER_SYSTEM_MAX_ID).delete()
|
||||
del_cnt, _ = SysModuleSettings.objects.all().delete()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,175 @@
|
|||
from collections import defaultdict
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db import transaction
|
||||
from django.db.models import Q
|
||||
from django.utils import timezone
|
||||
|
||||
from ..models.modelSys import SysModuleAccessProfile, SysModuleMembership
|
||||
|
||||
|
||||
def _resolve_employee(user_or_employee):
|
||||
"""Resolve either a SysEmployee or an authenticated Django user."""
|
||||
|
||||
from ..models.modelSys import SysEmployee
|
||||
|
||||
if isinstance(user_or_employee, SysEmployee):
|
||||
return user_or_employee
|
||||
if isinstance(user_or_employee, get_user_model()):
|
||||
try:
|
||||
return user_or_employee.sys_employee
|
||||
except SysEmployee.DoesNotExist as exc:
|
||||
raise ValueError("User does not have an employee record") from exc
|
||||
raise TypeError("Expected a SysEmployee or Django user")
|
||||
|
||||
|
||||
@transaction.atomic
|
||||
def apply_access_profiles(user_or_employee, profiles, *, replace=False):
|
||||
"""Apply profiles, creating one membership per affected module.
|
||||
|
||||
When ``replace`` is true, the supplied profiles replace the complete profile
|
||||
collection in each affected module. Memberships in other modules are kept.
|
||||
"""
|
||||
|
||||
employee = _resolve_employee(user_or_employee)
|
||||
profile_list = list(profiles)
|
||||
profiles_by_module = defaultdict(list)
|
||||
for profile in profile_list:
|
||||
if not isinstance(profile, SysModuleAccessProfile):
|
||||
raise TypeError("profiles must contain SysModuleAccessProfile objects")
|
||||
if not profile.is_active:
|
||||
raise ValueError(f"Access profile {profile.code!r} is inactive")
|
||||
profiles_by_module[profile.module_id].append(profile)
|
||||
|
||||
memberships = []
|
||||
for module_id, module_profiles in profiles_by_module.items():
|
||||
membership, _ = SysModuleMembership.objects.select_for_update().get_or_create(
|
||||
employee=employee,
|
||||
module_id=module_id,
|
||||
defaults={"is_active": True},
|
||||
)
|
||||
changed_fields = []
|
||||
if not membership.is_active:
|
||||
membership.is_active = True
|
||||
changed_fields.append("is_active")
|
||||
if changed_fields:
|
||||
membership.save(update_fields=changed_fields + ["updated_at"])
|
||||
if replace:
|
||||
membership.profiles.set(module_profiles)
|
||||
else:
|
||||
membership.profiles.add(*module_profiles)
|
||||
memberships.append(membership)
|
||||
return memberships
|
||||
|
||||
|
||||
def apply_access_profile(user_or_employee, profile, *, replace=False):
|
||||
"""Apply one access profile and return its module membership."""
|
||||
|
||||
return apply_access_profiles(
|
||||
user_or_employee, [profile], replace=replace,
|
||||
)[0]
|
||||
|
||||
|
||||
@transaction.atomic
|
||||
def revoke_access_profiles(user_or_employee, profiles):
|
||||
"""Remove profiles and deactivate memberships which become empty."""
|
||||
|
||||
employee = _resolve_employee(user_or_employee)
|
||||
profile_list = list(profiles)
|
||||
profiles_by_module = defaultdict(list)
|
||||
for profile in profile_list:
|
||||
if not isinstance(profile, SysModuleAccessProfile):
|
||||
raise TypeError("profiles must contain SysModuleAccessProfile objects")
|
||||
profiles_by_module[profile.module_id].append(profile)
|
||||
|
||||
memberships = []
|
||||
for module_id, module_profiles in profiles_by_module.items():
|
||||
membership = SysModuleMembership.objects.select_for_update().filter(
|
||||
employee=employee, module_id=module_id,
|
||||
).first()
|
||||
if membership is None:
|
||||
continue
|
||||
membership.profiles.remove(*module_profiles)
|
||||
if not membership.profiles.exists() and membership.is_active:
|
||||
membership.is_active = False
|
||||
membership.save(update_fields=("is_active", "updated_at"))
|
||||
memberships.append(membership)
|
||||
return memberships
|
||||
|
||||
|
||||
def user_has_module_profile(user, module_id, profile_code=None):
|
||||
"""Return whether a user has an active, currently valid membership."""
|
||||
|
||||
now = timezone.now()
|
||||
memberships = SysModuleMembership.objects.filter(
|
||||
employee__sys_user=user,
|
||||
employee__is_active=True,
|
||||
module_id=module_id,
|
||||
is_active=True,
|
||||
profiles__is_active=True,
|
||||
).filter(
|
||||
Q(valid_from__isnull=True) | Q(valid_from__lte=now),
|
||||
Q(valid_until__isnull=True) | Q(valid_until__gte=now),
|
||||
)
|
||||
if profile_code is not None:
|
||||
memberships = memberships.filter(profiles__code=profile_code)
|
||||
return memberships.exists()
|
||||
|
||||
|
||||
def get_user_module_membership(user, module_id):
|
||||
if not getattr(user, "is_authenticated", False):
|
||||
return None
|
||||
return SysModuleMembership.objects.filter(
|
||||
employee__sys_user=user, module_id=module_id, is_active=True,
|
||||
).select_related("employee", "employee__sys_user").first()
|
||||
|
||||
|
||||
def get_user_permission_codes(user):
|
||||
"""Return atomic permissions granted by active employee memberships."""
|
||||
|
||||
if not getattr(user, "is_authenticated", False):
|
||||
return set()
|
||||
if getattr(user, "is_superuser", False):
|
||||
return {("*", "*", "*")}
|
||||
cached = getattr(user, "_wanitil_permission_codes", None)
|
||||
if cached is not None:
|
||||
return cached
|
||||
now = timezone.now()
|
||||
grants = set(
|
||||
SysModuleMembership.objects.filter(
|
||||
employee__sys_user=user,
|
||||
employee__is_active=True,
|
||||
is_active=True,
|
||||
profiles__is_active=True,
|
||||
profiles__permissions__isnull=False,
|
||||
).filter(
|
||||
Q(valid_from__isnull=True) | Q(valid_from__lte=now),
|
||||
Q(valid_until__isnull=True) | Q(valid_until__gte=now),
|
||||
).values_list(
|
||||
"profiles__permissions__module",
|
||||
"profiles__permissions__action",
|
||||
"profiles__permissions__resource",
|
||||
)
|
||||
)
|
||||
# The Django user instance is request-scoped. This avoids repeating the
|
||||
# same permission query for every permission class without stale global
|
||||
# cache invalidation concerns.
|
||||
user._wanitil_permission_codes = grants
|
||||
return grants
|
||||
|
||||
|
||||
def user_has_permission_code(user, code):
|
||||
"""Check an exact code, supporting ``*`` wildcards in granted codes."""
|
||||
|
||||
try:
|
||||
module, action, resource = code.split(":")
|
||||
except ValueError:
|
||||
return False
|
||||
grants = get_user_permission_codes(user)
|
||||
candidates = {
|
||||
(module, action, resource), (module, action, "*"),
|
||||
(module, "*", resource), (module, "*", "*"),
|
||||
("*", action, resource), ("*", action, "*"),
|
||||
("*", "*", resource), ("*", "*", "*"),
|
||||
}
|
||||
return bool(grants.intersection(candidates))
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
sys_user
|
||||
sys_user_profile
|
||||
sys_user
|
||||
sys_employee
|
||||
sys_managment
|
||||
sys_object
|
||||
sys_field
|
||||
|
|
@ -33,4 +33,4 @@ adr_region
|
|||
adr_area
|
||||
adr_area_type
|
||||
adr_zone
|
||||
adr_zone_type
|
||||
adr_zone_type
|
||||
|
|
|
|||
|
|
@ -1,93 +1,4 @@
|
|||
##ROLES
|
||||
ROLE_ADMIN = 1
|
||||
ROLE_CLIENT = 11
|
||||
ROLE_SYS_MAN = 1000
|
||||
ROLE_SYS_USER_R = 1012
|
||||
ROLE_SYS_USER_W = 1013
|
||||
ROLE_SYS_PREF_R = 1022
|
||||
ROLE_SYS_PREF_W = 1023
|
||||
ROLE_SYS_SYSTEM_PREF_R = 1026
|
||||
ROLE_SYS_SYSTEM_PREF_W = 1027
|
||||
ROLE_SYS_SYSTEM_USER_R = 1052
|
||||
ROLE_SYS_SYSTEM_USER_W = 1053
|
||||
|
||||
ROLE_REP_MAN = 1500
|
||||
ROLE_REP_USER_R = 1512
|
||||
ROLE_REP_USER_W = 1513
|
||||
ROLE_REP_PREF_R = 1522
|
||||
ROLE_REP_PREF_W = 1523
|
||||
|
||||
ROLE_CON_MAN = 1100
|
||||
ROLE_CON_USER_R = 1112
|
||||
ROLE_CON_USER_W = 1113
|
||||
ROLE_CON_PREF_R = 1122
|
||||
ROLE_CON_PREF_W = 1123
|
||||
ROLE_CON_REP_R = 1126
|
||||
ROLE_CON_REP_W = 1127
|
||||
ROLE_ADR_MAN = 2100
|
||||
ROLE_ADR_USER_R = 2112
|
||||
ROLE_ADR_USER_W = 2113
|
||||
ROLE_ADR_PREF_R = 2122
|
||||
ROLE_ADR_PREF_W = 2123
|
||||
ROLE_ADR_REP_R = 2126
|
||||
ROLE_ADR_REP_W = 2127
|
||||
ROLE_CRM_MAN = 3100
|
||||
ROLE_CRM_USER_R = 3112
|
||||
ROLE_CRM_USER_W = 3113
|
||||
ROLE_CRM_PREF_R = 3122
|
||||
ROLE_CRM_PREF_W = 3123
|
||||
ROLE_CRM_REP_R = 3126
|
||||
ROLE_CRM_REP_W = 3127
|
||||
ROLE_SRV_MAN = 3200
|
||||
ROLE_SRV_USER_R = 3212
|
||||
ROLE_SRV_USER_W = 3213
|
||||
ROLE_SRV_PREF_R = 3222
|
||||
ROLE_SRV_PREF_W = 3223
|
||||
ROLE_SRV_REP_R = 3226
|
||||
ROLE_SRV_REP_W = 3227
|
||||
ROLE_DEV_MAN = 4100
|
||||
ROLE_DEV_USER_R = 4112
|
||||
ROLE_DEV_USER_W = 4113
|
||||
ROLE_DEV_PREF_R = 4122
|
||||
ROLE_DEV_PREF_W = 4123
|
||||
ROLE_DEV_REP_R = 4126
|
||||
ROLE_DEV_REP_W = 4127
|
||||
ROLE_CIM_MAN = 4200
|
||||
ROLE_CIM_USER_R = 4212
|
||||
ROLE_CIM_USER_W = 4213
|
||||
ROLE_CIM_PREF_R = 4222
|
||||
ROLE_CIM_PREF_W = 4223
|
||||
ROLE_CIM_REP_R = 4226
|
||||
ROLE_CIM_REP_W = 4227
|
||||
ROLE_REQ_MAN = 11100
|
||||
ROLE_REQ_USER_R = 11112
|
||||
ROLE_REQ_USER_W = 11113
|
||||
ROLE_REQ_PREF_R = 11122
|
||||
ROLE_REQ_PREF_W = 11123
|
||||
ROLE_REQ_REP_R = 11126
|
||||
ROLE_REQ_REP_W = 11137
|
||||
ROLE_REQ_EMP_R = 11132
|
||||
ROLE_REQ_EMP_W = 11133
|
||||
ROLE_INC_MAN = 11200
|
||||
ROLE_INC_USER_R = 11212
|
||||
ROLE_INC_USER_W = 11213
|
||||
ROLE_INC_PREF_R = 11222
|
||||
ROLE_INC_PREF_W = 11223
|
||||
ROLE_INC_REP_R = 11226
|
||||
ROLE_INC_REP_W = 11237
|
||||
ROLE_INC_EMP_R = 11232
|
||||
ROLE_INC_EMP_W = 11233
|
||||
ROLE_SLA_MAN = 21100
|
||||
ROLE_SLA_USER_R = 21112
|
||||
ROLE_SLA_USER_W = 21113
|
||||
ROLE_SLA_PREF_R = 21122
|
||||
ROLE_SLA_PREF_W = 21123
|
||||
ROLE_SLA_REP_R = 21126
|
||||
ROLE_SLA_REP_W = 21137
|
||||
ROLE_SLA_EMP_R = 21132
|
||||
ROLE_SLA_EMP_W = 21133
|
||||
|
||||
##MANAGMENTS
|
||||
##MANAGMENTS
|
||||
MMANAGMENT_SYS = 1000
|
||||
|
||||
MANAGMENT_CON = 1100
|
||||
|
|
@ -141,4 +52,4 @@ SYS_SETTING_DEMO_SETUP = 15 #Demo setup
|
|||
# python manage.py runscript demo.demo
|
||||
|
||||
USER_SERVICE = 'service'
|
||||
USER_SYSTEM_MAX_ID = 1000
|
||||
USER_SYSTEM_MAX_ID = 1000
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
"""Liveness and readiness probes for container orchestration."""
|
||||
|
||||
from django.db import connection
|
||||
from django.http import JsonResponse
|
||||
from django.views.decorators.cache import never_cache
|
||||
|
||||
|
||||
@never_cache
|
||||
def live(request):
|
||||
return JsonResponse({"status": "ok"})
|
||||
|
||||
|
||||
@never_cache
|
||||
def ready(request):
|
||||
try:
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute("SELECT 1")
|
||||
cursor.fetchone()
|
||||
except Exception:
|
||||
return JsonResponse({"status": "unavailable"}, status=503)
|
||||
return JsonResponse({"status": "ok"})
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue