# Ultimate Fansifter Users Helper


## Requirements
Minimum:
- VPN
- Neo4j Read-only credentials

Optimal:
- VPN
- Neo4j Read-only credentials
- SplitIO API key
- Access to pdp jump box
- Prod Bearer Token


## Usage
1. Show detailed info about users (profile, vendors access, permissions, feature flags)
2. Prepare new database PR to create new users or update them directly in repo
4. Update permissions
5. Prepare well formated list of users for adding to feature flag


## Pre-requisites
1. Install dependencies and create virtual env `poetry install`
2. `cd app && cp .env.shadow .env`
3. 

One of the flag -f, -e, -i is required for the script.

### 👤 Users info

```bash
  python main.py -e testemail@sony.com,testemail2@sony.com
```
Instead of using -e you can pass identities directly using -i flag
```bash
  python main.py -i asdasd-asdasd-asdasd-asdasd,a123asfd-12weqasd-213asd-12asd
```
Or use csv file as a source
```bash
  python main.py -f /path/to/file.csv
```
Highlight vendors
```bash
  python main.py -e testemail@sony.com,testemail2@sony.com -v 1234,2345-asdasd-as234-sdf3
```

### 💾 Create database PR
Input users csv file example<br>
<b>name, email, identityID [Optional], role (Admin/Analyst) [Optional]</b>
...

Fastest way to create right format CSV file by using Fansifter Beta Launch User group Google sheets
https://docs.google.com/spreadsheets/d/1yIjldIsZjk1N3HimJEkmDqAcGPkc8kF9xg_nZdFa5Pg/edit?usp=sharing

1. Take data range with users that you need
2. Paste in nearby sheets with name Exporting, previously deleted data from
3. While on the chosen Exporting sheet press File -> Download -> Comma Separated Values

Prepare new database PR for specific vendors
```bash
  python main.py -f /path/to/file.csv -v 1234,4567 -d FS-9324_name_of_pr
```

### Update PDP permissions
⚠️ For now permissions update works only with file specify and one vendor. See example below.

```bash
  python main.py -f /path/to/file.csv -v 1234 -p
```

### 👨‍💼 Grant Full Time Employee (FTE) permissions
Grant comprehensive permissions set to users with ALL_ORCHARD_LABELS_UUID for specified vendors.

**What FTE permissions include:**
- `fansifter_can_view_fan_data` - View fan analytics and audience data
- `fansifter_can_share_ad_campaign_audiences` - Share audiences to advertising platforms
- `fansifter_can_create_ad_reports` - Create and view advertising reports
- `fansifter_can_connect_ad_accounts` - Connect advertising accounts
- `fansifter_can_create_email_campaigns` - Create and manage email campaigns

**Usage:**
```bash
  # Using CSV file
  python main.py -f /path/to/file.csv -v vendor-uuid-1,vendor-uuid-2 --fte
  
  # Using emails directly
  python main.py -e john.doe@sony.com,jane.smith@sony.com -v vendor-uuid-1,vendor-uuid-2 --fte
  
  # Using identity UUIDs
  python main.py -i user-uuid-1,user-uuid-2 -v vendor-uuid-1,vendor-uuid-2 --fte
```

**Features:**
- ✅ **Smart Permission Granting**: Only adds missing permissions, skips users who already have all FTE permissions for a vendor
- ✅ **ALL_ORCHARD_LABELS_UUID Support**: Works specifically with users who have universal access
- ✅ **No Role Required**: Unlike other operations, FTE doesn't require users to have a role specified in the CSV file
- ✅ **Vendor-Specific**: Grants permissions only for specified vendors using `-v` flag
- ✅ **Multiple Input Methods**: Works with `-f` (CSV file), `-e` (emails), or `-i` (identity UUIDs)
- ✅ **Progress Feedback**: Shows detailed progress and results for each user and vendor
- ✅ **Error Handling**: Gracefully handles API errors and continues processing other users/vendors

**FTE List File:**
For faster onboarding, a pre-populated FTE list is available at `app/fansifter_fte_list.csv` containing all current Full Time Employees. You can use this file directly:

```bash
  python main.py -f app/fansifter_fte_list.csv -v vendor-uuid-1,vendor-uuid-2 --fte
```

**Example Output:**
```
Found 2 users with ALL_ORCHARD_LABELS_UUID access:
  - john.doe@sony.com
  - jane.smith@sony.com

Will grant FTE permissions for vendors:
  - Columbia Records (12345678-1234-1234-1234-123456789abc)
  - Sony Music Nashville (87654321-4321-4321-4321-cba987654321)

✅ john.doe@sony.com already has all FTE permissions for vendor 12345678-1234-1234-1234-123456789abc, skipping
Granting missing FTE permissions to john.doe@sony.com for vendor 87654321-4321-4321-4321-cba987654321: ['fansifter_can_create_ad_reports', 'fansifter_can_connect_ad_accounts']
✅ Successfully granted FTE permissions to john.doe@sony.com for vendor 87654321-4321-4321-4321-cba987654321
```

### SplitIO feature flags updates
```bash
  python main.py -f /path/to/file.csv --ff orchard_suite_show_audience_app,show_sme_data
```
Script will return comma-separated list of users that need to be updated (only addition for now)



## References 🔗
https://www.notion.so/Creating-Beta-Users-For-Fansifter-e28c6a2ac72c4287b1e796a7c688accc


## TODO
1. Update permissions table to show only users that will be updated (not all of them)
2. 