Example #1
0
def saveServiceAjax(request):
    '''
    save manager's service setting
    input: request
    return: json
    author: Arthur
    '''
    #Server Side Rule Check
    username = request.user.username
    postdata = getPostdata(request)

    if username:
        require_field = ['content']
        checker = DataChecker(postdata, require_field)

        if checker.get('status') == 'success':

            #是否存入翻譯
            lan_package = postdata.get('lan_package', None)
            if lan_package:
                FlowActiveGlobalObject.setSysLanDict("service", None,
                                                     lan_package)

            #static variable
            box_object = json.loads(postdata.get('content', ''))
            OmServiceDesign.objects.create(
                content=json.dumps(box_object),
                language_package=json.dumps(
                    FlowActiveGlobalObject.getSysLanDict('service')))

            OmService.objects.all().delete()

            ServiceList = []
            for key in box_object["list"]:
                thisSer = box_object["list"][key]
                if thisSer["type"] == "service":
                    flow_uuid = FlowActiveGlobalObject.APIgetUUID(
                        thisSer['api_path'])
                    ser = OmService(service_id=thisSer['id'],
                                    flow_uuid=flow_uuid,
                                    role=thisSer['setting']['setRole'],
                                    default_value=json.dumps(
                                        thisSer['default_value']))
                    ServiceList.append(ser)

            OmService.objects.bulk_create(ServiceList)

            info('%s update Service success' % username, request)
            return ResponseAjax(statusEnum.success, _('儲存成功。')).returnJSON()
        else:
            info('%s update Service error' % username, request)
            return ResponseAjax(statusEnum.not_found, checker.get('message'),
                                checker).returnJSON()
    else:
        info('%s update Service with no permission' % username, request)
        return ResponseAjax(statusEnum.no_permission,
                            _('您沒有權限進行此操作。')).returnJSON()
Example #2
0
def exportServcieAjax(request):
    if OmServiceDesign.objects.all().count() > 0:
        max = OmServiceDesign.objects.all().aggregate(Max('id')).get('id__max')
        box_object = list(
            OmServiceDesign.objects.filter(id=max).values('content'))
        box_object = json.loads(box_object[0]["content"])

        #翻譯語言
        lan_package = FlowActiveGlobalObject.getSysLanDict('service')
        result = {"box_object": box_object, "lan_package": lan_package}

        info(request,
             '%s export language package success.' % request.user.username)
        return ResponseAjax(statusEnum.success, _('匯出成功。'),
                            result).returnJSON()
