def insert(args): from quicky import tenancy if args['data'] != None: ret = {} try: lock.acquire() user_name = args['data']['login_account'] if User.objects.filter(username=user_name, schema=tenancy.get_schema()).exists() == 0: args['data']['username'] = generate_user_id() data = dict( username = args['data']['username'], login_account = args['data']['login_account'], display_name = args['data']['display_name'], role_code = (lambda data: data["role_code"] if data.has_key("role_code") else None)(args['data']), email = args['data']['email'], is_system = (lambda data: data["is_system"] if data.has_key("is_system") else False)(args['data']), never_expire = (lambda data: data["never_expire"] if data.has_key("never_expire") else False)(args['data']), manlevel_from = (lambda data: data["manlevel_from"] if data.has_key("manlevel_from") else None)(args['data']), manlevel_to = (lambda data: data["manlevel_to"] if data.has_key("manlevel_to") else None)(args['data']), mobile = (lambda data: data["mobile"] if data.has_key("mobile") else None)(args['data']), description = (lambda data: data["description"] if data.has_key("description") else None)(args['data']) ) ret = models.auth_user_info().insert(data) if ret.has_key('error') and ret['error'] != None: raise(Exception(ret['error']['code'])) try: user = User.objects.create_user( username=args['data']['username'], password=args['data']['password'], schema=tenancy.get_schema() ) user.save(schema=tenancy.get_schema()) lock.release() return ret except Exception as ex: models.auth_user_info().delete("username == {0}", args['data']['username']) lock.release() return dict( error = "Internal Server Error" ) lock.release() return dict( error = "existing login account" ) #Already account except Exception as ex: logger.debug(ex) lock.release() return ret return dict( error = "request parameter is not exist" )
def insert(args): from quicky import tenancy if args['data'] != None: ret = {} try: lock.acquire() user_name = args['data']['login_account'] if User.objects.filter(username=user_name).exists() == 0: args['data']['username'] = generate_user_id() data = dict( username = args['data']['username'], login_account = args['data']['login_account'], display_name = args['data']['display_name'], role_code = (lambda data: data["role_code"] if data.has_key("role_code") else None)(args['data']), email = args['data']['email'], is_system = (lambda data: data["is_system"] if data.has_key("is_system") else False)(args['data']), never_expire = (lambda data: data["never_expire"] if data.has_key("never_expire") else False)(args['data']), manlevel_from = (lambda data: data["manlevel_from"] if data.has_key("manlevel_from") else None)(args['data']), manlevel_to = (lambda data: data["manlevel_to"] if data.has_key("manlevel_to") else None)(args['data']), mobile = (lambda data: data["mobile"] if data.has_key("mobile") else None)(args['data']), description = (lambda data: data["description"] if data.has_key("description") else None)(args['data']) ) ret = models.auth_user_info().insert(data) if ret.has_key('error') and ret['error'] != None: raise(Exception(ret['error']['code'])) try: user = User.objects.create_user( username=args['data']['username'], password=args['data']['password'], schema=tenancy.get_schema() ) user.save(schema=tenancy.get_schema()) lock.release() return ret except Exception as ex: models.auth_user_info().delete("username == {0}", args['data']['username']) lock.release() return dict( error = "Internal Server Error" ) lock.release() return dict( error = "existing login account" ) #Already account except Exception as ex: logger.debug(ex) lock.release() return ret return dict( error = "request parameter is not exist" )
def update_role_code(args): try: if args['data'] != None: lock.acquire() if args['data'].has_key('role_code') and args['data'].has_key('users'): user_names = [x["username"]for x in args['data']['users']] ret = models.auth_user_info().update( dict( role_code = args['data']['role_code'] ), "username in {0}", user_names) lock.release() return ret return dict( error = "request parameter is not exist" ) except Exception as ex: logger.debug(ex) lock.release() raise(ex)
def delete(args): if args['data'] != None: try: user_names = models.auth_user_info().aggregate().project(username = 1).match("_id in {0}", [ObjectId(x["_id"])for x in args['data']]).get_list() models.auth_user().delete("username in {0}", [x["username"] for x in user_names]) ret = models.auth_user_info().delete("username in {0}", [x["username"]for x in args['data']]) return ret except Exception as ex: logger.debug(ex) return dict( error = ex.message ) return dict( error = "request parameter is not exist" )
def update_role_code(args): try: if args['data'] != None: lock.acquire() if args['data'].has_key('role_code') and args['data'].has_key('users'): user_names = [x["username"]for x in args['data']['users']] ret = models.auth_user_info().update( dict( role_code = args['data']['role_code'] ), "username in {0}", user_names) lock.release() return ret return dict( error = "request parameter is not exist" ) except Exception as ex: logger.debug(ex) lock.release() raise(ex)
def delete(args): if args['data'] != None: try: user_names = models.auth_user_info().aggregate().project(username = 1).match("_id in {0}", [ObjectId(x["_id"])for x in args['data']]).get_list() models.auth_user().delete("username in {0}", [x["username"] for x in user_names]) ret = models.auth_user_info().delete("_id in {0}", [ObjectId(x["_id"])for x in args['data']]) return ret except Exception as ex: logger.debug(ex) return dict( error = ex.message ) return dict( error = "request parameter is not exist" )
def get_list_email_by_dept(args): searchText = args['data'].get('search', '') pageSize = args['data'].get('pageSize', 0) pageIndex = args['data'].get('pageIndex', 20) sort = args['data'].get('sort', 20) pageIndex = (lambda pIndex: pIndex if pIndex != None else 0)(pageIndex) pageSize = (lambda pSize: pSize if pSize != None else 20)(pageSize) ret = qmongo.models.TM_EmailHR.aggregate ret.lookup(qmongo.models.HCSEM_Employees, "employee_code", "employee_code", "emp") ret.unwind("emp", False) ret.lookup(qmongo.models.HCSSYS_Departments, "department_code", "department_code", "dept") ret.unwind("dept", False) ret.left_join(models.auth_user_info(), "created_by", "username", "uc") ret.left_join(models.auth_user_info(), "modified_by", "username", "um") ret.project( employee_code="employee_code", full_name="concat(emp.last_name, ' ', emp.first_name)", email_address="email_address", department_code="department_code", level_code="dept.level_code", note="note", created_by="uc.login_account", created_on="created_on", modified_on="switch(case(modified_on!='',modified_on),'')", modified_by="switch(case(modified_by!='',um.login_account),'')").match( 'department_code != {0}', None) if args['data'].has_key('department_code'): ret.match("level_code == {0}", args['data']['department_code']) if (searchText != None): ret.match("contains(employee_code, @name) or " + \ "contains(full_name, @name) or " + \ "contains(email_address, @name) or " + \ "contains(note, @name) ", name=searchText.strip()) if (sort != None): ret.sort(sort) return ret.get_page(pageIndex, pageSize)
def update(args): from quicky import tenancy if args['data'] != None: try: lock.acquire() user_name = args['data']['login_account'] if models.auth_user_info().aggregate().match("_id == {0}", ObjectId(args['data']['_id'])).get_item() != None: data = dict( _id = args['data']['_id'], login_account = args['data']['login_account'], display_name = args['data']['display_name'], role_code = (lambda data: data["role_code"] if data.has_key("role_code") else None)(args['data']), email = args['data']['email'], is_system = (lambda data: data["is_system"] if data.has_key("is_system") else False)(args['data']), never_expire = (lambda data: data["never_expire"] if data.has_key("never_expire") else False)(args['data']), manlevel_from = (lambda data: data["manlevel_from"] if data.has_key("manlevel_from") else None)(args['data']), manlevel_to = (lambda data: data["manlevel_to"] if data.has_key("manlevel_to") else None)(args['data']), mobile = (lambda data: data["mobile"] if data.has_key("mobile") else None)(args['data']), description = (lambda data: data["description"] if data.has_key("description") else None)(args['data']) ) ret = models.auth_user_info().update( data, "_id == {0}", ObjectId(data['_id'])) if args['data']['change_password'] != None and args['data']['change_password'] == True: u = User.objects.get(username=args['data']['username']) u.set_password(args['data']['password']) u.save(schema=tenancy.get_schema()) lock.release() return ret lock.release() return None #Already account except Exception as ex: logger.debug(ex) lock.release() raise(ex) return None
def update(args): from quicky import tenancy if args['data'] != None: try: lock.acquire() user_name = args['data']['login_account'] if models.auth_user_info().aggregate().match("_id == {0}", ObjectId(args['data']['_id'])).get_item() != None: data = dict( login_account = args['data']['login_account'], display_name = args['data']['display_name'], role_code = (lambda data: data["role_code"] if data.has_key("role_code") else None)(args['data']), email = args['data']['email'], is_system = (lambda data: data["is_system"] if data.has_key("is_system") else False)(args['data']), never_expire = (lambda data: data["never_expire"] if data.has_key("never_expire") else False)(args['data']), manlevel_from = (lambda data: data["manlevel_from"] if data.has_key("manlevel_from") else None)(args['data']), manlevel_to = (lambda data: data["manlevel_to"] if data.has_key("manlevel_to") else None)(args['data']), mobile = (lambda data: data["mobile"] if data.has_key("mobile") else None)(args['data']), description = (lambda data: data["description"] if data.has_key("description") else None)(args['data']) ) ret = models.auth_user_info().update( data, "username == {0}", args['data']['username']) if args['data']['change_password'] != None and args['data']['change_password'] == True: u = User.objects.get(username=args['data']['username']) u.set_password(args['data']['password']) u.save(schema=tenancy.get_schema()) lock.release() return ret lock.release() return None #Already account except Exception as ex: logger.debug(ex) lock.release() raise(ex) return None
def get_department_group(): ret = qmongo.models.HCSSYS_Departments.aggregate ret.left_join(models.auth_user_info(), "created_by", "username", "uc") ret.left_join(models.auth_user_info(), "modified_by", "username", "um") ret.project( _id="_id", department_code="department_code", factor_group_name="factor_group_name", factor_group_name2="factor_group_name2", parent_code="parent_code", level="level", level_code="level_code", ordinal="ordinal", note="note", lock="lock", created_by="uc.login_account", created_on="created_on", modified_on="switch(case(modified_on!='',modified_on),'')", modified_by="switch(case(modified_by!='',um.login_account),'')", ) ret.sort(dict(ordinal=1)) return ret
def get_permission(args): user_role = models.auth_user_info().aggregate().project(username = 1, role_code = 1)\ .match("username == {0}", args['user'].username).get_item() ret = common.get_collection("AD_Roles").aggregate([{ "$match": { "role_code": user_role.get('role_code', None) } }, { "$unwind": { "path": "$permission", "preserveNullAndEmptyArrays": False } }, { "$match": { "permission.function_id": args['data']['function_id'] } }, { "$project": { "_id": 0, "function_id": "$permission.function_id", "read": "$permission.read", "create": "$permission.create", "write": "$permission.write", "delete": "$permission.delete", "export": "$permission.export", "import": "$permission.import", "copy": "$permission.copy", "attach": "$permission.attach", "download": "$permission.download", "print": "$permission.print", "action": "$permission.action" } }]) rs = list(ret) return (lambda x: x[0] if len(x) > 0 else { "function_id": args['data']['function_id'], "read": False, "create": False, "write": False, "delete": False, "export": False, "import": False, "copy": False, "attach": False, "download": False, "print": False, "action": False })(rs)
def get_list_with_searchtext(args): if args['data'] != None: try: searchText = args['data'].get('search', '') pageSize = args['data'].get('pageSize', 0) pageIndex = args['data'].get('pageIndex', 20) sort = args['data'].get('sort', 20) where = (lambda data: data["where"] if data.has_key("where") else {})(args['data']) pageIndex = (lambda pIndex: pIndex if pIndex != None else 0)(pageIndex) pageSize = (lambda pSize: pSize if pSize != None else 20)(pageSize) items = models.auth_user_info().aggregate().project( login_account = 1, username = 1, display_name = 1, role_code = 1, is_system = 1, never_expire = 1, manlevel_from = 1, manlevel_to = 1, email = 1, mobile = 1, description = 1, created_on = 1 ) if(searchText != None): items.match("contains(login_account, @name) or contains(display_name, @name) " + \ "or contains(role_code, @name) or contains(manlevel_from, @name) " + \ "or contains(manlevel_to, @name) or contains(created_on, @name)",name=searchText.strip()) if(where != None and where != {}): try: if where.has_key('filter') and where.has_key('value') and len(where['filter']) and len(where['value']): items.match(where["filter"],where["value"]) except Exception as ex: raise(Exception("syntax where error")) if(sort != None): items.sort(sort) return items.get_page(pageIndex, pageSize) except Exception as ex: raise(ex) return dict( error = "request parameter is not exist" )
def get_list_with_searchtext(args): if args['data'] != None: try: searchText = args['data'].get('search', '') pageSize = args['data'].get('pageSize', 0) pageIndex = args['data'].get('pageIndex', 20) sort = args['data'].get('sort', 20) where = (lambda data: data["where"] if data.has_key("where") else {})(args['data']) pageIndex = (lambda pIndex: pIndex if pIndex != None else 0)(pageIndex) pageSize = (lambda pSize: pSize if pSize != None else 20)(pageSize) items = models.auth_user_info().aggregate().project( login_account = 1, username = 1, display_name = 1, role_code = 1, is_system = 1, never_expire = 1, manlevel_from = 1, manlevel_to = 1, email = 1, mobile = 1, description = 1, created_on = 1 ) if(searchText != None): items.match("contains(login_account, @name) or contains(display_name, @name) " + \ "or contains(role_code, @name) or contains(manlevel_from, @name) " + \ "or contains(manlevel_to, @name) or contains(created_on, @name)",name=searchText) if(where != None and where != {}): try: if where.has_key('filter') and where.has_key('value') and len(where['filter']) and len(where['value']): items.match(where["filter"],where["value"]) except Exception as ex: raise(Exception("syntax where error")) if(sort != None): items.sort(sort) return items.get_page(pageIndex, pageSize) except Exception as ex: raise(ex) return dict( error = "request parameter is not exist" )
def remove_role_code_by_role(roles): try: lock.acquire() ret = models.auth_user_info().update( dict( role_code = None ), "role_code in {0}", roles) lock.release() return ret except Exception as ex: logger.debug(ex) lock.release() raise(ex)
def remove_role_code_by_role(roles): try: lock.acquire() ret = models.auth_user_info().update( dict( role_code = None ), "role_code in {0}", roles) lock.release() return ret except Exception as ex: logger.debug(ex) lock.release() raise(ex)
def get_list_approve_level_by_process_id(args): searchText = args['data'].get('search', '') pageSize = args['data'].get('pageSize', 0) pageIndex = args['data'].get('pageIndex', 20) sort = args['data'].get('sort', 20) pageIndex = (lambda pIndex: pIndex if pIndex != None else 0)(pageIndex) pageSize = (lambda pSize: pSize if pSize != None else 20)(pageSize) items = qmongo.models.TM_SetupProcessApproveLevel.aggregate # items.left_join(models.SYS_VW_ValueList(), "email_approve_to", "value", "email_approve") # items.match("(email_approve.list_name == @list_name and email_approve.language == @lan) or email_approve_to == @email_approve_to", # list_name="LSendEmail", lan= common.get_language(), email_approve_to = None) # items.left_join(models.SYS_VW_ValueList(), "email_reject_to", "value", "email_reject") # items.match("(email_reject.list_name == @list_name and email_reject.language == @lan) or email_reject_to == @email_reject_to", # list_name="LSendEmail", lan=common.get_language(), email_reject_to = None) items.left_join(SYS_VW_ValueList(), "approver_value", "value", "appr_val") items.match( "(appr_val.list_name == @list_name and appr_val.language == @lan) or approver_value == @approver_value", list_name="PERF_Approver", lan=common.get_language(), approver_value=None) items.left_join(models.auth_user_info(), "created_by", "username", "uc") items.left_join(models.auth_user_info(), "modified_by", "username", "um") items.project( rec_id=1, process_id=1, approve_level=1, approver_value=1, approver_value_display= "switch(case(appr_val.caption!='',appr_val.caption),'')", email_approve_code=1, email_approve_to=1, #email_approve_to_name="switch(case(email_approve.value!='',email_approve.value),'')", email_approve_cc=1, email_approve_more=1, email_reject_code=1, email_reject_to=1, #email_reject_to_name="switch(case(email_reject.value!='',email_reject.value),'')", email_reject_cc=1, email_reject_more=1, email_approve_cancel_code=1, email_approve_cancel_to=1, email_approve_cancel_cc=1, email_approve_cancel_more=1, email_reject_cancel_code=1, email_reject_cancel_to=1, email_reject_cancel_cc=1, email_reject_cancel_more=1, default_approver_code=1, not_receive_email=1, created_by="uc.login_account", created_on="created_on", modified_on="switch(case(modified_on!='',modified_on),'')", modified_by="switch(case(modified_by!='',um.login_account),'')").match( "process_id == {0}", int(args['data']['process_id'])) if (searchText != None): items.match("contains(process_name, @name)", name=searchText) if (sort != None): items.sort(sort) return items.get_page(pageIndex, pageSize)