From 1a204ae87244338dcb0dc34890136948737110c5 Mon Sep 17 00:00:00 2001 From: James Moffet Date: Tue, 26 Jul 2022 11:39:00 -0700 Subject: [PATCH] remove extra logs --- app/main/views/send.py | 30 +------------------------ app/main/views/uploads.py | 2 +- app/notify_client/service_api_client.py | 5 +---- app/s3_client/s3_csv_client.py | 2 -- app/s3_client/s3_logo_client.py | 4 +--- app/utils/user.py | 3 --- 6 files changed, 4 insertions(+), 42 deletions(-) diff --git a/app/main/views/send.py b/app/main/views/send.py index ebe42d742..98d4c8fb4 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -598,14 +598,11 @@ def send_from_contact_list(service_id, template_id, contact_list_id): def _check_messages(service_id, template_id, upload_id, preview_row, letters_as_pdf=False): - current_app.logger.info('Running _check_messages') try: # The happy path is that the job doesn’t already exist, so the # API will return a 404 and the client will raise HTTPError. - current_app.logger.info('Requesting job from api with upload_id/job_id: {}'.format(upload_id)) job_api_client.get_job(service_id, upload_id) - - current_app.logger.info('Job already exists for upload_id/job_id: {}, sending 302'.format(upload_id)) + # the job exists already - so go back to the templates page # If we just return a `redirect` (302) object here, we'll get # errors when we try and unpack in the check_messages route. @@ -616,25 +613,15 @@ def _check_messages(service_id, template_id, upload_id, preview_row, letters_as_ template_id=template_id )) except HTTPError as e: - current_app.logger.info('Job does not exist for upload_id/job_id: {}'.format(upload_id)) if e.status_code != 404: - current_app.logger.info('Expected 404 when fetching job with upload_id/job_id: {}, instead got: {}'.format(upload_id, e.status_code)) raise - current_app.logger.info('_check_messages is now evaluating uploaded file') - notification_count = service_api_client.get_notification_count(service_id) - current_app.logger.info('_check_messages notification_count is {}'.format(notification_count)) remaining_messages = (current_service.message_limit - notification_count) - current_app.logger.info('_check_messages remaining_messages is {}'.format(remaining_messages)) contents = s3download(service_id, upload_id) - - current_app.logger.info('_check_messages obtained file contents' ) db_template = current_service.get_template_with_user_permission_or_403(template_id, current_user) - - current_app.logger.info('_check_messages got db template with type: {}'.format(db_template['template_type'])) email_reply_to = None sms_sender = None @@ -643,8 +630,6 @@ def _check_messages(service_id, template_id, upload_id, preview_row, letters_as_ elif db_template['template_type'] == 'sms': sms_sender = get_sms_sender_from_session() - current_app.logger.info('_check_messages creating template from db_template') - template = get_template( db_template, current_service, @@ -664,7 +649,6 @@ def _check_messages(service_id, template_id, upload_id, preview_row, letters_as_ # recalculate the page count once we have the values page_count=get_page_count_for_letter(db_template), ) - current_app.logger.info('_check_messages creating recipients from file contents') recipients = RecipientCSV( contents, template=template, @@ -697,10 +681,8 @@ def _check_messages(service_id, template_id, upload_id, preview_row, letters_as_ page_count = get_page_count_for_letter(db_template, template.values) template.page_count = page_count - current_app.logger.info('_check_messages getting csv metadata') original_file_name = get_csv_metadata(service_id, upload_id).get('original_file_name', '') - current_app.logger.info('_check_messages returning dict') return dict( recipients=recipients, template=template, @@ -738,7 +720,6 @@ def _check_messages(service_id, template_id, upload_id, preview_row, letters_as_ ) @user_has_permissions('send_messages', restrict_admin_usage=True) def check_messages(service_id, template_id, upload_id, row_index=2): - current_app.logger.info('Check messages, getting data from upload with id {}'.format(upload_id)) data = _check_messages(service_id, template_id, upload_id, row_index) data['allowed_file_extensions'] = Spreadsheet.ALLOWED_FILE_EXTENSIONS @@ -750,21 +731,17 @@ def check_messages(service_id, template_id, upload_id, row_index=2): or data['recipients'].missing_column_headers or data['sent_previously'] ): - current_app.logger.info('Found column errors in upload') return render_template('views/check/column-errors.html', **data) if data['row_errors']: - current_app.logger.info('Found row errors in upload') return render_template('views/check/row-errors.html', **data) if ( data['errors'] or data['trying_to_send_letters_in_trial_mode'] ): - current_app.logger.info('Found other errors in upload') return render_template('views/check/column-errors.html', **data) - current_app.logger.info('Writing upload metadata') metadata_kwargs = { 'notification_count': data['count_of_recipients'], 'template_id': template_id, @@ -776,10 +753,8 @@ def check_messages(service_id, template_id, upload_id, row_index=2): # sender_id is not an option for sending letters. metadata_kwargs['sender_id'] = session['sender_id'] - current_app.logger.info('Setting upload metadata') set_metadata_on_csv_upload(service_id, upload_id, **metadata_kwargs) - current_app.logger.info('Returning 200 from check messages') return render_template('views/check/ok.html', **data) @@ -793,13 +768,11 @@ def check_messages(service_id, template_id, upload_id, row_index=2): ) @user_has_permissions('send_messages') def check_messages_preview(service_id, template_id, upload_id, filetype, row_index=2): - current_app.logger.info('Check messages preview, checking filetype') if filetype == 'pdf': page = None elif filetype == 'png': page = request.args.get('page', 1) else: - current_app.logger.info('Check messages preview, filetype is neither pdf nor png, so we return 404') abort(404) template = _check_messages( @@ -1075,7 +1048,6 @@ def send_notification(service_id, template_id): sender_id=session.get('sender_id', None), ) except HTTPError as exception: - current_app.logger.info('Service {} could not send notification: "{}"'.format( current_service.id, exception.message )) diff --git a/app/main/views/uploads.py b/app/main/views/uploads.py index d688e457f..1d27d79f2 100644 --- a/app/main/views/uploads.py +++ b/app/main/views/uploads.py @@ -170,7 +170,7 @@ def upload_letter(service_id): # TODO: get page count from the sanitise response once template preview handles malformed files nicely page_count = pdf_page_count(BytesIO(pdf_file_bytes)) except PdfReadError: - current_app.logger.info('Invalid PDF uploaded for service_id: {}'.format(service_id)) + current_app.logger.error('Invalid PDF uploaded for service_id: {}'.format(service_id)) return invalid_upload_error( "There’s a problem with your file", 'Notify cannot read this PDF.
Save a new copy of your file and try again.' diff --git a/app/notify_client/service_api_client.py b/app/notify_client/service_api_client.py index 955c2be6b..3bd2522a5 100644 --- a/app/notify_client/service_api_client.py +++ b/app/notify_client/service_api_client.py @@ -607,10 +607,7 @@ class ServiceAPIClient(NotifyAdminAPIClient): return self.post("/service/{}/set-as-broadcast-service".format(service_id), data) def get_notification_count(self, service_id): - # if cache is not set return 0 - current_app.logger.info("Pinging redis for daily_limit_cache_key(service_id): {}".format(daily_limit_cache_key(service_id))) - current_app.logger.info("Redis url is: {}".format( current_app.config['REDIS_URL'] )) - current_app.logger.info("Redis enabled is: {}".format( current_app.config['REDIS_ENABLED'] )) + # if cache is not set, or not enabled, return 0 if current_app.config['NOTIFY_ADMIN_API_CACHE_ENABLED']: count = redis_client.get(daily_limit_cache_key(service_id)) or 0 diff --git a/app/s3_client/s3_csv_client.py b/app/s3_client/s3_csv_client.py index d78148db8..b1646c9d9 100644 --- a/app/s3_client/s3_csv_client.py +++ b/app/s3_client/s3_csv_client.py @@ -46,8 +46,6 @@ def s3download(service_id, upload_id, bucket=None): def set_metadata_on_csv_upload(service_id, upload_id, bucket=None, **kwargs): - current_app.logger.info('set_metadata_on_csv_upload, service_id: {} upload_id: {} bucket: {}'.format(service_id, upload_id, bucket)) - current_app.logger.info('csv location to copy from is: {}/{}'.format(*get_csv_location(service_id, upload_id, bucket=bucket))) copy_from_object_result = get_csv_upload( service_id, upload_id, bucket=bucket ).copy_from( diff --git a/app/s3_client/s3_logo_client.py b/app/s3_client/s3_logo_client.py index 4c70579f8..5b1c487f3 100644 --- a/app/s3_client/s3_logo_client.py +++ b/app/s3_client/s3_logo_client.py @@ -13,10 +13,8 @@ LETTER_TEMP_LOGO_LOCATION = 'letters/static/images/letter-template/temp-{user_id def get_s3_object(bucket_name, filename): s3 = resource('s3') - current_app.logger.info('Requesting s3 object from bucket: {} with key: {}'.format(bucket_name, filename)) obj = s3.Object(bucket_name, filename) - string_body = obj.get()['Body'].read().decode('utf-8') - current_app.logger.info('s3 Object string body is: {}'.format(string_body)) + string_body = obj.get()['Body'].read().decode('utf-8') return obj diff --git a/app/utils/user.py b/app/utils/user.py index 5658a471c..23a12ccb1 100644 --- a/app/utils/user.py +++ b/app/utils/user.py @@ -19,12 +19,9 @@ def user_has_permissions(*permissions, **permission_kwargs): def wrap(func): @wraps(func) def wrap_func(*args, **kwargs): - current_app.logger.info('Checking user permissions') if not current_user.is_authenticated: - current_app.logger.info('User is not authenticated') return current_app.login_manager.unauthorized() if not current_user.has_permissions(*permissions, **permission_kwargs): - current_app.logger.info('Authenticated user does not have appropriate permissions') abort(403) return func(*args, **kwargs) return wrap_func