-
Notifications
You must be signed in to change notification settings - Fork 308
Allow admins to search unsearchable users #4190
Conversation
Part of #557. This covers the logic; it’s mostly a duplicate of `dashboard/index` with the buttons removed (admins can mark/unmark suspicious on the profile itself). Obviously needs to be put into a site template for ~users to see, and only needs the list, not the other frame.
Could you build the query in the block above (16-26) conditionally to avoid duplicated code? |
I was in a hurry. In case it wasn't clear enough, something like (excuse my python grammar):
|
Yay for Python from @nobodxbodon! 💃 🐍 |
I get what you're saying, just hitting a learning curve on how to work your example in so it works. |
I was confused because I didn't realize the
|
Something is still wrong with this, I need to look at it again. |
Okay @nobodxbodon, ready for review again with a simpler diff. Thanks for the help. |
…to admin-search-unsearchable
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.
Also needs tests.
@@ -14,16 +14,17 @@ if query: | |||
q = strip_accents(query) | |||
|
|||
if action in (None, 'search_usernames'): | |||
results['usernames'] = website.db.all(""" |
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.
Why change the indentation here? It makes the diff harder to read.
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.
Accident.
WHERE username %% %(q)s | ||
AND claimed_time IS NOT NULL | ||
""" | ||
+("" if user.ADMIN else " AND is_searchable") |
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.
Hmm ... could we find a way to do this without string interpolation? (Tbh this is the achilles heel of our db wiring; it's bad practice to construct SQL from strings because of the danger of SQL injection, but it's hard to avoid without a full-blown SQL model in Python, aka SQLAlchemy.)
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 first commit didn't work like that, FWIW.
…pay.com into admin-search-unsearchable
After thrashing about, I cleaned up the indents. |
This functionality seems to exist...investigating. There's a commit (6230342) in #4157 that is even called "Allow admins to search unsearchable users," but it doesn't have the string interpolation version--because it was introduced earlier, in a277c5d. I image this made it in there after I neglected to properly stash files when switching branches. As such, I am closing this PR and the original ticket. |
!m @mattbk |
Closes #3121.