| 459 | # Get rules for the file |
| 460 | # Return: The rules for the file or False if not allowed |
| 461 | def getRules(self, inner_path, content=None): |
| 462 | if not inner_path.endswith("content.json"): # Find the files content.json first |
| 463 | file_info = self.getFileInfo(inner_path) |
| 464 | if not file_info: |
| 465 | return False # File not found |
| 466 | inner_path = file_info["content_inner_path"] |
| 467 | |
| 468 | if inner_path == "content.json": # Root content.json |
| 469 | rules = {} |
| 470 | rules["signers"] = self.getValidSigners(inner_path, content) |
| 471 | return rules |
| 472 | |
| 473 | dirs = inner_path.split("/") # Parent dirs of content.json |
| 474 | inner_path_parts = [dirs.pop()] # Filename relative to content.json |
| 475 | inner_path_parts.insert(0, dirs.pop()) # Dont check in self dir |
| 476 | while True: |
| 477 | content_inner_path = "%s/content.json" % "/".join(dirs) |
| 478 | parent_content = self.contents.get(content_inner_path.strip("/")) |
| 479 | if parent_content and "includes" in parent_content: |
| 480 | return parent_content["includes"].get("/".join(inner_path_parts)) |
| 481 | elif parent_content and "user_contents" in parent_content: |
| 482 | return self.getUserContentRules(parent_content, inner_path, content) |
| 483 | else: # No inner path in this dir, lets try the parent dir |
| 484 | if dirs: |
| 485 | inner_path_parts.insert(0, dirs.pop()) |
| 486 | else: # No more parent dirs |
| 487 | break |
| 488 | |
| 489 | return False |
| 490 | |
| 491 | # Get rules for a user file |
| 492 | # Return: The rules of the file or False if not allowed |