backoffice: consider visibility in total formdata counts (#27483)

This commit is contained in:
Frédéric Péters 2018-10-21 15:54:35 +02:00
parent a636338d40
commit 9719d0ade6
2 changed files with 9 additions and 5 deletions

View File

@ -474,7 +474,7 @@ class ManagementDirectory(Directory):
if using_postgresql:
from wcs import sql
actionable_counts = sql.get_actionable_counts(user_roles)
total_counts = sql.get_total_counts()
total_counts = sql.get_total_counts(user_roles)
def append_form_entry(formdef):
if using_postgresql:

View File

@ -2030,13 +2030,17 @@ def get_actionable_counts(user_roles):
return counts
@guard_postgres
def get_total_counts():
def get_total_counts(user_roles):
conn, cur = get_connection_and_cursor()
criterias = [
Intersects('concerned_roles_array', user_roles),
]
where_clauses, parameters, func_clause = parse_clause(criterias)
statement = '''SELECT formdef_id, COUNT(*)
FROM wcs_all_forms
WHERE status != 'draft'
GROUP BY formdef_id'''
cur.execute(statement)
WHERE %s
GROUP BY formdef_id''' % ' AND '.join(where_clauses)
cur.execute(statement, parameters)
counts = {str(x): y for x, y in cur.fetchall()}
conn.commit()
cur.close()