<commit_before>module Spider; module Auth

    module RBACProvider
        
        def self.included(model)
            model.extend(ClassMethods)
        end
        
        # If the second argument is a symbol, it will be interpreted as the context
        def can?(permission, obj=nil, context=nil)
            if obj.is_a?(Symbol)
                context = obj
                obj = nil
            end
            context ||= self.class.rbac_contexts.first
            permission = permission.to_sym
            el = self.class.rbac_provider_elements[context]
            options = RBAC.options(context)
            if options[:superuser]
                val = self.get(options[:superuser])
                return true if val
            end
            val = self.get(el)
            has_perm = false
            val.each do |v|
                if v.id.to_sym == permission
                    has_perm = true
                    break
                end
            end
            perm_details = RBAC.context(context)[permission]
            if has_perm
                return true unless perm_details[:with_models] && obj
                model_el = self.class.elements_array.select{ |el| 
                    el.attributes[:rbac] == [context, permission] && el.type == obj.class
                }.first
                return false unless model_el
                return true if self.get(model_el).include?(obj)
                return false
            end
            self.class.rbac_inherit_from.each do |element|
                val = self.get(element)
                val = [val] unless val.is_a?(Enumerable)
                val.each do |v|<commit_msg>Fixed error if RBAC :superuser element does not exist (e.g. in groups)<commit_after>module Spider; module Auth

    module RBACProvider
        
        def self.included(model)
            model.extend(ClassMethods)
        end
        
        # If the second argument is a symbol, it will be interpreted as the context
        def can?(permission, obj=nil, context=nil)
            if obj.is_a?(Symbol)
                context = obj
                obj = nil
            end
            context ||= self.class.rbac_contexts.first
            permission = permission.to_sym
            el = self.class.rbac_provider_elements[context]
            options = RBAC.options(context)
            if options[:superuser]
                val = nil
                val = self.get(options[:superuser]) if self.class.elements[options[:superuser]]
                return true if val
            end
            val = self.get(el)
            has_perm = false
            val.each do |v|
                if v.id.to_sym == permission
                    has_perm = true
                    break
                end
            end
            perm_details = RBAC.context(context)[permission]
            if has_perm
                return true unless perm_details[:with_models] && obj
                model_el = self.class.elements_array.select{ |el| 
                    el.attributes[:rbac] == [context, permission] && el.type == obj.class
                }.first
                return false unless model_el
                return true if self.get(model_el).include?(obj)
                return false
            end
            self.class.rbac_inherit_from.each do |element|
                val = self.get(element)
                val = [val] unless val.is_a?(Enumerable)
                val.each do |v|
{'fraction_non_alphanumeric': 0.07652324574068727, 'fraction_numerical': 0.0, 'mean_word_length': 1.351663272233537, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7382278', 'n_tokens_mistral': 901, 'n_tokens_neox': 852, 'n_words': 230}