Просмотр исходного кода

HUE-8530 [organization] Move model to models2.py

Romain 6 лет назад
Родитель
Сommit
e625bb103f

+ 1 - 1
apps/beeswax/src/beeswax/models.py

@@ -39,7 +39,7 @@ from librdbms.server import dbms as librdbms_dbms
 from beeswax.design import HQLdesign
 
 if ENABLE_ORGANIZATIONS.get():
-  from useradmin.models import OrganizationUser as User
+  from useradmin.models2 import OrganizationUser as User
 else:
   from django.contrib.auth.models import User
 

+ 5 - 5
apps/jobsub/src/jobsub/models.py

@@ -18,23 +18,23 @@
 from builtins import str
 import logging
 
-from django.db import models
 from django.core import urlresolvers
 from django.contrib.auth.models import User
+from django.db import models
 from django.utils.translation import ugettext_lazy as _
 
 from desktop.conf import ENABLE_ORGANIZATIONS
 from desktop.lib.parameterization import find_parameters, bind_parameters
 
-
-LOG = logging.getLogger(__name__)
-
 if ENABLE_ORGANIZATIONS.get():
-  from useradmin.models import OrganizationUser as User
+  from useradmin.models2 import OrganizationUser as User
 else:
   from django.contrib.auth.models import User
 
 
