def get_enterprise_teams(self,
                             enterprise_id,
                             user_id=None,
                             query=None,
                             page=None,
                             page_size=None):
        from console.services.user_services import user_services
        if query is not None and page is not None and page_size is not None:
            tall = team_repo.get_teams_by_enterprise_id(enterprise_id,
                                                        user_id=user_id,
                                                        query=query)
            total = tall.count()
            paginator = Paginator(tall, page_size)
            raw_tenants = paginator.page(page)
            tenants = []
            for ent in raw_tenants:
                user = user_services.get_user_by_user_id(ent.creater)
                tenants.append({
                    "tenant_id": ent.tenant_id,
                    "tenant_name": ent.tenant_name,
                    "region": ent.region,
                    "is_active": ent.is_active,
                    "create_time": ent.create_time,
                    "creater": user.nick_name,
                    "tenant_alias": ent.tenant_alias,
                    "enterprise_id": ent.enterprise_id,
                })
            result = {"total": total, "tenants": tenants}
        else:
            result = team_repo.get_teams_by_enterprise_id(enterprise_id)

        return result
Esempio n. 2
0
    def get_paged_plugins(self, plugin_name="", is_complete=None, scope="", source="",
                          tenant=None, page=1, limit=10, order_by="", category=""):
        q = Q(enterprise_id__in=[tenant.enterprise_id, "public"])

        if source:
            q = q & Q(source=source)

        if is_complete:
            q = q & Q(is_complete=is_complete)

        if plugin_name:
            q = q & Q(plugin_name__icontains=plugin_name)

        if category:
            q = q & Q(category=category)

        if scope == 'team':
            q = q & Q(share_team=tenant.tenant_name)
        elif scope == 'goodrain':
            q = q & Q(scope='goodrain')
        elif scope == 'enterprise':
            tenants = team_repo.get_teams_by_enterprise_id(tenant.enterprise_id)
            tenant_names = [t.tenant_name for t in tenants]
            q = q & Q(share_team__in=tenant_names) & ~Q(scope='team')
        else:
            tenants = team_repo.get_teams_by_enterprise_id(tenant.enterprise_id)
            tenant_names = [t.tenant_name for t in tenants]

            q = q & (Q(share_team__in=tenant_names, scope="enterprise")
                     | Q(scope="goodrain") | Q(share_team=tenant.tenant_name, scope="team"))

        if order_by == 'is_complete':
            plugins = RainbondCenterPlugin.objects.filter(q).order_by('is_complete')
        else:
            plugins = RainbondCenterPlugin.objects.filter(q).order_by('-update_time')

        paged_plugins = Paginator(plugins, limit).page(page)

        data = [{
            'plugin_name': p.plugin_name,
            'plugin_key': p.plugin_key,
            'category': p.category,
            'pic': p.pic,
            'version': p.version,
            'desc': p.desc,
            'id': p.ID,
            'is_complete': p.is_complete,
            'source': p.source,
            'update_time': p.update_time,
            'details': p.details
        } for p in paged_plugins]

        return len(plugins), data
Esempio n. 3
0
 def get_current_enterprise_shared_apps(self, enterprise_id):
     tenants = team_repo.get_teams_by_enterprise_id(enterprise_id)
     tenant_names = [t.tenant_name for t in tenants]
     # 获取企业分享的应用,并且排除返回在团队内的
     return rainbond_app_repo.get_current_enter_visable_apps(
         enterprise_id).filter(share_team__in=tenant_names).exclude(
             scope="team")
Esempio n. 4
0
    def get_team_visiable_apps(self, tenant):
        tenants = team_repo.get_teams_by_enterprise_id(tenant.enterprise_id)
        tenant_names = [t.tenant_name for t in tenants]
        public_apps = Q(scope="goodrain")
        enterprise_apps = Q(share_team__in=tenant_names, scope="enterprise")
        team_apps = Q(share_team=tenant.tenant_name, scope="team")

        return rainbond_app_repo.get_complete_rainbond_apps().filter(
            public_apps | enterprise_apps | team_apps)
Esempio n. 5
0
 def get_enterprise_teams(self, enterprise_id, query=None, page=None, page_size=None, user=None):
     tall = team_repo.get_teams_by_enterprise_id(enterprise_id, query=query)
     total = tall.count()
     if page is not None and page_size is not None:
         paginator = Paginator(tall, page_size)
         raw_tenants = paginator.page(page)
     else:
         raw_tenants = tall
     tenants = []
     for tenant in raw_tenants:
         tenants.append(self.team_with_region_info(tenant, user))
     return tenants, total
