FIX: Don't responde with error 500 if domain is invalid when adding automatic membership domain (PR #9655)

Group#get_valid_email_domains accepts an optional block that can be called when the method finds an invalid email, however we unconditionally yield without checking if a block is actually given. This causes a 500 error (LocalJumpError) in Admin::GroupsController#automatic_membership_count because it calls get_valid_email_domains without passing a block to it.

This PR fixes the problem by checking block_given? before calling yield. I’ve also added a couple of test cases.

GitHub