Commit 011f49c
authored
Add migration-safe utility function for global permission assignment (ansible#870)
Fix AttributeError in migrations where fake models lack custom methods
like give_global_permission. This addresses Django's migration system
creating __fake__ models that only include database fields and basic ORM
methods, not custom instance methods.
Solution:
- Add give_global_permission_to_actor() utility function in _utils.py
- Function replicates RoleDefinition.give_global_permission() logic
- Works with migration fake models using apps.get_model()
- Enhanced team detection for migration context using model_name check
- Enables sharing code between models and migrations (Django best
practice)
The utility function handles:
- User and team assignment creation via get_or_create()
- Settings validation for singleton roles
- Cache clearing for permission updates
- Proper error handling with descriptive messages
This fix allows migrations to perform global permission assignments
without relying on custom model methods that don't exist on fake models.
Signed-off-by: Fabricio Aguiar <[email protected]>1 parent 93579cf commit 011f49c
1 file changed
+51
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
108 | 159 | | |
109 | 160 | | |
110 | 161 | | |
| |||
0 commit comments