Example #3
0
def loadServiceAjax(request):
    '''
    load manager's service setting
    return: json
    author: Arthur
    '''

    #Server Side Rule Check
    username = request.user.username
    postdata = getPostdata(request)
    result = {}
    if username:
        #static variable
        #         result['structure'] = OmServiceDesign.objects.all()
        #         if request.user.has_perm('omservice.OmServiceDesign_Manager'):
        #             result['objects'] = OmService.objects.all()
        #         else:
        #             #等待修改
        #             user_role_list = list(request.user.groups.all().values_list('id', flat=True))
        #             for service_obj in OmService.objects.all():
        #                 service_role_list = json.loads(service_obj.get('role','[]'))
        #                 if len(set(user_role_list) & set(service_role_list)):
        #                     result['objects'].append(service_obj)
        #print(OmServiceDesign.objects.all().count())
        if OmServiceDesign.objects.all().count() > 0:
            max = OmServiceDesign.objects.all().aggregate(
                Max('id')).get('id__max')
            result = list(
                OmServiceDesign.objects.filter(id=max).values('content'))

            box_object = json.loads(result[0]["content"])

            #檢查權限
            if request.user.has_perm('omservice.OmServiceDesign_Manage'):
                pass
            else:
                Service_List = list(OmService.objects.all())
                Group_List = list(request.user.groups.all().values_list(
                    'id', flat=True))
                if len(Group_List):
                    Group_List.append(-1)
                else:
                    Group_List = [-1]
                for thisSer in Service_List:
                    if len(set(json.loads(thisSer.role))
                           & set(Group_List)) == 0:
                        del box_object["list"][str(thisSer.service_id)]

            #檢查是否過期
            this_activeList = list(
                FlowActive.objects.filter(
                    undeploy_flag=0,
                    parent_uuid__isnull=True).values_list('flow_uuid',
                                                          flat=True))
            this_activeList = [o.hex for o in this_activeList]
            for idx in box_object["list"]:
                #print(box_object["list"][idx])
                if box_object["list"][idx]["type"] == "service":
                    if 'api_path' in box_object["list"][idx]:
                        flow_uuid = FlowActiveGlobalObject.APIgetUUID(
                            box_object["list"][idx]["api_path"])
                    else:
                        flow_uuid = box_object["list"][idx]["flow_uuid"]
                        box_object["list"][idx][
                            "api_path"] = FlowActiveGlobalObject.UUIDgetAPI(
                                flow_uuid)

                    if flow_uuid in this_activeList:
                        box_object["list"][idx]["available"] = 1
                    else:
                        box_object["list"][idx]["available"] = 0

            #翻譯語言
            if postdata.get('type') != "source":
                language_type = get_language()
                #print(FlowActiveGlobalObject.getSysLanDict('service'))
                lan_package = FlowActiveGlobalObject.getSysLanDict(
                    'service').get(language_type, None)

                if lan_package:
                    for idx in box_object["list"]:
                        this_service = box_object["list"][idx]
                        if this_service["setting"]["setTitle"]:
                            this_service["setting"]["setTitle"] = lan_package[
                                this_service["setting"]
                                ["setTitle"]] if checkJsonKey(
                                    lan_package,
                                    this_service["setting"]["setTitle"]
                                ) else this_service["setting"]["setTitle"]

                        if this_service["type"] == "service":
                            if this_service["setting"]["setTip"]:
                                this_service["setting"]["setTip"] = lan_package[
                                    this_service["setting"]
                                    ["setTip"]] if checkJsonKey(
                                        lan_package,
                                        this_service["setting"]["setTip"]
                                    ) else this_service["setting"]["setTip"]
                            for sup_idx in this_service["service"]["list"]:
                                this_step = this_service["service"]["list"][
                                    sup_idx]
                                if this_step["name"]:
                                    this_step["name"] = lan_package[
                                        this_step["name"]] if checkJsonKey(
                                            lan_package, this_step["name"]
                                        ) else this_step["name"]
                                if this_step["tip"]:
                                    this_step["tip"] = lan_package[
                                        this_step["tip"]] if checkJsonKey(
                                            lan_package, this_step["tip"]
                                        ) else this_step["tip"]

            #print(result[0]["content"])
            result[0]["content"] = json.dumps(box_object)

        return ResponseAjax(statusEnum.success, _('讀取成功。'),
                            result).returnJSON()
    else:
        error('%s load Service with no permission' % username, request)
        return ResponseAjax(statusEnum.no_permission,
                            _('您沒有權限進行此操作。')).returnJSON()
Example #4
0
def exportTranslationAjax(request):
    '''
    export workspace application language package
    '''
    #function variable
    require_field = ['language']
    #get postdata
    postdata = getPostdata(request)
    language_type = postdata.get('language', '')
    #server side rule check
    checker = DataChecker(postdata, require_field)
    if checker.get('status') == 'success':
        export = ''
        export_list = []
        if OmServiceDesign.objects.all().count() > 0:
            max = OmServiceDesign.objects.all().aggregate(
                Max('id')).get('id__max')
            result = list(
                OmServiceDesign.objects.filter(id=max).values('content'))

            box_object = json.loads(result[0]["content"])

            #翻譯語言
            #language_type = get_language()
            lan_package = FlowActiveGlobalObject.getSysLanDict('service').get(
                language_type, {})

            #翻譯「全部」
            #export = check2addExport('全部',export,export_list,lan_package,language_type)
            for idx in box_object["list"]:
                this_service = box_object["list"][idx]
                #翻譯「服務名稱」
                export = check2addExport(this_service["setting"]["setTitle"],
                                         export, export_list, lan_package,
                                         language_type)

                if this_service["type"] == "service":
                    #翻譯「服務說明」
                    export = check2addExport(this_service["setting"]["setTip"],
                                             export, export_list, lan_package,
                                             language_type)
                    for sup_idx in this_service["service"]["list"]:
                        this_step = this_service["service"]["list"][sup_idx]
                        #翻譯「服務步驟名稱」
                        export = check2addExport(this_step["name"], export,
                                                 export_list, lan_package,
                                                 language_type)
                        #翻譯「服務步驟說明」
                        export = check2addExport(this_step["tip"], export,
                                                 export_list, lan_package,
                                                 language_type)

        info('%s export language package success.' % request.user.username,
             request)
        return ResponseAjax(statusEnum.success, _('匯出成功。'),
                            export).returnJSON()
    else:
        info(
            '%s missing some require variable or the variable type error.' %
            request.user.username, request)
        return ResponseAjax(statusEnum.not_found, checker.get('message', ''),
                            checker).returnJSON()