def deleteRule(self, ruleId, buildingName, roomName, editorUuid): checkData(locals()) room = Room(buildingName = buildingName, roomName = roomName) room.retrieve() from app.backend.model.rule import Rule rule = Rule(id = ruleId) rule.retrieve() from app.backend.model.user import User editor = User(uuid = editorUuid) editor.retrieve() author = User(uuid = rule.authorUuid) author.retrieve() # If this room is not related to a room, I cannot modify it from this method if not rule.roomName: raise UserCredentialError("You cannot modify this group related rule.") # If this rule is not about this building if rule.buildingName != buildingName: raise UserCredentialError("You cannot modify the rule of another building.") if author.uuid != editor.uuid: if not rule.groupId and not rule.getRoom().roomName in list(r.roomName for r in editor.getRooms()): raise UserCredentialError("You cannot modify a rule of a room you do not own.") #if rule.getRoom() not in editor.getRooms(): # raise UserCredentialError("You cannot modify a rule of a room you do not own.") if rule.groupId: from app.backend.model.group import Group group = Group(buildingName = buildingName, id = groupId) group.retrieve() if not group: raise UserCredentialError("You cannot delete a rule of a room you do not own.") if not group.crossRoomsValidation: raise UserCredentialError("You cannot delete a rule you do not own.") if not group.id in list(g.id for g in editor.getGroups()): raise UserCredentialError("You cannot delete a rule belonging to a group you do not own.") if not rule.getRoom().roomName in list(r.roomName for r in group.getRooms()): raise UserCredentialError("You cannot delete a rule belonging to room that does not belongs to a group you do not own.") if editor.level < rule.getPriority(): raise UserCredentialError("You cannot modify this rule since it has a too high priority for your user level") room.deleteRule(rule) return {}