Esempio n. 6
0
    def get(self, request, *args, **kwargs):
        """指定用户可以加入哪些团队"""
        try:
            tenants = team_repo.get_tenants_by_user_id(
                user_id=self.user.user_id)
            team_names = tenants.values("tenant_name")
            team_name_list = [
                t_name.get("tenant_name") for t_name in team_names
            ]

            user_id = request.GET.get("user_id", None)
            if user_id:
                enterprise_id = user_repo.get_by_user_id(
                    user_id=user_id).enterprise_id
                team_list = team_repo.get_teams_by_enterprise_id(enterprise_id)
                apply_team = apply_repo.get_applicants_team(user_id=user_id)
            else:
                enterprise_id = user_repo.get_by_user_id(
                    user_id=self.user.user_id).enterprise_id
                team_list = team_repo.get_teams_by_enterprise_id(enterprise_id)
                apply_team = apply_repo.get_applicants_team(
                    user_id=self.user.user_id)
            applied_team = [
                team_repo.get_team_by_team_name(team_name=team_name) for
                team_name in [team_name.team_name for team_name in apply_team]
            ]
            join_list = []
            for join_team in team_list:
                if join_team not in applied_team and join_team.tenant_name not in team_name_list:
                    join_list.append(join_team)
            join_list = [{
                "team_name": j_team.tenant_name,
                "team_alias": j_team.tenant_alias,
                "team_id": j_team.tenant_id
            } for j_team in join_list]
            result = general_message(200, "success", "查询成功", list=join_list)
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
        return Response(result, status=result["code"])
Esempio n. 7
0
 def get(self, request, enterprise_id, *args, **kwargs):
     """指定用户可以加入哪些团队"""
     tenants = team_repo.get_tenants_by_user_id(user_id=self.user.user_id)
     team_names = tenants.values("tenant_name")
     # 已加入的团队
     team_name_list = [t_name.get("tenant_name") for t_name in team_names]
     team_list = team_repo.get_teams_by_enterprise_id(enterprise_id)
     apply_team = apply_repo.get_append_applicants_team(user_id=self.user.user_id)
     # 已申请过的团队
     applied_team = [team_name.team_name for team_name in apply_team]
     can_join_team_list = []
     for join_team in team_list:
         if join_team.tenant_name not in applied_team and join_team.tenant_name not in team_name_list:
             can_join_team_list.append(join_team.tenant_name)
     join_list = [{
         "team_name": j_team.tenant_name,
         "team_alias": j_team.tenant_alias,
         "team_id": j_team.tenant_id
     } for j_team in team_repo.get_team_by_team_names(can_join_team_list)]
     result = general_message(200, "success", "查询成功", list=join_list)
     return Response(result, status=result["code"])
Esempio n. 8
0
 def get_http_rules_by_enterprise_id(self, enterprise_id, is_auto_ssl=None):
     teams = team_repo.get_teams_by_enterprise_id(enterprise_id)
     if not teams:
         return []
     team_ids = []
     team_names = {}
     for team in teams:
         team_ids.append(team.tenant_id)
         team_names[team.tenant_id] = team.tenant_name
     domains = domain_repo.get_domains_by_tenant_ids(team_ids, is_auto_ssl)
     rules = []
     region_ids = []
     service_ids = []
     # append tenant name
     for domain in domains:
         rule = model_to_dict(domain)
         rule["create_time"] = domain.create_time
         rule["team_name"] = team_names[domain.tenant_id]
         region_ids.append(domain.region_id)
         service_ids.append(domain.service_id)
         rules.append(rule)
     # append region name
     region_ids_new = list(set(region_ids))
     regions = region_repo.get_regions_by_region_ids(
         enterprise_id, region_ids_new)
     region_names = {}
     for region in regions:
         region_names[region.region_id] = region.region_name
     # append app id
     app_ids = group_service.get_app_id_by_service_ids(service_ids)
     re_rules = []
     for rule in rules:
         rule["region_name"] = region_names.get(rule["region_id"])
         rule["app_id"] = app_ids.get(rule["service_id"])
         # ignore region name or app id not found rule
         if rule["region_name"] and rule["app_id"]:
             re_rules.append(rule)
     return re_rules
Esempio n. 9
0
 def get_enterprise_teams(self, enterprise_id):
     return team_repo.get_teams_by_enterprise_id(enterprise_id)