Include all subscription information in the slice data

CURA-7717
This commit is contained in:
Kostas Karmas 2020-10-14 11:43:22 +02:00
parent 095e34fe8d
commit 1521430d42
3 changed files with 6 additions and 24 deletions

View file

@ -122,12 +122,13 @@ 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 organization_id = user_data.get("organization", {}).get("organization_id", ""),
subscriptions = user_data.get("subscriptions", [])
) )
@staticmethod @staticmethod
@ -150,22 +151,3 @@ 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,6 +1,6 @@
# Copyright (c) 2020 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, List
class BaseModel: class BaseModel:
@ -27,8 +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] organization_id = None # type: Optional[str]
subscriptions = None # type: Optional[List[Dict[str, Any]]]
class AuthenticationResponse(BaseModel): class AuthenticationResponse(BaseModel):

View file

@ -125,8 +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 "" data["organization_id"] = user_profile.get("organization_id", "") if user_profile else ""
data["subscriptions"] = user_profile.get("subscriptions", []) 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: