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
2de73991
Unverified
Commit
2de73991
authored
Dec 18, 2023
by
Garfield Dai
Committed by
GitHub
Dec 18, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: only tenant owner can subscription. (#1770)
parent
354d033e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
1 deletion
+19
-1
billing.py
api/controllers/console/billing/billing.py
+3
-1
billing_service.py
api/services/billing_service.py
+16
-0
No files found.
api/controllers/console/billing/billing.py
View file @
2de73991
...
@@ -37,6 +37,8 @@ class Subscription(Resource):
...
@@ -37,6 +37,8 @@ class Subscription(Resource):
parser
.
add_argument
(
'interval'
,
type
=
str
,
required
=
True
,
location
=
'args'
,
choices
=
[
'month'
,
'year'
])
parser
.
add_argument
(
'interval'
,
type
=
str
,
required
=
True
,
location
=
'args'
,
choices
=
[
'month'
,
'year'
])
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
BillingService
.
is_tenant_owner
(
current_user
)
return
BillingService
.
get_subscription
(
args
[
'plan'
],
return
BillingService
.
get_subscription
(
args
[
'plan'
],
args
[
'interval'
],
args
[
'interval'
],
current_user
.
email
,
current_user
.
email
,
...
@@ -50,7 +52,7 @@ class Invoices(Resource):
...
@@ -50,7 +52,7 @@ class Invoices(Resource):
@
account_initialization_required
@
account_initialization_required
@
only_edition_cloud
@
only_edition_cloud
def
get
(
self
):
def
get
(
self
):
BillingService
.
is_tenant_owner
(
current_user
)
return
BillingService
.
get_invoices
(
current_user
.
email
)
return
BillingService
.
get_invoices
(
current_user
.
email
)
...
...
api/services/billing_service.py
View file @
2de73991
import
os
import
os
import
requests
import
requests
from
extensions.ext_database
import
db
from
models.account
import
TenantAccountJoin
class
BillingService
:
class
BillingService
:
base_url
=
os
.
environ
.
get
(
'BILLING_API_URL'
,
'BILLING_API_URL'
)
base_url
=
os
.
environ
.
get
(
'BILLING_API_URL'
,
'BILLING_API_URL'
)
...
@@ -55,3 +59,15 @@ class BillingService:
...
@@ -55,3 +59,15 @@ class BillingService:
response
=
requests
.
request
(
method
,
url
,
json
=
json
,
params
=
params
,
headers
=
headers
)
response
=
requests
.
request
(
method
,
url
,
json
=
json
,
params
=
params
,
headers
=
headers
)
return
response
.
json
()
return
response
.
json
()
@
staticmethod
def
is_tenant_owner
(
current_user
):
tenant_id
=
current_user
.
current_tenant_id
join
=
db
.
session
.
query
(
TenantAccountJoin
)
.
filter
(
TenantAccountJoin
.
tenant_id
==
tenant_id
,
TenantAccountJoin
.
account_id
==
current_user
.
id
)
.
first
()
if
join
.
role
!=
'owner'
:
raise
ValueError
(
'Only tenant owner can perform this action'
)
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