Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ They are:
- [How we Calculate DORA](#-how-we-calculate-dora)
- [Roadmap](#%EF%B8%8F-roadmap)
- [Contributing guidelines](#%EF%B8%8F-contributing-guidelines)
- [Developer Automations](#-developer-automations)
- [Security guidelines](#%EF%B8%8F-security-guidelines)
- [License](#license)

Expand Down Expand Up @@ -371,6 +372,29 @@ To get started contributing to middleware check out our [CONTRIBUTING.md](https:

We appreciate your contributions and look forward to working together to make Middleware even better!

## 👨‍💻 Developer Automations

This sections contains some automation scripts that can generate boilder plate code to extend certain features and ship faster 🚀

### 1. Adding New Settings in Backend

- Context: Adding a new setting required context of the Settings System, changes across some files and making adpater and defaults based on the new setting class structure.
- This can now be done by running the `python make_new_setting.py` scripts in the `./backend/dev_scripts` directory

If you are in the root directory, you can run:
```
python ./backend/dev_scripts/make_new_setting.py
```

- Enter the Setting name in the consitent format.
- Add the required keys and thier types. Enter `done` once you have added all the fields.
- Update Imports and Linting.
- You are good to go :tada"
- Note: For more non primite types in the setting such as uuid, enums etc, you will have to make changes to the generated adpaters.


https://github.com/middlewarehq/middleware/assets/70485812/f0529fa7-a2cb-44b1-ae07-2a7c97f56bef

# ⛓️ Security guidelines

To get started contributing to middleware check out our [SECURITY.md](https://github.com/middlewarehq/middleware/blob/main/SECURITY.md).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def _add_entity(config_settings: ConfigurationSettings, response):

def _add_setting_data(config_settings: ConfigurationSettings, response):

# Add new if statements to add settings response for new settings
if isinstance(config_settings.specific_settings, IncidentSettings):
response["setting"] = {
"title_includes": config_settings.specific_settings.title_filters
Expand All @@ -50,6 +49,8 @@ def _add_setting_data(config_settings: ConfigurationSettings, response):
]
}

# ADD NEW API ADAPTER HERE

return response

response = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def _adapt_incident_types_setting_from_setting_data(
]
)

# ADD NEW DICT TO DATACLASS ADAPTERS HERE

def _handle_config_setting_from_db_setting(
self, setting_type: SettingType, setting_data
):
Expand All @@ -75,6 +77,8 @@ def _handle_config_setting_from_db_setting(
if setting_type == SettingType.INCIDENT_SOURCES_SETTING:
return self._adapt_incident_source_setting_from_setting_data(setting_data)

# ADD NEW HANDLE FROM DB SETTINGS HERE

raise Exception(f"Invalid Setting Type: {setting_type}")

def _adapt_config_setting_from_db_setting(self, setting: Settings):
Expand Down Expand Up @@ -147,6 +151,8 @@ def _adapt_incident_types_setting_from_json(
]
)

# ADD NEW DICT TO API ADAPTERS HERE

def _handle_config_setting_from_json_data(
self, setting_type: SettingType, setting_data
):
Expand All @@ -164,6 +170,8 @@ def _handle_config_setting_from_json_data(
if setting_type == SettingType.INCIDENT_TYPES_SETTING:
return self._adapt_incident_types_setting_from_json(setting_data)

# ADD NEW HANDLE FROM JSON DATA HERE

raise Exception(f"Invalid Setting Type: {setting_type}")

def _adapt_incident_setting_json_data(
Expand Down Expand Up @@ -195,6 +203,8 @@ def _adapt_incident_types_setting_json_data(
]
}

# ADD NEW DATACLASS TO JSON DATA ADAPTERS HERE

def _handle_config_setting_to_db_setting(
self, setting_type: SettingType, specific_setting
):
Expand All @@ -219,6 +229,8 @@ def _handle_config_setting_to_db_setting(
):
return self._adapt_incident_source_setting_json_data(specific_setting)

# ADD NEW HANDLE TO DB SETTINGS HERE

raise Exception(f"Invalid Setting Type: {setting_type}")

def _adapt_specific_setting_data_from_json(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ def get_default_setting_data(setting_type: SettingType):
"incident_types": [incident_type.value for incident_type in incident_types]
}

# ADD NEW DEFAULT SETTING HERE

raise Exception(f"Invalid Setting Type: {setting_type}")
9 changes: 9 additions & 0 deletions backend/analytics_server/mhq/service/settings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,12 @@ class IncidentTypesSetting(BaseSetting):
@dataclass
class IncidentSourcesSetting(BaseSetting):
incident_sources: List[IncidentSource]


# ADD NEW SETTING CLASS HERE

# Sample Future Settings
# @dataclass
# class PRSettings(BaseSetting):
# number_filters: List[str]
# merge_time: List[str]
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ def settings_type_validator(setting_type: str):
if setting_type == SettingType.INCIDENT_SOURCES_SETTING.value:
return SettingType.INCIDENT_SOURCES_SETTING

# ADD NEW VALIDATOR HERE

raise BadRequest(f"Invalid Setting Type: {setting_type}")
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SettingType(Enum):
INCIDENT_TYPES_SETTING = "INCIDENT_TYPES_SETTING"
INCIDENT_SOURCES_SETTING = "INCIDENT_SOURCES_SETTING"
EXCLUDED_PRS_SETTING = "EXCLUDED_PRS_SETTING"
# ADD NEW SETTING TYPE ENUM HERE


class Settings(db.Model):
Expand Down
Loading