Forráskód Böngészése

HUE-8530 [organization] Skeleton of Organization model

Romain 6 éve
szülő
commit
21f5e1a17c

+ 1 - 1
apps/impala/src/impala/dbms.py

@@ -188,4 +188,4 @@ class ImpalaDbms(HiveServer2Dbms):
   def _get_different_tables(self, database):
     beeswax_tables = self._get_beeswax_tables(database)
     impala_tables = self.get_tables(database=database)
-    return set(beeswax_tables).symmetric_difference(impala_tables)
+    return set(beeswax_tables).symmetric_difference(impala_tables)

+ 72 - 2
apps/useradmin/src/useradmin/models.py

@@ -66,8 +66,74 @@ from hadoop import cluster
 
 import useradmin.conf
 
+
 LOG = logging.getLogger(__name__)
 
+
+
+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 OrganizationGroupPermission(models.Model):
+#   """
+#   Represents the permissions a group has.
+#   """
+#   group = models.ForeignKey(OrganizationGroup)
+#   hue_permission = models.ForeignKey("HuePermission")
+
+
+# In class UserProfile
+#
+#   def get_groups(self):
+#     return self.user.groups.all()
+# to update
+
+# User
+# --> switch to email as PK
+# AUTH_USER_MODEL = 'auth.User'
+
+# Enabled when:
+# desktop.conf.ENABLE_ORGANIZATIONS.get()
+
+
 class UserProfile(models.Model):
   """
   WARNING: Some of the columns in the UserProfile object have been added
@@ -134,7 +200,8 @@ class UserProfile(models.Model):
     if self.has_hue_permission(perm):
       return
     else:
-      raise PopupException(_t("You do not have permissions to %(description)s.") % dict(description=perm.description))
+      raise PopupException(_t("You do not have permissions to %(description)s.") % {'description': perm.description})
+
 
 def get_profile(user):
   """
@@ -170,6 +237,7 @@ def create_profile_for_user(user):
     LOG.exception("Failed to automatically create user profile.")
     return None
 
+
 class LdapGroup(models.Model):
   """
   Groups that come from LDAP originally will have an LdapGroup
@@ -177,6 +245,7 @@ class LdapGroup(models.Model):
   """
   group = models.ForeignKey(auth_models.Group, related_name="group")
 
+
 class GroupPermission(models.Model):
   """
   Represents the permissions a group has.
@@ -185,7 +254,6 @@ class GroupPermission(models.Model):
   hue_permission = models.ForeignKey("HuePermission")
 
 
-# Permission Management
 class HuePermission(models.Model):
   """
   Set of non-object specific permissions that an app supports.
@@ -197,6 +265,7 @@ class HuePermission(models.Model):
   description = models.CharField(max_length=255)
 
   groups = models.ManyToManyField(auth_models.Group, through=GroupPermission)
+  organization_groups = models.ManyToManyField(OrganizationGroup)
 
   def __str__(self):
     return "%s.%s:%s(%d)" % (self.app, self.action, self.description, self.pk)
@@ -205,6 +274,7 @@ class HuePermission(models.Model):
   def get_app_permission(cls, hue_app, action):
     return HuePermission.objects.get(app=hue_app, action=action)
 
+
 def get_default_user_group(**kwargs):
   default_user_group = useradmin.conf.DEFAULT_USER_GROUP.get()
   if default_user_group is None:

+ 1 - 0
apps/useradmin/src/useradmin/views.py

@@ -57,6 +57,7 @@ from useradmin.forms import SyncLdapUsersGroupsForm, AddLdapGroupsForm, AddLdapU
 
 from desktop.auth.backend import is_admin
 
+
 LOG = logging.getLogger(__name__)
 
 __users_lock = threading.Lock()

+ 3 - 0
desktop/conf.dist/hue.ini

@@ -212,6 +212,9 @@
   # Choose whether to use new charting library across the whole Hue.
   ## use_new_charts=false
 
+  # Choose whether to allow multi tenancy or not.
+  ## enable_organizations=false
+
   # Editor autocomplete timeout (ms) when fetching columns, fields, tables etc.
   # To disable this type of autocompletion set the value to 0.
   ## editor_autocomplete_timeout=30000

+ 3 - 0
desktop/conf/pseudo-distributed.ini.tmpl

@@ -216,6 +216,9 @@
   # Choose whether to use new charting library across the whole Hue.
   ## use_new_charts=false
 
+  # Choose whether to allow multi tenancy or not.
+  ## enable_organizations=false
+
   # Editor autocomplete timeout (ms) when fetching columns, fields, tables etc.
   # To disable this type of autocompletion set the value to 0.
   ## editor_autocomplete_timeout=30000

+ 7 - 0
desktop/core/src/desktop/conf.py

@@ -1655,6 +1655,13 @@ IS_K8S_ONLY = Config(
   help=_('Choose whether to pick configs only from [desktop] [[cluster]]')
 )
 
+ENABLE_ORGANIZATIONS = Config(
+  key='enable_organizations',
+  default=False,
+  type=coerce_bool,
+  help=_('Choose whether to allow multi tenancy or not.')
+)
+
 
 ENABLE_PROMETHEUS = Config(
   key='enable_prometheus',