<commit_before>class HutService {

    boolean transactional = true

    def visibleHuts(String hutgroup) {
        def criteria = Hut.createCriteria();

        if (hutgroup) {
            return criteria.listDistinct {
                and {
                    eq('openHut', true)
                    owner {
                        eq('id', Long.valueOf(hutgroup))
                    }
                }
            }
        }

        return criteria.listDistinct {
            eq('openHut', true)
        }
    }

    def visibleHuts(Person p, String hutgroup) {
        if (p.admin) {
            return Hut.list()
        }

        def criteria = Hut.createCriteria();

        if (hutgroup) {
            return criteria.listDistinct {
                and {
                    or {
                        eq('openHut', true)
                        users {
                            users {
                                eq('userId', p.userId)
                            }
                        }
                        owner {
                            eq('userId', p.userId)
                        }
                    }
                    owner {
                        eq('id', Long.valueOf(hutgroup))
                    }
                }
            }
        }

        return criteria.listDistinct {
            or {
                eq('openHut', true)
                users {
                    users {
                        eq('userId', p.userId)
                    }
                }
                owner {
                    eq('userId', p.userId)
                }
            }
        }<commit_msg>Fix broken criteria<commit_after>class HutService {

    boolean transactional = true

    def visibleHuts(String hutgroup) {
        def criteria = Hut.createCriteria();

        if (hutgroup) {
            return criteria.listDistinct {
                and {
                    eq('openHut', true)
                    owner {
                        eq('id', Long.valueOf(hutgroup))
                    }
                }
            }
        }

        return criteria.listDistinct {
            eq('openHut', true)
        }
    }

    def visibleHuts(Person p, String hutgroup) {
        if (p.admin) {
            return Hut.list()
        }

        log.debug("Person ${p}, Group ${hutgroup}")

        def criteria = Hut.createCriteria();

        // I still believe that this should work but it is generating an invalid query
//        if (hutgroup) {
//            return criteria.listDistinct {
//                and {
//                    or {
//                        eq('openHut', true)
//                        users {
//                            users {
//                                eq('userId', p.userId)
//                            }
//                        }
//                        owner {
//                            eq('userId', p.userId)
//                        }
//                    }
//                    owner {
//                        eq('id', Long.valueOf(hutgroup))
//                    }
//                }
//            }
//        }

        def list = criteria.listDistinct {
            or {
                eq('openHut', true)
                users {
                    users {
                        eq('userId', p.userId)
                    }
                }
                owner {
                    eq('userId', p.userId)
                }
            }
        }

        log.debug("List ${list}")

        if (hutgroup) {
            def removals = [];

            list.each {hut -> if (hut.owner.id != Long.valueOf(hutgroup)) {removals.add(hut)}}

            log.debug("Removals ${list}")

            removals.each {hut -> list.remove(hut)}

            log.debug("List after removals ${list}")
        }

        return list;
{'fraction_non_alphanumeric': 0.0998185117967332, 'fraction_numerical': 0.0, 'mean_word_length': 0.7449118046132972, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7547917', 'n_tokens_mistral': 977, 'n_tokens_neox': 901, 'n_words': 178}