Przeglądaj źródła

HUE-967 [useradmin] Useradmin shouldn't depend on the existence of other apps

With transactional DBs, the useradmin app had to be the last app to sync.
With introspection, this is no longer the case. The useradmin app can be sync'd
at any point and start populating the HuePermission model.
The HuePermission model accepts strings, which makes it independent
of the model itself.
abec 13 lat temu
rodzic
commit
0d7b1c79f8

+ 1 - 28
apps/useradmin/src/useradmin/migrations/0001_permissions_and_profiles.py

@@ -1,39 +1,12 @@
 # encoding: utf-8
-import datetime
 from south.db import db
 from south.v2 import DataMigration
 from django.db import models
 
-from desktop.lib.classes import classproperty
-
 from useradmin.models import UserProfile
 
+
 class Migration(DataMigration):
-    depends_on = (
-      # List of dependencies filled by the depends_on classproperty
-    )
-
-    def _depends_on(cls):
-      """
-      Ensure useradmin is migrated last by placing its migrations after all other migrations
-      """
-      from desktop.appmanager import DESKTOP_MODULES
-      import pkgutil
-
-      dependent_migrations = []
-      for module in DESKTOP_MODULES:
-        if module.name not in __name__:
-          try:
-            package = module.module.migrations
-            for importer, modname, ispkg in pkgutil.iter_modules(package.__path__):
-              dependent_migrations.append((module.name, modname))
-          except AttributeError:
-            # No migrations for this iteration
-            pass
-
-      return tuple(dependent_migrations)
-
-    depends_on = classproperty(_depends_on)
 
     def forwards(self, orm):
         """

+ 5 - 6
apps/useradmin/src/useradmin/models.py

@@ -213,15 +213,14 @@ def update_app_permissions(**kwargs):
   the best thing we can do, since some apps might not
   have models, but nonetheless, "syncdb" is typically
   run when apps are installed.
-
-  This code executes when useradmin is sync'd since useradmin should be sync'd last.
   """
   # Map app->action->HuePermission.
 
-  # Only execute for useradmin app since useradmin is sync'd last.
-  # The HuePermission model needs to be sync'd for the following code to work.
-  # Since all apps should have been sync'd before useradmin, referencing them
-  # here is functional.
+  # The HuePermission model needs to be sync'd for the following code to work
+  # The point of 'if u'useradmin_huepermission' in connection.introspection.table_names():'
+  # is to check if Useradmin has been installed.
+  # It is okay to follow appmanager.DESKTOP_APPS before they've been sync'd
+  # because apps are referenced by app name in Hue permission and not by model ID.
   if u'useradmin_huepermission' in connection.introspection.table_names():
     current = {}