Here is a small trytond-console script to assign groups to the standard wizards listed in the advisory. It preserves existing groups and model restrictions, and commits changes when run.
It also reports other wizards without groups, including custom ones, for manual review.
"""Run with trytond-console -d DATABASE -c CONFIG -f this_file.py."""
ADMIN = ('res.group_admin',)
ACCOUNT = ('account.group_account',)
ACCOUNT_ADMIN = ('account.group_account_admin',)
BUDGET = ('account_budget.group_budget',)
STOCK = ('stock.group_stock',)
# Suggested policy for the security advisory and related upstream actions.
# Review against your installation's permissions before applying.
GROUPS = {
'res.user.config': ADMIN,
'company.company.config': ('company.group_company_admin',),
'ir.module.config': ADMIN,
'ir.translation.set': ADMIN,
'ir.translation.clean': ADMIN,
'account.create_chart': ACCOUNT_ADMIN,
'account.update_chart': ACCOUNT_ADMIN,
'account.fiscalyear.create_periods': ACCOUNT_ADMIN,
'account.fiscalyear.balance_non_deferral': ACCOUNT_ADMIN,
'account.move.reconcile_lines': ACCOUNT,
'account.move.unreconcile_lines': ACCOUNT,
'account.reconcile': ACCOUNT,
'account.move.cancel': ACCOUNT,
'account.move.template.create': ACCOUNT,
'account.move.line.group': ACCOUNT,
'account.general_ledger.account.party.open': ACCOUNT,
'account.asset.create_moves': ACCOUNT,
'account.asset.print_depreciation_table': ACCOUNT,
'account.budget.copy': BUDGET,
'analytic_account.budget.copy': BUDGET,
'account.budget.line.create_periods': BUDGET,
'account.fr.fec': ACCOUNT,
'account.statement.reconcile': (
'account.group_account', 'account.group_account_admin',
'account_statement.group_statement'),
'account.stock.eu.intrastat.declaration.export': ACCOUNT,
'stock.shipment.pack': STOCK,
'stock.package.pack': STOCK,
}
def update_wizards(pool, transaction):
Action = pool.get('ir.action.wizard')
Data = pool.get('ir.model.data')
identifiers = {}
for record in Data.search([('model', '=', 'ir.action.wizard')]):
identifiers.setdefault(record.db_id, []).append(
'%s.%s' % (record.module, record.fs_id))
changes = []
for action in Action.search([]):
if action.groups:
continue # Preserve existing permissions.
name = action.wiz_name
if name not in GROUPS:
print('REVIEW id=%s wizard=%s xml=%s model=%s (no groups)' % (
action.id, name, ','.join(identifiers.get(action.id, []))
or '<no XML ID>', action.model or '<none>'), flush=True)
elif not action.model: # Preserve existing model-based restrictions.
groups = [Data.get_id(*xml_id.split('.', 1))
for xml_id in GROUPS[name]]
changes.append((action, groups))
print('ADD id=%s wizard=%s groups=%s (previously empty)' % (
action.id, name, ','.join(GROUPS[name])), flush=True)
# Resolve the complete plan before writing; commit everything together.
for action, groups in changes:
Action.write([action], {'groups': [('add', groups)]})
for action, groups in changes:
if {g.id for g in Action(action.id).groups} != set(groups):
raise RuntimeError('Verification failed: %s' % action.wiz_name)
transaction.commit()
print('COMMITTED: %s action(s)' % len(changes), flush=True)
# These variables are supplied by trytond-console.
if 'pool' in globals() and 'transaction' in globals():
update_wizards(pool, transaction)