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 Link and Webhook initializers #391

Closed
wants to merge 14 commits into from

Conversation

MajesticFalcon
Copy link
Contributor

@MajesticFalcon MajesticFalcon commented Jan 16, 2021

Related Issue:

New Behavior

Custom link and web hooks can now be created via startup scripts.
...

Contrast to Current Behavior

Current implementation is missing this behavior.
...

Discussion: Benefits and Drawbacks

...

Changes to the Wiki

...

Proposed Release Note Entry

Added custom_link initializer
Added webhook initializer
...

Double Check

  • I have read the comments and followed the PR template.
  • I have explained my PR according to the information in the comments.
  • My PR targets the develop branch.

@MajesticFalcon MajesticFalcon changed the title Feature Feature - Custom Link and Webhook initializers Jan 16, 2021
@MajesticFalcon
Copy link
Contributor Author

@cimnine, as requested, I pulled the new features into a new branch. The code was already outdated so I also updated the startup scripts and added error handling, icon printing, etc.

@cimnine cimnine added the enhancement The issue describes an enhancement that we would like to implement in the future. label Jan 19, 2021
@cimnine cimnine added this to the 0.28.0 milestone Jan 19, 2021
@cimnine cimnine changed the base branch from release to develop January 20, 2021 08:07
initializers/custom_links.yml Outdated Show resolved Hide resolved
startup_scripts/280_custom_links.py Outdated Show resolved Hide resolved
startup_scripts/280_custom_links.py Outdated Show resolved Hide resolved
startup_scripts/290_webhooks.py Show resolved Hide resolved
startup_scripts/290_webhooks.py Outdated Show resolved Hide resolved
@cimnine cimnine changed the title Feature - Custom Link and Webhook initializers Add Custom Link and Webhook initializers Jan 20, 2021
@cimnine cimnine mentioned this pull request Jan 20, 2021
3 tasks
Copy link
Collaborator

@cimnine cimnine left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution! This could one day even the way to do full fledged integration testing of the webhooks feature. Really cool!

