Skip to content

Commit

Permalink
add app setting type constants (#1458)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Jan 6, 2025
1 parent f7727c7 commit fd1ba4d
Show file tree
Hide file tree
Showing 22 changed files with 384 additions and 273 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Added

- **Projectroles**
- ``SODARUser.get_display_name()`` helper (#1487)
- App setting type constants (#1458)

Changed
-------
Expand Down
3 changes: 2 additions & 1 deletion adminalerts/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# SODAR constants
APP_SETTING_SCOPE_USER = SODAR_CONSTANTS['APP_SETTING_SCOPE_USER']
APP_SETTING_TYPE_BOOLEAN = SODAR_CONSTANTS['APP_SETTING_TYPE_BOOLEAN']


class SiteAppPlugin(SiteAppPluginPoint):
Expand All @@ -31,7 +32,7 @@ class SiteAppPlugin(SiteAppPluginPoint):
app_settings = {
'notify_email_alert': {
'scope': APP_SETTING_SCOPE_USER,
'type': 'BOOLEAN',
'type': APP_SETTING_TYPE_BOOLEAN,
'default': True,
'label': 'Receive email for admin alerts',
'description': (
Expand Down
1 change: 1 addition & 0 deletions docs/source/major_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ v1.1.0 (WIP)
Release Highlights
==================

- Add app setting type constants
- Remove support for features deprecated in v1.0
- Remove squashed migrations

Expand Down
122 changes: 66 additions & 56 deletions example_project_app/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
# SODAR constants
PROJECT_TYPE_PROJECT = SODAR_CONSTANTS['PROJECT_TYPE_PROJECT']
PROJECT_TYPE_CATEGORY = SODAR_CONSTANTS['PROJECT_TYPE_CATEGORY']
APP_SETTING_SCOPE_PROJECT = SODAR_CONSTANTS['APP_SETTING_SCOPE_PROJECT']
APP_SETTING_SCOPE_USER = SODAR_CONSTANTS['APP_SETTING_SCOPE_USER']
APP_SETTING_SCOPE_PROJECT_USER = SODAR_CONSTANTS[
'APP_SETTING_SCOPE_PROJECT_USER'
]
APP_SETTING_SCOPE_SITE = SODAR_CONSTANTS['APP_SETTING_SCOPE_SITE']
APP_SETTING_TYPE_BOOLEAN = SODAR_CONSTANTS['APP_SETTING_TYPE_BOOLEAN']
APP_SETTING_TYPE_INTEGER = SODAR_CONSTANTS['APP_SETTING_TYPE_INTEGER']
APP_SETTING_TYPE_JSON = SODAR_CONSTANTS['APP_SETTING_TYPE_JSON']
APP_SETTING_TYPE_STRING = SODAR_CONSTANTS['APP_SETTING_TYPE_STRING']

# Local constants
EXAMPLE_MODIFY_API_MSG = (
Expand Down Expand Up @@ -51,17 +61,17 @@ class ProjectAppPlugin(ProjectModifyPluginMixin, ProjectAppPluginPoint):
# TODO: Unify naming
app_settings = {
'project_str_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_PROJECT'],
'type': 'STRING',
'scope': APP_SETTING_SCOPE_PROJECT,
'type': APP_SETTING_TYPE_STRING,
'label': 'String setting',
'default': '',
'description': 'Example string project setting',
'placeholder': 'Example string',
'user_modifiable': True,
},
'project_int_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_PROJECT'],
'type': 'INTEGER',
'scope': APP_SETTING_SCOPE_PROJECT,
'type': APP_SETTING_TYPE_INTEGER,
'label': 'Integer setting',
'default': 0,
'description': 'Example integer project setting',
Expand All @@ -70,17 +80,17 @@ class ProjectAppPlugin(ProjectModifyPluginMixin, ProjectAppPluginPoint):
'widget_attrs': {'class': 'text-success'},
},
'project_str_setting_options': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_PROJECT'],
'type': 'STRING',
'scope': APP_SETTING_SCOPE_PROJECT,
'type': APP_SETTING_TYPE_STRING,
'label': 'String setting with options',
'default': 'string1',
'description': 'Example string project setting with options',
'options': ['string1', 'string2'],
'user_modifiable': True,
},
'project_int_setting_options': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_PROJECT'],
'type': 'INTEGER',
'scope': APP_SETTING_SCOPE_PROJECT,
'type': APP_SETTING_TYPE_INTEGER,
'label': 'Integer setting with options',
'default': 0,
'description': 'Example integer project setting with options',
Expand All @@ -89,25 +99,25 @@ class ProjectAppPlugin(ProjectModifyPluginMixin, ProjectAppPluginPoint):
'widget_attrs': {'class': 'text-success'},
},
'project_bool_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_PROJECT'],
'type': 'BOOLEAN',
'scope': APP_SETTING_SCOPE_PROJECT,
'type': APP_SETTING_TYPE_BOOLEAN,
'label': 'Boolean setting',
'default': False,
'description': 'Example boolean project setting',
'user_modifiable': True,
},
'project_global_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_PROJECT'],
'type': 'BOOLEAN',
'scope': APP_SETTING_SCOPE_PROJECT,
'type': APP_SETTING_TYPE_BOOLEAN,
'label': 'Global boolean setting',
'default': False,
'description': 'Example global boolean project setting',
'user_modifiable': True,
'global': True,
},
'project_json_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_PROJECT'],
'type': 'JSON',
'scope': APP_SETTING_SCOPE_PROJECT,
'type': APP_SETTING_TYPE_JSON,
'label': 'JSON setting',
'default': {
'Example': 'Value',
Expand All @@ -119,32 +129,32 @@ class ProjectAppPlugin(ProjectModifyPluginMixin, ProjectAppPluginPoint):
'widget_attrs': {'class': 'text-danger'},
},
'project_hidden_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_PROJECT'],
'type': 'STRING',
'scope': APP_SETTING_SCOPE_PROJECT,
'type': APP_SETTING_TYPE_STRING,
'label': 'Hidden setting',
'default': '',
'description': 'Example hidden project setting',
'user_modifiable': False,
},
'project_hidden_json_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_PROJECT'],
'type': 'JSON',
'scope': APP_SETTING_SCOPE_PROJECT,
'type': APP_SETTING_TYPE_JSON,
'label': 'Hidden JSON setting',
'description': 'Example hidden JSON project setting',
'user_modifiable': False,
},
'user_str_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_USER'],
'type': 'STRING',
'scope': APP_SETTING_SCOPE_USER,
'type': APP_SETTING_TYPE_STRING,
'label': 'String setting',
'default': '',
'description': 'Example string user setting',
'placeholder': 'Example string',
'user_modifiable': True,
},
'user_int_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_USER'],
'type': 'INTEGER',
'scope': APP_SETTING_SCOPE_USER,
'type': APP_SETTING_TYPE_INTEGER,
'label': 'Integer setting',
'default': 0,
'description': 'Example integer user setting',
Expand All @@ -153,17 +163,17 @@ class ProjectAppPlugin(ProjectModifyPluginMixin, ProjectAppPluginPoint):
'widget_attrs': {'class': 'text-success'},
},
'user_str_setting_options': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_USER'],
'type': 'STRING',
'scope': APP_SETTING_SCOPE_USER,
'type': APP_SETTING_TYPE_STRING,
'label': 'String setting with options',
'default': 'string1',
'options': ['string1', 'string2'],
'description': 'Example string user setting with options',
'user_modifiable': True,
},
'user_int_setting_options': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_USER'],
'type': 'INTEGER',
'scope': APP_SETTING_SCOPE_USER,
'type': APP_SETTING_TYPE_INTEGER,
'label': 'Integer setting with options',
'default': 0,
'options': [0, 1],
Expand All @@ -172,16 +182,16 @@ class ProjectAppPlugin(ProjectModifyPluginMixin, ProjectAppPluginPoint):
'widget_attrs': {'class': 'text-success'},
},
'user_bool_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_USER'],
'type': 'BOOLEAN',
'scope': APP_SETTING_SCOPE_USER,
'type': APP_SETTING_TYPE_BOOLEAN,
'label': 'Boolean setting',
'default': False,
'description': 'Example boolean user setting',
'user_modifiable': True,
},
'user_json_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_USER'],
'type': 'JSON',
'scope': APP_SETTING_SCOPE_USER,
'type': APP_SETTING_TYPE_JSON,
'label': 'JSON setting',
'default': {
'Example': 'Value',
Expand All @@ -193,33 +203,33 @@ class ProjectAppPlugin(ProjectModifyPluginMixin, ProjectAppPluginPoint):
'widget_attrs': {'class': 'text-danger'},
},
'user_hidden_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_USER'],
'type': 'STRING',
'scope': APP_SETTING_SCOPE_USER,
'type': APP_SETTING_TYPE_STRING,
'default': '',
'description': 'Example hidden user setting',
'user_modifiable': False,
},
'project_user_str_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_PROJECT_USER'],
'type': 'STRING',
'scope': APP_SETTING_SCOPE_PROJECT_USER,
'type': APP_SETTING_TYPE_STRING,
'default': '',
'description': 'Example string project user setting',
},
'project_user_int_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_PROJECT_USER'],
'type': 'INTEGER',
'scope': APP_SETTING_SCOPE_PROJECT_USER,
'type': APP_SETTING_TYPE_INTEGER,
'default': 0,
'description': 'Example int project user setting',
},
'project_user_bool_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_PROJECT_USER'],
'type': 'BOOLEAN',
'scope': APP_SETTING_SCOPE_PROJECT_USER,
'type': APP_SETTING_TYPE_BOOLEAN,
'default': False,
'description': 'Example bool project user setting',
},
'project_user_json_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_PROJECT_USER'],
'type': 'JSON',
'scope': APP_SETTING_SCOPE_PROJECT_USER,
'type': APP_SETTING_TYPE_JSON,
'default': {
'Example': 'Value',
'list': [1, 2, 3, 4, 5],
Expand All @@ -228,62 +238,62 @@ class ProjectAppPlugin(ProjectModifyPluginMixin, ProjectAppPluginPoint):
'description': 'Example json project user setting',
},
'project_callable_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_PROJECT'],
'type': 'STRING',
'scope': APP_SETTING_SCOPE_PROJECT,
'type': APP_SETTING_TYPE_STRING,
'label': 'Callable project setting',
'default': get_example_setting_default,
'description': 'Example callable project setting',
},
'user_callable_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_USER'],
'type': 'STRING',
'scope': APP_SETTING_SCOPE_USER,
'type': APP_SETTING_TYPE_STRING,
'label': 'Callable user setting',
'default': get_example_setting_default,
'description': 'Example callable user setting',
},
'project_user_callable_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_PROJECT_USER'],
'type': 'STRING',
'scope': APP_SETTING_SCOPE_PROJECT_USER,
'type': APP_SETTING_TYPE_STRING,
'default': get_example_setting_default,
'description': 'Example callable project user setting',
},
'project_callable_setting_options': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_PROJECT'],
'type': 'STRING',
'scope': APP_SETTING_SCOPE_PROJECT,
'type': APP_SETTING_TYPE_STRING,
'label': 'Callable setting with options',
'default': get_example_setting_default,
'options': get_example_setting_options,
'description': 'Example callable project setting with options',
'user_modifiable': True,
},
'user_callable_setting_options': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_USER'],
'type': 'STRING',
'scope': APP_SETTING_SCOPE_USER,
'type': APP_SETTING_TYPE_STRING,
'label': 'Callable setting with options',
'default': get_example_setting_default,
'options': get_example_setting_options,
'description': 'Example callable user setting with options',
'user_modifiable': True,
},
'project_user_callable_setting_options': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_PROJECT_USER'],
'type': 'STRING',
'scope': APP_SETTING_SCOPE_PROJECT_USER,
'type': APP_SETTING_TYPE_STRING,
'default': get_example_setting_default,
'options': get_example_setting_options,
'description': 'Example callable project user setting with options',
},
'category_bool_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_PROJECT'],
'type': 'BOOLEAN',
'scope': APP_SETTING_SCOPE_PROJECT,
'type': APP_SETTING_TYPE_BOOLEAN,
'label': 'Category boolean setting',
'default': False,
'description': 'Example boolean project category setting',
'user_modifiable': True,
'project_types': [PROJECT_TYPE_CATEGORY],
},
'site_bool_setting': {
'scope': SODAR_CONSTANTS['APP_SETTING_SCOPE_SITE'],
'type': 'BOOLEAN',
'scope': APP_SETTING_SCOPE_SITE,
'type': APP_SETTING_TYPE_BOOLEAN,
'label': 'Site boolean setting',
'default': False,
'description': 'Example boolean site setting',
Expand Down
3 changes: 2 additions & 1 deletion filesfolders/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

# SODAR constants
APP_SETTING_SCOPE_PROJECT = SODAR_CONSTANTS['APP_SETTING_SCOPE_PROJECT']
APP_SETTING_TYPE_BOOLEAN = SODAR_CONSTANTS['APP_SETTING_TYPE_BOOLEAN']

# Local constants
SHOW_LIST_COLUMNS = getattr(settings, 'FILESFOLDERS_SHOW_LIST_COLUMNS', False)
Expand All @@ -40,7 +41,7 @@ class ProjectAppPlugin(ProjectAppPluginPoint):
app_settings = {
'allow_public_links': {
'scope': APP_SETTING_SCOPE_PROJECT,
'type': 'BOOLEAN',
'type': APP_SETTING_TYPE_BOOLEAN,
'default': False,
'label': 'Allow public links',
'description': 'Allow generation of public links for files',
Expand Down
Loading

0 comments on commit fd1ba4d

Please sign in to comment.