+LOG = logging.getLogger(__name__)
+
+
 class JobDesign(models.Model):
   """
   DEPRECATED!!!

+ 1 - 1
apps/oozie/src/oozie/models.py

@@ -65,7 +65,7 @@ else:
   from cStringIO import StringIO as string_io
 
 if ENABLE_ORGANIZATIONS.get():
-  from useradmin.models import OrganizationUser as User
+  from useradmin.models2 import OrganizationUser as User
 else:
   from django.contrib.auth.models import User
 

+ 1 - 2
apps/pig/src/pig/models.py

@@ -31,9 +31,8 @@ from desktop.lib.exceptions_renderable import PopupException
 from desktop.models import Document as Doc, SAMPLE_USER_ID
 from hadoop.fs.hadoopfs import Hdfs
 
-
 if ENABLE_ORGANIZATIONS.get():
-  from useradmin.models import OrganizationUser as User
+  from useradmin.models2 import OrganizationUser as User
 else:
   from django.contrib.auth.models import User
 

+ 35 - 0
apps/search/src/search/migrations/0002_auto_20190716_1435.py

@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.20 on 2019-07-16 14:35
+from __future__ import unicode_literals
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    initial = True
+
+    dependencies = [
+        ('search', '0001_initial'),
+        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='collection',
+            name='owner',
+            field=models.ForeignKey(default=None, help_text='User who created the job.', null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Owner'),
+        ),
+        migrations.AddField(
+            model_name='collection',
+            name='result',
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='search.Result'),
+        ),
+        migrations.AddField(
+            model_name='collection',
+            name='sorting',
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='search.Sorting'),
+        ),
+    ]

+ 1 - 2
apps/search/src/search/models.py

@@ -30,9 +30,8 @@ from libsolr.api import SolrApi
 
 from search.conf import SOLR_URL
 
-
 if ENABLE_ORGANIZATIONS.get():
-  from useradmin.models import OrganizationUser as User
+  from useradmin.models2 import OrganizationUser as User
 else:
   from django.contrib.auth.models import User
 

+ 2 - 2
apps/useradmin/src/useradmin/forms.py

@@ -30,12 +30,12 @@ from desktop import conf as desktop_conf
 from desktop.lib.django_util import get_username_re_rule, get_groupname_re_rule
 from desktop.settings import LANGUAGES
 
+from useradmin.hue_password_policy import hue_get_password_validators
 from useradmin.models import GroupPermission, HuePermission
 from useradmin.models import get_default_user_group
-from useradmin.hue_password_policy import hue_get_password_validators
 
 if desktop_conf.ENABLE_ORGANIZATIONS.get():
-  from useradmin.models import OrganizationUser as HueUser
+  from useradmin.models2 import OrganizationUser as HueUser
 else:
   from desktop.models import HueUser
 

+ 3 - 126
apps/useradmin/src/useradmin/models.py

@@ -58,136 +58,13 @@ from hadoop import cluster
 
 import useradmin.conf
 
-
-LOG = logging.getLogger(__name__)
-
-
-# -----------------------------------------------------------------------
-#  Organizations
-# -----------------------------------------------------------------------
-
-# TODO models2.py
-
 if ENABLE_ORGANIZATIONS.get():
-
-  class OrganizationManager(models.Manager):
-    use_in_migrations = True
-
-    def get_by_natural_key(self, name):
-      return self.get(name=name)
-
-  class Organization(models.Model):
-    name = models.CharField(max_length=200, help_text=_t("The name of the organization"))
-    is_active = models.BooleanField(default=True)
-
-    objects = OrganizationManager()
-
-
-  class OrganizationGroupManager(models.Manager):
-
-    def natural_key(self):
-      return (self.organization, self.name,)
-
-  class OrganizationGroup(models.Model):
-    name = models.CharField(_t('name'), max_length=80, unique=False)
-    organization = models.ForeignKey(Organization)
-
-    permissions = models.ManyToManyField(
-        'HuePermission',
-        verbose_name=_t('permissions'),
-        blank=True,
-    )
-
-    objects = OrganizationGroupManager()
-
-    class Meta:
-      verbose_name = _t('organization group')
-      verbose_name_plural = _t('organization groups')
-      unique_together = ('name', 'organization',)
-
-    def __str__(self):
-      return '%s %s' % (self.organization, self.name)
-
-
-  class UserManager(BaseUserManager):
-    """Define a model manager for User model with no username field."""
-
-    use_in_migrations = True
-
-    def _create_user(self, email, password, **extra_fields):
-        """Create and save a User with the given email and password."""
-        if not email:
-            raise ValueError('The given email must be set')
-        email = self.normalize_email(email)
-        user = self.model(email=email, **extra_fields)
-        user.set_password(password)
-        user.save(using=self._db)
-        return user
-
-    def create_user(self, email, password=None, **extra_fields):
-        """Create and save a regular User with the given email and password."""
-        extra_fields.setdefault('is_staff', False)
-        extra_fields.setdefault('is_superuser', False)
-        return self._create_user(email, password, **extra_fields)
-
-    def create_superuser(self, email, password, **extra_fields):
-        """Create and save a SuperUser with the given email and password."""
-        extra_fields.setdefault('is_staff', True)
-        extra_fields.setdefault('is_superuser', True)
-
-        if extra_fields.get('is_staff') is not True:
-            raise ValueError('Superuser must have is_staff=True.')
-        if extra_fields.get('is_superuser') is not True:
-            raise ValueError('Superuser must have is_superuser=True.')
-
-        return self._create_user(email, password, **extra_fields)
-
-  def default_organization():
-    default_organization, created = Organization.objects.get_or_create(name='default')
-    return default_organization
-
-  class OrganizationUser(AbstractUser):
-      """User model."""
-
-      username = None
-      email = models.EmailField(_t('email address'), unique=True)
-      token = models.CharField(_t('token'), max_length=128, default=None, null=True)
-      customer_id = models.CharField(_t('Customer id'), max_length=128, default=None, null=True)
-      organization = models.ForeignKey(Organization, on_delete=models.CASCADE)
-
-      groups = models.ManyToManyField(
-          OrganizationGroup,
-          verbose_name=_t('groups'),
-          blank=True,
-          help_text=_t(
-              'The groups this user belongs to. A user will get all permissions '
-              'granted to each of their groups.'
-          ),
-          related_name="user_set",
-          related_query_name="user",
-      )
-
-      USERNAME_FIELD = 'email'
-      REQUIRED_FIELDS = []
-
-      objects = UserManager()
-
-      @property
-      def username(self):
-        return self.email
-
-      @username.setter
-      def username(self, value):
-        pass
-
-
-
-if ENABLE_ORGANIZATIONS.get():
-  from useradmin.models import OrganizationUser as User, OrganizationGroup as Group
+  from useradmin.models2 import OrganizationUser as User, OrganizationGroup as Group
 else:
   from django.contrib.auth.models import User, Group
 
-# -----------------------------------------------------------------------
+
+LOG = logging.getLogger(__name__)
 
 
 class UserProfile(models.Model):

+ 1 - 1
desktop/core/src/desktop/auth/backend.py

@@ -55,7 +55,7 @@ from useradmin import ldap_access
 from useradmin.models import get_profile, get_default_user_group, UserProfile
 
 if ENABLE_ORGANIZATIONS.get():
-  from useradmin.models import OrganizationUser as User, Organization
+  from useradmin.models2 import OrganizationUser as User, Organization
 else:
   from django.contrib.auth.models import User
 

+ 1 - 1
desktop/core/src/desktop/auth/forms.py

@@ -32,7 +32,7 @@ from useradmin.hue_password_policy import hue_get_password_validators
 from desktop.auth.backend import is_admin
 
 if conf.ENABLE_ORGANIZATIONS.get():
-  from useradmin.models import OrganizationUser as User
+  from useradmin.models2 import OrganizationUser as User
 else:
   from django.contrib.auth.models import User
 

+ 1 - 1
desktop/core/src/desktop/models.py

@@ -62,7 +62,7 @@ else:
   from urllib import quote as urllib_quote
 
 if ENABLE_ORGANIZATIONS.get():
-  from useradmin.models import OrganizationUser as User, OrganizationGroup as Group
+  from useradmin.models2 import OrganizationUser as User, OrganizationGroup as Group
 else:
   from django.contrib.auth.models import User, Group