def grant_channel_access(request, agent_id, shop_id, channel_id): logger = logging.getLogger(__name__) correlation_id = get_correlation_id_from_username(request.user) logger = setup_logger(request, logger, correlation_id) logger.info( "Checking permission for [{}] username with [{}] permission".format( request.user, 'CAN_BLOCK_AGENT_CHANNELS')) if not check_permissions_by_user(request.user, 'CAN_BLOCK_AGENT_CHANNELS'): return {"status": 1, "msg": ''} logger.info('========== Start grant access to channel ==========') url = settings.DOMAIN_NAMES + api_settings.CHANNEL_GRANT_PERMISSION.format( channel_id=channel_id) params = { 'shop_id': shop_id, 'user_id': agent_id, 'user_type': { 'id': 2, 'name': 'agent' } } result = ajax_functions._post_method(request, url, "", logger, params) logger.info('========== Finish grant access to channel ==========') return result
def cash_sofs(request, user_id): logger = logging.getLogger(__name__) correlation_id = get_correlation_id_from_username(request.user) logger = setup_logger(request, logger, correlation_id) url = CASH_SOFS_URL params = {'user_id': user_id, 'user_type': 2} result = ajax_functions._post_method(request, url, "", logger, params) return result
def reset_password(request, agent_id, identity_id): if not check_permissions_by_user(request.user, 'CAN_RESETPASSWORD_AGENT'): return logger = logging.getLogger(__name__) correlation_id = get_correlation_id_from_username(request.user) logger = setup_logger(request, logger, correlation_id) logger.info('========== Start reset password==========') url = settings.DOMAIN_NAMES + api_settings.AGENT_IDENTITY_RESET_PASSWORD.format(agent_id, identity_id) params = {} result = ajax_functions._post_method(request, url, "", logger, params, timeout=settings.GLOBAL_TIMEOUT) logger.info('========== Finish reset password ==========') return result
def regenerate(request, client_id): if not check_permissions_by_user(request.user, 'CAN_REGENERATE_CLIENTS'): return logger = logging.getLogger(__name__) correlation_id = get_correlation_id_from_username(request.user) logger = setup_logger(request, logger, correlation_id) logger.info('========== Start regenerating client secret ==========') url = api_settings.REGENERATE_CLIENT_SECRET_URL.format(client_id) result = ajax_functions._post_method(request, url, "regenerating client secret", logger) logger.info('========== Finish regenerating client secret ==========') return result
def get_user_name(request): logger = logging.getLogger(__name__) correlation_id = get_correlation_id_from_username(request.user) logger = setup_logger(request, logger, correlation_id) logger.info('========== Start get user name ==========') user_id = request.POST.get('id') user_type = request.POST.get('type') if user_type == "2": url = api_settings.SEARCH_AGENT else: url = api_settings.MEMBER_CUSTOMER_PATH params = {'id': user_id} result = ajax_functions._post_method(request, url, "", logger, params) logger.info('========== Finish get user name ==========') return result
def get(self, request, *args, **kwargs): self.logger.info('========== Start getting Specific SOF ==========') service_id = kwargs.get('service_id') currency = get_currency_by_service_id(request, service_id) user_id = kwargs.get('user_id') sof_type = kwargs.get('sof_type') params = { 'user_id': user_id, 'currency': currency, } if sof_type == '2': path = api_settings.CASH_SOFS_URL params['user_type'] = int(sof_type) params['paging'] = False params['page_index'] = -1 is_success, status_code, status_message, data = RestFulClient.post( url=path, headers=self._get_headers(), loggers=self.logger, params=params) msg = status_message or '' if status_code in ['access_token_expire', 'authentication_fail', 'invalid_access_token']: self.logger.info("{} for {} username".format(msg, request.user)) messages.add_message(request, messages.INFO, str('Your login credentials have expired. Please login again.')) code = 1 response = JsonResponse({"status": code, "msg": msg}) if status_code == "success": code = 2 response = JsonResponse({"status": code, "msg": msg, "data":data['cash_sofs']}) else: code = 3 response = JsonResponse({"status": code, "msg": msg}) else: path = api_settings.BANK_SOFS_URL params['user_type_id'] = 2 params['is_deleted'] = False response = ajax_functions._post_method(request, path, "", self.logger, params) self.logger.info('========== Finish getting Specific SOF ==========') return response
def revoke_channel_access(request, customerId, channelId): logger = logging.getLogger(__name__) correlation_id = get_correlation_id_from_username(request.user) logger = setup_logger(request, logger, correlation_id) logger.info( "Checking permission for [{}] username with [{}] permission".format( request.user, 'CAN_BLOCK_CUSTOMER_CHANNELS')) if not check_permissions_by_user(request.user, 'CAN_BLOCK_CUSTOMER_CHANNELS'): return {"status": 1, "msg": ''} logger.info('========== Start block access to channel ==========') url = settings.DOMAIN_NAMES + api_settings.CUSTOMER_CHANNEL_REVOKE_URL.format( channelId) params = { 'user_id': customerId, 'user_type': { "id": 1, 'name': 'customer' } } result = ajax_functions._post_method(request, url, "", logger, params) logger.info('========== Finish block access to channel ==========') return result