# Design Locks
## Context
Designs live Grou RFE. Bunch of other services have a need to prohibit changes to a given design. For example, once a design is used to start a group order form, it cannot be changed anymore.
Some of the other services that may have this need:
* OrderService
* Group Order Forms
* Fulcrum
## Current state
* GOF creates a design lock through RFE design-service api each time a GOF is created (AKA the correct way).
* There is no mechanism to delete a design lock. If GOFs can be deleted (I did not check), this needs to be introduced
* RFE has code to throw an error when updating a design if this design has a lock set on it. But this code is behind a disabled feature flag. It is this way since September 2017
* Because the feature flag is disabled, it just does a DB lookup in the DB table group_orders. This works, but it works only because GOF and RFE share the same MySQL database.
* There is a design lock for every GOF, therefore no DB migration is required to enable Design Locks being used in RFE. Checked by `select count(*) from design_locks where design_id NOT IN (select design_id from group_orders);`
* The mechanism by which a design lock is checked (RFE LockChecking::LockChecker) could be a bit nicer, but it's not horrible
* While the check for design being included in a GOF is done in the _controller_, the check for if a design is included in a order happens in the _model_ (through an API call to the order service)
## Requirements
* GOF, Orders, ... shoud all use design locks in the same way
* RFE Design Service Api should be able to communicate that a design is not updateable / not deletable
* Possibly: There are different "kinds" of locks that we want to be able to use, for example:
* GOFs only wants to prohibit updates that change the design price. (a name change does not change the price and is allowed, Art change changes the price and is not allowed)
* Something else wants to prohibit all updates to the design
## Plan of implementation
0. (Suggestion, not required) Instead of having GOF design lock, Order design lock... have "Prohibit Delete Design Lock", "Prohibit Price Changing Edit Design Lock", "Prohibit All Edits Design Locks"
1. Enable the code to use design locks to prohibit updates to designs used in GOF.
2. Add an API functionality to remove a design lock
3.
> Q: How do we lock designs used in an order?
A: When an order is being created (I don't know where this code lives), call RFE design lock service in the same way as GOF does it now. When Rails Backend is swapping a design for order it needs to remove the design lock for the old design and add a new design lock.
Q: How do we lock designs used in a fundraiser?
A: When a fundraising campaign is being created (I don't know where this code lives), call RFE design lock service in the same way as GOF does it now
This lets us unify the way we do the pre-update checks and reuse code from step 1.
This step does require a DB migration, to backfill design locks for all existing orders, campaigns..
4. When a RFE design service API returns information about a design, have it loop through its designs locks and according to them set attributes as
`update_allowed`, `delete_allowed`, `non_price_changing_update_allowed`...
(If we need to display some more information to the user, e.g. "You cannot edit this design because it's used Group Order Form 5412", considering adding some metadata from the design locks to the API response)