No description
- Python 100%
| .gitignore | ||
| .pre-commit-config.yaml | ||
| config.json.example | ||
| README.md | ||
| requirements.txt | ||
| sync_folders.py | ||
Filer Helper
This directory contains scripts for managing file system structures based on portal group membership. It exists to extend the functionality of Nextcloud's external storage system.
sync_folders.py
A standalone script that:
- Gets all portal users via the portal API
- Creates folders in a specific directory for each user_id (for ALL portal users)
- Creates symlinks from user_id folders to folders using the user's display name (only for users in configured groups, or all users with
--all-usersflag)
Setup
-
Copy
config.json.exampletoconfig.json:cp config.json.example config.json -
Edit
config.jsonwith your settings:api_base_url: Base URL of the portal (e.g., "https://portal.example.com")api_key: API key for authentication (get from portal admin)groups: List of group names to get members from (supports "portal." prefix)user_id_directory: Base directory where user_id folders will be createddisplay_name_directory: Base directory where display name symlinks will be created (for group members)all_display_name_directory: Base directory where display name symlinks will be created when using--all-usersflag (required when using--all-users)use_member_work_override(optional): Iftrue, uses the "Member Work override" field if set, otherwise falls back to standard display name logic. Defaults tofalse.
Usage
python sync_folders.py
Or to create links for all users (not just those in configured groups):
python sync_folders.py --all-users
The script will:
- Connect to the portal API using the configured API key
- Get all portal users via
/api/users/allendpoint - Create folders for each user_id in the
user_id_directory(for ALL users) - Get members from the configured groups via
/api/groups/<group_name>/membersendpoint - Create symlinks from
display_name_directory/{display_name}touser_id_directory/{user_id}(only for users in configured groups, or all users if--all-usersis used)
Display Name
Display names are obtained from the API response. The /api/groups/<group_name>/members endpoint returns all group members with their display_name calculated using the standard portal logic:
first_name last_name(if both exist)display_name(from profile)nickname(from profile)primary_email(from user)user_id(as fallback)
Requirements
- Python 3.8+
requestslibrary (install withpip install -r requirements.txt)- Portal API access with a valid API key
- Appropriate file system permissions for creating directories and symlinks
API Key
To get an API key:
- Log in to the portal as an admin
- Navigate to the API keys section
- Create a new API key
- Copy the key and add it to
config.json
The API key should have access to the /api/groups/<group_name>/members endpoint.