import re
with open('addons/education_lms/security/security.xml', 'r') as f:
text = f.read()
# I need to restore the original domain AND add perm_read="True"
# Let's replace the whole Student Course Access rule.
new_course_rule = """
Student Course Access
[
('state', 'in', ['published', 'closed']),
('program_id', 'in', user.student_ids.mapped('program_id').ids),
('academic_year_id', 'in', user.student_ids.mapped('academic_year_id').ids),
'|', ('term_id', '=', False), ('term_id', 'in', user.student_ids.mapped('academic_term_id').ids),
'|', ('batch_id', '=', False), ('batch_id', 'in', user.student_ids.mapped('batch_id').ids),
]
"""
text = re.sub(
r'.*?',
new_course_rule,
text,
flags=re.DOTALL
)
with open('addons/education_lms/security/security.xml', 'w') as f:
f.write(text)