Beispiel #1
0
    def get(self, request, *args, **kwargs):

        enterprise_id = request.GET.get("enterprise_id", None)
        if enterprise_id:
            enter = enterprise_services.get_enterprise_by_enterprise_id(enterprise_id)
            if not enter:
                return Response(
                    generate_result("0404", "enterprise is not found", "企业不存在"))
            try:
                tenant_list = tenant_service.get_all_tenant()
                if not tenant_list:
                    result = generate_result('0000', 'success', '查询成功', list=[])
                    return Response(result)
                bean = dict()
                bean["tenant_num"] = len(tenant_list)
                user_list = user_repo.get_all_users()
                bean["user_num"] = len(user_list)
                sort_list = []
                cursor = connection.cursor()
                cursor.execute(
                    "select t.tenant_alias,t.tenant_id, count(s.ID) as num from tenant_info as t left join tenant_service as s on t.tenant_id=s.tenant_id group by tenant_id order by num desc limit 0,5;")
                tenant_tuples = cursor.fetchall()
                for tenant_tuple in tenant_tuples:
                    tenant_alias_list = list()
                    tenant_alias_list.append(tenant_tuple[0])
                    sort_list.append(tenant_alias_list)
                result = generate_result('0000', 'success', '查询成功', list=sort_list, bean=bean)
            except Exception as e:
                logger.exception(e)
                result = generate_result('9999', 'system error', '系统异常')
            return Response(result)
        else:
            result = generate_result("1003", "the enterprise alias cannot be empty", "企业别名不能为空")
            return Response(result)
Beispiel #2
0
    def get(self, request, *args, **kwargs):
        """
        登录页面获取云帮Logo、标题、github、gitlab配置信息(不要Authorization头)
        ---
        """
        try:
            # 判断是否已经初始化权限默认数据,没有则初始化
            status = role_perm_repo.initialize_permission_settings()
            code = 200
            data = dict()
            logo = config_service.get_image()
            host_name = request.get_host()
            build_absolute_uri = request.build_absolute_uri()
            scheme = "http"
            if build_absolute_uri.startswith("https"):
                scheme = "https"
            data["logo"] = "{0}".format(str(logo))
            # 判断是否为公有云
            if settings.MODULES.get('SSO_LOGIN'):
                data["url"] = "https://sso.goodrain.com/#/login/"
                data["is_public"] = True
            else:
                data["url"] = "{0}://{1}/index#/user/login".format(scheme, request.get_host())
                data["is_public"] = False

            title = config_service.get_config_by_key("TITLE")
            if not title:
                config = config_service.add_config("TITLE", "好雨云帮", "string", "云帮title")
                title = config.value
            data["title"] = title
            if settings.MODULES.get('SSO_LOGIN'):
                data["is_user_register"] = True
            else:
                users = user_repo.get_all_users()
                if users:
                    data["is_user_register"] = True
                else:
                    data["is_user_register"] = False

            github_config = config_service.get_github_config()
            data["github_config"] = github_config

            gitlab_config = config_service.get_gitlab_config()
            data["gitlab_config"] = gitlab_config


            result = general_message(code, "query success", "Logo获取成功", bean=data, initialize_info=status)
            return Response(result, status=code)
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
        return Response(result)
Beispiel #3
0
 def is_user_register(self):
     if user_repo.get_all_users():
         return True
     return False
