@@ -32,7 +32,7 @@ def __init__(self):
3232 self ._tracked_relationships = set ()
3333 self ._trackers = dict ()
3434
35- def register (self , * args , parent_field_name = 'organization' ):
35+ def register (self , * args : Type [ Model ] , parent_field_name : Optional [ str ] = 'organization' ):
3636 if self .apps_ready :
3737 raise RuntimeError ('Cannot register model to permission_registry after apps are ready' )
3838 for cls in args :
@@ -142,16 +142,24 @@ def create_managed_roles(self, apps) -> list[tuple[Model, bool]]:
142142 ret .append ((rd , created ))
143143 return ret
144144
145- def call_when_apps_ready (self , apps , app_config ):
145+ def call_when_apps_ready (self , apps , app_config ) -> None :
146146 from ansible_base .rbac import triggers
147147 from ansible_base .rbac .evaluations import bound_has_obj_perm , bound_singleton_permissions , connect_rbac_methods
148148 from ansible_base .rbac .management import create_dab_permissions
149149
150150 self .apps = apps
151- self .apps_ready = True
152151
152+ # Finish registering models
153153 if self .team_model not in self ._registry :
154- self ._registry .add (self .team_model )
154+ self .register (self .team_model )
155+
156+ for model_name , kwargs in settings .ANSIBLE_BASE_RBAC_MODEL_REGISTRY .items ():
157+ model = apps .get_model (model_name )
158+ if model not in self ._registry :
159+ self .register (model , ** kwargs )
160+
161+ # This will lock-down the registry, raising an error for any other registrations
162+ self .apps_ready = True
155163
156164 # Do no specify sender for create_dab_permissions, because that is passed as app_config
157165 # and we want to create permissions for external apps, not the dab_rbac app
0 commit comments