Join the users in a group.

def group_with(self, to_user, project, bypass_limit=False):
        """Join the users in a group."""
        from_user = self
        from_assoc = from_user.fetch_group_assoc(project)
        to_assoc = to_user.fetch_group_assoc(project)

        if from_user == to_user or from_assoc == to_assoc and from_assoc:
            raise GroupWithException('You are already part of that group.')

        if not from_assoc and not to_assoc:
            to_assoc = UserToGroup(group=Group(project=project),
                                   project=project, user=to_user)
            Session.add(to_assoc)
            from_count = 1
        elif not to_assoc:
            from_assoc, to_assoc = to_assoc, from_assoc
            from_user, to_user = to_user, from_user
            from_count = 1
        elif not from_assoc:
            from_count = 1
        elif to_assoc.user_count > from_assoc.user_count:
            from_assoc, to_assoc = to_assoc, from_assoc
            from_user, to_user = to_user, from_user
            from_count = from_assoc.user_count
        else:
            from_count = from_assoc.user_count

        if not bypass_limit and \
                project.group_max < to_assoc.user_count + from_count:
            raise GroupWithException('There are too many users to join that '
                                     'group.')

        if from_assoc:  # Move the submissions and users
            old_group = from_assoc.group
            for submission in from_assoc.group.submissions[:]:
                submission.group = to_assoc.group
            for assoc in from_assoc.group.group_assocs[:]:
                assoc.group = to_assoc.group
            if to_assoc.group.viewed_at is None:
                to_assoc.group.viewed_at = old_group.viewed_at
            elif old_group.viewed_at:
                to_assoc.group.viewed_at = max(old_group.viewed_at,
                                               to_assoc.group.viewed_at)
            Session.delete(old_group)
        else:  # Add the user to the group
            from_assoc = UserToGroup(group=to_assoc.group, project=project,
                                     user=from_user)
            Session.add(from_assoc)

        # Update the group's submissions' files' permissions
        files = set(assoc.file for sub in to_assoc.group.submissions
                    for assoc in sub.files)
        for user in to_assoc.group.users:
            user.files.update(files)

        return to_assoc.group