Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
eb1ea8cf
Commit
eb1ea8cf
authored
Feb 28, 2024
by
takatost
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add app description
add update app api
parent
4b2778b7
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
83 additions
and
4 deletions
+83
-4
app.py
api/controllers/console/app/app.py
+22
-1
app_fields.py
api/fields/app_fields.py
+4
-0
f9107f83abab_add_desc_for_apps.py
api/migrations/versions/f9107f83abab_add_desc_for_apps.py
+32
-0
model.py
api/models/model.py
+3
-1
workflow.py
api/models/workflow.py
+3
-1
app_service.py
api/services/app_service.py
+19
-1
No files found.
api/controllers/console/app/app.py
View file @
eb1ea8cf
from
flask_login
import
current_user
from
flask_restful
import
Resource
,
abort
,
inputs
,
marshal_with
,
reqparse
from
flask_restful
import
Resource
,
inputs
,
marshal_with
,
reqparse
from
werkzeug.exceptions
import
Forbidden
,
BadRequest
from
controllers.console
import
api
...
...
@@ -48,6 +48,7 @@ class AppListApi(Resource):
"""Create app"""
parser
=
reqparse
.
RequestParser
()
parser
.
add_argument
(
'name'
,
type
=
str
,
required
=
True
,
location
=
'json'
)
parser
.
add_argument
(
'description'
,
type
=
str
,
location
=
'json'
)
parser
.
add_argument
(
'mode'
,
type
=
str
,
choices
=
ALLOW_CREATE_APP_MODES
,
location
=
'json'
)
parser
.
add_argument
(
'icon'
,
type
=
str
,
location
=
'json'
)
parser
.
add_argument
(
'icon_background'
,
type
=
str
,
location
=
'json'
)
...
...
@@ -81,6 +82,7 @@ class AppImportApi(Resource):
parser
=
reqparse
.
RequestParser
()
parser
.
add_argument
(
'data'
,
type
=
str
,
required
=
True
,
nullable
=
False
,
location
=
'json'
)
parser
.
add_argument
(
'name'
,
type
=
str
,
location
=
'json'
)
parser
.
add_argument
(
'description'
,
type
=
str
,
location
=
'json'
)
parser
.
add_argument
(
'icon'
,
type
=
str
,
location
=
'json'
)
parser
.
add_argument
(
'icon_background'
,
type
=
str
,
location
=
'json'
)
args
=
parser
.
parse_args
()
...
...
@@ -102,6 +104,25 @@ class AppApi(Resource):
"""Get app detail"""
return
app_model
@
setup_required
@
login_required
@
account_initialization_required
@
get_app_model
@
marshal_with
(
app_detail_fields_with_site
)
def
put
(
self
,
app_model
):
"""Update app"""
parser
=
reqparse
.
RequestParser
()
parser
.
add_argument
(
'name'
,
type
=
str
,
required
=
True
,
nullable
=
False
,
location
=
'json'
)
parser
.
add_argument
(
'description'
,
type
=
str
,
location
=
'json'
)
parser
.
add_argument
(
'icon'
,
type
=
str
,
location
=
'json'
)
parser
.
add_argument
(
'icon_background'
,
type
=
str
,
location
=
'json'
)
args
=
parser
.
parse_args
()
app_service
=
AppService
()
app_model
=
app_service
.
update_app
(
app_model
,
args
)
return
app_model
@
setup_required
@
login_required
@
account_initialization_required
...
...
api/fields/app_fields.py
View file @
eb1ea8cf
...
...
@@ -5,6 +5,7 @@ from libs.helper import TimestampField
app_detail_kernel_fields
=
{
'id'
:
fields
.
String
,
'name'
:
fields
.
String
,
'description'
:
fields
.
String
,
'mode'
:
fields
.
String
,
'icon'
:
fields
.
String
,
'icon_background'
:
fields
.
String
,
...
...
@@ -41,6 +42,7 @@ model_config_fields = {
app_detail_fields
=
{
'id'
:
fields
.
String
,
'name'
:
fields
.
String
,
'description'
:
fields
.
String
,
'mode'
:
fields
.
String
,
'icon'
:
fields
.
String
,
'icon_background'
:
fields
.
String
,
...
...
@@ -62,6 +64,7 @@ model_config_partial_fields = {
app_partial_fields
=
{
'id'
:
fields
.
String
,
'name'
:
fields
.
String
,
'description'
:
fields
.
String
,
'mode'
:
fields
.
String
,
'icon'
:
fields
.
String
,
'icon_background'
:
fields
.
String
,
...
...
@@ -109,6 +112,7 @@ site_fields = {
app_detail_fields_with_site
=
{
'id'
:
fields
.
String
,
'name'
:
fields
.
String
,
'description'
:
fields
.
String
,
'mode'
:
fields
.
String
,
'icon'
:
fields
.
String
,
'icon_background'
:
fields
.
String
,
...
...
api/migrations/versions/f9107f83abab_add_desc_for_apps.py
0 → 100644
View file @
eb1ea8cf
"""add desc for apps
Revision ID: f9107f83abab
Revises: cc04d0998d4d
Create Date: 2024-02-28 08:16:14.090481
"""
from
alembic
import
op
import
sqlalchemy
as
sa
# revision identifiers, used by Alembic.
revision
=
'f9107f83abab'
down_revision
=
'cc04d0998d4d'
branch_labels
=
None
depends_on
=
None
def
upgrade
():
# ### commands auto generated by Alembic - please adjust! ###
with
op
.
batch_alter_table
(
'apps'
,
schema
=
None
)
as
batch_op
:
batch_op
.
add_column
(
sa
.
Column
(
'description'
,
sa
.
Text
(),
server_default
=
sa
.
text
(
"''::character varying"
),
nullable
=
False
))
# ### end Alembic commands ###
def
downgrade
():
# ### commands auto generated by Alembic - please adjust! ###
with
op
.
batch_alter_table
(
'apps'
,
schema
=
None
)
as
batch_op
:
batch_op
.
drop_column
(
'description'
)
# ### end Alembic commands ###
api/models/model.py
View file @
eb1ea8cf
...
...
@@ -14,7 +14,6 @@ from extensions.ext_database import db
from
libs.helper
import
generate_string
from
.account
import
Account
,
Tenant
from
.workflow
import
Workflow
,
WorkflowRun
class
DifySetup
(
db
.
Model
):
...
...
@@ -59,6 +58,7 @@ class App(db.Model):
id
=
db
.
Column
(
UUID
,
server_default
=
db
.
text
(
'uuid_generate_v4()'
))
tenant_id
=
db
.
Column
(
UUID
,
nullable
=
False
)
name
=
db
.
Column
(
db
.
String
(
255
),
nullable
=
False
)
description
=
db
.
Column
(
db
.
Text
,
nullable
=
False
,
server_default
=
db
.
text
(
"''::character varying"
))
mode
=
db
.
Column
(
db
.
String
(
255
),
nullable
=
False
)
icon
=
db
.
Column
(
db
.
String
(
255
))
icon_background
=
db
.
Column
(
db
.
String
(
255
))
...
...
@@ -279,6 +279,7 @@ class AppModelConfig(db.Model):
@
property
def
workflow
(
self
):
if
self
.
workflow_id
:
from
api.models.workflow
import
Workflow
return
db
.
session
.
query
(
Workflow
)
.
filter
(
Workflow
.
id
==
self
.
workflow_id
)
.
first
()
return
None
...
...
@@ -692,6 +693,7 @@ class Message(db.Model):
@
property
def
workflow_run
(
self
):
if
self
.
workflow_run_id
:
from
api.models.workflow
import
WorkflowRun
return
db
.
session
.
query
(
WorkflowRun
)
.
filter
(
WorkflowRun
.
id
==
self
.
workflow_run_id
)
.
first
()
return
None
...
...
api/models/workflow.py
View file @
eb1ea8cf
...
...
@@ -5,7 +5,6 @@ from sqlalchemy.dialects.postgresql import UUID
from
extensions.ext_database
import
db
from
models.account
import
Account
from
models.model
import
EndUser
class
CreatedByRole
(
Enum
):
...
...
@@ -242,6 +241,7 @@ class WorkflowRun(db.Model):
@
property
def
created_by_end_user
(
self
):
from
models.model
import
EndUser
created_by_role
=
CreatedByRole
.
value_of
(
self
.
created_by_role
)
return
EndUser
.
query
.
get
(
self
.
created_by
)
\
if
created_by_role
==
CreatedByRole
.
END_USER
else
None
...
...
@@ -356,6 +356,7 @@ class WorkflowNodeExecution(db.Model):
@
property
def
created_by_end_user
(
self
):
from
models.model
import
EndUser
created_by_role
=
CreatedByRole
.
value_of
(
self
.
created_by_role
)
return
EndUser
.
query
.
get
(
self
.
created_by
)
\
if
created_by_role
==
CreatedByRole
.
END_USER
else
None
...
...
@@ -418,6 +419,7 @@ class WorkflowAppLog(db.Model):
@
property
def
created_by_end_user
(
self
):
from
models.model
import
EndUser
created_by_role
=
CreatedByRole
.
value_of
(
self
.
created_by_role
)
return
EndUser
.
query
.
get
(
self
.
created_by
)
\
if
created_by_role
==
CreatedByRole
.
END_USER
else
None
api/services/app_service.py
View file @
eb1ea8cf
...
...
@@ -97,10 +97,11 @@ class AppService:
app
=
App
(
**
app_template
[
'app'
])
app
.
name
=
args
[
'name'
]
app
.
description
=
args
.
get
(
'description'
,
''
)
app
.
mode
=
args
[
'mode'
]
app
.
icon
=
args
[
'icon'
]
app
.
icon_background
=
args
[
'icon_background'
]
app
.
tenant_id
=
account
.
current_
tenant_id
app
.
tenant_id
=
tenant_id
db
.
session
.
add
(
app
)
db
.
session
.
flush
()
...
...
@@ -145,6 +146,7 @@ class AppService:
tenant_id
=
tenant_id
,
mode
=
app_data
.
get
(
'mode'
),
name
=
args
.
get
(
"name"
)
if
args
.
get
(
"name"
)
else
app_data
.
get
(
'name'
),
description
=
args
.
get
(
"description"
)
if
args
.
get
(
"description"
)
else
app_data
.
get
(
'description'
,
''
),
icon
=
args
.
get
(
"icon"
)
if
args
.
get
(
"icon"
)
else
app_data
.
get
(
'icon'
),
icon_background
=
args
.
get
(
"icon_background"
)
if
args
.
get
(
"icon_background"
)
\
else
app_data
.
get
(
'icon_background'
),
...
...
@@ -205,6 +207,22 @@ class AppService:
return
yaml
.
dump
(
export_data
)
def
update_app
(
self
,
app
:
App
,
args
:
dict
)
->
App
:
"""
Update app
:param app: App instance
:param args: request args
:return: App instance
"""
app
.
name
=
args
.
get
(
'name'
)
app
.
description
=
args
.
get
(
'description'
,
''
)
app
.
icon
=
args
.
get
(
'icon'
)
app
.
icon_background
=
args
.
get
(
'icon_background'
)
app
.
updated_at
=
datetime
.
utcnow
()
db
.
session
.
commit
()
return
app
def
update_app_name
(
self
,
app
:
App
,
name
:
str
)
->
App
:
"""
Update app name
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment