@@ -42,10 +42,12 @@ def authorize(username, resource='', resourceId='', resourceParam=''):
42
42
if username not in bridgeConfig ["apiUsers" ] and request .remote_addr != "127.0.0.1" :
43
43
return [{"error" : {"type" : 1 , "address" : "/" + resource + "/" + resourceId , "description" : "unauthorized user" }}]
44
44
45
- if resourceId not in ["0" , "new" , "timezones" ] and resourceId != '' and resourceId not in bridgeConfig [resource ]:
45
+ if resourceId not in ["0" , "new" , "timezones" , "whitelist" ] and resourceId != '' and resourceId not in bridgeConfig [resource ]:
46
+ logging .debug (str (resourceId ) + " not in bridgeConfig " + str (resource ))
46
47
return [{"error" : {"type" : 3 , "address" : "/" + resource + "/" + resourceId , "description" : "resource, " + resource + "/" + resourceId + ", not available" }}]
47
48
48
49
if resourceId != "0" and resourceParam != '' and not hasattr (bridgeConfig [resource ][resourceId ], resourceParam ):
50
+ logging .debug (str (resourceId ) + " has no attribute " + str (resourceParam ))
49
51
return [{"error" : {"type" : 3 , "address" : "/" + resource + "/" + resourceId + "/" + resourceParam , "description" : "resource, " + resource + "/" + resourceId + "/" + resourceParam + ", not available" }}]
50
52
if request .remote_addr != "127.0.0.1" :
51
53
bridgeConfig ["apiUsers" ][username ].last_use_date = datetime .utcnow ().strftime (
@@ -126,7 +128,7 @@ def get(self, username, resource):
126
128
return capabilities ()
127
129
else :
128
130
response = {}
129
- if resource in ["lights" , "groups" , "scenes" , "rules" , "resourcelinks" , "schedules" , "sensors" ]:
131
+ if resource in ["lights" , "groups" , "scenes" , "rules" , "resourcelinks" , "schedules" , "sensors" , "apiUsers" ]:
130
132
for object in bridgeConfig [resource ]:
131
133
response [object ] = bridgeConfig [resource ][object ].getV1Api ().copy ()
132
134
elif resource == "config" :
@@ -457,6 +459,18 @@ def delete(self, username, resource, resourceid, param):
457
459
authorisation = authorize (username , resource , resourceid )
458
460
if "success" not in authorisation :
459
461
return authorisation
462
+ if resourceid == "whitelist" :
463
+ for config in ["lights" , "groups" , "scenes" , "rules" , "resourcelinks" , "schedules" , "sensors" ]:
464
+ for object in bridgeConfig [config ]:
465
+ if "owner" in bridgeConfig [config ][object ].getV1Api ():
466
+ current_owner = bridgeConfig [config ][object ].getV1Api ()["owner" ]
467
+ if current_owner == param :
468
+ logging .debug ("transfer ownership from: " + str (current_owner ) + " to: " + str (username ))
469
+ bridgeConfig [config ][object ].owner = bridgeConfig ["apiUsers" ][username ]
470
+ logging .debug ("Deleted api user: " + str (param ) + " " + bridgeConfig ["apiUsers" ][param ].name )
471
+ del bridgeConfig ["apiUsers" ][param ]
472
+ configManager .bridgeConfig .save_config ()
473
+ return [{"success" : "/" + resource + "/" + resourceid + "/" + param + " deleted." }]
460
474
if param not in bridgeConfig [resource ][resourceid ]:
461
475
return [{"error" : {"type" : 4 , "address" : "/" + resource + "/" + resourceid , "description" : "method, DELETE, not available for resource, " + resource + "/" + resourceid }}]
462
476
0 commit comments