# How to Feature Control

# Background

## What’s a Feature Control?

Feature Control is a long-ago concept introduced in legacy PHP days, and even preceded feature flags. It is a mechanism for allowing Label Managers (employees) to toggle features on/off on a per-vendor (account) basis.

## Why do we need Feature Controls? Why isn’t it a Feature Flag?

Feature flags are for short-term/new features. We use feature flags as part of our SDLC to enable CI/CD, specifically to reduce risk when deploying new code. Feature flags SHOULD be torn down after the feature is released.

Feature Controls are for features that NOT every Vendor (account) should receive, especially because it is not relevant/applicable to their terms with The Orchard/Sony Music/etc. For example, if the contract with a Vendor (account) does not support Film distribution, the Film Release Builder feature should not be available to any user accessing that Vendor (account).

## What’s a Vendor Restricted Feature?

This is the same concept/backed by the same technical details. You’ve come to the right place 👯‍♂️. We sometimes talk about Feature Controls in terms of the features enabled for a Vendor (account). Other times, we talk about Feature Controls in terms of the features restricted for a Vendor (account).

## How do Label Managers (employees) manage a Vendor’s (Account’s) Feature Controls?

Feature Controls can be managed in OA, from the Vendor’s (Account’s) page:

![[https://oa.qaorch.com/cont_mgmt/view_vendor.php?vendor_id=7123](https://oa.qaorch.com/cont_mgmt/view_vendor.php?vendor_id=7123), clicking Edit provides an interface to change what the Vendor has access to.](How%20to%20Feature%20Control/Screenshot_2024-10-22_at_5.40.23_PM.png)

[https://oa.qaorch.com/cont_mgmt/view_vendor.php?vendor_id=7123](https://oa.qaorch.com/cont_mgmt/view_vendor.php?vendor_id=7123), clicking Edit provides an interface to change what the Vendor has access to.

## How do Feature Controls impact the permissions available to assign to an Identity?

### (Legacy) Workstation

The `ui_restriction` table contains a list of UI elements that are only available with specific Features. There is no impact on permissions available. Accounts and Identities is not actively supporting this area. This “outdated” doc may be helpful: [Feature Controls (OUTDATED)](https://www.notion.so/Feature-Controls-OUTDATED-14894b40547c43468ff40d063afafd53?pvs=21) 

### Suite Apps (Current)

There is no such thing.

### Suite Apps (Future)

The Accounts & Identities team, in conjunction with Permissions Platform team, is working on ensuring the enabling of a Feature will provide the ability to make additional permissions available for assignment from Settings app. This is WIP. If you have this use case, please hit us up on #accounts-team-public.

# Technical Details

All Feature Controls are defined and maintained in the `art_relations` MySQL database. There are a few key database tables:

- `features` - a list of all the features. There are two columns of note:
    - `feature_name`
    - `is_default` , historically used to decide whether to enable the feature by default
- `vendor_restricted_features` - the presence of a row in this table indicates the vendor (account) should not have access to the specified feature

## GraphQL

Get a Vendor’s [enabled Feature Controls](https://github.com/theorchard/graphql-account/blob/f5a1940557e4d65b219d9c251f42cff2c7521cb1/src/schema/Vendor.graphql#L42-L49):

```bash
query VendorFeatures($vendorId: Int!) {
  vendor(vendorId: $vendorId) {
    vendorFeatures {
      name
      id
    }
  }
}
```

![Screenshot 2024-10-22 at 6.08.20 PM.png](How%20to%20Feature%20Control/Screenshot_2024-10-22_at_6.08.20_PM.png)

## Adding a new Feature Control

For each of the steps, be sure the change is merged/deployed prior to moving onto the next step.

### 1. Add to `features` and backfill `vendor_restricted_features`

This is done via [Database DML PR](https://www.notion.so/Database-Deploy-Process-3742829fd69d49469cba7e22ca80bcad?pvs=21), like: https://github.com/theorchard/database/pull/5829/files

- You should set `is_default` based on what a typical Orchard Vendor (account) should receive. This impacts the defaults when adding a new Vendor (account) in OA:

![Screenshot 2024-10-22 at 6.25.16 PM.png](How%20to%20Feature%20Control/d4eab4d2-7b11-4aeb-b59f-b781833b7f4f.png)

### 2. Update ows-account

Add the new feature, along with its feature_id in the `FEATURES` enum

[https://github.com/theorchard/ows-account/blob/da94af0c2eaf35aa9a04c648940cd516de2d2f23/account/constants/features.py#L6-L39](https://github.com/theorchard/ows-account/blob/da94af0c2eaf35aa9a04c648940cd516de2d2f23/account/constants/features.py#L6-L39)

Add the new feature to either enum `DEFAULT_RESTRICTED_FEATURES` or `DEFAULT_ENABLED_FEATURES` 

[https://github.com/theorchard/ows-account/blob/da94af0c2eaf35aa9a04c648940cd516de2d2f23/account/constants/features.py#L42-L79](https://github.com/theorchard/ows-account/blob/da94af0c2eaf35aa9a04c648940cd516de2d2f23/account/constants/features.py#L42-L79)

### 3. Update lambda-gda-account-creation

Add the new feature, along with its feature_id in the `FEATURES` enum

[https://github.com/theorchard/lambda-gda-account-creation/blob/5cb6d8c9916088840c5a405db596ad388578e407/lambda/create_vendor/constants/features.py#L5-L38](https://github.com/theorchard/lambda-gda-account-creation/blob/5cb6d8c9916088840c5a405db596ad388578e407/lambda/create_vendor/constants/features.py#L5-L38)

Add the new feature to either enum `DEFAULT_RESTRICTED_FEATURES` or `DEFAULT_ENABLED_FEATURES` 

[https://github.com/theorchard/lambda-gda-account-creation/blob/5cb6d8c9916088840c5a405db596ad388578e407/lambda/create_vendor/constants/features.py#L41-L78](https://github.com/theorchard/lambda-gda-account-creation/blob/5cb6d8c9916088840c5a405db596ad388578e407/lambda/create_vendor/constants/features.py#L41-L78)

### [optional] Gate visibility of the new feature in OA using a Feature Flag

This is helpful for when your Product Manager tells you they are not ready for all OA Users (employees) to see the Feature Control, and certainly not ready to let Label Managers (employees) enable the Feature Control for any Vendors (Accounts) yet.

[https://github.com/theorchard/orchard/blob/2f8953f1e0756ed1737979aeb531404d92010b04/public/oa/cont_mgmt/includes/panelLabelInfoForm.inc#L1288-L1318](https://github.com/theorchard/orchard/blob/2f8953f1e0756ed1737979aeb531404d92010b04/public/oa/cont_mgmt/includes/panelLabelInfoForm.inc#L1288-L1318)