# profile-users-scripts

## This is repo for all temporary scripts related to profile users.


## Scripts:


#### 1. create_profile_users

It creates auth0 user for this email. It also creates identity and a profile nodes if they dont exist, for each row in csv.
The profile can be specified as an argument to the script whereas it set to InsightsProfile in the yarn task.
It also gives the Profile access to all the artist ids, vendor ids and subaccount ids that are provided.
Currently this script has mapping of profile type to application name and addtional profile types nee

This takes in a csv file. Structure of CSV file

```
"First Name","Last Name","Email","Artist Info IDs","Vendor IDs","SubAccount Ids","Roles"
"Jorja","Smith","email@theorchard.com","878152,675402,1686714,1552280","34842","","analytics"

```
* For OrchardAdminProfiles, you dont need to specifiy any roles.
* For all other profiles, you must specific a list of roles that will get validated by ows-permissions.

###### CMD:
```
$ yarn start:create-users simple.csv
$ node start-create-profile-users.js profiles.csv PublishingProfile

```
###### Job: https://pipeline.theorchard.io/job/create-non-label-user/



#### 2. remove_artist_access

It removes InsightsProfile access to artist ids provided in the csv.

This takes in a csv file. Structure of CSV file

```
profileId, artistIds
346, 1552280
```

###### CMD:
```
$ yarn start:remove-artist-access simple.csv

```

###### Job: https://pipeline.theorchard.io/job/remove-artist-access/



#### 3. send-push-notifications

This is to send push notification to all devices an identity has.
This relies on ENV vars for most of the inputs. The inputs are provided by jenkins job in input.

Inputs:
- Environment
- identity_ids -- Enter multiple identity ids each on a new line.
- message_title
- message_body
- json_data

###### CMD:
```
$ yarn start:send-push-notifications

```

###### Job: https://pipeline.theorchard.io/job/prod-push-notification/



## Setup:

This requires "node": ">=10.15.3" . You can use `nvm` to get node.
Install all dependencies.
```
yarn
```


#### 4. create-gsuite-users

It creates or updates an Identity and the specified Profile nodes in graph only.
The corresponding pipeline to set the profile and upload the csv is: https://pipeline.theorchard.io/job/backfill-profile-users-scripts/

The current profiles that are supported are:

AbacusProfile
ContentProfile
InsightsProfile
OrchAdminProfile
PodcastProfile
PublishingProfile
SongwhipProfile
DocumentsProfile
DistributionProfile

This takes in a csv file. Structure of CSV file

```
fname,lname,email,role
"f","l","test@theorchard.com","Engineering"

```

This script has 3 job types in the Jenkins pipeline:

* `create_gsuite_users` - Creates or updates a list of Identities and Profiles
* `create_gsuite_users_with_vendor_star` - Creates or updates a list of Identities and Profiles and provides Vendor(*) access
* `create_gsuite_users_with_vendor_star_extended` - Creates or updates a list of Identities and Profiles, provides Vendor(*) access, and provides a method for setting a user's default brand and assigning additional vendors.


`create_gsuite_users_with_vendor_star_extended` expects a CSV with the following structure:

```
fname,lname,email,role,vendorIds,defaultBrand
"f","l","test@theorchard.com","Engineering","1234,5678","theorchard"
```

###### CMD:
```
$ yarn start:create-gsuite-users simple.csv

```
###### Job: tbd

#### 5. add users to organizations

It adds members to Organizations based on defaultBrand in Identity.

This takes in a csv file. Structure of CSV file

```
identityId
db29857e-b9f8-4611-aa92-0ea5ee808888

```

###### CMD:
```
$ yarn start:add-organization-members identities.csv

```
###### Job: https://pipeline.theorchard.io/job/add-users-auth0-orgs/

#### 6. re-save users

It re-saves list of users.

This takes in multiline environment variable with user ids per line and graphql endpoint.

```
export GRAPHQL_ENDPOINT=https://qa-graphql-gateway.theorchard.io/graphql
export SUPER_ADMIN='71dae95d-7555-44e8-860b-856b815ced3b'
export PROFILE_TYPE='SettingsProfile'
export PROFILE_ID=39826
export ROLE='administrator'
export APOLLO_CLIENT='frontend-settings'
export IDENTITY_IDS="
4dae5371-2384-4108-86fa-0ff548eaf1e8
965c5d87-ceb3-4a71-bec5-38e729105e7a
fb567e89-62f2-4d0d-810c-f2b0c5758538
"
```

###### CMD:
```
$ yarn start:re-save-users
$ node re_save_users.js
```
###### Job: https://pipeline.theorchard.io/job/backfill-profile-users-scripts/

###### CMD:
```
$ yarn start:add_role_to_profile
$ node add_role_to_profile.js profileUuid <add|remove> roleToAddOrRemove
```
###### Job: https://pipeline.theorchard.io/job/backfill-profile-users-scripts/

#### 7. create_workstation_users.js
Creates workstation user at the vendor and subaccount level
Addings DB entries to `contact` and `vend_contact` tables as well as required
Auth0 and Neo4j entries required to ensure Login works.
Valid ingestion CSV header: 
['vendorId', 'subAccountId', 'name', 'email', 'roles']

resourceType is implied by the presence of Vendor ID or Vendor ID & Subaccount ID
For other scenarios, the row read will fail out

Send password reset email is also `False`
The script currently will *only* append access to existing users, as overwriteExistingAccess is set to `False`
Create_Auth0_User must be set to `True` for proper user profile creation
Set Master Contact is set to `True` as it will set the profile as the default "Login As Admin" in Workstation

The following values are hardcoded:
```
        send_password_reset: false,
        overwrite_existing_access: false,
        set_email_verified: true,
        create_auth0_user: true,
        master_contact: true
```
