def _update_project_groups(self, request, data, project_id, domain_id):
    groups_to_modify = 0
    member_step = self.get_step(PROJECT_GROUP_MEMBER_SLUG)
    try:
        available_roles = self._get_available_roles(request)
        project_groups = api.keystone.group_list(request, domain=domain_id, project=project_id)
        groups_to_modify = len(project_groups)
        for group in project_groups:
            current_roles = api.keystone.roles_for_group(self.request, group=group.id, project=project_id)
            current_role_ids = [role.id for role in current_roles]
            for role in available_roles:
                field_name = member_step.get_member_field_name(role.id)
                if (group.id in data[field_name]):
                    if (role.id not in current_role_ids):
                        api.keystone.add_group_role(request, role=role.id, group=group.id, project=project_id)
                    else:
                        index = current_role_ids.index(role.id)
                        current_role_ids.pop(index)
            for id_to_delete in current_role_ids:
                api.keystone.remove_group_role(request, role=id_to_delete, group=group.id, project=project_id)
            groups_to_modify -= 1
        for role in available_roles:
            field_name = member_step.get_member_field_name(role.id)
            groups_to_modify += len(data[field_name])
        for role in available_roles:
            groups_added = 0
            field_name = member_step.get_member_field_name(role.id)
            project_group_ids = [x.id for x in project_groups]
            for group_id in data[field_name]:
                if (group_id not in project_group_ids):
                    api.keystone.add_group_role(request, role=role.id, group=group_id, project=project_id)
                groups_added += 1
            groups_to_modify -= groups_added
        return True
    except Exception:
        exceptions.handle(request, (_('Failed to modify %s project members, update project groups and update project quotas.') % groups_to_modify))
        return False
def _update_project_groups(self, request, data, project_id, domain_id):
    groups_to_modify = 0
    member_step = self.get_step(PROJECT_GROUP_MEMBER_SLUG)
    try:
        available_roles = self._get_available_roles(request)
        project_groups = api.keystone.group_list(request, domain=domain_id, project=project_id)
        groups_to_modify = len(project_groups)
        for group in project_groups:
            current_roles = api.keystone.roles_for_group(self.request, group=group.id, project=project_id)
            current_role_ids = [role.id for role in current_roles]
            for role in available_roles:
                field_name = member_step.get_member_field_name(role.id)
                if (group.id in data[field_name]):
                    if (role.id not in current_role_ids):
                        api.keystone.add_group_role(request, role=role.id, group=group.id, project=project_id)
                    else:
                        index = current_role_ids.index(role.id)
                        current_role_ids.pop(index)
            for id_to_delete in current_role_ids:
                api.keystone.remove_group_role(request, role=id_to_delete, group=group.id, project=project_id)
            groups_to_modify -= 1
        for role in available_roles:
            field_name = member_step.get_member_field_name(role.id)
            groups_to_modify += len(data[field_name])
        for role in available_roles:
            groups_added = 0
            field_name = member_step.get_member_field_name(role.id)
            project_group_ids = [x.id for x in project_groups]
            for group_id in data[field_name]:
                if (group_id not in project_group_ids):
                    api.keystone.add_group_role(request, role=role.id, group=group_id, project=project_id)
                groups_added += 1
            groups_to_modify -= groups_added
        return True
    except Exception:
        exceptions.handle(request, (_('Failed to modify %s project members, update project groups and update project quotas.') % groups_to_modify))
        return False