-
Notifications
You must be signed in to change notification settings - Fork 48
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
Restore no-targets welcome message, add Messier option. #1171
Conversation
This PR addresses two things: 1. Restores the message in the target list table when there are no targets yet in the database, pointing the user to add a target manually or add one from a broker. This functionality was broken presumably at some point when the table became an inclusion tag. 2. Add an option to import the Messier catalog, a quick and easy option for someone who has just set up a TOM and wants to explore it's functionality quickly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!
A few comments.
@@ -43,8 +43,14 @@ | |||
<tr> | |||
<td colspan="5"> | |||
{% if target_count == 0 and not query_string %} | |||
No targets yet. You might want to <a href="{% url 'tom_targets:create' %}">create a target manually</a> | |||
or <a href="{% url 'tom_alerts:list' %}">import one from an alert broker</a>. | |||
There are no targets in the database. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be a bit misleading if a user doesn't have permissions to see the targets in the DB.
If a logged out user clicks on this when targets are in the DB, it will prompt a login then the page will crash.
Method Not Allowed (GET): /targets/seed/
Method Not Allowed (GET): /targets/seed/
Method Not Allowed: /targets/seed/
Method Not Allowed: /targets/seed/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty confusing. I created a second, non-admin user and when I login, I can't see any targets. I create a target on my admin user, and it's in the public group, still I can't see anything on the non-admin user. I had to explicitly create a group, add the new user to the group, and add those targets to that group to see them on any non-admin user. Is this intentionally how it's supposed to work?
I would have thought that by default targets would be added to the inferred public group. But that doesn't seem to be the case - I can actually import the messier objects as a non-admin user but can't see them unless I log in as an admin.
How should these seed objects be created so that non-admin users can see them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I figured it out. It's because the user must have the tom_targets.Target.view_target permission:
Line 74 in 4a46922
permission_required = f'{Target._meta.app_label}.view_target' |
This doesn't seem like it's set when a user is created by an admin in the user section, but maybe it should be? I don't see this mentioned anywhere in the docs. If I wasn't already familiar with the Django permissions system and knew I could set it in /admin I don't think I'd have been able to figure this out as easily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, the permissions structure is complicated because different toms have different needs. We can't really dictate who gets to see what.
That being said, by default, a non-admin user SHOULD be able to see everything in the public group, but AnonymousUser
should not. By default the public group doesn't have access to new targets. This includes the Messier objects.
if I go and update them individually to give the public user group access (Target detail page --> update) then I can see them just fine from my non-admin user.
However, if I delete them and try to create them again via the button, from this test user, they are created, but they aren't created with permissions such that either the public group, or even that specific test user has access.
The issue I mentioned above is actually with regards to the AnonymousUser
. If you log out and go to the target list page, and try to add messier objects, it will prompt a login as you try to pass through targets/seed
, and give a 405. We probably should hide the create button for the AnonymousUser
. or have the logic:
if no targets, and no login --> display "Login to see targets"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, I think it doesn't matter if public is given access by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A TOM developer might have their TOM permissions configured in such a way that there may be Targets in the db, but they're just not visible to the current user. So, I'm not sure the toolkit itself can, without more logic, claim that there are no Targets in the database.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jchate6 I see what you're saying. Latest commit will check if the user is authenticated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A TOM developer might have their TOM permissions configured in such a way that there may be Targets in the db, but they're just not visible to the current user. So, I'm not sure the toolkit itself can, without more logic, claim that there are no Targets in the database.
I added this logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea behind this issue
was to put the add-messier-catalog code snippet into a form that was more broadly useful (i.e. a flexible management command that users could use to add targets). With use cases like:
./manage.py addtarget Vega
./manage.py addtarget --catalog NED NCG 1234
which could query NED, while the default catalog is SIMBAD. I'm fine with just searching one catalog at a time, but one suggestion was query multiple catalogs in some order until the queried object is found (but this seems overly complicated to me)./manage.py addtarget --messier
which is how the code snippet might be packaged up.
I think this turns the messier.py
code snippet, which is nice for testing by devs to a useful feature for users.
] | ||
|
||
|
||
def seed_messier_targets(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is really about creating Targets, the context (that we're seeding the db) isn't really the point and I'd like not to introduce a new concept (i.e."seeding") without a stronger reason. So, can we rename the function to something like create_messier_targets
? and I'm not sure what to call the module right now.
@@ -0,0 +1,121 @@ | |||
from tom_targets.models import Target, TargetList | |||
|
|||
messier_targets = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm on the fence about single-source-of-truth vs. network-is-slow-and-don't-hammer-SIMBAD arguments.
If we consider the code as someplace a TOM developer might look to as an example of how one might add a Target with an alias, the logic of: I queried SIMBAD and the result came back with a different name than I queried with, so add that as an additional TargetName motivates and demonstrates that.
Also, messier.py
provides an example of how to add a target_extra for Object Type, which I kind of liked.
@@ -43,8 +43,14 @@ | |||
<tr> | |||
<td colspan="5"> | |||
{% if target_count == 0 and not query_string %} | |||
No targets yet. You might want to <a href="{% url 'tom_targets:create' %}">create a target manually</a> | |||
or <a href="{% url 'tom_alerts:list' %}">import one from an alert broker</a>. | |||
There are no targets in the database. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A TOM developer might have their TOM permissions configured in such a way that there may be Targets in the db, but they're just not visible to the current user. So, I'm not sure the toolkit itself can, without more logic, claim that there are no Targets in the database.
@@ -25,6 +26,7 @@ | |||
path('create/', TargetCreateView.as_view(), name='create'), | |||
path('import/', TargetImportView.as_view(), name='import'), | |||
path('export/', TargetExportView.as_view(), name='export'), | |||
path('seed/', TargetSeedView.as_view(), name='seed'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above comment wrt seed
The idea here stems from my experience as a "new tom user" yesterday. I spun up a new TOM, and was presented with an empty table that said "No targets match those filters". I tried to use a broker to add some targets, it's not intuitive and I couldn't get any of them to work in a few minutes. Manual creation is easy but feels bad if you don't have a RA/DEC memorized of a real target. So the idea is to provide an option for a small set of usable targets immediately, if the user wants them, as well as to point them to the other methods of adding targets. I would call that seeding. I don't really care what or how we do it. If we want to use a broker like SIMBAD, or we want to use the NGC catalog, or something else entirely, I don't think it matters - these targets are in most cases all going to be deleted anyway. All that matters if we give the user something, anything, that actually exposes the functionality of the TOM immediately. Also in regard to management commands, I would like to understand the reasoning better for adding more functionality with them. I wouldn't call management commands user-friendly. In fact in some deployment scenarios, users won't be able to use them at all. So that's why I avoided adding this as a management command. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One optional request, but otherwise good to merge.
You might want to <a href="{% url 'tom_targets:create' %}">create a target manually</a>, | ||
<a href="{% url 'tom_alerts:list' %}">import one from an alert broker</a> | ||
or | ||
<form method="POST" action="{% url 'tom_targets:seed' %}" class="d-inline"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a link for this to the tom_targets.templates.tom_tagets.partials.recent_targets.html
partial used on the index page after the "create a target" link?
I think if our goal is to quickly and obviously populate a tom with targets, this would be a great spot to do that from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, added.
Added tests, and the links to help create targets to the recent targets partial. |
This PR addresses two things: