Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Fix #447 -- Sendmail plugin: Create new mail based on an old one #476

Merged
merged 7 commits into from
May 6, 2017
Merged

[WIP] Fix #447 -- Sendmail plugin: Create new mail based on an old one #476

merged 7 commits into from
May 6, 2017

Conversation

asv-hungvt
Copy link
Contributor

Hi @raphaelm ,

I am sticked at how to add the mail content to the new form. I used the initial but it said there was an error at the init() of the mail form. It supposed to accept the message argument and add the content when init right?
event

Another question, is thispull request created correctly? I used git push origin feature/new-send-mail but it said there was no branch as provided.

Thanks in advance :)

Copy link
Member

@raphaelm raphaelm left a comment

Choose a reason for hiding this comment

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

Hi! This looks like a good start. I left a few comments in there that should also help with your current problem.

Another question, is thispull request created correctly? I used git push origin feature/new-send-mail but it said there was no branch as provided.

Well, this one (#476) seems to work, while #455 did not. I'm not sure why, I'd probably need to see the exact error message of "git push" as well as a "git status" output to help. But we can just continue here.

@@ -29,6 +29,12 @@ class SenderView(EventPermissionRequiredMixin, FormView):
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs['event'] = self.request.event
from_log_id = self.request.GET.get('from_log')
message = LogEntry.objects.get(id=from_log_id).display()
Copy link
Member

Choose a reason for hiding this comment

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

This will cause an error whenever you don't have the from_log parameter. I would enclose all of this in a if 'from_log' in self.request.GET block.

Copy link
Member

Choose a reason for hiding this comment

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

Also, we need to

  • Check that the user can actually use this LogEntry, e.g. LogEntry.objects.get(id=from_log_id, event=self.request.event, action_type='pretix.plugins.sendmail.sent').display() to narrow the choice down so people cannot access texts from other events
  • Check for errors, i.e.
    try:
        message = …
    except LogEntry.DoesNotExist:
        raise Http404(_('You suppliad an invalid log entry ID'))
    
    using a from django.http import Http404 at the top of the file.

Copy link
Contributor Author

@asv-hungvt asv-hungvt Apr 29, 2017

Choose a reason for hiding this comment

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

Everything works perfectly except the query it return a invalid id
These are the values:
from_log_id = 1
self.request.event = 2018
action_type = 'pretix.plugins.sendmail.sent'

the from_log_id is got from the history template as the URL query param. I can see the sql from the DoDT tab but couldn't look for the query for the from_log_id. Can you show me how can I check if the record is in the DB?

Copy link
Member

Choose a reason for hiding this comment

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

Hi @asv-hungvt, I'm unsure if I really understand your question correctly. Something like the following should work:

if 'from_log' in self.request.GET:
    try:
        message = LogEntry.objects.get(
            id=from_log_id, 
            event=self.request.event,
            action_type='pretix.plugins.sendmail.sent'
        ).display()
    except LogEntry.DoesNotExist:
        raise Http404(_('You supplied an invalid log entry ID'))

from_log_id = self.request.GET.get('from_log')
message = LogEntry.objects.get(id=from_log_id).display()
kwargs['message'] = message
self.form_class(initial=kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

Drop this line, it doesn't make a lot of sense. What you want to do instead is kwargs['initial'] = {'message': message}. Django will later pass the kwargs to form_class in a different place.

@@ -29,6 +29,7 @@
<pre>{{ value.message|linebreaksbr }}</pre>
{% endfor %}
</p>
<a href="{% url 'plugins:sendmail:send' organizer=request.event.organizer.slug event=request.event.slug %}?from_log={{ log.pdata.mailid }}">Send mail</a>
Copy link
Member

Choose a reason for hiding this comment

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

This should be translatable, e.g. {% trans "Send a new email based on this" %}

kwargs['message'] = message
self.form_class(initial=kwargs)
print("content")
print(LogEntry.objects.get(id=from_log_id).display())
Copy link
Member

Choose a reason for hiding this comment

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

Fine for debugging now, be sure to remove them later 😉

@@ -142,5 +148,6 @@ def get_context_data(self, **kwargs):
log.pdata['sendto'] = [
status[s] for s in log.pdata['sendto']
]
log.pdata['mailid'] = log.object_id
Copy link
Member

Choose a reason for hiding this comment

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

You can just access log.object_id in the template, so there's not really a need for this.

@asv-hungvt
Copy link
Contributor Author

Hi @raphaelm ,

Can you check this #476 (comment)

@@ -29,6 +29,7 @@
<pre>{{ value.message|linebreaksbr }}</pre>
{% endfor %}
</p>
<a href="{% url 'plugins:sendmail:send' organizer=request.event.organizer.slug event=request.event.slug %}?from_log={{ log.id }}">{% trans "Send a new email based on this" %}</a>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

hi @raphaelm ,

I think it is more reasonable when we use from_log={{ log.id }} instead of from_log={{ log.object_id }}

After using id, the message can be copied now. Please review the code :)

Copy link
Member

Choose a reason for hiding this comment

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

I think it is more reasonable when we use from_log={{ log.id }} instead of from_log={{ log.object_id }}

Sure, my bad 🙈

Please review the code :)

I'll do as soon as possible!

Copy link
Member

@raphaelm raphaelm left a comment

Choose a reason for hiding this comment

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

Hey! In general, the code is okay, but still doesn't work. 😉

First of all, when the from_log GET parameter is not set, you still execute the line kwargs['initial'] = {'message': message} which obviously fails because message has not been defined. You need to put that at the end of the try: block.

Secondly, if the query parameter is set, you don't insert the proper message into the form. You could do something like the following (with the appropriate imports):

                logentry = LogEntry.objects.get(
                    id=from_log_id,
                    event=self.request.event,
                    action_type='pretix.plugins.sendmail.sent'
                )
                message = LazyI18nString(logentry.parsed_data['message'])

).display()
except LogEntry.DoesNotExist:
raise Http404(_('You supplied an invalid log entry ID'))
kwargs['initial'] = {'message': message}
Copy link
Member

Choose a reason for hiding this comment

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

You need to but this into the try part, otherwise this fails if you try to send an email without using an old email as the base.

@asv-hungvt
Copy link
Contributor Author

The code is ok now, please review it. Thanks for pointing out the mistake ;)

@raphaelm
Copy link
Member

raphaelm commented May 6, 2017

Hi,

looks great! Travis complains about wrongly ordered imports, you can fix this with a simple isort -rc pretix automatically.

Cheers
Raphael

@codecov
Copy link

codecov bot commented May 6, 2017

Codecov Report

Merging #476 into master will increase coverage by 1.32%.
The diff coverage is 30%.

@@            Coverage Diff             @@
##           master     #476      +/-   ##
==========================================
+ Coverage   80.57%   81.89%   +1.32%     
==========================================
  Files         166      165       -1     
  Lines       11429    11639     +210     
==========================================
+ Hits         9209     9532     +323     
+ Misses       2220     2107     -113
Impacted Files Coverage Δ
src/pretix/plugins/sendmail/views.py 88.29% <30%> (-7%) ⬇️
src/pretix/plugins/pretixdroid/signals.py 37.5% <0%> (-9.87%) ⬇️
src/pretix/control/forms/organizer.py 68.33% <0%> (-6.67%) ⬇️
src/pretix/base/models/event.py 59.21% <0%> (-4.52%) ⬇️
src/pretix/base/signals.py 93.87% <0%> (-3.8%) ⬇️
src/pretix/base/ticketoutput.py 71.42% <0%> (-3.58%) ⬇️
src/pretix/plugins/ticketoutputpdf/ticketoutput.py 85.71% <0%> (-1.39%) ⬇️
src/pretix/control/context.py 92.15% <0%> (-1.33%) ⬇️
src/pretix/presale/views/checkout.py 85.71% <0%> (-0.78%) ⬇️
src/pretix/base/exporters/orderlist.py 36.66% <0%> (-0.63%) ⬇️
... and 30 more

@asv-hungvt
Copy link
Contributor Author

Hi,

Yay it's done!

Cheers,
Hung

@raphaelm
Copy link
Member

raphaelm commented May 6, 2017

Yay! 🎈
Thank you very much for your contribution!

@raphaelm raphaelm merged commit 5eac3cf into pretix:master May 6, 2017
@asv-hungvt
Copy link
Contributor Author

Thank you for your kind instruction ;)

aph3rson added a commit to aph3rson/pretix that referenced this pull request May 11, 2017
Sync master with master of pretix/pretix@300f8f6

* Automatically sort new products to the end

* Drop "squash your commits" from the dev guide

* Add variation descriptions and allow to order addons

* Link to Django's runserver options in dev docs

* Allow <br> tags in rich text

* Copy from event: deal with deleted items

* Make validate_cart useful together with addons

* Fix collapsing panels in the addon choice step

* Button text change if addons are present

* Update translations

* Squash migrations and bump version

* Ticket PDFs: Do not hide attendee name if code is hidden

* Add a user guide on payments

* Link PayPal and Stripe documentation in the respective forms

* Hide payment fees if they are all equal to 0.00

* Refs pretix#39 -- New concept of "teams" (pretix#478)

* New models

* CRUD UI

* UI for adding/removing team members

* Log display for teams

* Fix invitations, move frontend

* Drop old models (incomplete)

* Drop more old stuff

* Drop even more old stuff

* Fix tests

* Fix permission test

* flake8 fix

* Add tests fore the new code

* Rebase migrations

* Fix typo in method name

* Update translations

* Force ordering of events on dashboard

* Fix typos in events

* Prepare the pretixdroid API for an async mode in the app

* Pretixdroid tests: Ignore microseconds (chopped by mysql)

* pretixdroid API: Add related lookups

* Add idempotenty nonces to pretixdroid API

* pretixdroid: force-accepting unpaids and time display

* Marked webfonts as binary files (pretix#487)

Webfonts now listed as binary in `.gitattributes`.
Works on pretix#486

* Fix pretix#456 -- Allow products to be excluded from ticket-generation (pretix#483)

* Added non-admission setting to event

`ticket_download_nonadm` now setting in storage. Still need logic for
order page/PDF generation.
Works on pretix#456.

* Download button considers `ticket_download_nonadm`

Modified Django tags to look at item admission attribute and
`ticket_download_nonadm` setting.
Works on pretix#456.

* Ticket output for non-admission disabled

PDFs/etc. will only be permitted/generated for items with the
`admission` attribute, or if the `ticket_download_nonadm` event setting
is true. Applies to single and whole-order ticket downloads.
Works on pretix#456.

* Fixed product exclusion in PDF output

Forgot PDF output was a plugin, now includes same check as base
`BaseTicketOutput.generate_order`.
Works on pretix#456

* Mail signature (pretix#485)

* added signature field -- no function yet

* added mail signature feature

* fixed style issue

* fixed problem with signature default

* added unit test for mail signatures

* added unit test for mail signatures

* [WIP] Fix pretix#447 -- Sendmail plugin: Create new mail based on an old one (pretix#476)

* send old email content to the new one

* error key event

* test commit

* query bad ID

* query bad ID

* query bad ID

* query bad ID

* Update pretixdroid API version

* Refs pretix#447 -- Extend copying old mails to subject and receipients

* Fixed bugs and added test for date range rendering (pretix#488)

* fixed bug for same dates, added unit check for daterange

* fixed local language override in unit test

* Fix pretix#297 -- pretixdroid: Show metrics in the control panel (pretix#481)

* add checkin status page

add dashboard widget
add checkin page under orders

* modify checkin logic

added new fields in checkin page
added filter items

* add tests for checkins & minor improvement

* support addin_product & noadm setting logic

* remove name ordering check test case

* Fix pretix#379 -- Add logo to event organizers (pretix#431)

* [WIP] Add logo to event organizers.

* Fix indentation issues.

* Refactor code

Refactor code

Refactor code

* Add new migration

* Take files into account for organizer sform (settings form)

* Fix grammer

* Make bootstrap form errors specific to each fieldset

* Display logo on organizer's page

* Fix PR issues

Fix PR issues

Fix PR issues

* Reorder imports

* Remove conflicting migration

* Fix rebase conflict

* Fix pretix#41 -- Drag-and-drop ticket editor

Undo/redo

Useful toolbox

Font selection

Add text content

Use hex for colors

JS-side dump and load

Save

Load layout, proper undo/redo

First steps to Python rendering

More PDF rendering

Copy and paste

Buttons for keyboard actions

Splash Screen

Block unbeforeunload in dirty state

Remove debugging output

Preview

Upload new PDFs via the editor

Fix bugs during PDF reload, link in settings form

New default ticket

Add OpenSans BI

Custom fonts, fix tests

* Added bootstrap-colorpicker

* Allow inline PDF display in CSP header

* Add fontpack to list of plugins

* Update German translation

* Add ticketoutputpdf's assets to MANIFEST.i

* Fix migration of old ticket styles

* Fix iCal download URL

* Multi-line location field, new field for admission time

* Admission date and time in editor

* Remove icon from "add to calendar"

* Try to fix PDF display problems in Safari

* Proxy cachedfiles that are used as editor previews

* Check Event.presale_is_running in more places

* Fix CSS generation with an empty color field

* Fix missing placeholders and reformat the sendmail view

* Fix bug that lead to wrong payment amount when switching payment method to PayPal later

* Update translation
raphaelm pushed a commit that referenced this pull request May 17, 2017
* Syncing fork to upstream (#1)

Sync master with master of 300f8f6

* Automatically sort new products to the end

* Drop "squash your commits" from the dev guide

* Add variation descriptions and allow to order addons

* Link to Django's runserver options in dev docs

* Allow <br> tags in rich text

* Copy from event: deal with deleted items

* Make validate_cart useful together with addons

* Fix collapsing panels in the addon choice step

* Button text change if addons are present

* Update translations

* Squash migrations and bump version

* Ticket PDFs: Do not hide attendee name if code is hidden

* Add a user guide on payments

* Link PayPal and Stripe documentation in the respective forms

* Hide payment fees if they are all equal to 0.00

* Refs #39 -- New concept of "teams" (#478)

* New models

* CRUD UI

* UI for adding/removing team members

* Log display for teams

* Fix invitations, move frontend

* Drop old models (incomplete)

* Drop more old stuff

* Drop even more old stuff

* Fix tests

* Fix permission test

* flake8 fix

* Add tests fore the new code

* Rebase migrations

* Fix typo in method name

* Update translations

* Force ordering of events on dashboard

* Fix typos in events

* Prepare the pretixdroid API for an async mode in the app

* Pretixdroid tests: Ignore microseconds (chopped by mysql)

* pretixdroid API: Add related lookups

* Add idempotenty nonces to pretixdroid API

* pretixdroid: force-accepting unpaids and time display

* Marked webfonts as binary files (#487)

Webfonts now listed as binary in `.gitattributes`.
Works on #486

* Fix #456 -- Allow products to be excluded from ticket-generation (#483)

* Added non-admission setting to event

`ticket_download_nonadm` now setting in storage. Still need logic for
order page/PDF generation.
Works on #456.

* Download button considers `ticket_download_nonadm`

Modified Django tags to look at item admission attribute and
`ticket_download_nonadm` setting.
Works on #456.

* Ticket output for non-admission disabled

PDFs/etc. will only be permitted/generated for items with the
`admission` attribute, or if the `ticket_download_nonadm` event setting
is true. Applies to single and whole-order ticket downloads.
Works on #456.

* Fixed product exclusion in PDF output

Forgot PDF output was a plugin, now includes same check as base
`BaseTicketOutput.generate_order`.
Works on #456

* Mail signature (#485)

* added signature field -- no function yet

* added mail signature feature

* fixed style issue

* fixed problem with signature default

* added unit test for mail signatures

* added unit test for mail signatures

* [WIP] Fix #447 -- Sendmail plugin: Create new mail based on an old one (#476)

* send old email content to the new one

* error key event

* test commit

* query bad ID

* query bad ID

* query bad ID

* query bad ID

* Update pretixdroid API version

* Refs #447 -- Extend copying old mails to subject and receipients

* Fixed bugs and added test for date range rendering (#488)

* fixed bug for same dates, added unit check for daterange

* fixed local language override in unit test

* Fix #297 -- pretixdroid: Show metrics in the control panel (#481)

* add checkin status page

add dashboard widget
add checkin page under orders

* modify checkin logic

added new fields in checkin page
added filter items

* add tests for checkins & minor improvement

* support addin_product & noadm setting logic

* remove name ordering check test case

* Fix #379 -- Add logo to event organizers (#431)

* [WIP] Add logo to event organizers.

* Fix indentation issues.

* Refactor code

Refactor code

Refactor code

* Add new migration

* Take files into account for organizer sform (settings form)

* Fix grammer

* Make bootstrap form errors specific to each fieldset

* Display logo on organizer's page

* Fix PR issues

Fix PR issues

Fix PR issues

* Reorder imports

* Remove conflicting migration

* Fix rebase conflict

* Fix #41 -- Drag-and-drop ticket editor

Undo/redo

Useful toolbox

Font selection

Add text content

Use hex for colors

JS-side dump and load

Save

Load layout, proper undo/redo

First steps to Python rendering

More PDF rendering

Copy and paste

Buttons for keyboard actions

Splash Screen

Block unbeforeunload in dirty state

Remove debugging output

Preview

Upload new PDFs via the editor

Fix bugs during PDF reload, link in settings form

New default ticket

Add OpenSans BI

Custom fonts, fix tests

* Added bootstrap-colorpicker

* Allow inline PDF display in CSP header

* Add fontpack to list of plugins

* Update German translation

* Add ticketoutputpdf's assets to MANIFEST.i

* Fix migration of old ticket styles

* Fix iCal download URL

* Multi-line location field, new field for admission time

* Admission date and time in editor

* Remove icon from "add to calendar"

* Try to fix PDF display problems in Safari

* Proxy cachedfiles that are used as editor previews

* Check Event.presale_is_running in more places

* Fix CSS generation with an empty color field

* Fix missing placeholders and reformat the sendmail view

* Fix bug that lead to wrong payment amount when switching payment method to PayPal later

* Update translation

* Revert "Syncing fork to upstream (#1)"

This reverts commit 847d409.
Merged wrong, my bad.

* Formatted OTP secret

New variable `secretGrouped` in `2fa_confirm_totp.html`, user-friendly
version of OTP secret (split every 4 characters).
Works on #443.

* Adds manual secret entry OTP setup screen

`secretGrouped` exposed in user-friendly fashion. Includes short
instructions, copy-to-clipboard button, and js to hide instructions
unless user clicks on "Can't scan the barcode?" link.
Works on #443.

* Minor indentation issuer

Fixed indentation issue (L40).
Works on #443.

* Minor spacing issues

L265 of `user.py` failing flake8 tests, minor spacing fixes.

* Fixes indentation in `2fa_confirm_totp.html`

Per #490 (comment),
fixes an issue with indentation.
Works on #443, member of #490.

* Removed `aria-*` attributes

Per #490 (comment),
removes `aria` attributes from sub-tutorial.
Works on #443, member of #490.

* Pretix capitalization issue

Per #490 (comment),
fixes an issue with capitalization of pretix.
Works on #443, member of #490.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants