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

Add custom code for support #61

Merged
merged 2 commits into from
Nov 14, 2022

Conversation

zzacharo
Copy link
Contributor

@zzacharo zzacharo commented Oct 19, 2022

@kpsherva kpsherva linked an issue Oct 27, 2022 that may be closed by this pull request
3 tasks
@alejandromumo alejandromumo self-assigned this Nov 4, 2022
@alejandromumo alejandromumo force-pushed the add-custom-code-for-support branch 2 times, most recently from afe39fb to 7eb327c Compare November 11, 2022 10:38
@alejandromumo alejandromumo force-pushed the add-custom-code-for-support branch from 7eb327c to 0f0c8ee Compare November 11, 2022 10:48
...getInputProps(),
// Display the dropzone input, otherwise it's hidden by default.
style: {
'display': 'block'
Copy link
Member

Choose a reason for hiding this comment

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

react-dropzone has an input element that is hidden.

In other parts of invenio we keep it that way and re-implement it with either a button or a box for drag and drop. Here I went for a simpler solution, might not be the best though.

"""Constructor."""
super().__init__()

def send_support_email(
Copy link
Member

@alejandromumo alejandromumo Nov 11, 2022

Choose a reason for hiding this comment

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

This can be simplified into a method that works solely with contexts, as suggested by @slint personally.

I can tackle this in a separate task.

Same applies for the method send_confirmation_email

)


class FormValidationError(ZenodoRDMError):
Copy link
Member

Choose a reason for hiding this comment

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

Currently not in use. Can be used when Marshmallow fails to validate the form data or simply removed (marshmallow already throws a ValidationError) .

return redirect(url_for("invenio_app_rdm.index"))

def handle_form(self, form_data):
"""Form controller."""
Copy link
Member

Choose a reason for hiding this comment

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

Currently the only handler is to send two emails. However it can grow into different behaviors (e.g. based on a category do something else)

try:
data = self.validate_form(data)
except (ValidationError) as e:
return str(e), 400
Copy link
Member

Choose a reason for hiding this comment

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

I am unsure whether this error handling is ideal.

Please let me know if it can be improved.

Copy link
Contributor

@kpsherva kpsherva Nov 11, 2022

Choose a reason for hiding this comment

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

should raise (not return) a rest error, there are defined already in flask resources

Copy link
Member

@alejandromumo alejandromumo Nov 14, 2022

Choose a reason for hiding this comment

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

Thanks! I realized 500 errors already have a default handler and we can work with that.

For ValidationError I added a custom handler. It returns an object similar to what we have in other modules, making the response serializable to formik. E.g.

{
  "errors": [
    {
      "field": "email",
      "messages": [
        "Not a valid email address."
      ]
    },
    {
      "field": "description",
      "messages": [
        "Description length must be bigger than 20 characters"
      ]
    }
  ]
}

Dockerfile Show resolved Hide resolved
const inpProps = {
...getInputProps(),
// Display the dropzone input, otherwise it's hidden by default.
style: {
Copy link
Contributor

Choose a reason for hiding this comment

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

can this styling be moved to theme files?

Comment on lines 152 to 110
const initialValues = {
email: userMail,
name: name,
category: defaultCategory,
sysInfo: false,
files: null
}
Copy link
Contributor

Choose a reason for hiding this comment

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

does it make sense to be moved to the constructor instead of redeclaring it on each render?

"If this issue persists you can send "
"us an email directly to {}".format(self.email_service.support_emails)
)
except (Exception) as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

this will catch any exception and will make debugging harder, is it on purpose ?

Copy link
Member

Choose a reason for hiding this comment

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

it emulates the original one https://github.com/zenodo/zenodo/blob/master/zenodo/modules/support/views.py#L68, with more granular error catching (e.g. not sending the support email is not the same as not sending the confirmation email).

I agree that we lose the message and it will a nightmare to debug, especially since it is working with e-mail. Is there a standard way of logging exceptions in invenio?

Copy link
Contributor

@kpsherva kpsherva left a comment

Choose a reason for hiding this comment

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

all the comments can be addressed in the second iteration if that is easier to manage

@alejandromumo alejandromumo force-pushed the add-custom-code-for-support branch from 0f0c8ee to 6757fa4 Compare November 14, 2022 10:54
@alejandromumo alejandromumo force-pushed the add-custom-code-for-support branch from 6757fa4 to 5a864aa Compare November 14, 2022 14:16
site/babel.ini Outdated Show resolved Hide resolved
@alejandromumo alejandromumo force-pushed the add-custom-code-for-support branch from 5a864aa to 41910e4 Compare November 14, 2022 15:10
@alejandromumo alejandromumo force-pushed the add-custom-code-for-support branch from 41910e4 to d118c1a Compare November 14, 2022 15:47
@zzacharo zzacharo merged commit 2f8900b into zenodo:master Nov 14, 2022
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.

support form: integrate zenodo implementation
5 participants