Skip to content

Commit

Permalink
Fix "TODO" search for Santa targets & ballots
Browse files Browse the repository at this point in the history
  • Loading branch information
np5 committed Sep 7, 2024
1 parent c086a8d commit 182cb78
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
7 changes: 7 additions & 0 deletions tests/santa/test_ballots_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@ def test_ballots_reset_ballot_included(self):
def test_ballots_todo_filter(self):
_, realm_user2 = force_realm_user(realm=self.realm)
self._login("santa.view_ballot")
TargetState.objects.create(
target=self.file_target,
configuration=self.configuration,
state=TargetState.State.UNTRUSTED,
score=0,
reset_at=datetime.now() - timedelta(days=1)
)
force_ballot(self.file_target, self.realm_user, [(self.configuration, True, 192)])
force_ballot(self.metabundle_target, realm_user2, [(self.configuration, False, 934)])
response = self.client.get(reverse("santa:ballots"), {"todo": "on"})
Expand Down
24 changes: 16 additions & 8 deletions zentral/contrib/santa/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,8 @@ def search_query(
else:
bi_where = ce_where = bu_where = mbu_where = ""
ti_where = "where c.organizational_unit ~ '[A-Z0-9]{10}'"
ch_where = "where f.cdhash IS NOT NULL"
si_where = "where f.signing_id IS NOT NULL"
ch_where = "where (f.cdhash = '') IS FALSE"
si_where = "where (f.signing_id = '') IS FALSE"
wheres = []
havings = []
# target state
Expand Down Expand Up @@ -629,15 +629,19 @@ def search_query(
)
# no votes from user
if username or email:
todo_cfg_where = ""
todo_cfg_where = "and (nets.reset_at is null or nets.reset_at < nev.created_at)"
if configuration_pk:
todo_cfg_where = "and nev.configuration_id = %(configuration_pk)s"
todo_cfg_where = f"{todo_cfg_where} and nev.configuration_id = %(configuration_pk)s"
wheres.append(
"not exists ("
" select * from santa_vote nev"
" join santa_ballot neb on (nev.ballot_id = neb.id)"
" left join santa_targetstate nets on ("
" neb.target_id = nets.target_id"
" and nev.configuration_id = nets.configuration_id"
" )"
" left join realms_realmuser neu on (neb.realm_user_id = neu.uuid)"
" where neb.target_id = t.id "
" where neb.target_id = t.id and neb.replaced_by_id is null"
" and (neb.user_uid = %(username)s or neu.username = %(username)s"
" or neb.user_uid = %(email)s or neu.username = %(email)s)"
f" {todo_cfg_where}"
Expand Down Expand Up @@ -936,15 +940,19 @@ def results(self, current_username, current_email, offset, limit):
where_list.append("(ts.reset_at is null or v.created_at is null or v.created_at > ts.reset_at)")
todo = self.cleaned_data.get("todo")
if todo:
todo_cfg_where = ""
todo_cfg_where = "and (nets.reset_at is null or nets.reset_at < nev.created_at)"
if configuration:
todo_cfg_where = "and nev.configuration_id = %(configuration_pk)s"
todo_cfg_where = f"{todo_cfg_where} and nev.configuration_id = %(configuration_pk)s"
where_list.append(
"not exists ("
" select * from santa_vote nev"
" join santa_ballot neb on (nev.ballot_id = neb.id)"
" join santa_targetstate nets on ("
" neb.target_id = nets.target_id"
" and nev.configuration_id = nets.configuration_id"
" )"
" left join realms_realmuser neu on (neb.realm_user_id = neu.uuid)"
" where neb.target_id = t.id "
" where neb.target_id = t.id and neb.replaced_by_id is null"
" and (neb.user_uid = %(current_username)s or neu.username = %(current_username)s"
" or neb.user_uid = %(current_email)s or neu.username = %(current_email)s)"
f" {todo_cfg_where}"
Expand Down

0 comments on commit 182cb78

Please sign in to comment.