Skip to content

Merge updates to attachments scanning into master#11

Open
lbrant1 wants to merge 7 commits into
imsweb:masterfrom
lbrant1:lbrant/master
Open

Merge updates to attachments scanning into master#11
lbrant1 wants to merge 7 commits into
imsweb:masterfrom
lbrant1:lbrant/master

Conversation

@lbrant1
Copy link
Copy Markdown
Contributor

@lbrant1 lbrant1 commented Aug 20, 2018

No description provided.

Comment thread attachments/views.py Outdated
from django.utils.encoding import force_text
from django.views.decorators.csrf import csrf_exempt
from django.core.mail import send_mail
from django.conf.global_settings import DEFAULT_FROM_EMAIL
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want settings.DEFAULT_FROM_EMAIL

Comment thread attachments/views.py Outdated
content_type = 'text/plain' if request.POST.get('X-Requested-With', '') == 'IFrame' else 'application/json'
try:
f = request.FILES['attachment']
if getattr(settings, 'ATTACHMENTS_MAXIMUM_FILE_SIZE', False):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicky, but you can just grab the setting once with getattr, instead of every time down below. It's less maintenance if we ever need to change a default value or something, and just shorter lines.

Comment thread attachments/views.py Outdated
#send email to email list
email_list = getattr(settings, 'ATTACHMENTS_VIRUS_EMAIL')
subject = 'VIRUS UPLOAD ALERT: " + user_prefix + "attempted to upload a file containing a virus to the system'
message = log_message
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of building this message in code, why not add a new templates/attachments/virus_email.txt template, and use loader.render_to_string to build the message. Has the advantage that sites can provide their own templates if they want.

Comment thread attachments/views.py
now = datetime.datetime.now()
now = now.strftime('%m-%d-%Y %H:%M:%S')
#request.user may not exist so set up user_prefix to use right prefix for messages on virus upload
user = getattr(request, 'user', None)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just pass user into the template and let it decide, via something like {{ user|default_if_none:"Some Guy" }}. The less formatting in code the better.

Comment thread attachments/views.py Outdated
{'user_prefix': user_prefix,
'filename' : f.name,
'virus_signature' : virus[path][1],
'time' : now,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to pass in now - Django has a {% now %} template tag.

Comment thread attachments/views.py Outdated
#send email to email list
email_list = getattr(settings, 'ATTACHMENTS_VIRUS_EMAIL')
subject = 'VIRUS UPLOAD ALERT: " + user_prefix + " attempted to upload a file containing a virus to the system'
message = log_message
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just pass log_message to the call below, why set a separate variable?

Comment thread attachments/views.py Outdated
from django.core.mail import send_mail

from attachments.exceptions import VirusFoundException
from settings import DEFAULT_FROM_EMAIL
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

settings are already imported above (from django.conf import settings) - you can get rid of this and just use settings.DEFAULT_FROM_EMAIL below.

Comment thread attachments/views.py Outdated
now = datetime.datetime.now()
now = now.strftime('%m-%d-%Y %H:%M:%S')
user = getattr(request, 'user', None)
log_message = loader.render_to_string('virus_email.txt',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be attachments/virus_email.txt? Same for virus_subject.txt below? Also, it doesn't seem that the now variable is used anywhere, can it be removed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants