@@ -86,7 +86,25 @@ async def get_accessible_products(
8686 )
8787
8888
89- @router .post ("/licenses/trial" , status_code = http_status .HTTP_201_CREATED )
89+ @router .post (
90+ "/licenses/trial" ,
91+ status_code = http_status .HTTP_201_CREATED ,
92+ responses = {
93+ 409 : {
94+ "description" : "Duplicate Error" ,
95+ "content" : {
96+ "application/json" : {
97+ "example" : {
98+ "detail" : (
99+ "Trial license creation failed:"
100+ " A trial license for this entity already exists"
101+ ),
102+ },
103+ },
104+ },
105+ },
106+ },
107+ )
90108async def create_trial_license (
91109 data : LicenseTrialSchema ,
92110 token_data : Tuple [str , Dict [str , Any ]] = Depends (authorize_with_memberships_token ),
@@ -112,6 +130,11 @@ async def create_trial_license(
112130
113131 # Do the actual check, if the owner EID is part of the memberships.
114132 if Entity (type_ = data .owner_type , eid = data .owner_eid ) not in memberships :
133+ logger .warn (
134+ "license owner does not match any users membership" ,
135+ owner_type = data .owner_type ,
136+ owner_eid = data .owner_eid ,
137+ )
115138 raise HTTPException (
116139 status_code = http_status .HTTP_422_UNPROCESSABLE_ENTITY ,
117140 message = (
@@ -140,7 +163,7 @@ async def create_trial_license(
140163 "A trial license for this entity already exists"
141164 ),
142165 )
143- license_ = await LicensingService (repository (tm .session )).create_license (
166+ license_dict = await LicensingService (repository (tm .session )).create_license (
144167 hierarchy_provider_uri = payload ["iss" ],
145168 manager_eid = payload ["sub" ],
146169 product_eid = data .product_eid ,
@@ -158,10 +181,10 @@ async def create_trial_license(
158181 logger .info (
159182 "Successfully created license" ,
160183 is_trial = True ,
161- uuid = license_ ["uuid" ],
162- product = license_ ["product_eid" ],
163- owner_type = license_ ["owner_type" ],
164- nof_seats = license_ ["nof_seats" ],
184+ uuid = license_dict ["uuid" ],
185+ product = license_dict ["product_eid" ],
186+ owner_type = license_dict ["owner_type" ],
187+ nof_seats = license_dict ["nof_seats" ],
165188 )
166189 except DuplicateEntryException :
167190 raise HTTPException (
@@ -171,7 +194,7 @@ async def create_trial_license(
171194 "A license with these properties already exists"
172195 ),
173196 )
174- return license_
197+ return LicenseCreatedSchema . parse_obj ( license_dict )
175198
176199
177200@router .post ("/licenses" , status_code = http_status .HTTP_200_OK )
@@ -187,9 +210,9 @@ async def get_available_licenses(
187210 ### Example Bearer Token structure
188211 ```
189212 {
190- "iss": "https://your-domain .com/ucm",
213+ "iss": "https://acc.bettermarks .com/ucm",
191214 "exp": 1701799583.393268,
192- "sub": "3@DE_tesyt ",
215+ "sub": "3@DE_bettermarks ",
193216 "iat": 1701798983.393283,
194217 "jti": "77ab5b01-83a0-44f3-a086-d25162aae84e",
195218 "hashes": {
0 commit comments