Exemplo n.º 1
0
def saveDashboardAjax(request):
    '''
    save user's omdashboard 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':
            #static variable
            dashboard = OmDashboard.objects.get_or_create(user=request.user)[0]
            setattr(dashboard, "content", postdata.get('content', ''))
            dashboard.save()
            info('%s update Dashboard success' % username, request)
            return ResponseAjax(statusEnum.success, _('儲存成功')).returnJSON()
        else:
            info('%s update Dashboard error' % username, request)
            return ResponseAjax(statusEnum.not_found, checker.get('message'),
                                checker).returnJSON()
    else:
        info('%s update Dashboard with no permission' % username, request)
        return ResponseAjax(statusEnum.no_permission,
                            _('您沒有權限進行此操作。')).returnJSON()
Exemplo n.º 2
0
def loadSidebarDesignAjax(request):
    '''
    load left side bar design json
    input: request
    return: json
    author: Kolin Hsu
    '''
    if request.user.is_superuser:
        #function variable
        result = {}
        count = 0
        sidebar_design = GlobalObject.__sidebarDesignObj__['sidebar_design']
        #get item id count
        for item in sidebar_design:
            flow_uuid = item['flow_uuid']
            if flow_uuid == 'custom':
                item_id = int(item['id'][7:])
                if item_id > count:
                    count = item_id
        result['sidebar_design'] = sidebar_design
        result['count'] = count
        info('%s load SidebarDesign success.' % request.user.username, request)
        return ResponseAjax(statusEnum.success, _('讀取成功。'),
                            result).returnJSON()
    else:
        info('%s has no permission.' % request.user.username, request)
        return ResponseAjax(statusEnum.no_permission,
                            _('您沒有權限進行此操作。')).returnJSON()
Exemplo n.º 3
0
def getFormObjAjax(request):
    '''
    load service_object's form_object
    return: json
    author: Arthur
    '''
    username = request.user.username
    postdata = getPostdata(request)
    result = {}

    if username:
        require_field = ['api_path']
        checker = DataChecker(postdata, require_field)
        if checker.get('status') == 'success':
            flow_uuid = FlowActiveGlobalObject.APIgetUUID(
                postdata.get('api_path'))
            thisQuery = list(
                FlowActive.objects.filter(flow_uuid=flow_uuid,
                                          undeploy_flag=False).values(
                                              'formobject', 'attachment'))
            if len(thisQuery):
                result = thisQuery[0]
                language = get_language()
                app_id = FlowActiveGlobalObject.UUIDSearch(
                    flow_uuid).flow_app_id
                formobject = Translator('formobject', 'active', language,
                                        app_id, None).Do(result['formobject'])
                result['formobject'] = json.dumps(formobject)
        return ResponseAjax(statusEnum.success, _('讀取成功。'),
                            result).returnJSON()
    else:
        error('%s get form_object with no permission' % username, request)
        return ResponseAjax(statusEnum.no_permission,
                            _('您沒有權限進行此操作。')).returnJSON()
Exemplo n.º 4
0
def uploadLicenseFileAjax(request):
    '''
    upload license file
    input: request
    return: list
    author: Kolin Hsu
    '''
    if request.user.is_superuser:
        #function variable
        upload_file = request.FILES.get("file", None)
        if upload_file:
            license_file = open(
                os.path.join(settings.BASE_DIR, 'omflow/syscom/',
                             'license.bin'), 'wb+')
            for chunk in upload_file.chunks():
                license_file.write(chunk)
            license_file.close()
            info('%s upload license file success.' % request.user.username,
                 request)
            return ResponseAjax(statusEnum.success, _('上傳成功。')).returnJSON()
        else:
            info('%s upload license file error.' % request.user.username,
                 request)
            return ResponseAjax(statusEnum.not_found, _('請選擇檔案。')).returnJSON()
    else:
        info('%s has no permission.' % request.user.username, request)
        return ResponseAjax(statusEnum.no_permission,
                            _('您沒有權限進行此操作。')).returnJSON()
Exemplo n.º 5
0
def listMessageHistoryAjax(request):
    '''
    show messages detail list
    input: request
    return: messages content object
    author: Kolin Hsu
    '''
    postdata = getPostdata(request)
    messages_id = postdata.get('messages_id', None)
    if messages_id is not None:
        box_lst = list(
            request.user.messagebox_set.filter(
                messages_id=messages_id).values_list('id', flat=True))
        result = list(
            MessageHistory.objects.filterformat(
                'id',
                'create_user__nick_name',
                'create_group_name',
                'createtime',
                'messagebox__read',
                'messagehistoryfiles__main_id',
                messagebox__id__in=box_lst,
                messagebox__omuser_id=request.user.id).distinct().order_by(
                    '-createtime'))
        info('%s list message history success.' % request.user.username,
             request)
        return ResponseAjax(statusEnum.success, _('搜尋成功'), result).returnJSON()
    else:
        info('%s list message history error.' % request.user.username, request)
        return ResponseAjax(statusEnum.no_permission,
                            _('請提供訊息編號')).returnJSON()
Exemplo n.º 6
0
def deleteMessageHistoryAjax(request):
    '''
    create messages content
    input: request
    return: json
    author: Kolin Hsu
    '''
    postdata = getPostdata(request)
    messagehistory_id_list = postdata.get('messagehistory_id', '')
    action = postdata.get('action', 'delete')
    if messagehistory_id_list:
        if action == 'delete':
            request.user.messagebox_set.filter(
                messagehistory_id__in=messagehistory_id_list).update(
                    delete=True)
            info('%s delete message success.' % request.user.username, request)
            return ResponseAjax(statusEnum.success, _('刪除訊息成功')).returnJSON()
        else:
            request.user.messagebox_set.filter(
                messagehistory_id__in=messagehistory_id_list).update(
                    delete=False)
            return ResponseAjax(statusEnum.success, _('訊息還原成功')).returnJSON()
    else:
        info('%s delete message success.' % request.user.username, request)
        return ResponseAjax(statusEnum.no_permission,
                            _('找不到訊息資料')).returnJSON()
Exemplo n.º 7
0
def ldapManualSyncAjax(request):
    '''
    LDAP manual Sync
    input: execute LDAP functions
    return: messages
    author: Pei Lin
    '''
    if check_app('omldap'):
        from omldap.views import ldapManualSync
        result = ldapManualSync(request)
        if result["status"] == "success":
            info('%s ldap Check Connect success.' % request.user.username,
                 request)
            return ResponseAjax(statusEnum.success,
                                result['message']).returnJSON()
        elif result["status"] == "fail":
            info('%s ldap Check Connect error.' % request.user.username,
                 request)
            return ResponseAjax(statusEnum.not_found,
                                result['message']).returnJSON()
        else:
            info('%s ldap Check Connect error.' % request.user.username,
                 request)
            return ResponseAjax(statusEnum.no_permission,
                                result['message']).returnJSON()
    else:
        info('%s ldap Check Connect error.' % request.user.username, request)
        return ResponseAjax(statusEnum.not_found,
                            _('您尚未安裝omldap APP,請聯絡原廠。')).returnJSON()
Exemplo n.º 8
0
def loadDashboardAjax(request):
    '''
    load user's dashboard settinomdashboardput: request
    return: json
    author: Arthur
    '''
    #Server Side Rule Check
    checkMigrate()
    username = request.user.username
    result = {}
    if username:
        #static variable
        if OmDashboard.objects.filter(user=request.user).count() > 0:
            result = list(
                OmDashboard.objects.filter(
                    user=request.user).values('content'))
            #result = list(OmDashboard.objects_d.filter('content',user=request.user))
        else:
            result = [{
                "content":
                '{"index":44,"list":{"3":{"id":3,"type":"box3","setting":{"setTitle":"","setColor":"box-default"}},"4":{"id":4,"type":"box3","setting":{"setTitle":"","setColor":"box-default"}},"5":{"id":5,"type":"box3","setting":{"setTitle":"","setColor":"box-default"}},"6":{"id":6,"type":"box3","setting":{"setTitle":"","setColor":"box-default"}},"7":{"id":7,"type":"box12","setting":{"setTitle":"全球產量分布","setColor":"box-primary"}},"9":{"id":9,"type":"box4","setting":{"setTitle":"","setColor":"box-default"}},"10":{"id":10,"type":"box4","setting":{"setTitle":"","setColor":"box-default"}},"11":{"id":11,"type":"box4","setting":{"setTitle":"","setColor":"box-default"}},"12":{"id":12,"type":"box4","setting":{"setTitle":"","setColor":"box-default"}},"15":{"id":15,"type":"word","setting":{"setTitle":"","setTip":"","setIcon":"fa fa-file-text","setColor":"bg-blue","setUnit":"單位","setForm":"","setColumn":[""],"setTime":"all","setType":["static"]}},"16":{"id":16,"type":"word","setting":{"setTitle":"","setTip":"","setIcon":"fa fa-envelope","setColor":"bg-yellow","setUnit":"單位","setForm":"","setColumn":[""],"setTime":"all","setType":["static"]}},"17":{"id":17,"type":"word","setting":{"setTitle":"","setTip":"","setIcon":"fa fa-thumbs-up","setColor":"bg-green","setUnit":"單位","setForm":"","setColumn":[""],"setTime":"all","setType":["static"]}},"18":{"id":18,"type":"word","setting":{"setTitle":"","setTip":"","setIcon":"fa fa-line-chart","setColor":"bg-red","setUnit":"單位","setForm":"","setColumn":[""],"setTime":"all","setType":["static"]}},"20":{"id":20,"type":"meter-bar","setting":{"setTitle":"","setTip":"台北","setColor":"progress-bar-blue","setMax":"100","setUnit":"單位","setForm":"","setColumn":[""],"setTime":"all","setType":["static"]}},"21":{"id":21,"type":"meter-bar","setting":{"setTitle":"","setTip":"東京","setColor":"progress-bar-aqua","setMax":"100","setUnit":"單位","setForm":"","setColumn":[""],"setTime":"all","setType":["static"]}},"22":{"id":22,"type":"meter-bar","setting":{"setTitle":"","setTip":"首爾","setColor":"progress-bar-green","setMax":"100","setUnit":"單位","setForm":"","setColumn":[""],"setTime":"all","setType":["static"]}},"23":{"id":23,"type":"meter-bar","setting":{"setTitle":"","setTip":"紐約","setColor":"progress-bar-yellow","setMax":"100","setUnit":"單位","setForm":"","setColumn":[""],"setTime":"all","setType":["static"]}},"24":{"id":24,"type":"meter-bar","setting":{"setTitle":"","setTip":"曼谷","setColor":"progress-bar-red","setMax":"100","setUnit":"單位","setForm":"","setColumn":[""],"setTime":"all","setType":["static"]}},"25":{"id":25,"type":"meter-bar","setting":{"setTitle":"","setTip":"新加坡","setColor":"color-purple","setMax":"100","setUnit":"單位","setForm":"","setColumn":[""],"setTime":"all","setType":["static"]}},"26":{"id":26,"type":"tube","setting":{"setTitle":"","setTip":"","setIcon":"fa fa-heartbeat","setColor":"bg-red","setUnit":"單位","setMax":"100","setForm":"","setColumn":[""],"setTime":"all","setType":["static"]}},"27":{"id":27,"type":"tube","setting":{"setTitle":"","setTip":"","setIcon":"fa fa-leaf","setColor":"bg-green","setUnit":"單位","setMax":"100","setForm":"","setColumn":[""],"setTime":"all","setType":["static"]}},"28":{"id":28,"type":"tube","setting":{"setTitle":"","setTip":"","setIcon":"fa fa-car","setColor":"bg-blue","setUnit":"單位","setMax":"100","setForm":"","setColumn":[""],"setTime":"all","setType":["static"]}},"30":{"id":30,"type":"bar","setting":{"setTitle":"","setColor":"1","setHeight":"240","setYstart":"0","setForm":"","setColumn":[""],"setTime":"all","setType":["static"],"setGroup":[""]}},"31":{"id":31,"type":"box12","setting":{"setTitle":"","setColor":"box-default"}},"39":{"id":39,"type":"box4","setting":{"setTitle":"","setColor":"box-default"}},"40":{"id":40,"type":"box4","setting":{"setTitle":"","setColor":"box-default"}},"41":{"id":41,"type":"pie","setting":{"setTitle":"","setColor":"0","setUnit":"","setHeight":"320","setForm":"","setColumn":[""],"setTime":"all","setType":["static"],"setGroup":[""]}},"43":{"id":43,"type":"pie","setting":{"setTitle":"","setColor":"3","setUnit":"","setHeight":"320","setForm":"","setColumn":[""],"setTime":"all","setType":["static"],"setGroup":[""]}}},"tree":[{"id":"3","tree":[{"id":"15"}]},{"id":"4","tree":[{"id":"17"}]},{"id":"5","tree":[{"id":"16"}]},{"id":"6","tree":[{"id":"18"}]},{"id":"7","tree":[{"id":"9","tree":[{"id":"20"},{"id":"21"},{"id":"22"},{"id":"23"},{"id":"24"},{"id":"25"}]},{"id":"40","tree":[{"id":"41"}]},{"id":"39","tree":[{"id":"43"}]}]},{"id":"10","tree":[{"id":"26"}]},{"id":"11","tree":[{"id":"27"}]},{"id":"12","tree":[{"id":"28"}]},{"id":"31","tree":[{"id":"30"}]}]}'
            }]

        return ResponseAjax(statusEnum.success, _('讀取成功'), result).returnJSON()
    else:
        error('%s load Dashboard with no permission' % username, request)
        return ResponseAjax(statusEnum.no_permission,
                            _('您沒有權限進行此操作。')).returnJSON()
Exemplo n.º 9
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()
Exemplo n.º 10
0
def listFilesAjax(request):
    '''
    list files
    input: request
    return: list
    author: Kolin Hsu
    '''
    if request.user.is_superuser:
        #function variable
        field_list = []
        query = ''
        #server side rule check
        require_field = ['app_name']
        postdata = getPostdata(request)
        checker = DataChecker(postdata, require_field)
        if checker.get('status') == 'success':
            #get post data
            app_name = postdata.get('app_name', '')
            createtime = postdata.get('createtime', '')
            if app_name == 'ommessage':
                field_list = ['file__icontains']
                query = MessageHistoryFiles.objects.filter(
                    delete=False,
                    createtime__lte=createtime).values('file', 'size',
                                                       'createtime', 'main_id')
            if app_name == 'omformflow':
                field_list = ['file__icontains']
                query = OmdataFiles.objects.filter(
                    delete=False,
                    createtime__lte=createtime).values('file', 'size',
                                                       'createtime')
            if field_list or query:
                result = DatatableBuilder(request, query, field_list)
                info('%s list file success.' % request.user.username, request)
                return JsonResponse(result)
            else:
                info('%s list file error.' % request.user.username, request)
                return ResponseAjax(statusEnum.not_found,
                                    _('請提供正確的APP名稱。')).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()
    else:
        info('%s has no permission.' % request.user.username, request)
        return ResponseAjax(statusEnum.no_permission,
                            _('您沒有權限進行此操作。')).returnJSON()
Exemplo n.º 11
0
def requestAjax(request):
    '''
    send user's service request
    return: json
    author: Arthur
    '''
    username = request.user.username
    postdata = request.POST.copy()
    files = request.FILES.getlist('files', '')
    result = {}
    #print(postdata)
    if username:
        require_field = ['api_path', 'service_id', 'formdata']
        checker = DataChecker(postdata, require_field)
        if checker.get('status') == 'success':
            #判斷權限
            postdata['flow_uuid'] = FlowActiveGlobalObject.APIgetUUID(
                postdata.get('api_path'))
            thisQuery = list(
                OmService.objects.filter(
                    service_id=postdata.get('service_id')))
            if len(thisQuery):
                service_obj = thisQuery[0]
                #print(service_obj.default_value)
                service_obj = json.loads(service_obj.default_value)

                postdata["formdata"] = json.loads(postdata["formdata"])
                for default_col in service_obj:
                    postdata["formdata"].append(default_col)

                postdata["formdata"] = json.dumps(postdata["formdata"])
            else:
                info('%s update Service error' % username, request)
                return ResponseAjax(statusEnum.error, _('查無此服務。')).returnJSON()

            result = createOmData(postdata, request.user.username, files)
            if result['status']:
                return ResponseAjax(statusEnum.success,
                                    result['message']).returnJSON()
            else:
                return ResponseAjax(statusEnum.not_found,
                                    result['message']).returnJSON()
        else:
            return ResponseAjax(statusEnum.not_found,
                                _('缺少必填欄位。')).returnJSON()
    else:
        error('%s request_service with no permission' % username, request)
        return ResponseAjax(statusEnum.no_permission,
                            _('您沒有權限進行此操作。')).returnJSON()
Exemplo n.º 12
0
def loadSystemConfigAjax(request):
    '''
    show system log level
    input: request
    return: log level
    author: Kolin Hsu
    '''
    if request.user.is_superuser:
        result = {}
        POOL_MAX_WORKER = SystemSetting.objects.get(
            name='pool_max_worker').value
        PI_agree = SystemSetting.objects.get(name='PI_agree').value
        SU_agree = SystemSetting.objects.get(name='SU_agree').value
        loglevel = logging.getLevelName(
            logging.getLogger('django').getEffectiveLevel())
        ldapstr = SystemSetting.objects.get(name='ldap_config').value
        ldap_config = json.loads(ldapstr)
        settingsloglevel = settings.LOG_LEVEL
        result['LOG_LEVEL'] = loglevel
        result['POOL_MAX_WORKER'] = POOL_MAX_WORKER
        result[
            'settings_log_level'] = "Log level is already changed,settings LEVEL is " + settingsloglevel
        result['ldap_config'] = ldap_config
        result['PI_agree'] = PI_agree
        result['SU_agree'] = SU_agree
        try:
            with open(
                    os.path.join(settings.BASE_DIR, 'omflow/syscom',
                                 'license.bin'), 'rb') as file:
                license_file = file.read().decode('UTF-8')
                file.close()
        except:
            license_file = ''
        result['license'] = license_file
        #told front end which field has been modified
        if loglevel != settings.LOG_LEVEL:
            result['Level_Change'] = True
        else:
            result['Level_Change'] = False
        info('%s load SystemConfig success.' % request.user.username, request)
        return ResponseAjax(statusEnum.success, _('讀取成功。'),
                            result).returnJSON()
    else:
        info('%s has no permission.' % request.user.username, request)
        return ResponseAjax(statusEnum.no_permission, _('您沒有權限進行此操作。'),
                            result).returnJSON()
Exemplo n.º 13
0
def deleteFilesAjax(request):
    '''
    delete files
    input: request
    return: status
    author: Kolin Hsu
    '''
    if request.user.is_superuser:
        #server side rule check
        require_field = ['app_name', 'path']
        postdata = getPostdata(request)
        checker = DataChecker(postdata, require_field)
        if checker.get('status') == 'success':
            #get post data
            app_name = postdata.get('app_name', '')
            path_list = postdata.get('path', '')
            if app_name == 'ommessage':
                for path in path_list:
                    file_path = os.path.join(settings.MEDIA_ROOT, path)
                    if os.path.isfile(file_path):
                        os.remove(file_path)
                        messagehistoryfile = MessageHistoryFiles.objects.get(
                            file=path)
                        messagehistoryfile.delete = True
                        messagehistoryfile.save()
            elif app_name == 'omformflow':
                for path in path_list:
                    file_path = os.path.join(settings.MEDIA_ROOT, path)
                    if os.path.isfile(file_path):
                        os.remove(file_path)
                        omdatafiles = OmdataFiles.objects.get(file=path)
                        omdatafiles.delete = True
                        omdatafiles.save()
            info('%s delete file success.' % request.user.username, request)
            return ResponseAjax(statusEnum.success, _('刪除成功。')).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()
    else:
        info('%s has no permission.' % request.user.username, request)
        return ResponseAjax(statusEnum.no_permission,
                            _('您沒有權限進行此操作。')).returnJSON()
Exemplo n.º 14
0
def importTranslationAjax(request):
    '''
    import service language package
    input: request
    return: json
    author: Arthur
    '''
    #function variable
    require_field = ['language']
    #server side rule check
    postdata = getPostdata(request)
    language_str = postdata.get('language_list', '')
    language = postdata.get('language', '')
    checker = DataChecker(postdata, require_field)
    if checker.get('status') == 'success':
        #wa = WorkspaceApplication.objects.get(id=app_id)
        #language_dict = json.loads(wa.language_package)
        max = OmServiceDesign.objects.all().aggregate(Max('id')).get('id__max')
        this_service = OmServiceDesign.objects.get(id=max)
        language_dict = json.loads(this_service.language_package)

        temp_dict = {}
        language_list = language_str.split('\r\n')
        for line in language_list:
            if line:
                sp_index = line.find(':')
                if line[:sp_index] == 'original':
                    key = line[sp_index + 1:]
                else:
                    temp_dict[key] = line[sp_index + 1:]
        language_dict[language] = temp_dict
        language_str = json.dumps(language_dict)
        this_service.language_package = language_str
        this_service.save()
        #set global
        FlowActiveGlobalObject.setSysLanDict("service", language, temp_dict)
        info('%s import language package success.' % request.user.username,
             request)
        return ResponseAjax(statusEnum.success, _('匯入成功。')).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()
Exemplo n.º 15
0
 def handle_problems(*args, **kwargs):
     try:
         return fun(*args, **kwargs)
     except Exception as e:
         if not args:
             error(e)
         else:
             error(e, args[0])
         return ResponseAjax(statusEnum.error, e.__str__()).returnJSON()
Exemplo n.º 16
0
def loadOrganizationAjax(request):
    '''
    load organization
    input: request
    return: json
    author: Kolin Hsu
    ''' 
    result = loadOrganization()
    info('%s load organization success.' % request.user.username,request)
    return ResponseAjax(statusEnum.success, _('讀取成功。'), result).returnJSON()
Exemplo n.º 17
0
def permissionDenied(request):
    '''
    return permission denied
    input: request
    return: json
    author: Kolin Hsu
    '''
    info('%s has no permission.' % request.user.username, request)
    return ResponseAjax(statusEnum.no_permission,
                        _('您沒有權限進行此操作。')).returnJSON()
Exemplo n.º 18
0
def deletePositionAjax(request):
    '''
    delete position
    input: request
    return: json
    author: Kolin Hsu
    '''
    #function variable
    require_field = ['id']
    #server side rule check
    postdata = getPostdata(request)
    checker = DataChecker(postdata, require_field)
    #get post data
    id_list = postdata.get('id','')
    if checker.get('status') == 'success':
        Position.objects.filter(id__in=id_list).delete()
        info('%s update position success.' % request.user.username,request)
        return ResponseAjax(statusEnum.success, _('刪除成功。')).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()
Exemplo n.º 19
0
def getFormListAjax(request):
    '''
    load form_list
    return: json
    author: Arthur
    '''
    #Server Side Rule Check
    username = request.user.username
    result = {}
    if username:
        #static variable
        #omdata_list = list(filter(lambda x: re.match("^Omdata_.{32}$", x.__name__), apps.get_models()))

        app = list(
            ActiveApplication.objects.filterformat('id',
                                                   'app_name',
                                                   undeploy_flag=False))
        flow = list(
            FlowActive.objects.filterformat('id',
                                            'flow_uuid',
                                            'api_path',
                                            'flow_name',
                                            'flow_app_id',
                                            undeploy_flag=False,
                                            parent_uuid=None))
        result = {'app': app, 'flow': flow}

        #翻譯
        lang = get_language()
        result['app'] = Translator('datatable_multi_app', 'active', lang, None,
                                   None).Do(result['app'])
        result['flow'] = Translator('datatable_multi_app', 'active', lang,
                                    None, None).Do(result['flow'])

        return ResponseAjax(statusEnum.success, _('讀取成功。'),
                            result).returnJSON()
    else:
        error('%s load form_list with no permission' % username, request)
        return ResponseAjax(statusEnum.no_permission,
                            _('您沒有權限進行此操作。')).returnJSON()
Exemplo n.º 20
0
def composeMessageDetailAjax(request):
    '''
    create messages
    input: request
    return: json
    author: Kolin Hsu
    '''
    result = {}
    postdata = getPostdata(request)
    messagehistory_id = postdata.get('messagehsitory_id', '')
    reply_history = []
    if messagehistory_id:
        display_field = [
            'messages_id__subject', 'content', 'createtime', 'messages_id',
            'create_user_id', 'create_user__nick_name', 'create_group_id',
            'create_group_name', 'delete_users_username', 'receive_groups_name'
        ]
        reply_history = list(
            MessageHistory.objects.filterformat(*display_field,
                                                id=messagehistory_id))[0]
        #取出history members的nick_name(給引用使用)
        receivers = list(
            HistoryMembers.objects.filter(
                messagehistory_id=messagehistory_id).values_list(
                    'user_id__nick_name', flat=True))
        #取出history members的nick_name以及id(給回覆的選單使用)
        reply_users = list(
            HistoryMembers.objects.filter(
                messagehistory_id=messagehistory_id).values(
                    'user_id', 'user_id__nick_name'))
        #取出history groups的name以及id(給回覆的選單使用)
        reply_groups = list(
            HistoryGroups.objects.filter(
                messagehistory_id=messagehistory_id).values(
                    'group_id', 'group_id__name'))
        #把已刪除的使用者以及組織名稱放入陣列中
        if reply_history['delete_users_username']:
            receivers.extend(
                literal_eval(reply_history['delete_users_username']))
        if reply_history['receive_groups_name']:
            receivers.extend(literal_eval(
                reply_history['receive_groups_name']))
        result['reply_users'] = reply_users
        result['reply_groups'] = reply_groups
        result['receivers'] = receivers
    request_user_group_list = list(
        request.user.groups.filter(omgroup__functional_flag=False).values(
            'id', 'name'))
    result['reply_history'] = reply_history
    result['request_user_group_list'] = request_user_group_list
    info('%s load message success.' % request.user.username, request)
    return ResponseAjax(statusEnum.success, _('請求處理成功'), result).returnJSON()
Exemplo n.º 21
0
def loadWorkinfoAjax(request):
    '''
    show workinfo
    input: request
    return: json
    author: Kolin Hsu
    '''
    if settings.OMFLOW_TYPE == 'collector':
        node = 1
    else:
        node = 0
    #get new workinfo data
    messages = 0  #request.user.messagebox_set.filter(read=0).count()
    #mission
    #取得我(群組)曾經處理過的任務
    mission_list = list(
        Missions.objects.filter(
            Q(update_user_id=request.user.username) & Q(history=True)
            & Q(closed=False) & Q(is_active=True)
            & Q(deploy_flag=True)).values('flow_uuid', 'data_no'))
    #將查詢結果分為兩個list  建立對照的dict--(以flow_uuid為KEY,該流程的單號組成list為VALUE)
    flow_uuid_list = []
    data_no_list = []
    mapping_dict = {}
    for i in mission_list:
        mapping_data_no_list = mapping_dict.get(i['flow_uuid'], [])
        mapping_data_no_list.append(i['data_no'])
        if len(mapping_data_no_list) == 1:
            mapping_dict[i['flow_uuid']] = mapping_data_no_list
        if i['flow_uuid'] not in flow_uuid_list:
            flow_uuid_list.append(i['flow_uuid'])
        if i['data_no'] not in data_no_list:
            data_no_list.append(i['data_no'])
    #將所有flow_uuid_list、data_no_list組合的max id查出來
    try:
        max_mission_list = list(
            Missions.objects.filter(flow_uuid__in=flow_uuid_list,
                                    data_no__in=data_no_list).values(
                                        'flow_uuid',
                                        'data_no').annotate(max_id=Max('id')))
        #透過對照dict找出真正該撈出來的max id
        max_id_list = []
        for m in max_mission_list:
            mapping_no_list = mapping_dict.get(m['flow_uuid'], None)
            if m['data_no'] in mapping_no_list:
                max_id_list.append(m['max_id'])
        missions = Missions.objects.filter(id__in=max_id_list).count()
    except:
        missions = '999+'
    result = {'messages': messages, 'missions': missions, 'node': node}
    debug('%s load workinfo success.' % request.user.username, request)
    return ResponseAjax(statusEnum.success, _('更新成功。'), result).returnJSON()
Exemplo n.º 22
0
def searchGroupUserAjax(request):
    '''
    list sender
    input: request
    return: json
    author: Kolin Hsu
    '''
    postdata = getPostdata(request)
    searchkey = postdata.get('searchkey', '')
    field_list = ['groups__id']
    ordercolumn = 'nick_name'
    result = UserSearch(field_list, searchkey, ordercolumn)
    info('%s search users by group success.' % request.user.username, request)
    return ResponseAjax(statusEnum.success, _('請求處理成功'), result).returnJSON()
Exemplo n.º 23
0
def createPositionAjax(request):
    '''
    create position
    input: request
    return: json
    author: Kolin Hsu
    '''
    #get post data
    postdata = getPostdata(request)
    display_name = postdata.get('display_name','')
    description = postdata.get('description','')
    Position.objects.create(display_name=display_name,description=description)
    info('%s create position success.' % request.user.username,request)
    return ResponseAjax(statusEnum.success, _('建立成功。')).returnJSON()
Exemplo n.º 24
0
def updatePositionAjax(request):
    '''
    update position
    input: request
    return: json
    author: Kolin Hsu
    '''
    #function variable
    require_field = ['id']
    #server side rule check
    postdata = getPostdata(request)
    checker = DataChecker(postdata, require_field)
    #get post data
    pos_id = postdata.get('id','')
    display_name = postdata.get('display_name','')
    description = postdata.get('description','')
    if checker.get('status') == 'success':
        Position.objects.filter(id=pos_id).update(display_name=display_name,description=description)
        info('%s update position success.' % request.user.username,request)
        return ResponseAjax(statusEnum.success, _('更新成功。')).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()
Exemplo n.º 25
0
def searchSendGroupAjax(request):
    '''
    list sender
    input: request
    return: json
    author: Kolin Hsu
    '''
    postdata = getPostdata(request)
    searchkey = postdata.get('searchkey', '')
    adGroup = postdata.get('adGroup', ['1', '0'])
    field_list = ['name__icontains']
    ordercolumn = 'name'
    result = GroupSearch(field_list, searchkey, ordercolumn, adGroup)
    info('%s search send group success.' % request.user.username, request)
    return ResponseAjax(statusEnum.success, _('請求處理成功'), result).returnJSON()
Exemplo n.º 26
0
def listSidebarDesignAjax(request):
    '''
    list left side bar custom item
    input: request
    return: json
    author: Kolin Hsu
    '''
    #function variable
    result = []
    sidebar_design = GlobalObject.__sidebarDesignObj__['sidebar_design']
    for item in sidebar_design:
        if item['flow_uuid'] == 'custom':
            result.append(item)
    info('%s list SidebarDesign success.' % request.user.username, request)
    return ResponseAjax(statusEnum.success, _('讀取成功。'), result).returnJSON()
Exemplo n.º 27
0
def ldapCheckConnectAjax(request):
    '''
    use ldap3 check connection
    input: use bind_user to connect LDAP 
    return: connection status
    author: Jia Liu
    '''
    if check_app('omldap'):
        from omldap.views import ldapCheckConnect
        result = ldapCheckConnect(request)
        if result["status"] == "success":
            info('%s ldap Check Connect success.' % request.user.username,
                 request)
            return ResponseAjax(statusEnum.success,
                                result['message']).returnJSON()
        else:
            info('%s ldap Check Connect error.' % request.user.username,
                 request)
            return ResponseAjax(statusEnum.not_found,
                                result['message']).returnJSON()
    else:
        info('%s ldap Check Connect error.' % request.user.username, request)
        return ResponseAjax(statusEnum.not_found,
                            _('您尚未安裝omldap APP,請聯絡原廠。')).returnJSON()
Exemplo n.º 28
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()
Exemplo n.º 29
0
def getDiskStatusAjax(request):
    '''
    check server disk space enough or not
    input: request
    return: boolean
    author: Kolin Hsu
    '''
    postdata = getPostdata(request)
    file_size = int(postdata.get('file_size', '0'))
    disk_obj = shutil.disk_usage("/")
    disk_free = disk_obj.free // (2**20)
    if disk_free - file_size > 10:
        result = True
    else:
        result = False
    info('%s get disk status success.' % request.user.username, request)
    return ResponseAjax(statusEnum.success, _('查詢成功。'), result).returnJSON()
Exemplo n.º 30
0
def updateOrganizationAjax(request):
    '''
    update organization
    input: request
    return: json
    author: Kolin Hsu
    '''
    postdata = getPostdata(request)
    org_str = postdata.get('org','{}')
    o = Organization.objects.filter(name='organization')
    if o:
        o.update(value=org_str)
    else:
        Organization.objects.create(name='organization',value=org_str)
    setOrgToGlobal(org_str)
    info('%s update organization success.' % request.user.username,request)
    return ResponseAjax(statusEnum.success, _('更新成功。')).returnJSON()