Skip to content

Commit 572fdca

Browse files
authored
Merge pull request #185 from adamkovacs2000/main
feat: Implement .albumprops inheritance system
2 parents 09cb1c6 + d26b4e3 commit 572fdca

File tree

3 files changed

+633
-103
lines changed

3 files changed

+633
-103
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
*.idea
22
.vscode/*
3+
4+
.history

README.md

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,11 @@ share_with:
703703
# or provide user mail address
704704
- user: "user2@example.org"
705705
role: "viewer"
706+
# role is optional and defaults to "viewer" if not specified
707+
- user: "user3@example.org"
708+
# Special role "none" can be used to remove inherited users
709+
- user: "user4"
710+
role: "none"
706711
# Set album thumbnail, valid values: first, last, random or fully qualified path of an asset that is (or will be) assigned to the album
707712
thumbnail_setting: "first"
708713
# Sort order in album, valid values: asc, desc
@@ -711,9 +716,217 @@ sort_oder: "desc"
711716
visibility: 'timeline'
712717
# Flag indicating whether assets in this albums can be commented on and liked
713718
comments_and_likes_enabled: false
719+
# Flag indicating whether properties should be inherited down the directory tree
720+
inherit: true
721+
# List of property names that should be inherited (if not specified, all properties are inherited)
722+
inherit_properties:
723+
- "description"
724+
- "share_with"
725+
- "visibility"
714726
```
715727
All properties are optional.
716728

729+
#### Property Inheritance
730+
731+
The script supports property inheritance from parent folders through the `inherit` and `inherit_properties` settings:
732+
733+
- **`inherit: true`**: Enables inheritance of properties from parent `.albumprops` files
734+
- **`inherit_properties`**: Specifies which properties to inherit (if omitted, all properties are inherited)
735+
736+
##### Inheritance Rules
737+
738+
1. **Inheritance Chain**: Properties are inherited from the root path down to the current folder
739+
2. **Property Precedence**: Properties in deeper folders override those in parent folders
740+
3. **Inheritance Termination**: If a folder has `inherit: false` or no `inherit` property, while having a `.albumprops`.file, the inheritance chain stops at that folder
741+
742+
##### Special `share_with` Inheritance
743+
744+
The `share_with` property has special inheritance behavior:
745+
- **Addition**: Users from parent folders are automatically included
746+
- **Modification**: User roles can be changed by specifying the same user with a different role
747+
- **Removal**: Users can be removed by setting their role to `"none"`
748+
749+
##### Album Merging Behavior
750+
751+
When multiple directories use the same `override_name` and contribute to a single album, the following rules apply:
752+
753+
1. **Most Restrictive Role Wins**: If the same user is specified with different roles across multiple directories, the most restrictive role is applied:
754+
- `viewer` is more restrictive than `editor`
755+
- Example: User specified as `editor` in one directory and `viewer` in another → final role is `viewer`
756+
757+
2. **User Removal is Permanent**: If a user is set to `role: "none"` in any directory contributing to the album, they cannot be re-added by other directories:
758+
- Once removed with `role: "none"`, the user is permanently excluded from that album
759+
- Subsequent attempts to add the same user with any role will be ignored
760+
761+
3. **User Accumulation**: Users from all contributing directories are combined, following the above precedence rules
762+
763+
This ensures consistent and predictable behavior when multiple folder structures contribute to the same album via `override_name`.
764+
765+
766+
##### Inheritance Examples
767+
768+
**Example 1: Basic Inheritance**
769+
770+
`/photos/.albumprops`:
771+
```yaml
772+
inherit: true
773+
description: "Family photos"
774+
share_with:
775+
- user: "dad"
776+
role: "editor"
777+
```
778+
779+
`/photos/2023/.albumprops`:
780+
```yaml
781+
inherit: true
782+
share_with:
783+
- user: "mom"
784+
role: "viewer"
785+
```
786+
787+
Result for `/photos/2023/vacation/`:
788+
```yaml
789+
# - description: "Family photos" (inherited)
790+
# - share_with: dad (editor), mom (viewer)
791+
```
792+
793+
**Example 2: Property Override and User Management**
794+
795+
`/photos/.albumprops`:
796+
```yaml
797+
inherit: true
798+
description: "Family photos"
799+
visibility: "timeline"
800+
share_with:
801+
- user: "dad"
802+
role: "editor"
803+
- user: "mom"
804+
role: "viewer"
805+
```
806+
807+
`/photos/private/.albumprops`:
808+
```yaml
809+
inherit: true
810+
inherit_properties: ["description"] # Only inherit description
811+
visibility: "archive" # Override visibility
812+
share_with:
813+
- user: "mom"
814+
role: "none" # Remove mom from sharing
815+
- user: "admin"
816+
role: "editor" # Add admin
817+
```
818+
819+
Result for `/photos/private/secrets/`:
820+
```yaml
821+
# - description: "Family photos" (inherited)
822+
# - visibility: "archive" (overridden, not inherited due to inherit_properties)
823+
# - share_with: dad (editor, inherited), admin (editor, added)
824+
# - mom is removed from sharing
825+
```
826+
827+
**Example 3: Stopping Inheritance**
828+
829+
`/photos/.albumprops`:
830+
```yaml
831+
inherit: true
832+
description: "Family photos"
833+
share_with:
834+
- user: "family"
835+
role: "viewer"
836+
```
837+
838+
`/photos/work/.albumprops`:
839+
```yaml
840+
inherit: false # Stop inheritance
841+
description: "Work photos"
842+
share_with:
843+
- user: "colleague"
844+
role: "editor"
845+
```
846+
847+
Result for `/photos/work/project/`:
848+
```yaml
849+
# - description: "Work photos" (from /photos/work/, no inheritance)
850+
# - share_with: colleague (editor, no family member inherited)
851+
```
852+
853+
**Example 4: Album Merging with `override_name`**
854+
855+
`/photos/2023/Christmas/.albumprops`:
856+
```yaml
857+
override_name: "Family Photos"
858+
description: "Family photos"
859+
inherit: true
860+
share_with:
861+
- user: "dad"
862+
role: "editor"
863+
```
864+
865+
`/photos/2023/Christmas/Cookies/.albumprops`:
866+
```yaml
867+
inherit: true
868+
share_with:
869+
- user: "mom"
870+
role: "viewer"
871+
```
872+
873+
`/photos/2023/Vacation/.albumprops`:
874+
```yaml
875+
override_name: "Family Photos"
876+
description: "Family photos"
877+
share_with:
878+
- user: "dad"
879+
role: "viewer" # More restrictive than editor
880+
```
881+
882+
Result: Single album "Family Photos" containing all photos from all three directories:
883+
```yaml
884+
# - name: "Family Photos" (from override_name)
885+
# - description: "Family photos" (inherited/specified)
886+
# - share_with: dad (viewer - most restrictive wins), mom (viewer)
887+
```
888+
889+
**Example 5: User Removal with `role: "none"`**
890+
891+
`/photos/family/.albumprops`:
892+
```yaml
893+
override_name: "Shared Album"
894+
share_with:
895+
- user: "dad"
896+
role: "editor"
897+
- user: "mom"
898+
role: "viewer"
899+
- user: "child"
900+
role: "viewer"
901+
```
902+
903+
`/photos/family/private/.albumprops`:
904+
```yaml
905+
override_name: "Shared Album" # Same album name
906+
share_with:
907+
- user: "child"
908+
role: "none" # Remove child from sharing
909+
- user: "grandpa"
910+
role: "editor"
911+
```
912+
913+
`/photos/family/work/.albumprops`:
914+
```yaml
915+
override_name: "Shared Album" # Same album name
916+
share_with:
917+
- user: "child"
918+
role: "viewer" # This will be ignored - child was set to "none"
919+
- user: "colleague"
920+
role: "viewer"
921+
```
922+
923+
Result: Single album "Shared Album" containing photos from all directories:
924+
```yaml
925+
# - name: "Shared Album"
926+
# - share_with: dad (editor), mom (viewer), grandpa (editor), colleague (viewer)
927+
# - child is permanently removed and cannot be re-added
928+
```
929+
717930
>[!IMPORTANT]
718931
>The `override_name` property makes it possible assign assets to an album that does not have anything to do with their folder name. That way, it is also possible to merge assets from different folders (even under different `root_paths`) into the same album.
719932
>If the script finds multiple `.albumprops` files using the same `override_name` property, it enforced that all properties that exist in at least one of the `.albumprops` files are identical in all files that use the same `override_name`. If this is not the case, the script will exit with an error.

0 commit comments

Comments
 (0)