Include organization id and type of enterprise plan in slice data

CURA-7717
This commit is contained in:
Kostas Karmas 2020-10-13 16:30:29 +02:00
parent 602e09e8af
commit ceda3e70bd
4 changed files with 35 additions and 6 deletions

View File

@ -1,11 +1,11 @@
# Copyright (c) 2019 Ultimaker B.V. # Copyright (c) 2020 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
from datetime import datetime from datetime import datetime
import json import json
import random import random
from hashlib import sha512 from hashlib import sha512
from base64 import b64encode from base64 import b64encode
from typing import Optional from typing import Optional, Any, Dict, Tuple
import requests import requests
@ -16,6 +16,7 @@ from cura.OAuth2.Models import AuthenticationResponse, UserProfile, OAuth2Settin
catalog = i18nCatalog("cura") catalog = i18nCatalog("cura")
TOKEN_TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M:%S" TOKEN_TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M:%S"
class AuthorizationHelpers: class AuthorizationHelpers:
"""Class containing several helpers to deal with the authorization flow.""" """Class containing several helpers to deal with the authorization flow."""
@ -121,10 +122,12 @@ class AuthorizationHelpers:
if not user_data or not isinstance(user_data, dict): if not user_data or not isinstance(user_data, dict):
Logger.log("w", "Could not parse user data from token: %s", user_data) Logger.log("w", "Could not parse user data from token: %s", user_data)
return None return None
enterprise_info = self.extractEnterpriseSubscriptionInformation(user_data)
return UserProfile( return UserProfile(
user_id = user_data["user_id"], user_id = user_data["user_id"],
username = user_data["username"], username = user_data["username"],
profile_image_url = user_data.get("profile_image_url", "") profile_image_url = user_data.get("profile_image_url", ""),
**enterprise_info
) )
@staticmethod @staticmethod
@ -147,3 +150,22 @@ class AuthorizationHelpers:
encoded = sha512(verification_code.encode()).digest() encoded = sha512(verification_code.encode()).digest()
return b64encode(encoded, altchars = b"_-").decode() return b64encode(encoded, altchars = b"_-").decode()
@staticmethod
def extractEnterpriseSubscriptionInformation(user_data: Dict[str, Any]) -> Dict[str, Any]:
"""
Extracts information related to the enterprise subscription of the account.
:param user_data: Dictionary containing the unencoded user_data received by the JWT
:returns: enterprise_info: Dictionary containing information related to enterprise subscriptions
"""
enterprise_info = {}
subscriptions = user_data.get("subscriptions", [])
enterprise_subscription = {}
for subscription in subscriptions:
if subscription.get("type_id", "") == "customer.enterprise":
enterprise_subscription = subscription
break
enterprise_info["enterprise_plan"] = enterprise_subscription.get("plan_id", "")
enterprise_info["organization_id"] = user_data.get("organization", {}).get("organization_id", "")
return enterprise_info

View File

@ -1,4 +1,4 @@
# Copyright (c) 2019 Ultimaker B.V. # Copyright (c) 2020 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
from typing import Optional, Dict, Any from typing import Optional, Dict, Any
@ -27,6 +27,8 @@ class UserProfile(BaseModel):
user_id = None # type: Optional[str] user_id = None # type: Optional[str]
username = None # type: Optional[str] username = None # type: Optional[str]
profile_image_url = None # type: Optional[str] profile_image_url = None # type: Optional[str]
enterprise_plan = None # type: Optional[str]
organization_id = None # type: Optional[str]
class AuthenticationResponse(BaseModel): class AuthenticationResponse(BaseModel):

View File

@ -1,4 +1,4 @@
# Copyright (c) 2018 Ultimaker B.V. # Copyright (c) 2020 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
import json import json
@ -116,6 +116,7 @@ class SliceInfo(QObject, Extension):
machine_manager = self._application.getMachineManager() machine_manager = self._application.getMachineManager()
print_information = self._application.getPrintInformation() print_information = self._application.getPrintInformation()
user_profile = self._application.getCuraAPI().account.userProfile
global_stack = machine_manager.activeMachine global_stack = machine_manager.activeMachine
@ -124,6 +125,8 @@ class SliceInfo(QObject, Extension):
data["schema_version"] = 0 data["schema_version"] = 0
data["cura_version"] = self._application.getVersion() data["cura_version"] = self._application.getVersion()
data["cura_build_type"] = ApplicationMetadata.CuraBuildType data["cura_build_type"] = ApplicationMetadata.CuraBuildType
data["enterprise_plan"] = user_profile.get("enterprise_plan", "") if user_profile else ""
data["organization_id"] = user_profile.get("organization_id", "") if user_profile else ""
active_mode = self._application.getPreferences().getValue("cura/active_mode") active_mode = self._application.getPreferences().getValue("cura/active_mode")
if active_mode == 0: if active_mode == 0:

View File

@ -6,7 +6,9 @@
<b>Machine Type:</b> Ultimaker S5<br/> <b>Machine Type:</b> Ultimaker S5<br/>
<b>Intent Profile:</b> Default<br/> <b>Intent Profile:</b> Default<br/>
<b>Quality Profile:</b> Fast<br/> <b>Quality Profile:</b> Fast<br/>
<b>Using Custom Settings:</b> No <b>Using Custom Settings:</b> No<br/>
<b>Enterprise Plan:</b> Essentials<br/>
<b>Organization ID:</b> Ultimaker B.V.
<h3>Extruder 1:</h3> <h3>Extruder 1:</h3>
<ul> <ul>