|
6 | 6 | # MIT License see the LICENSE file for more details. |
7 | 7 |
|
8 | 8 | from indico.core.plugins import IndicoPluginBlueprint |
| 9 | +from indico.util.caching import memoize |
| 10 | +from indico.web.flask.util import make_view_func |
9 | 11 |
|
10 | | -from indico_affiliation_extras.controllers import ( |
| 12 | +from indico_affiliation_extras.controllers.admin import ( |
11 | 13 | RHAffiliationGroup, |
12 | 14 | RHAffiliationGroups, |
13 | 15 | RHAffiliationTag, |
|
18 | 20 | RHEmailRepresentativesPreview, |
19 | 21 | RHEmailRepresentativesSend, |
20 | 22 | ) |
| 23 | +from indico_affiliation_extras.controllers.catalogs import ( |
| 24 | + RHAffiliationCatalogCountries, |
| 25 | + RHAffiliationCatalogGroups, |
| 26 | + RHAffiliationCatalogSearch, |
| 27 | + RHAffiliationCatalogTags, |
| 28 | + RHCloneAffiliationCatalog, |
| 29 | + RHCreateAffiliationCatalog, |
| 30 | + RHDeleteAffiliationCatalog, |
| 31 | + RHEditAffiliationCatalog, |
| 32 | + RHManageCategoryAffiliations, |
| 33 | + RHManageEventAffiliations, |
| 34 | + RHResolveAffiliations, |
| 35 | + RHToggleDefaultCatalog, |
| 36 | +) |
| 37 | +from indico_affiliation_extras.controllers.regform import ( |
| 38 | + RHAffiliationUserCount, |
| 39 | + RHAffiliationUserCountByIds, |
| 40 | + RHInviteByAffiliation, |
| 41 | + RHManageSearchRepresentationAffiliation, |
| 42 | + RHRegFormAffiliationCountries, |
| 43 | + RHRegFormAffiliationGroups, |
| 44 | + RHRegFormAffiliations, |
| 45 | + RHRegFormAffiliationTags, |
| 46 | + RHRegFormSearchAffiliationsExtended, |
| 47 | + RHSearchRepresentationAffiliation, |
| 48 | +) |
| 49 | + |
| 50 | + |
| 51 | +blueprint = IndicoPluginBlueprint('affiliation_extras', __name__) |
| 52 | + |
| 53 | +_admin_prefix = '/admin/plugins/affiliation_extras' |
| 54 | + |
21 | 55 |
|
| 56 | +@memoize |
| 57 | +def _dispatch(event_rh, category_rh): |
| 58 | + event_view = make_view_func(event_rh) |
| 59 | + category_view = make_view_func(category_rh) |
| 60 | + |
| 61 | + def view_func(**kwargs): |
| 62 | + return category_view(**kwargs) if kwargs['object_type'] == 'category' else event_view(**kwargs) |
| 63 | + |
| 64 | + return view_func |
22 | 65 |
|
23 | | -blueprint = IndicoPluginBlueprint('affiliation_extras', __name__, url_prefix='/api/admin/plugins/affiliation_extras') |
24 | 66 |
|
25 | 67 | blueprint.add_url_rule( |
26 | | - '/representatives/email/metadata', |
| 68 | + f'{_admin_prefix}/representatives/email/metadata', |
27 | 69 | 'email_representatives_metadata', |
28 | 70 | RHEmailRepresentativesMetadata, |
29 | 71 | methods=('POST',), |
30 | 72 | ) |
31 | 73 | blueprint.add_url_rule( |
32 | | - '/representatives/email/preview', 'email_representatives_preview', RHEmailRepresentativesPreview, methods=('POST',) |
| 74 | + f'{_admin_prefix}/representatives/email/preview', |
| 75 | + 'email_representatives_preview', |
| 76 | + RHEmailRepresentativesPreview, |
| 77 | + methods=('POST',), |
33 | 78 | ) |
34 | 79 | blueprint.add_url_rule( |
35 | | - '/representatives/email/send', 'email_representatives_send', RHEmailRepresentativesSend, methods=('POST',) |
| 80 | + f'{_admin_prefix}/representatives/email/send', |
| 81 | + 'email_representatives_send', |
| 82 | + RHEmailRepresentativesSend, |
| 83 | + methods=('POST',), |
36 | 84 | ) |
37 | 85 | blueprint.add_url_rule( |
38 | | - '/representatives/email/image', |
| 86 | + f'{_admin_prefix}/representatives/email/image', |
39 | 87 | 'email_representatives_image_upload', |
40 | 88 | RHEmailRepresentativesImageUpload, |
41 | 89 | methods=('POST',), |
42 | 90 | ) |
43 | 91 |
|
44 | | -blueprint.add_url_rule('/groups', 'api_affiliation_groups', RHAffiliationGroups, methods=('GET', 'POST')) |
45 | 92 | blueprint.add_url_rule( |
46 | | - '/groups/<int:group_id>', 'api_affiliation_group', RHAffiliationGroup, methods=('GET', 'PATCH', 'DELETE') |
| 93 | + f'{_admin_prefix}/groups', 'api_affiliation_groups', RHAffiliationGroups, methods=('GET', 'POST') |
| 94 | +) |
| 95 | +blueprint.add_url_rule( |
| 96 | + f'{_admin_prefix}/groups/<int:group_id>', |
| 97 | + 'api_affiliation_group', |
| 98 | + RHAffiliationGroup, |
| 99 | + methods=('GET', 'PATCH', 'DELETE'), |
| 100 | +) |
| 101 | +blueprint.add_url_rule(f'{_admin_prefix}/tags', 'api_affiliation_tags', RHAffiliationTags, methods=('GET', 'POST')) |
| 102 | +blueprint.add_url_rule( |
| 103 | + f'{_admin_prefix}/tags/<int:tag_id>', 'api_affiliation_tag', RHAffiliationTag, methods=('GET', 'PATCH', 'DELETE') |
| 104 | +) |
| 105 | +blueprint.add_url_rule(f'{_admin_prefix}/contact-lists/names', 'api_contact_list_names', RHContactListNames) |
| 106 | +_regform_prefix = f'{_admin_prefix}/events/<int:event_id>/regforms/<int:reg_form_id>' |
| 107 | + |
| 108 | +blueprint.add_url_rule( |
| 109 | + f'{_regform_prefix}/affiliations', |
| 110 | + 'api_reg_form_affiliations', |
| 111 | + RHRegFormAffiliations, |
| 112 | +) |
| 113 | +blueprint.add_url_rule( |
| 114 | + f'{_regform_prefix}/affiliation-groups', |
| 115 | + 'api_reg_form_affiliation_groups', |
| 116 | + RHRegFormAffiliationGroups, |
47 | 117 | ) |
48 | | -blueprint.add_url_rule('/tags', 'api_affiliation_tags', RHAffiliationTags, methods=('GET', 'POST')) |
49 | 118 | blueprint.add_url_rule( |
50 | | - '/tags/<int:tag_id>', 'api_affiliation_tag', RHAffiliationTag, methods=('GET', 'PATCH', 'DELETE') |
| 119 | + f'{_regform_prefix}/affiliation-tags', |
| 120 | + 'api_reg_form_affiliation_tags', |
| 121 | + RHRegFormAffiliationTags, |
51 | 122 | ) |
52 | | -blueprint.add_url_rule('/contact-lists/names', 'api_contact_list_names', RHContactListNames) |
| 123 | +blueprint.add_url_rule( |
| 124 | + f'{_regform_prefix}/countries', |
| 125 | + 'api_reg_form_countries', |
| 126 | + RHRegFormAffiliationCountries, |
| 127 | +) |
| 128 | +blueprint.add_url_rule( |
| 129 | + f'{_regform_prefix}/affiliations/search', |
| 130 | + 'api_reg_form_search_affiliations', |
| 131 | + RHRegFormSearchAffiliationsExtended, |
| 132 | +) |
| 133 | +blueprint.add_url_rule( |
| 134 | + f'{_regform_prefix}/affiliations/user-count', |
| 135 | + 'api_affiliation_user_count_by_ids', |
| 136 | + RHAffiliationUserCountByIds, |
| 137 | + methods=('POST',), |
| 138 | +) |
| 139 | +blueprint.add_url_rule( |
| 140 | + f'{_regform_prefix}/affiliation-user-count', |
| 141 | + 'api_affiliation_user_count', |
| 142 | + RHAffiliationUserCount, |
| 143 | + methods=('POST',), |
| 144 | +) |
| 145 | +blueprint.add_url_rule( |
| 146 | + f'{_regform_prefix}/invite', |
| 147 | + 'api_invite_by_affiliation', |
| 148 | + RHInviteByAffiliation, |
| 149 | + methods=('POST',), |
| 150 | +) |
| 151 | +blueprint.add_url_rule( |
| 152 | + '/event/<int:event_id>/affiliation-extras/registration/<int:reg_form_id>/affiliations/' |
| 153 | + '<int:field_id>/list/<int:affiliation_list_id>', |
| 154 | + 'search_registration_affiliation', |
| 155 | + RHSearchRepresentationAffiliation, |
| 156 | +) |
| 157 | +blueprint.add_url_rule( |
| 158 | + '/event/<int:event_id>/manage/affiliation-extras/registration/<int:reg_form_id>/affiliations/' |
| 159 | + '<int:field_id>/list/<int:affiliation_list_id>', |
| 160 | + 'search_registration_affiliation_management', |
| 161 | + RHManageSearchRepresentationAffiliation, |
| 162 | +) |
| 163 | + |
| 164 | +# SPA page routes (React Router handles display) |
| 165 | +_management_page = _dispatch(RHManageEventAffiliations, RHManageCategoryAffiliations) |
| 166 | + |
| 167 | +for object_type in ('event', 'category'): |
| 168 | + if object_type == 'category': |
| 169 | + prefix = '/category/<int:category_id>' |
| 170 | + else: |
| 171 | + prefix = '/event/<int:event_id>' |
| 172 | + prefix += '/manage/affiliations' |
| 173 | + defaults = {'object_type': object_type} |
| 174 | + |
| 175 | + # SPA page routes (React Router handles display) |
| 176 | + blueprint.add_url_rule(f'{prefix}/', 'manage_affiliations', _management_page, defaults=defaults) |
| 177 | + blueprint.add_url_rule(f'{prefix}/new/', 'create_catalog', _management_page, defaults=defaults) |
| 178 | + blueprint.add_url_rule(f'{prefix}/<int:catalog_id>/', 'catalog_detail', _management_page, defaults=defaults) |
| 179 | + |
| 180 | + # Catalog API |
| 181 | + blueprint.add_url_rule( |
| 182 | + f'{prefix}/api/affiliations/catalogs', |
| 183 | + 'api_create_catalog', |
| 184 | + RHCreateAffiliationCatalog, |
| 185 | + defaults=defaults, |
| 186 | + methods=('POST',), |
| 187 | + ) |
| 188 | + blueprint.add_url_rule( |
| 189 | + f'{prefix}/api/affiliations/catalogs/<int:catalog_id>', |
| 190 | + 'api_edit_catalog', |
| 191 | + RHEditAffiliationCatalog, |
| 192 | + defaults=defaults, |
| 193 | + methods=('PATCH',), |
| 194 | + ) |
| 195 | + blueprint.add_url_rule( |
| 196 | + f'{prefix}/api/affiliations/catalogs/<int:catalog_id>', |
| 197 | + 'api_delete_catalog', |
| 198 | + RHDeleteAffiliationCatalog, |
| 199 | + defaults=defaults, |
| 200 | + methods=('DELETE',), |
| 201 | + ) |
| 202 | + blueprint.add_url_rule( |
| 203 | + f'{prefix}/api/affiliations/catalogs/<int:catalog_id>/clone', |
| 204 | + 'api_clone_catalog', |
| 205 | + RHCloneAffiliationCatalog, |
| 206 | + defaults=defaults, |
| 207 | + methods=('POST',), |
| 208 | + ) |
| 209 | + blueprint.add_url_rule( |
| 210 | + f'{prefix}/api/affiliations/catalogs/<int:catalog_id>/toggle-default', |
| 211 | + 'api_toggle_default_catalog', |
| 212 | + RHToggleDefaultCatalog, |
| 213 | + defaults=defaults, |
| 214 | + methods=('POST',), |
| 215 | + ) |
| 216 | + blueprint.add_url_rule( |
| 217 | + f'{prefix}/api/affiliations/resolve', |
| 218 | + 'api_resolve_affiliations', |
| 219 | + RHResolveAffiliations, |
| 220 | + defaults=defaults, |
| 221 | + methods=('POST',), |
| 222 | + ) |
| 223 | + |
| 224 | + # Scoped reference-data reads for the catalog editor and invite dialog pickers |
| 225 | + blueprint.add_url_rule( |
| 226 | + f'{prefix}/api/affiliations/groups', |
| 227 | + 'api_affiliation_catalog_groups', |
| 228 | + RHAffiliationCatalogGroups, |
| 229 | + defaults=defaults, |
| 230 | + ) |
| 231 | + blueprint.add_url_rule( |
| 232 | + f'{prefix}/api/affiliations/tags', |
| 233 | + 'api_affiliation_catalog_tags', |
| 234 | + RHAffiliationCatalogTags, |
| 235 | + defaults=defaults, |
| 236 | + ) |
| 237 | + blueprint.add_url_rule( |
| 238 | + f'{prefix}/api/affiliations/countries', |
| 239 | + 'api_affiliation_catalog_countries', |
| 240 | + RHAffiliationCatalogCountries, |
| 241 | + defaults=defaults, |
| 242 | + ) |
| 243 | + blueprint.add_url_rule( |
| 244 | + f'{prefix}/api/affiliations/search', |
| 245 | + 'api_affiliation_catalog_search', |
| 246 | + RHAffiliationCatalogSearch, |
| 247 | + defaults=defaults, |
| 248 | + ) |
0 commit comments