No description
Find a file
2026-01-08 17:02:13 +08:00
.gitignore Initial filer helper 2026-01-04 20:57:31 +08:00
.pre-commit-config.yaml Add ruff precommit 2026-01-08 17:02:13 +08:00
config.json.example Add new directory for all users 2026-01-05 10:13:25 +08:00
README.md Add new directory for all users 2026-01-05 10:13:25 +08:00
requirements.txt Initial filer helper 2026-01-04 20:57:31 +08:00
sync_folders.py Add new directory for all users 2026-01-05 10:13:25 +08:00

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-users flag)

Setup

  1. Copy config.json.example to config.json:

    cp config.json.example config.json
    
  2. Edit config.json with 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 created
    • display_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-users flag (required when using --all-users)
    • use_member_work_override (optional): If true, uses the "Member Work override" field if set, otherwise falls back to standard display name logic. Defaults to false.

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:

  1. Connect to the portal API using the configured API key
  2. Get all portal users via /api/users/all endpoint
  3. Create folders for each user_id in the user_id_directory (for ALL users)
  4. Get members from the configured groups via /api/groups/<group_name>/members endpoint
  5. Create symlinks from display_name_directory/{display_name} to user_id_directory/{user_id} (only for users in configured groups, or all users if --all-users is 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:

  1. first_name last_name (if both exist)
  2. display_name (from profile)
  3. nickname (from profile)
  4. primary_email (from user)
  5. user_id (as fallback)

Requirements

  • Python 3.8+
  • requests library (install with pip 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:

  1. Log in to the portal as an admin
  2. Navigate to the API keys section
  3. Create a new API key
  4. Copy the key and add it to config.json

The API key should have access to the /api/groups/<group_name>/members endpoint.