Beispiel #4
0
    def get(self, request, *args, **kwargs):
        """
        登录页面获取云帮Logo、标题、github、gitlab配置信息(不要Authorization头)
        ---
        """
        try:
            # 判断是否已经初始化权限默认数据,没有则初始化
            status = role_perm_repo.initialize_permission_settings()
            code = 200
            data = dict()
            logo = config_service.get_image()
            build_absolute_uri = request.build_absolute_uri()
            scheme = "http"

            if build_absolute_uri.startswith("https"):
                scheme = "https"
            data["logo"] = "{0}".format(str(logo))
            # 判断是否为公有云
            if settings.MODULES.get('SSO_LOGIN'):
                data["url"] = os.getenv(
                    "SSO_BASE_URL", "https://sso.goodrain.com") + "/#/login/"
                data["is_public"] = True
            else:
                data["url"] = "{0}://{1}/index#/user/login".format(
                    scheme, request.get_host())
                data["is_public"] = False

            title = config_service.get_config_by_key("TITLE")
            if not title:
                config = config_service.add_config(
                    "TITLE", "Rainbond-企业云应用操作系统,开发、交付云解决方案", "string",
                    "云帮title")
                title = config.value
            data["title"] = title
            if settings.MODULES.get('SSO_LOGIN'):
                data["is_user_register"] = True
            else:
                users = user_repo.get_all_users()
                if users:
                    data["is_user_register"] = True
                else:
                    data["is_user_register"] = False

            is_regist = config_service.get_config_by_key("REGISTER_STATUS")
            if not is_regist:
                is_regist = config_service.add_config(key="REGISTER_STATUS",
                                                      default_value="yes",
                                                      type="string",
                                                      desc="开启/关闭注册").value
            if is_regist == "yes":
                data["is_regist"] = True
            else:
                data["is_regist"] = False
            # if register_config[0].value != "yes":
            #     data["is_regist"] = False
            # else:
            #     data["is_regist"] = True

            github_config = config_service.get_github_config()
            data["github_config"] = github_config

            gitlab_config = config_service.get_gitlab_config()
            data["gitlab_config"] = gitlab_config

            data["eid"] = None
            enterprise = enterprise_repo.get_enterprise_first()
            if enterprise:
                data["eid"] = enterprise.enterprise_id
                data["enterprise_name"] = enterprise.enterprise_alias
                market_token = market_sycn_service.get_enterprise_access_token(
                    enterprise.enterprise_id, "market")
                if market_token:
                    data["market_url"] = market_token.access_url
                else:
                    data["market_url"] = os.getenv(
                        'GOODRAIN_APP_API', settings.APP_SERVICE_API["url"])
            data["version"] = os.getenv("RELEASE_DESC", "public-cloud")
            result = general_message(code,
                                     "query success",
                                     "Logo获取成功",
                                     bean=data,
                                     initialize_info=status)
            return Response(result, status=code)
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
        return Response(result)
Beispiel #5
0
    def get(self, request, *args, **kwargs):
        try:
            code = 200
            status = role_perm_repo.initialize_permission_settings()
            data = config_service.initialization_or_get_config()
            base_data = config_service.initialization_or_get_base_config()
            data.update(base_data)
            logo = config_service.get_image()
            data["logo"] = "{0}".format(str(logo))
            title = config_service.get_config_by_key("TITLE")
            if not title:
                config = config_service.add_config(
                    "TITLE",
                    "Rainbond-企业云应用操作系统,开发、交付云解决方案",
                    "string",
                    desc="云帮title")
                title = config.value
            else:
                title = title.value
            data["title"] = title
            data["version"] = os.getenv("RELEASE_DESC", "public-cloud")
            result = general_message(code,
                                     "query success",
                                     u"Logo获取成功",
                                     bean=data,
                                     initialize_info=status)
            data["eid"] = None
            enterprise = enterprise_repo.get_enterprise_first()
            if enterprise:
                data["eid"] = enterprise.enterprise_id
                data["enterprise_name"] = enterprise.enterprise_alias

            build_absolute_uri = request.build_absolute_uri()
            scheme = "http"
            if build_absolute_uri.startswith("https"):
                scheme = "https"
            if settings.MODULES.get('SSO_LOGIN'):
                data["url"] = os.getenv(
                    "SSO_BASE_URL", "https://sso.goodrain.com") + "/#/login/"
                data["is_public"] = True
            else:
                data["url"] = "{0}://{1}/index#/user/login".format(
                    scheme, request.get_host())
                data["is_public"] = False

            if settings.MODULES.get('SSO_LOGIN'):
                data["is_user_register"] = True
            else:
                users = user_repo.get_all_users()
                if users:
                    data["is_user_register"] = True
                else:
                    data["is_user_register"] = False

            data["eid"] = None
            enterprise = enterprise_repo.get_enterprise_first()
            if enterprise:
                data["eid"] = enterprise.enterprise_id
                data["enterprise_name"] = enterprise.enterprise_alias
                market_token = market_sycn_service.get_enterprise_access_token(
                    enterprise.enterprise_id, "market")
                if market_token:
                    data["market_url"] = market_token.access_url
                else:
                    data["market_url"] = os.getenv(
                        'GOODRAIN_APP_API', settings.APP_SERVICE_API["url"])
            data["version"] = os.getenv("RELEASE_DESC", "public-cloud")
            return Response(result, status=code)
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
        return Response(result)