Skip to content

Commit 9ac8161

Browse files
add remove apiuser (diyhue#1012)
* fix typo * fix connection error because of api version * RDM002 * rdm002 * update mqtt sensor * fix sensor type * add remove apiuser
1 parent 2bffc8a commit 9ac8161

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

BridgeEmulator/flaskUI/restful.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ def authorize(username, resource='', resourceId='', resourceParam=''):
4242
if username not in bridgeConfig["apiUsers"] and request.remote_addr != "127.0.0.1":
4343
return [{"error": {"type": 1, "address": "/" + resource + "/" + resourceId, "description": "unauthorized user"}}]
4444

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))
4647
return [{"error": {"type": 3, "address": "/" + resource + "/" + resourceId, "description": "resource, " + resource + "/" + resourceId + ", not available"}}]
4748

4849
if resourceId != "0" and resourceParam != '' and not hasattr(bridgeConfig[resource][resourceId], resourceParam):
50+
logging.debug(str(resourceId) + " has no attribute " + str(resourceParam))
4951
return [{"error": {"type": 3, "address": "/" + resource + "/" + resourceId + "/" + resourceParam, "description": "resource, " + resource + "/" + resourceId + "/" + resourceParam + ", not available"}}]
5052
if request.remote_addr != "127.0.0.1":
5153
bridgeConfig["apiUsers"][username].last_use_date = datetime.utcnow().strftime(
@@ -126,7 +128,7 @@ def get(self, username, resource):
126128
return capabilities()
127129
else:
128130
response = {}
129-
if resource in ["lights", "groups", "scenes", "rules", "resourcelinks", "schedules", "sensors"]:
131+
if resource in ["lights", "groups", "scenes", "rules", "resourcelinks", "schedules", "sensors", "apiUsers"]:
130132
for object in bridgeConfig[resource]:
131133
response[object] = bridgeConfig[resource][object].getV1Api().copy()
132134
elif resource == "config":
@@ -457,6 +459,18 @@ def delete(self, username, resource, resourceid, param):
457459
authorisation = authorize(username, resource, resourceid)
458460
if "success" not in authorisation:
459461
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."}]
460474
if param not in bridgeConfig[resource][resourceid]:
461475
return [{"error": {"type": 4, "address": "/" + resource + "/" + resourceid, "description": "method, DELETE, not available for resource, " + resource + "/" + resourceid}}]
462476

BridgeEmulator/services/updateManager.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ def githubCheck():
5252
if publish_time > creation_time:
5353
logging.info("update on github")
5454
bridgeConfig["config"]["swupdate2"]["state"] = "allreadytoinstall"
55-
bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "allreadytoinstall"
55+
#bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "allreadytoinstall"
5656
elif githubUICheck() == True:
5757
logging.info("UI update on github")
5858
bridgeConfig["config"]["swupdate2"]["state"] = "anyreadytoinstall"
59-
bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "anyreadytoinstall"
59+
#bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "anyreadytoinstall"
6060
else:
6161
logging.info("no update for diyHue or UI on github")
6262
bridgeConfig["config"]["swupdate2"]["state"] = "noupdates"
@@ -94,19 +94,13 @@ def githubUICheck():
9494
def githubInstall():
9595
if bridgeConfig["config"]["swupdate2"]["state"] == "anyreadytoinstall":#ui update
9696
bridgeConfig["config"]["swupdate2"]["state"] = "installing"
97-
bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "installing"
97+
#bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "installing"
9898
subprocess.Popen("sh githubUIInstall.sh",shell=True, close_fds=True)
9999
if bridgeConfig["config"]["swupdate2"]["state"] == "allreadytoinstall":#diyhue + ui update
100100
bridgeConfig["config"]["swupdate2"]["state"] = "installing"
101-
bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "installing"
101+
#bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "installing"
102102
subprocess.Popen("sh githubInstall.sh",shell=True, close_fds=True)
103103

104-
def githubInstall_test():
105-
logging.info("work in progress")
106-
bridgeConfig["config"]["swupdate2"]["install"] = False
107-
bridgeConfig["config"]["swupdate2"]["state"] = "noupdates"
108-
bridgeConfig["config"]["swupdate2"]["bridge"]["state"] = "noupdates"
109-
110104
def startupCheck():
111105
if bridgeConfig["config"]["swupdate2"]["install"] == True:
112106
bridgeConfig["config"]["swupdate2"]["install"] = False

0 commit comments

Comments
 (0)