Refactor common code from groups permissions

We use extract class to make sure duplicate code is removed