First: I'm using Debian 10, but this might also work in Ubuntu.
The only way I was able to disable CD/DVD reading/writing was to create -- as root -- the following cron job:
@reboot mv /dev/sr0 /dev/sr0_block
Remember to check the device file name for your CD-ROM. You could use the lsblk command for that. In my case, it is sr0.
To re-enable functioning just comment or delete the cron job line and restart the computer.
Note that if you just rename the sr0 file, without adding a cron job, you'll find the change unmade after reboot.
I'm sorry this is an ugly trick, but I have tried: removing users from cdrom group, changing permissions of /media, blacklisting cdrom and sr_mod modules and even the eject -i 1 command. That is the only thing that worked for me.