Files
dify/api/controllers/console/app/site.py
T
+40 5bbf685035 feat: fix i18n missing keys and merge upstream/main (#24615)
Signed-off-by: -LAN- <[email protected]>
Signed-off-by: kenwoodjw <[email protected]>
Signed-off-by: Yongtao Huang <[email protected]>
Signed-off-by: yihong0618 <[email protected]>
Signed-off-by: zhanluxianshen <[email protected]>
Co-authored-by: -LAN- <[email protected]>
Co-authored-by: GuanMu <[email protected]>
Co-authored-by: Davide Delbianco <[email protected]>
Co-authored-by: NeatGuyCoding <[email protected]>
Co-authored-by: kenwoodjw <[email protected]>
Co-authored-by: Yongtao Huang <[email protected]>
Co-authored-by: Yongtao Huang <[email protected]>
Co-authored-by: Qiang Lee <[email protected]>
Co-authored-by: 李强04 <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Asuka Minato <[email protected]>
Co-authored-by: Matri Qi <[email protected]>
Co-authored-by: huayaoyue6 <[email protected]>
Co-authored-by: Bowen Liang <[email protected]>
Co-authored-by: znn <[email protected]>
Co-authored-by: crazywoola <[email protected]>
Co-authored-by: crazywoola <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: yihong <[email protected]>
Co-authored-by: Muke Wang <[email protected]>
Co-authored-by: wangmuke <[email protected]>
Co-authored-by: Wu Tianwei <[email protected]>
Co-authored-by: quicksand <[email protected]>
Co-authored-by: 非法操作 <[email protected]>
Co-authored-by: zxhlyh <[email protected]>
Co-authored-by: Eric Guo <[email protected]>
Co-authored-by: Zhedong Cen <[email protected]>
Co-authored-by: jiangbo721 <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: hjlarry <[email protected]>
Co-authored-by: lxsummer <[email protected]>
Co-authored-by: 湛露先生 <[email protected]>
Co-authored-by: Guangdong Liu <[email protected]>
Co-authored-by: QuantumGhost <[email protected]>
Co-authored-by: Claude <[email protected]>
Co-authored-by: Yessenia-d <[email protected]>
Co-authored-by: huangzhuo1949 <[email protected]>
Co-authored-by: huangzhuo <[email protected]>
Co-authored-by: 17hz <[email protected]>
Co-authored-by: Amy <[email protected]>
Co-authored-by: Joel <[email protected]>
Co-authored-by: Nite Knite <[email protected]>
Co-authored-by: Yeuoly <[email protected]>
Co-authored-by: Petrus Han <[email protected]>
Co-authored-by: iamjoel <[email protected]>
Co-authored-by: Kalo Chin <[email protected]>
Co-authored-by: Ujjwal Maurya <[email protected]>
Co-authored-by: Maries <[email protected]>
2025-08-27 15:07:28 +08:00

111 lines
4.1 KiB
Python

from flask_login import current_user
from flask_restx import Resource, marshal_with, reqparse
from werkzeug.exceptions import Forbidden, NotFound
from constants.languages import supported_language
from controllers.console import api
from controllers.console.app.wraps import get_app_model
from controllers.console.wraps import account_initialization_required, setup_required
from extensions.ext_database import db
from fields.app_fields import app_site_fields
from libs.datetime_utils import naive_utc_now
from libs.login import login_required
from models import Site
def parse_app_site_args():
parser = reqparse.RequestParser()
parser.add_argument("title", type=str, required=False, location="json")
parser.add_argument("icon_type", type=str, required=False, location="json")
parser.add_argument("icon", type=str, required=False, location="json")
parser.add_argument("icon_background", type=str, required=False, location="json")
parser.add_argument("description", type=str, required=False, location="json")
parser.add_argument("default_language", type=supported_language, required=False, location="json")
parser.add_argument("chat_color_theme", type=str, required=False, location="json")
parser.add_argument("chat_color_theme_inverted", type=bool, required=False, location="json")
parser.add_argument("customize_domain", type=str, required=False, location="json")
parser.add_argument("copyright", type=str, required=False, location="json")
parser.add_argument("privacy_policy", type=str, required=False, location="json")
parser.add_argument("custom_disclaimer", type=str, required=False, location="json")
parser.add_argument(
"customize_token_strategy", type=str, choices=["must", "allow", "not_allow"], required=False, location="json"
)
parser.add_argument("prompt_public", type=bool, required=False, location="json")
parser.add_argument("show_workflow_steps", type=bool, required=False, location="json")
parser.add_argument("use_icon_as_answer_icon", type=bool, required=False, location="json")
return parser.parse_args()
class AppSite(Resource):
@setup_required
@login_required
@account_initialization_required
@get_app_model
@marshal_with(app_site_fields)
def post(self, app_model):
args = parse_app_site_args()
# The role of the current user in the ta table must be editor, admin, or owner
if not current_user.is_editor:
raise Forbidden()
site = db.session.query(Site).where(Site.app_id == app_model.id).first()
if not site:
raise NotFound
for attr_name in [
"title",
"icon_type",
"icon",
"icon_background",
"description",
"default_language",
"chat_color_theme",
"chat_color_theme_inverted",
"customize_domain",
"copyright",
"privacy_policy",
"custom_disclaimer",
"customize_token_strategy",
"prompt_public",
"show_workflow_steps",
"use_icon_as_answer_icon",
]:
value = args.get(attr_name)
if value is not None:
setattr(site, attr_name, value)
site.updated_by = current_user.id
site.updated_at = naive_utc_now()
db.session.commit()
return site
class AppSiteAccessTokenReset(Resource):
@setup_required
@login_required
@account_initialization_required
@get_app_model
@marshal_with(app_site_fields)
def post(self, app_model):
# The role of the current user in the ta table must be admin or owner
if not current_user.is_admin_or_owner:
raise Forbidden()
site = db.session.query(Site).where(Site.app_id == app_model.id).first()
if not site:
raise NotFound
site.code = Site.generate_code(16)
site.updated_by = current_user.id
site.updated_at = naive_utc_now()
db.session.commit()
return site
api.add_resource(AppSite, "/apps/<uuid:app_id>/site")
api.add_resource(AppSiteAccessTokenReset, "/apps/<uuid:app_id>/site/access-token-reset")