Please also see my previous feedback. I would like to merge this in the version we're currently preparing. If you can't look at the feedback right now (that's perfectly ok!), I'd appreciate a quick message so that we can get all the other changes out.

initializers/custom_links.yml Show resolved Hide resolved
initializers/webhooks.yml Outdated Show resolved Hide resolved
startup_scripts/290_webhooks.py Outdated Show resolved Hide resolved
startup_scripts/290_webhooks.py Outdated Show resolved Hide resolved
cimnine added a commit that referenced this pull request Jan 20, 2021
MajesticFalcon and others added 5 commits January 20, 2021 15:47
Co-authored-by: Christian Mäder <cimnine@users.noreply.github.com>
Co-authored-by: Christian Mäder <cimnine@users.noreply.github.com>
Co-authored-by: Christian Mäder <cimnine@users.noreply.github.com>
Co-authored-by: Christian Mäder <cimnine@users.noreply.github.com>
Co-authored-by: Christian Mäder <cimnine@users.noreply.github.com>
@MajesticFalcon
Copy link
Contributor Author

Thank you for the contribution! This could one day even the way to do full fledged integration testing of the webhooks feature. Really cool!

Please also see my previous feedback. I would like to merge this in the version we're currently preparing. If you can't look at the feedback right now (that's perfectly ok!), I'd appreciate a quick message so that we can get all the other changes out.

I typically get on around 8pm CST. I am just seeing this, I apologize if this is late notice. I can fix it tonight.

MajesticFalcon and others added 2 commits January 20, 2021 21:25
Co-authored-by: Christian Mäder <cimnine@users.noreply.github.com>
Move to a more standard method of object handling
@cimnine
Copy link
Collaborator

cimnine commented Jan 21, 2021

I typically get on around 8pm CST. I am just seeing this, I apologize if this is late notice. I can fix it tonight.

No need to apologize. I don't expect people to have time immediately. I just wanted to know whether we should proceed with the release or if you think you will have time soon-ish to look at the comments :)

@MajesticFalcon
Copy link
Contributor Author

MajesticFalcon commented Jan 21, 2021

I typically get on around 8pm CST. I am just seeing this, I apologize if this is late notice. I can fix it tonight.

No need to apologize. I don't expect people to have time immediately. I just wanted to know whether we should proceed with the release or if you think you will have time soon-ish to look at the comments :)

Thank you for your help! Is there anything left to do before merging this in?

Copy link
Collaborator

@cimnine cimnine left a comment

Choose a reason for hiding this comment

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

Thank you for your effort to improve and fix the code. I've again added some recommendations. If you find them actionable, please make sure to check the rest of this PR's changes if these remarks apply there as well, as I typically don't add a remark twice when it's the identical remark, just on a different subset of the code.
Otherwise I welcome your argument wherever you disagree :)

Comment on lines +17 to +21
# - name: link_to_localhost
# text: 'Link to the users localhost'
# url: 'http://localhost'
# new_window: True
# content_type: device
Copy link
Collaborator

Choose a reason for hiding this comment

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

This part is still wrong:

Suggested change
# - name: link_to_localhost
# text: 'Link to the users localhost'
# url: 'http://localhost'
# new_window: True
# content_type: device
# - name: link_to_localhost
# text: 'Link to the users localhost'
# url: 'http://localhost'
# new_window: True
# content_type: device

You can run the test locally to see if your changes work and integrate with all the other initializers:

./build-latest.sh && ./test.sh latest

if link['content_type_id'] is not None:
custom_link = CustomLink(**link)
if not CustomLink.objects.filter(name=custom_link.name):
custom_link.save()
Copy link
Collaborator

Choose a reason for hiding this comment

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

You did change the implementation to get_or_create after my comment in 290_webhooks.py – didn't that work with custom links, was this just an oversight or didn't you intentionally not change it here?

for link in custom_links:
content_type = link.pop('content_type')
link['content_type_id'] = get_content_type_id(content_type)
if link['content_type_id'] is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggest to change the logic here as follows:

Suggested change
if link['content_type_id'] is not None:
if link['content_type_id'] is None:
print("⚠️ Unable to create Custom Link '{0}': The content_type '{1}' is unknown".format(link.name, content_type))
continue

This will make it obvious which custom link failed to get created and why.

try:
return ContentType.objects.get(model=content_type_str).id
except ContentType.DoesNotExist:
print("⚠️ Error determining content type id for user declared var: {0}".format(content_type_str))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
print("⚠️ Error determining content type id for user declared var: {0}".format(content_type_str))
return None

... or ...

Suggested change
print("⚠️ Error determining content type id for user declared var: {0}".format(content_type_str))
pass

... (not sure which is more idiomatic in Python).

The error is technically accurate, but not actionable for our users.
They will not know what went wrong. And because we don't have access to the context here (i.e. the custom_link.name is not known, and it would be a drag to pass it to this function just in case there's an error), I would skip a message here and replace it with an error in the caller. (As per above suggestion.)

custom_link = CustomLink(**link)
if not CustomLink.objects.filter(name=custom_link.name):
custom_link.save()
print("🖥️ Created Custom Link {0}".format(custom_link.name))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
print("🖥️ Created Custom Link {0}".format(custom_link.name))
print("🖥️ Created Custom Link '{0}'".format(custom_link.name))

It's cool to have this additional information, which custom link was created. Though it's good habit to enclose strings into quotation signs when printing them to stdout. Otherwise it's really hard to see if there is e.g. an extra whitespace where there shouldn't have been one.

@cimnine cimnine added the awaiting answer There is still some open discussion. label Jan 26, 2021
@cimnine cimnine modified the milestones: 0.28.0, 1.0.0 Jan 27, 2021
@cimnine
Copy link
Collaborator

cimnine commented Feb 8, 2021

Merged with commit f33c647

@cimnine cimnine closed this Feb 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting answer There is still some open discussion. enhancement The issue describes an enhancement that we would like to implement in the future.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants