refactor has permission code