Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 更新本地ArkID版本 #1297

Merged
merged 1 commit into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions api/v1/views/platform_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from api.v1.schema.platform_config import *
from arkid.core.models import Platform
from arkid.core.error import ErrorCode, ErrorDict, SuccessDict
from arkid.core.event import Event, dispatch_event, SET_FRONTEND_URL
from arkid.core.event import Event, dispatch_event, SET_FRONTEND_URL, UPDATE_LOCAL_ARKID_VERSION


@api.get("/platform_config/",response=PlatformConfigOut, tags=["平台配置"])
Expand Down Expand Up @@ -103,20 +103,36 @@ def set_frontend_url(request, data:FrontendUrlSchemaIn):
)


@api.get("/version/",response=VersionOut, tags=["平台配置"], auth=None)
def get_version(request):
@api.get("/version/",response=VersionOut, tags=["平台配置"])
@operation(roles=[NORMAL_USER, TENANT_ADMIN, PLATFORM_ADMIN])
def get_version(request, local_version=None):
""" 获取ArkId版本
"""
version = os.environ.get('ARKID_VERSION', '')
update_url = settings.UPDATE_URL

if settings.IS_CENTRAL_ARKID:
if local_version:
dispatch_event(
Event(
tag=UPDATE_LOCAL_ARKID_VERSION,
tenant=request.tenant,
request=request,
data = {"local_version": local_version}
)
)
new_version = ''
update_available = False
else:
try:
from arkid.common.arkstore import get_saas_token
token = request.user.auth_token
tenant = request.tenant
saas_token, saas_tenant_id, saas_tenant_slug = get_saas_token(tenant, token)
arkid_saas_version_url = settings.ARKID_SAAS_URL + '/api/v1/version/'
resp = requests.get(arkid_saas_version_url, timeout=5).json()
headers = {'Authorization': f'Token {saas_token}'}
params = {"local_version": version}
resp = requests.get(arkid_saas_version_url, params=params, headers=headers, timeout=5).json()
new_version = resp.get('data', {}).get('version', '')
if version and new_version and version < new_version:
update_available = True
Expand Down
4 changes: 4 additions & 0 deletions arkid/core/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ def unlisten_event(tag, func, **kwargs):

GET_STATISTICS_CHARTS = 'GET_STATISTICS_CHARTS'

UPDATE_LOCAL_ARKID_VERSION = 'UPDATE_LOCAL_ARKID_VERSION'


# register events
register_event(
Expand Down Expand Up @@ -465,3 +467,5 @@ def unlisten_event(tag, func, **kwargs):
register_event(REQUEST_RESPONSE_LOGGGING, _('REQUEST_RESPONSE_LOGGGING', 'Django请求日志'))

register_event(GET_STATISTICS_CHARTS, _('GET_STATISTICS_CHARTS', 'Django请求日志'))

register_event(UPDATE_LOCAL_ARKID_VERSION, _('UPDATE_LOCAL_ARKID_VERSION', '更新本地ArkID版本'))